Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
645514f8
Commit
645514f8
authored
Jun 17, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Honour base path from @WebAppConfiguration in @WebMvcTest"
See gh-16485
parent
7340d546
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
8 deletions
+14
-8
WebMvcTestContextBootstrapper.java
...oconfigure/web/servlet/WebMvcTestContextBootstrapper.java
+1
-2
WebMvcTestWithWebAppConfigurationTests.java
...rvlet/mockmvc/WebMvcTestWithWebAppConfigurationTests.java
+3
-3
SpringBootTestContextBootstrapper.java
.../boot/test/context/SpringBootTestContextBootstrapper.java
+10
-3
No files found.
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java
View file @
645514f8
...
@@ -34,8 +34,7 @@ class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
...
@@ -34,8 +34,7 @@ class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
@Override
@Override
protected
MergedContextConfiguration
processMergedContextConfiguration
(
MergedContextConfiguration
mergedConfig
)
{
protected
MergedContextConfiguration
processMergedContextConfiguration
(
MergedContextConfiguration
mergedConfig
)
{
MergedContextConfiguration
processedMergedConfiguration
=
super
.
processMergedContextConfiguration
(
mergedConfig
);
MergedContextConfiguration
processedMergedConfiguration
=
super
.
processMergedContextConfiguration
(
mergedConfig
);
return
new
WebMergedContextConfiguration
(
processedMergedConfiguration
,
return
new
WebMergedContextConfiguration
(
processedMergedConfiguration
,
determineResourceBasePath
(
mergedConfig
));
getServletResourceBasePath
(
mergedConfig
));
}
}
@Override
@Override
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/WebMvcTestWithWebAppConfigurationTests.java
View file @
645514f8
...
@@ -32,8 +32,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
...
@@ -32,8 +32,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
/**
* Tests for {@link WebMvcTest
} when loading resources via {@link ServletContext} with
* Tests for {@link WebMvcTest
@WebMvcTest} when loading resources via the
* {@link WebAppConfiguration}.
* {@link
ServletContext} with {@link WebAppConfiguration @
WebAppConfiguration}.
*
*
* @author Lorenzo Dee
* @author Lorenzo Dee
*/
*/
...
@@ -46,7 +46,7 @@ public class WebMvcTestWithWebAppConfigurationTests {
...
@@ -46,7 +46,7 @@ public class WebMvcTestWithWebAppConfigurationTests {
private
ServletContext
servletContext
;
private
ServletContext
servletContext
;
@Test
@Test
public
void
getResource
Location
()
throws
Exception
{
public
void
whenBasePathIsCustomizedResourcesCanBeLoadedFromThat
Location
()
throws
Exception
{
testResource
(
"/inwebapp"
,
"src/test/webapp"
);
testResource
(
"/inwebapp"
,
"src/test/webapp"
);
testResource
(
"/inmetainfresources"
,
"/META-INF/resources"
);
testResource
(
"/inmetainfresources"
,
"/META-INF/resources"
);
testResource
(
"/inresources"
,
"/resources"
);
testResource
(
"/inresources"
,
"/resources"
);
...
...
spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java
View file @
645514f8
...
@@ -154,8 +154,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
...
@@ -154,8 +154,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
WebApplicationType
webApplicationType
=
getWebApplicationType
(
mergedConfig
);
WebApplicationType
webApplicationType
=
getWebApplicationType
(
mergedConfig
);
if
(
webApplicationType
==
WebApplicationType
.
SERVLET
if
(
webApplicationType
==
WebApplicationType
.
SERVLET
&&
(
webEnvironment
.
isEmbedded
()
||
webEnvironment
==
WebEnvironment
.
MOCK
))
{
&&
(
webEnvironment
.
isEmbedded
()
||
webEnvironment
==
WebEnvironment
.
MOCK
))
{
mergedConfig
=
new
WebMergedContextConfiguration
(
mergedConfig
,
mergedConfig
=
new
WebMergedContextConfiguration
(
mergedConfig
,
determineResourceBasePath
(
mergedConfig
));
getServletResourceBasePath
(
mergedConfig
));
}
}
else
if
(
webApplicationType
==
WebApplicationType
.
REACTIVE
else
if
(
webApplicationType
==
WebApplicationType
.
REACTIVE
&&
(
webEnvironment
.
isEmbedded
()
||
webEnvironment
==
WebEnvironment
.
MOCK
))
{
&&
(
webEnvironment
.
isEmbedded
()
||
webEnvironment
==
WebEnvironment
.
MOCK
))
{
...
@@ -187,7 +186,15 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
...
@@ -187,7 +186,15 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
return
WebApplicationType
.
SERVLET
;
return
WebApplicationType
.
SERVLET
;
}
}
protected
String
getServletResourceBasePath
(
MergedContextConfiguration
configuration
)
{
/**
* Determines the resource base path for web applications using the value of
* {@link WebAppConfiguration @WebAppConfiguration}, if any, on the test class of the
* given {@code configuration}. Defaults to {@code src/main/webapp} in its absence.
* @param configuration the configure to examine
* @return the resource base path
* @since 2.1.6
*/
protected
String
determineResourceBasePath
(
MergedContextConfiguration
configuration
)
{
WebAppConfiguration
webAppConfiguration
=
AnnotatedElementUtils
WebAppConfiguration
webAppConfiguration
=
AnnotatedElementUtils
.
findMergedAnnotation
(
configuration
.
getTestClass
(),
WebAppConfiguration
.
class
);
.
findMergedAnnotation
(
configuration
.
getTestClass
(),
WebAppConfiguration
.
class
);
return
(
webAppConfiguration
!=
null
)
?
webAppConfiguration
.
value
()
:
"src/main/webapp"
;
return
(
webAppConfiguration
!=
null
)
?
webAppConfiguration
.
value
()
:
"src/main/webapp"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment