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
8c3f80eb
Commit
8c3f80eb
authored
Jul 01, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use mock servlet container for welcome page tests
Fixes gh-3371
parent
b5c435f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
11 deletions
+16
-11
WelcomePageMockMvcTests.java
...ework/boot/autoconfigure/web/WelcomePageMockMvcTests.java
+16
-11
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WelcomePageMockMvcTests.java
View file @
8c3f80eb
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
...
@@ -27,6 +30,8 @@ import org.junit.Test;
...
@@ -27,6 +30,8 @@ import org.junit.Test;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
...
@@ -34,9 +39,6 @@ import org.springframework.test.web.servlet.MockMvc;
...
@@ -34,9 +39,6 @@ import org.springframework.test.web.servlet.MockMvc;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.ConfigurableWebApplicationContext
;
import
org.springframework.web.context.ConfigurableWebApplicationContext
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
/**
/**
* Tests for welcome page using {@link MockMvc} and {@link SpringJUnit4ClassRunner}.
* Tests for welcome page using {@link MockMvc} and {@link SpringJUnit4ClassRunner}.
*
*
...
@@ -67,7 +69,7 @@ public class WelcomePageMockMvcTests {
...
@@ -67,7 +69,7 @@ public class WelcomePageMockMvcTests {
public
void
homePageCustomLocation
()
throws
Exception
{
public
void
homePageCustomLocation
()
throws
Exception
{
this
.
wac
=
(
ConfigurableWebApplicationContext
)
new
SpringApplicationBuilder
(
this
.
wac
=
(
ConfigurableWebApplicationContext
)
new
SpringApplicationBuilder
(
TestConfiguration
.
class
).
properties
(
TestConfiguration
.
class
).
properties
(
"spring.resources.staticLocations:classpath:/custom/"
).
run
();
"spring.resources.staticLocations:classpath:/custom/"
).
run
();
this
.
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
wac
).
build
();
this
.
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
wac
).
build
();
this
.
mockMvc
.
perform
(
get
(
"/"
)).
andExpect
(
status
().
isOk
()).
andReturn
();
this
.
mockMvc
.
perform
(
get
(
"/"
)).
andExpect
(
status
().
isOk
()).
andReturn
();
}
}
...
@@ -76,7 +78,7 @@ public class WelcomePageMockMvcTests {
...
@@ -76,7 +78,7 @@ public class WelcomePageMockMvcTests {
public
void
homePageCustomLocationNoTrailingSlash
()
throws
Exception
{
public
void
homePageCustomLocationNoTrailingSlash
()
throws
Exception
{
this
.
wac
=
(
ConfigurableWebApplicationContext
)
new
SpringApplicationBuilder
(
this
.
wac
=
(
ConfigurableWebApplicationContext
)
new
SpringApplicationBuilder
(
TestConfiguration
.
class
).
properties
(
TestConfiguration
.
class
).
properties
(
"spring.resources.staticLocations:classpath:/custom"
).
run
();
"spring.resources.staticLocations:classpath:/custom"
).
run
();
this
.
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
wac
).
build
();
this
.
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
wac
).
build
();
this
.
mockMvc
.
perform
(
get
(
"/"
)).
andExpect
(
status
().
isOk
()).
andReturn
();
this
.
mockMvc
.
perform
(
get
(
"/"
)).
andExpect
(
status
().
isOk
()).
andReturn
();
}
}
...
@@ -84,12 +86,10 @@ public class WelcomePageMockMvcTests {
...
@@ -84,12 +86,10 @@ public class WelcomePageMockMvcTests {
@Target
(
ElementType
.
TYPE
)
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Documented
@Import
({
EmbeddedServletContainerAutoConfiguration
.
EmbeddedTomcat
.
class
,
@Import
({
ServerPropertiesAutoConfiguration
.
class
,
EmbeddedServletContainerAutoConfiguration
.
class
,
DispatcherServletAutoConfiguration
.
class
,
WebMvcAutoConfiguration
.
class
,
ServerPropertiesAutoConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
DispatcherServletAutoConfiguration
.
class
,
WebMvcAutoConfiguration
.
class
,
ErrorMvcAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
})
HttpMessageConvertersAutoConfiguration
.
class
,
ErrorMvcAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
})
protected
static
@interface
MinimalWebConfiguration
{
protected
static
@interface
MinimalWebConfiguration
{
}
}
...
@@ -97,6 +97,11 @@ public class WelcomePageMockMvcTests {
...
@@ -97,6 +97,11 @@ public class WelcomePageMockMvcTests {
@MinimalWebConfiguration
@MinimalWebConfiguration
public
static
class
TestConfiguration
{
public
static
class
TestConfiguration
{
@Bean
public
MockEmbeddedServletContainerFactory
embeddedServletContainerFactory
()
{
return
new
MockEmbeddedServletContainerFactory
();
}
// For manual testing
// For manual testing
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
TestConfiguration
.
class
,
args
);
SpringApplication
.
run
(
TestConfiguration
.
class
,
args
);
...
...
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