From 33f0ea348065b86dbc51bedd5be599374de62cf9 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 31 Mar 2016 16:55:28 +0100 Subject: [PATCH] Rework SpringApplicationTest to support web modes Rework the new testing support so that @SpringApplicationTest can be used for standard integration tests, web integration tests with a mock Servlet environment and web integration tests with an embedded servlet container. This means that it a replacement for 1.3's @IntegrationTest and @WebIntegrationTest and allows all SpringApplication testing to be configured using a common annotation. The old @IntegrationTest and @WebIntegrationTest along with their supporting classes have been reinstated to their previous form (while remaining deprecated). This should ensure that they continue to work in 1.4 exactly as they did in 1.3 giving users a smooth path to @SpringApplicationTest. See gh-5477 --- .../EndpointMvcIntegrationTests.java | 7 +- ...ointServerContextPathIntegrationTests.java | 8 +- ...MvcEndpointServerPortIntegrationTests.java | 8 +- .../SpringIntegrationMetricReaderTests.java | 4 +- ...urceAutoConfigurationIntegrationTests.java | 4 +- ...igurationCustomFilterContextPathTests.java | 11 +- ...utoConfigurationCustomFilterPathTests.java | 9 +- ...ConfigurationCustomLoadOnStartupTests.java | 14 +- ...rationCustomObjectMapperProviderTests.java | 9 +- ...gurationCustomServletContextPathTests.java | 10 +- ...toConfigurationCustomServletPathTests.java | 10 +- ...toConfigurationDefaultFilterPathTests.java | 9 +- ...oConfigurationDefaultServletPathTests.java | 10 +- ...onfigurationObjectMapperProviderTests.java | 9 +- ...utoConfigurationServletContainerTests.java | 5 +- ...figurationWithoutApplicationPathTests.java | 9 +- ...acheAutoConfigurationIntegrationTests.java | 7 +- .../MustacheStandaloneIntegrationTests.java | 6 +- .../web/MustacheWebIntegrationTests.java | 7 +- ...serInfoTokenServicesRefreshTokenTests.java | 5 +- .../BasicErrorControllerIntegrationTests.java | 7 +- .../RemappedErrorViewIntegrationTests.java | 7 +- .../HttpTunnelIntegrationTests.java | 5 +- .../HelloWebSecurityApplicationTests.java | 5 +- .../src/checkstyle/checkstyle.xml | 2 +- .../SampleActuatorLog4J2ApplicationTests.java | 5 +- .../SampleActuatorUiApplicationPortTests.java | 6 +- .../ui/SampleActuatorUiApplicationTests.java | 5 +- ...pertiesSampleActuatorApplicationTests.java | 5 +- ...AndPathSampleActuatorApplicationTests.java | 8 +- ...agementSampleActuatorApplicationTests.java | 6 +- ...nsecureSampleActuatorApplicationTests.java | 6 +- ...gementAddressActuatorApplicationTests.java | 8 +- ...entPathSampleActuatorApplicationTests.java | 6 +- ...AndPathSampleActuatorApplicationTests.java | 7 +- ...entPortSampleActuatorApplicationTests.java | 6 +- ...agementSampleActuatorApplicationTests.java | 6 +- .../actuator/NonSensitiveHealthTests.java | 6 +- .../SampleActuatorApplicationTests.java | 5 +- ...nsecureSampleActuatorApplicationTests.java | 7 +- ...letPathSampleActuatorApplicationTests.java | 6 +- ...hutdownSampleActuatorApplicationTests.java | 5 +- .../SampleAtmosphereApplicationTests.java | 5 +- .../SampleCassandraApplicationTests.java | 4 +- .../mongo/SampleMongoApplicationTests.java | 4 +- .../SampleHateoasApplicationTests.java | 5 +- .../SampleHypermediaUiApplicationTests.java | 6 +- ...pleHypermediaApplicationHomePageTests.java | 5 +- .../jersey/SampleJerseyApplicationTests.java | 5 +- .../SampleJersey1ApplicationTests.java | 5 +- .../ssl/SampleJettySslApplicationTests.java | 5 +- .../jetty/SampleJettyApplicationTests.java | 5 +- .../ssl/SampleJetty8SslApplicationTests.java | 5 +- .../jetty8/SampleJetty8ApplicationTests.java | 5 +- .../SampleJetty93ApplicationTests.java | 5 +- ...mpleDropwizardMetricsApplicationTests.java | 5 +- .../SampleOpenTsdbExportApplicationTests.java | 5 +- .../SampleRedisExportApplicationTests.java | 5 +- ...eSecureOAuth2ResourceApplicationTests.java | 5 +- .../SampleSecureOAuth2ApplicationTests.java | 5 +- .../SampleServletApplicationTests.java | 5 +- ...pringTestSampleSimpleApplicationTests.java | 4 +- ...pleTestApplicationWebIntegrationTests.java | 5 +- .../testng/SampleTestNGApplicationTests.java | 5 +- .../jsp/SampleWebJspApplicationTests.java | 5 +- ...leTomcatTwoConnectorsApplicationTests.java | 5 +- .../ssl/SampleTomcatSslApplicationTests.java | 5 +- ...igurationSampleTomcatApplicationTests.java | 5 +- .../tomcat/SampleTomcatApplicationTests.java | 5 +- .../jsp/SampleWebJspApplicationTests.java | 5 +- .../SampleTraditionalApplicationTests.java | 5 +- .../SampleUndertowSslApplicationTests.java | 5 +- .../SampleUndertowApplicationTests.java | 5 +- .../SampleWebFreeMarkerApplicationTests.java | 5 +- .../SampleGroovyTemplateApplicationTests.java | 5 +- .../jsp/SampleWebJspApplicationTests.java | 5 +- .../SampleMethodSecurityApplicationTests.java | 5 +- .../SampleWebMustacheApplicationTests.java | 5 +- ...SampleWebSecureCustomApplicationTests.java | 5 +- .../github/SampleGithubApplicationTests.java | 5 +- ...SampleWebSecureCustomApplicationTests.java | 5 +- .../secure/SampleSecureApplicationTests.java | 5 +- .../SampleWebStaticApplicationTests.java | 5 +- .../web/ui/SampleWebUiApplicationTests.java | 5 +- .../SampleWebVelocityApplicationTests.java | 5 +- .../SampleWebSocketsApplicationTests.java | 5 +- ...omContainerWebSocketsApplicationTests.java | 5 +- .../SampleWebSocketsApplicationTests.java | 5 +- ...omContainerWebSocketsApplicationTests.java | 5 +- .../SampleWebSocketsApplicationTests.java | 5 +- ...omContainerWebSocketsApplicationTests.java | 5 +- .../sample/ws/SampleWsApplicationTests.java | 5 +- .../boot/test/IntegrationTest.java | 18 +- .../IntegrationTestPropertiesListener.java | 1 - .../MergedContextConfigurationProperties.java | 1 - .../test/SpringApplicationConfiguration.java | 16 +- .../test/SpringApplicationContextLoader.java | 256 +++++++++++++++++- ...AppIntegrationTestContextBootstrapper.java | 65 +++++ .../boot/test/WebIntegrationTest.java | 9 +- .../boot/test/context/IntegrationTest.java | 71 ----- .../IntegrationTestContextBootstrapper.java | 73 ----- .../SpringApplicationConfiguration.java | 7 +- .../SpringApplicationContextLoader.java | 59 ++-- .../test/context/SpringApplicationTest.java | 87 +++++- ...ingApplicationTestContextBootstrapper.java | 29 +- ...ringApplicationTestContextCustomizer.java} | 37 ++- ...licationTestContextCustomizerFactory.java} | 14 +- .../test/context/web/WebIntegrationTest.java | 88 ------ ...WebIntegrationTestContextBootstrapper.java | 66 ----- .../boot/test/context/web/package-info.java | 21 -- .../main/resources/META-INF/spring.factories | 2 +- ...ingApplicationWebIntegrationTestTests.java | 3 +- ...ationTestWebEnvironmentEmbeddedTests.java} | 26 +- ...cationConfigurationActiveProfileTests.java | 2 +- ...pringApplicationConfigurationJmxTests.java | 2 +- ...ApplicationConfigurationMockMvcTests.java} | 7 +- .../SpringApplicationContextLoaderTests.java | 25 +- ...SpringApplicationIntegrationTestTests.java | 120 -------- ...ApplicationTestPropertyLocationTests.java} | 23 +- ...ionTestWebEnvironmentDefinedPortTests.java | 49 ++++ ...plicationTestWebEnvironmentMockTests.java} | 6 +- ...tionTestWebEnvironmentRandomPortTests.java | 49 ++++ 122 files changed, 947 insertions(+), 823 deletions(-) create mode 100644 spring-boot-test/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java delete mode 100644 spring-boot-test/src/main/java/org/springframework/boot/test/context/IntegrationTest.java delete mode 100644 spring-boot-test/src/main/java/org/springframework/boot/test/context/IntegrationTestContextBootstrapper.java rename spring-boot-test/src/main/java/org/springframework/boot/test/context/{web/WebIntegrationTestContextCustomizer.java => SpringApplicationTestContextCustomizer.java} (56%) rename spring-boot-test/src/main/java/org/springframework/boot/test/context/{web/WebIntegrationTestContextCustomizerFactory.java => SpringApplicationTestContextCustomizerFactory.java} (75%) delete mode 100644 spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTest.java delete mode 100644 spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextBootstrapper.java delete mode 100644 spring-boot-test/src/main/java/org/springframework/boot/test/context/web/package-info.java rename spring-boot-test/src/test/java/org/springframework/boot/test/context/{web/SpringApplicationWebIntegrationTestTests.java => AbstractSpringApplicationTestWebEnvironmentEmbeddedTests.java} (77%) rename spring-boot-test/src/test/java/org/springframework/boot/test/context/{web/SpringApplicationMockMvcTests.java => SpringApplicationConfigurationMockMvcTests.java} (93%) delete mode 100644 spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationIntegrationTestTests.java rename spring-boot-test/src/test/java/org/springframework/boot/test/context/{SpringApplicationIntegrationTestPropertyLocationTests.java => SpringApplicationTestPropertyLocationTests.java} (74%) create mode 100644 spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentDefinedPortTests.java rename spring-boot-test/src/test/java/org/springframework/boot/test/context/{SpringApplicationTestTests.java => SpringApplicationTestWebEnvironmentMockTests.java} (91%) create mode 100644 spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentRandomPortTests.java diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java index 63af038b246..22d0914530f 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java @@ -49,8 +49,9 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConverters; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -58,7 +59,6 @@ import org.springframework.context.annotation.Import; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -74,8 +74,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringApplicationConfiguration(Application.class) -@IntegrationTest("server.port=0") -@WebAppConfiguration +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class EndpointMvcIntegrationTests { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java index eb85c76f330..84f258ec2c1 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java @@ -24,8 +24,9 @@ import org.junit.runner.RunWith; import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication; import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpointServerContextPathIntegrationTests.SpringBootHypermediaApplication; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.hateoas.ResourceSupport; import org.springframework.http.HttpEntity; @@ -36,7 +37,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -52,8 +52,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; */ @RunWith(SpringRunner.class) @SpringApplicationConfiguration(SpringBootHypermediaApplication.class) -@WebAppConfiguration -@IntegrationTest({ "server.port=0", "server.contextPath=/spring" }) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "server.contextPath=/spring" }) @DirtiesContext public class HalBrowserMvcEndpointServerContextPathIntegrationTests { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java index bd8b70d867d..d9a4090dee4 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerPortIntegrationTests.java @@ -24,8 +24,9 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication; import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpointServerPortIntegrationTests.SpringBootHypermediaApplication; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.hateoas.ResourceSupport; import org.springframework.http.HttpEntity; @@ -36,7 +37,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -52,8 +52,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; */ @RunWith(SpringRunner.class) @SpringApplicationConfiguration(SpringBootHypermediaApplication.class) -@WebAppConfiguration -@IntegrationTest({ "server.port=0", "management.port=0" }) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.port=0" }) @DirtiesContext public class HalBrowserMvcEndpointServerPortIntegrationTests { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java index 71191196739..ebdc6a435ea 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/integration/SpringIntegrationMetricReaderTests.java @@ -23,8 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.metrics.integration.SpringIntegrationMetricReaderTests.TestConfiguration; import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringApplicationConfiguration(TestConfiguration.class) -@IntegrationTest("spring.jmx.enabled=true") +@SpringApplicationTest("spring.jmx.enabled=true") @DirtiesContext public class SpringIntegrationMetricReaderTests { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationIntegrationTests.java index f38d0f70801..1198a9b609b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationIntegrationTests.java @@ -23,8 +23,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.MessageSourceAutoConfigurationIntegrationTests.Config; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; @@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; PropertyPlaceholderAutoConfiguration.class }) @RunWith(SpringRunner.class) @DirtiesContext -@IntegrationTest("spring.messages.basename:test/messages") +@SpringApplicationTest("spring.messages.basename:test/messages") public class MessageSourceAutoConfigurationIntegrationTests { @Autowired diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java index 7d2d395b5d4..95c8b8805ef 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java @@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -56,8 +57,8 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true, value = {"spring.jersey.type=filter", - "server.contextPath=/app" }) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "spring.jersey.type=filter", "server.contextPath=/app" }) public class JerseyAutoConfigurationCustomFilterContextPathTests { @Autowired @@ -65,8 +66,8 @@ public class JerseyAutoConfigurationCustomFilterContextPathTests { @Test public void contextLoads() { - ResponseEntity entity = this.restTemplate.getForEntity( - "/app/rest/hello", String.class); + ResponseEntity entity = this.restTemplate.getForEntity("/app/rest/hello", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java index 75b2b874aa8..0f308bd3a1c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java @@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -56,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true, value = "spring.jersey.type=filter") +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jersey.type=filter") public class JerseyAutoConfigurationCustomFilterPathTests { @Autowired @@ -64,8 +65,8 @@ public class JerseyAutoConfigurationCustomFilterPathTests { @Test public void contextLoads() { - ResponseEntity entity = this.restTemplate.getForEntity( - "/rest/hello", String.class); + ResponseEntity entity = this.restTemplate.getForEntity("/rest/hello", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java index 85576b5a212..c5817649b51 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java @@ -33,7 +33,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; @@ -48,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true, value = "spring.jersey.servlet.load-on-startup=5") +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jersey.servlet.load-on-startup=5") public class JerseyAutoConfigurationCustomLoadOnStartupTests { @Autowired @@ -56,8 +57,9 @@ public class JerseyAutoConfigurationCustomLoadOnStartupTests { @Test public void contextLoads() { - assertThat(new DirectFieldAccessor(this.context.getBean("jerseyServletRegistration")) - .getPropertyValue("loadOnStartup")).isEqualTo(5); + assertThat( + new DirectFieldAccessor(this.context.getBean("jerseyServletRegistration")) + .getPropertyValue("loadOnStartup")).isEqualTo(5); } @MinimalWebConfiguration @@ -72,9 +74,9 @@ public class JerseyAutoConfigurationCustomLoadOnStartupTests { @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented - @Import({EmbeddedServletContainerAutoConfiguration.class, + @Import({ EmbeddedServletContainerAutoConfiguration.class, ServerPropertiesAutoConfiguration.class, JerseyAutoConfiguration.class, - PropertyPlaceholderAutoConfiguration.class}) + PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java index 385a375cca5..e57fc2c48e0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java @@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObje import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -56,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true, value = "spring.jackson.serialization-inclusion=non_null") +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jackson.serialization-inclusion=non_null") public class JerseyAutoConfigurationCustomObjectMapperProviderTests { @Autowired @@ -64,8 +65,8 @@ public class JerseyAutoConfigurationCustomObjectMapperProviderTests { @Test public void contextLoads() { - ResponseEntity response = this.restTemplate.getForEntity( - "/rest/message", String.class); + ResponseEntity response = this.restTemplate.getForEntity("/rest/message", + String.class); assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode()); assertThat("{\"subject\":\"Jersey\"}").isEqualTo(response.getBody()); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java index 6d996c91217..5a16438a64f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java @@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -53,10 +54,11 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Dave Syer */ + @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true, value = "server.contextPath=/app") +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "server.contextPath=/app") public class JerseyAutoConfigurationCustomServletContextPathTests { @Autowired @@ -64,8 +66,8 @@ public class JerseyAutoConfigurationCustomServletContextPathTests { @Test public void contextLoads() { - ResponseEntity entity = this.restTemplate.getForEntity( - "/app/rest/hello", String.class); + ResponseEntity entity = this.restTemplate.getForEntity("/app/rest/hello", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java index 6ecb35fca71..41f47d580f9 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java @@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -53,10 +54,11 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Dave Syer */ + @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class JerseyAutoConfigurationCustomServletPathTests { @Autowired @@ -64,8 +66,8 @@ public class JerseyAutoConfigurationCustomServletPathTests { @Test public void contextLoads() { - ResponseEntity entity = this.restTemplate.getForEntity( - "/rest/hello", String.class); + ResponseEntity entity = this.restTemplate.getForEntity("/rest/hello", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java index c576b1ecc67..f55e8ec98dd 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java @@ -37,7 +37,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefa import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -55,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true, value = "spring.jersey.type=filter") +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jersey.type=filter") public class JerseyAutoConfigurationDefaultFilterPathTests { @Autowired @@ -63,8 +64,8 @@ public class JerseyAutoConfigurationDefaultFilterPathTests { @Test public void contextLoads() { - ResponseEntity entity = this.restTemplate - .getForEntity("/hello", String.class); + ResponseEntity entity = this.restTemplate.getForEntity("/hello", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java index 2d99e6c8dc3..f349d4247d6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java @@ -37,7 +37,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefa import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -52,10 +53,11 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Dave Syer */ + @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class JerseyAutoConfigurationDefaultServletPathTests { @Autowired @@ -63,8 +65,8 @@ public class JerseyAutoConfigurationDefaultServletPathTests { @Test public void contextLoads() { - ResponseEntity entity = this.restTemplate - .getForEntity("/hello", String.class); + ResponseEntity entity = this.restTemplate.getForEntity("/hello", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java index 597cf17694f..5a9d770f56c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java @@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObje import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -56,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class JerseyAutoConfigurationObjectMapperProviderTests { @Autowired @@ -64,8 +65,8 @@ public class JerseyAutoConfigurationObjectMapperProviderTests { @Test public void contextLoads() { - ResponseEntity response = this.restTemplate.getForEntity( - "/rest/message", String.class); + ResponseEntity response = this.restTemplate.getForEntity("/rest/message", + String.class); assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode()); assertThat("{\"subject\":\"Jersey\",\"body\":null}") .isEqualTo(response.getBody()); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java index 852efe8d279..5d7a83d38be 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java @@ -35,7 +35,8 @@ import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoCo import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -54,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class JerseyAutoConfigurationServletContainerTests { @ClassRule diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java index d173d2dd878..8f89cfa6ced 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java @@ -37,7 +37,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -55,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@WebIntegrationTest(randomPort = true, value = "spring.jersey.application-path=/api") +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jersey.application-path=/api") public class JerseyAutoConfigurationWithoutApplicationPathTests { @Autowired @@ -63,8 +64,8 @@ public class JerseyAutoConfigurationWithoutApplicationPathTests { @Test public void contextLoads() { - ResponseEntity entity = this.restTemplate.getForEntity( - "/api/hello", String.class); + ResponseEntity entity = this.restTemplate.getForEntity("/api/hello", + String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java index 07003671317..276816fd6d5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java @@ -36,15 +36,15 @@ import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfigura import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.stereotype.Controller; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import static org.assertj.core.api.Assertions.assertThat; @@ -57,9 +57,8 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest({ "server.port:0", +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.mustache.prefix:classpath:/mustache-templates/" }) -@WebAppConfiguration public class MustacheAutoConfigurationIntegrationTests { @Autowired diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java index 0abac11d893..a51a673b38b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java @@ -25,8 +25,9 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.mustache.MustacheStandaloneIntegrationTests.Application; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; @@ -42,7 +43,8 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest({ "spring.main.web_environment=false", "env.foo=There", "foo=World" }) +@SpringApplicationTest(webEnvironment = WebEnvironment.NONE, properties = { + "env.foo=There", "foo=World" }) public class MustacheStandaloneIntegrationTests { @Autowired diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java index 8116909558f..c05aa2bc6f7 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java @@ -41,8 +41,9 @@ import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfigura import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -50,7 +51,6 @@ import org.springframework.context.annotation.Import; import org.springframework.stereotype.Controller; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import static org.assertj.core.api.Assertions.assertThat; @@ -64,8 +64,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest("server.port:0") -@WebAppConfiguration +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class MustacheWebIntegrationTests { @Autowired diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java index 91efeda25b1..49f711dfdf8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java @@ -31,7 +31,8 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfi import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; @@ -59,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest({ "server.port=0", +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "security.oauth2.resource.userInfoUri:http://example.com", "security.oauth2.client.clientId=foo" }) @DirtiesContext diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java index fce906ec321..1bdff3d1ed1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java @@ -34,8 +34,9 @@ import org.junit.runner.RunWith; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.web.BasicErrorControllerIntegrationTests.TestConfiguration; import org.springframework.boot.autoconfigure.web.BasicErrorControllerMockMvcTests.MinimalWebConfiguration; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; @@ -46,7 +47,6 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.validation.BindException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.RequestBody; @@ -68,9 +68,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringApplicationConfiguration(TestConfiguration.class) -@WebAppConfiguration @DirtiesContext -@IntegrationTest("server.port=0") +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class BasicErrorControllerIntegrationTests { private ConfigurableApplicationContext context; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java index 5799c0ee808..524a9a0ae8e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java @@ -26,15 +26,15 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.ErrorPage; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.stereotype.Controller; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.client.RestTemplate; @@ -45,8 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @SpringApplicationConfiguration(TestConfiguration.class) @RunWith(SpringRunner.class) -@WebAppConfiguration -@IntegrationTest({ "server.servletPath:/spring/*", "server.port:0" }) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "server.servletPath:/spring/*") @DirtiesContext public class RemappedErrorViewIntegrationTests { diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java index bc07eff5737..06313ee3448 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java @@ -39,7 +39,8 @@ import org.springframework.boot.devtools.tunnel.server.PortProvider; import org.springframework.boot.devtools.tunnel.server.SocketTargetServerConnection; import org.springframework.boot.devtools.tunnel.server.StaticPortProvider; import org.springframework.boot.devtools.tunnel.server.TargetServerConnection; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Phillip Webb */ @RunWith(SpringRunner.class) -@WebIntegrationTest +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class HttpTunnelIntegrationTests { @Autowired diff --git a/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java b/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java index 14c38e3f295..394d2baf635 100644 --- a/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java +++ b/spring-boot-integration-tests/spring-boot-security-tests/spring-boot-security-test-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java @@ -23,7 +23,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; @@ -34,7 +35,7 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class HelloWebSecurityApplicationTests { @Autowired diff --git a/spring-boot-parent/src/checkstyle/checkstyle.xml b/spring-boot-parent/src/checkstyle/checkstyle.xml index 9e19149b301..61889c05365 100644 --- a/spring-boot-parent/src/checkstyle/checkstyle.xml +++ b/spring-boot-parent/src/checkstyle/checkstyle.xml @@ -71,7 +71,7 @@ + value="org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo, org.springframework.boot.test.context.SpringApplicationTest.Mode.*" /> diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java index 9c630bca54b..81399e83421 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -37,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleActuatorLog4J2ApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java index f69abc87115..44b488e2ba3 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java @@ -23,7 +23,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -38,7 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.port:0" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.port:0" }) @DirtiesContext public class SampleActuatorUiApplicationPortTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java index f9542200b72..a9562b347e6 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java @@ -23,7 +23,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleActuatorUiApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index c2b59ac18c0..453166f0c56 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -40,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext @ActiveProfiles("endpoints") public class EndpointsPropertiesSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java index 944f2feff3b..eeec119dec6 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java @@ -25,7 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -40,8 +41,9 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.port=0", "management.context-path=/admin", - "management.security.enabled=false" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.port=0", "management.context-path=/admin", + "management.security.enabled=false" }) @DirtiesContext public class InsecureManagementPortAndPathSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java index 6e9fc7dedde..19d40c6350f 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -39,7 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.security.enabled:false" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.security.enabled:false" }) @DirtiesContext @ActiveProfiles("unsecure-management") public class InsecureManagementSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java index 65f78ec4039..5df3e819fe7 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -38,7 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "security.basic.enabled:false" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "security.basic.enabled:false" }) @DirtiesContext public class InsecureSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java index ec4b2679d3e..7f494ae0666 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java @@ -23,7 +23,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -38,8 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.port=0", "management.address=127.0.0.1", - "management.context-path:/admin" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.port=0", "management.address=127.0.0.1", + "management.context-path:/admin" }) @DirtiesContext public class ManagementAddressActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java index 9936ebe073b..6f8065bb19f 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -37,7 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.context_path=/admin" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.context_path=/admin" }) @DirtiesContext public class ManagementPathSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java index 29598c4fe06..2dd7a908c6e 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -25,7 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -40,8 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.port=0", - "management.context-path=/admin" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.port=0", "management.context-path=/admin" }) @DirtiesContext public class ManagementPortAndPathSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java index 540fff5dae2..c4169ecc0ba 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -25,7 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -40,7 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.port=0" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.port=0" }) @DirtiesContext public class ManagementPortSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java index 21b6e1b6d21..1aada073742 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -39,7 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.port=-1" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.port=-1" }) @DirtiesContext public class NoManagementSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java index 46cd2d4bcbc..b361b53aac6 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java @@ -20,7 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -35,7 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Phillip Webb */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "endpoints.health.sensitive=false" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "endpoints.health.sensitive=false" }) @DirtiesContext public class NonSensitiveHealthTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java index d2dacf2db6b..640da701e18 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java @@ -27,7 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Stephane Nicoll */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java index 12a39ef8476..f97e42f1cfb 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -38,8 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "security.basic.enabled:false", - "server.servletPath:/spring" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "security.basic.enabled:false", "server.servletPath:/spring" }) @DirtiesContext public class ServletPathInsecureSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java index 19bde50b469..0b905b625f6 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -37,7 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "server.servletPath=/spring" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "server.servletPath=/spring" }) @DirtiesContext public class ServletPathSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java index f11647e88d6..4514010467b 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class ShutdownSampleActuatorApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java index 7c506759165..70289e73d9c 100644 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java @@ -31,7 +31,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringApplicationConfiguration(SampleAtmosphereApplication.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleAtmosphereApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java index 8f48ab7ce6e..aea5bcf090d 100644 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java @@ -22,7 +22,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.context.IntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.TestExecutionListeners.MergeMode; @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS, listeners = { OrderedCassandraTestExecutionListener.class }) -@IntegrationTest("spring.data.cassandra.port=9142") +@SpringApplicationTest("spring.data.cassandra.port=9142") @CassandraDataSet(keyspace = "mykeyspace", value = "setup.cql") @EmbeddedCassandra(timeout = 60000) public class SampleCassandraApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java index e9aabfaabf3..8b79dfecf25 100644 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java @@ -20,7 +20,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.context.IntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.test.context.junit4.SpringRunner; @@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@IntegrationTest +@SpringApplicationTest public class SampleMongoApplicationTests { @ClassRule diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java index d9368e72b3e..f6e12149f25 100644 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -35,7 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleHateoasApplicationTests { @LocalServerPort diff --git a/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java index 8de7e331748..9f3e34ee221 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java @@ -23,7 +23,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -35,7 +36,8 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@WebIntegrationTest(value = { "management.context-path=" }, randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "management.context-path=" }) public class SampleHypermediaUiApplicationTests { @LocalServerPort diff --git a/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java b/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java index c3879d4d996..f7b8799a556 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java +++ b/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java @@ -23,7 +23,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -35,7 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleHypermediaApplicationHomePageTests { @LocalServerPort diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java index 5ce6b102cd6..e1a64351e7a 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java @@ -20,7 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -30,7 +31,7 @@ import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleJerseyApplicationTests { @LocalServerPort diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java index b61909d4e07..15d652d4184 100644 --- a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java @@ -20,14 +20,15 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleJersey1ApplicationTests { @LocalServerPort diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java index 61d465e3e56..9eacbf20c56 100644 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java @@ -25,7 +25,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -41,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleJettySslApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java index ba567f36d64..0eb311a5ebd 100644 --- a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleJettyApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java index 183f9569f29..90d30dcea1e 100644 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java @@ -25,7 +25,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -41,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleJetty8SslApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java index e03987dc1ad..3fe03f08c67 100644 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleJetty8ApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java index e6b8123e9ab..fdda6caff28 100644 --- a/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleJetty93ApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java index 567bef6b731..8c1700559cd 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.metrics.GaugeService; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleDropwizardMetricsApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/test/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplicationTests.java b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/test/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplicationTests.java index 7a6074965a1..c172e94546b 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/test/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/test/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplicationTests.java @@ -19,7 +19,8 @@ package sample.metrics.opentsdb; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @@ -29,7 +30,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleOpenTsdbExportApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-metrics-redis/src/test/java/sample/metrics/redis/SampleRedisExportApplicationTests.java b/spring-boot-samples/spring-boot-sample-metrics-redis/src/test/java/sample/metrics/redis/SampleRedisExportApplicationTests.java index 50216760bab..7052f4ac700 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-redis/src/test/java/sample/metrics/redis/SampleRedisExportApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-metrics-redis/src/test/java/sample/metrics/redis/SampleRedisExportApplicationTests.java @@ -19,7 +19,8 @@ package sample.metrics.redis; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @@ -29,7 +30,7 @@ import org.springframework.test.context.junit4.SpringRunner; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(value = "spring.jmx.enabled=true", randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jmx.enabled=true") @DirtiesContext public class SampleRedisExportApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-secure-oauth2-resource/src/test/java/sample/secure/oauth2/resource/SampleSecureOAuth2ResourceApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure-oauth2-resource/src/test/java/sample/secure/oauth2/resource/SampleSecureOAuth2ResourceApplicationTests.java index 55ba65c6b9c..bcc7ea62c01 100644 --- a/spring-boot-samples/spring-boot-sample-secure-oauth2-resource/src/test/java/sample/secure/oauth2/resource/SampleSecureOAuth2ResourceApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-secure-oauth2-resource/src/test/java/sample/secure/oauth2/resource/SampleSecureOAuth2ResourceApplicationTests.java @@ -21,7 +21,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.hateoas.MediaTypes; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.FilterChainProxy; @@ -41,7 +42,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC * @author Greg Turnquist */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleSecureOAuth2ResourceApplicationTests { @Autowired diff --git a/spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java index 78e0b83d489..1455a8b8d9b 100644 --- a/spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.hateoas.MediaTypes; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.codec.Base64; @@ -49,7 +50,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC * @author Greg Turnquist */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleSecureOAuth2ApplicationTests { @Autowired diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java index 87ef6bbc895..5db955175f4 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -37,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleServletApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java index 7e3a63ddf4a..1cbbd45292d 100644 --- a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java @@ -20,7 +20,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.IntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringRunner; @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@IntegrationTest +@SpringApplicationTest public class SpringTestSampleSimpleApplicationTests { @Autowired diff --git a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java index 94801f81c49..8f0d0ec2dcf 100644 --- a/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java @@ -25,7 +25,8 @@ import sample.test.service.VehicleDetailsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestDatabase; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.test.context.junit4.SpringRunner; @@ -38,7 +39,7 @@ import static org.mockito.BDDMockito.given; * @author Phillip Webb */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @AutoConfigureTestDatabase public class SampleTestApplicationWebIntegrationTests { diff --git a/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java b/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java index c6b05c97993..bdd81a6387d 100644 --- a/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java @@ -19,7 +19,8 @@ package sample.testng; import org.testng.annotations.Test; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -33,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Phillip Webb */ -@WebIntegrationTest("server.port:0") +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTests { diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java index 1d5ec027374..7451211c7b8 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java @@ -20,7 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Phillip Webb */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebJspApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java index 3c0cf3e72f9..6974cef02d0 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java @@ -32,7 +32,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -50,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleTomcatTwoConnectorsApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java index 579bd815f1d..f1b12910978 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/ssl/SampleTomcatSslApplicationTests.java @@ -25,7 +25,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -36,7 +37,7 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleTomcatSslApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java index ac474bb030d..6141942b6bf 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -29,7 +29,8 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfi import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class NonAutoConfigurationSampleTomcatApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java index fa540e36ef1..5cce794944c 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleTomcatApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java index a8cf3be0c91..60344a6d562 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java @@ -20,7 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Phillip Webb */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebJspApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java index cecf71666f3..3b4f889e6f1 100644 --- a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java @@ -20,7 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleTraditionalApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java index 6b460d0a537..2bb50e3fd56 100644 --- a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java @@ -25,7 +25,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -41,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Ivan Sopov */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleUndertowSslApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java index c7c243d69eb..a86c7dd3456 100644 --- a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleUndertowApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java index a3e7c413a49..dc8e961bae0 100644 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebFreeMarkerApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java index 64518cc6830..7b6d2725ea5 100644 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleGroovyTemplateApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java index 112a981d459..0cb9d6cbc8c 100644 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java @@ -20,7 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Phillip Webb */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebJspApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java index a2a9b328eba..1d1d928dc69 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleMethodSecurityApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java index af7d33fb18c..a9d10e94f68 100644 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebMustacheApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java index bd92672a6ec..16b57e03720 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebSecureCustomApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java index 10a281e463d..63c4f9c9256 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -38,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleGithubApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java index 731c42fed03..d41dc72ae1d 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebSecureCustomApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java index 9251df87b96..eb95dc032b8 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java @@ -24,7 +24,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleSecureApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java index b97ae871b60..f58ec114157 100644 --- a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/web/staticcontent/SampleWebStaticApplicationTests.java @@ -20,7 +20,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -36,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebStaticApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java index e15cc1a38bf..9df1383d046 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebUiApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java index 00c86478da1..0910f28f39f 100644 --- a/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java @@ -22,7 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Andy Wilkinson */ @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebVelocityApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java index 604c66d6e57..96cb9fb20c8 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java @@ -34,7 +34,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringApplicationConfiguration(SampleJettyWebSocketsApplication.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebSocketsApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java index 6b9d92b49f6..7b95fb8ae3f 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java @@ -37,7 +37,8 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringApplicationConfiguration({ SampleJettyWebSocketsApplication.class, CustomContainerConfiguration.class }) -@WebIntegrationTest +@SpringApplicationTest(webEnvironment = WebEnvironment.DEFINED_PORT) @DirtiesContext public class CustomContainerWebSocketsApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java index 6a3b8530167..a1b855c3969 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java @@ -34,7 +34,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringApplicationConfiguration(SampleTomcatWebSocketApplication.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebSocketsApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java index 4bff42ae559..142a80972d6 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java @@ -37,7 +37,8 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringApplicationConfiguration({ SampleTomcatWebSocketApplication.class, CustomContainerConfiguration.class }) -@WebIntegrationTest +@SpringApplicationTest(webEnvironment = WebEnvironment.DEFINED_PORT) @DirtiesContext public class CustomContainerWebSocketsApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java index e5c2c57cd1c..42ff1746961 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java @@ -34,7 +34,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringApplicationConfiguration(SampleUndertowWebSocketsApplication.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) @DirtiesContext public class SampleWebSocketsApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java index 5dc5686e1d3..724baf61601 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java @@ -37,7 +37,8 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringApplicationConfiguration({ SampleUndertowWebSocketsApplication.class, CustomContainerConfiguration.class }) -@WebIntegrationTest +@SpringApplicationTest(webEnvironment = WebEnvironment.DEFINED_PORT) @DirtiesContext public class CustomContainerWebSocketsApplicationTests { diff --git a/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java b/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java index 4dab7d00d51..807b172dc95 100644 --- a/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java @@ -27,7 +27,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.web.WebIntegrationTest; +import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.ws.client.core.WebServiceTemplate; @@ -35,7 +36,7 @@ import org.springframework.ws.client.core.WebServiceTemplate; import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) -@WebIntegrationTest(randomPort = true) +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleWsApplicationTests { @Rule diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTest.java index a3785967cfb..600c65dc270 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTest.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTest.java @@ -23,8 +23,13 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.springframework.core.annotation.AliasFor; +import org.springframework.boot.test.context.SpringApplicationTest; import org.springframework.core.env.Environment; +import org.springframework.test.context.TestExecutionListeners; +import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener; +import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; +import org.springframework.test.context.support.DirtiesContextTestExecutionListener; +import org.springframework.test.context.transaction.TransactionalTestExecutionListener; /** * Test class annotation signifying that the tests are "integration tests" and therefore @@ -36,14 +41,18 @@ import org.springframework.core.env.Environment; * * @author Dave Syer * @see WebIntegrationTest - * @deprecated since 1.4.0 in favor of - * {@link org.springframework.boot.test.context.IntegrationTest} + * @deprecated since 1.4.0 in favor of {@link SpringApplicationTest} */ @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -@org.springframework.boot.test.context.IntegrationTest +// Leave out the ServletTestExecutionListener because it only deals with Mock* servlet +// stuff. A real embedded application will not need the mocks. +@TestExecutionListeners(listeners = { IntegrationTestPropertiesListener.class, + DependencyInjectionTestExecutionListener.class, + DirtiesContextTestExecutionListener.class, + TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class }) @Deprecated public @interface IntegrationTest { @@ -52,7 +61,6 @@ public @interface IntegrationTest { * {@link Environment} before the test runs. * @return the environment properties */ - @AliasFor(annotation = org.springframework.boot.test.context.IntegrationTest.class, attribute = "value") String[] value() default {}; } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java b/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java index 39b211e3b76..b121e9031da 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/IntegrationTestPropertiesListener.java @@ -16,7 +16,6 @@ package org.springframework.boot.test; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAttributes; diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java b/spring-boot-test/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java index a2d44a59784..cc80cbac11d 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/MergedContextConfigurationProperties.java @@ -20,7 +20,6 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; -import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.util.ReflectionTestUtils; diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java index e4566933d72..27f170614b6 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationConfiguration.java @@ -42,11 +42,11 @@ import org.springframework.test.context.ContextConfiguration; * @deprecated since 1.4.0 in favor of * {@link org.springframework.boot.test.context.SpringApplicationConfiguration} */ +@ContextConfiguration(loader = SpringApplicationContextLoader.class) @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -@org.springframework.boot.test.context.SpringApplicationConfiguration @Deprecated public @interface SpringApplicationConfiguration { @@ -55,7 +55,7 @@ public @interface SpringApplicationConfiguration { * @see ContextConfiguration#classes() * @return the context configuration classes */ - @AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "value") + @AliasFor("classes") Class[] value() default {}; /** @@ -63,7 +63,7 @@ public @interface SpringApplicationConfiguration { * @see ContextConfiguration#locations() * @return the context configuration locations */ - @AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "locations") + @AliasFor(annotation = ContextConfiguration.class, attribute = "locations") String[] locations() default {}; /** @@ -71,7 +71,7 @@ public @interface SpringApplicationConfiguration { * @see ContextConfiguration#classes() * @return the context configuration classes */ - @AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "classes") + @AliasFor("value") Class[] classes() default {}; /** @@ -79,7 +79,7 @@ public @interface SpringApplicationConfiguration { * @see ContextConfiguration#initializers() * @return the context configuration initializers */ - @AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "initializers") + @AliasFor(annotation = ContextConfiguration.class, attribute = "initializers") Class>[] initializers() default {}; /** @@ -87,7 +87,7 @@ public @interface SpringApplicationConfiguration { * @see ContextConfiguration#inheritLocations() * @return {@code true} if context locations should be inherited */ - @AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "inheritLocations") + @AliasFor(annotation = ContextConfiguration.class, attribute = "inheritLocations") boolean inheritLocations() default true; /** @@ -95,7 +95,7 @@ public @interface SpringApplicationConfiguration { * @see ContextConfiguration#inheritInitializers() * @return {@code true} if context initializers should be inherited */ - @AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "inheritInitializers") + @AliasFor(annotation = ContextConfiguration.class, attribute = "inheritInitializers") boolean inheritInitializers() default true; /** @@ -103,7 +103,7 @@ public @interface SpringApplicationConfiguration { * @see ContextConfiguration#name() * @return the name of the context hierarchy level */ - @AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "name") + @AliasFor(annotation = ContextConfiguration.class, attribute = "name") String name() default ""; } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java index 85a9ac64247..a244d6d7c3e 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java @@ -16,15 +16,46 @@ package org.springframework.boot.test; +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.springframework.beans.BeanUtils; import org.springframework.boot.SpringApplication; +import org.springframework.boot.context.web.ServletContextApplicationContextInitializer; import org.springframework.boot.test.context.SpringApplicationTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.SpringVersion; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.StandardEnvironment; import org.springframework.mock.web.MockServletContext; +import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextLoader; +import org.springframework.test.context.MergedContextConfiguration; +import org.springframework.test.context.support.AbstractContextLoader; +import org.springframework.test.context.support.AnnotationConfigContextLoaderUtils; +import org.springframework.test.context.support.TestPropertySourceUtils; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.context.web.WebMergedContextConfiguration; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; +import org.springframework.web.context.support.GenericWebApplicationContext; /** * A {@link ContextLoader} that can be used to test Spring Boot applications (those that * normally startup using {@link SpringApplication}). Can be used to test non-web features - * (like a repository layer) or start an fully-configured embedded servlet container. + * (like a repository layer) or start a fully-configured embedded servlet container. *

* Use {@code @WebIntegrationTest} (or {@code @IntegrationTest} with * {@code @WebAppConfiguration}) to indicate that you want to use a real servlet container @@ -37,18 +68,225 @@ import org.springframework.test.context.ContextLoader; * @author Phillip Webb * @author Andy Wilkinson * @see org.springframework.boot.test.context.SpringApplicationTest - * @see org.springframework.boot.test.context.IntegrationTest - * @see org.springframework.boot.test.context.web.WebIntegrationTest + * @see org.springframework.boot.test.IntegrationTest + * @see org.springframework.boot.test.WebIntegrationTest * @deprecated since 1.4.0 in favor of - * {@link SpringApplicationTest @SpringApplicationTest}, - * {@link org.springframework.boot.test.context.IntegrationTest @IntegrationTest}, - * {@link org.springframework.boot.test.context.web.WebIntegrationTest @WebIntegrationTest} - * annotations. + * {@link SpringApplicationTest @SpringApplicationTest} * {@link org.springframework.boot.test.context.SpringApplicationContextLoader} can also * be considered if absolutely necessary. */ @Deprecated -public class SpringApplicationContextLoader - extends org.springframework.boot.test.context.SpringApplicationContextLoader { +public class SpringApplicationContextLoader extends AbstractContextLoader { + + @Override + public ApplicationContext loadContext(final MergedContextConfiguration config) + throws Exception { + assertValidAnnotations(config.getTestClass()); + SpringApplication application = getSpringApplication(); + application.setMainApplicationClass(config.getTestClass()); + application.setSources(getSources(config)); + ConfigurableEnvironment environment = new StandardEnvironment(); + if (!ObjectUtils.isEmpty(config.getActiveProfiles())) { + setActiveProfiles(environment, config.getActiveProfiles()); + } + Map properties = getEnvironmentProperties(config); + addProperties(environment, properties); + application.setEnvironment(environment); + List> initializers = getInitializers(config, + application); + if (config instanceof WebMergedContextConfiguration) { + new WebConfigurer().configure(config, application, initializers); + } + else { + application.setWebEnvironment(false); + } + application.setInitializers(initializers); + ConfigurableApplicationContext applicationContext = application.run(); + return applicationContext; + } + + private void assertValidAnnotations(Class testClass) { + boolean hasWebAppConfiguration = AnnotationUtils.findAnnotation(testClass, + WebAppConfiguration.class) != null; + boolean hasWebIntegrationTest = AnnotationUtils.findAnnotation(testClass, + WebIntegrationTest.class) != null; + if (hasWebAppConfiguration && hasWebIntegrationTest) { + throw new IllegalStateException("@WebIntegrationTest and " + + "@WebAppConfiguration cannot be used together"); + } + } + + /** + * Builds new {@link org.springframework.boot.SpringApplication} instance. You can + * override this method to add custom behavior + * @return {@link org.springframework.boot.SpringApplication} instance + */ + protected SpringApplication getSpringApplication() { + return new SpringApplication(); + } + + private Set getSources(MergedContextConfiguration mergedConfig) { + Set sources = new LinkedHashSet(); + sources.addAll(Arrays.asList(mergedConfig.getClasses())); + sources.addAll(Arrays.asList(mergedConfig.getLocations())); + Assert.state(!sources.isEmpty(), "No configuration classes " + + "or locations found in @SpringApplicationConfiguration. " + + "For default configuration detection to work you need " + + "Spring 4.0.3 or better (found " + SpringVersion.getVersion() + ")."); + return sources; + } + + private void setActiveProfiles(ConfigurableEnvironment environment, + String[] profiles) { + EnvironmentTestUtils.addEnvironment(environment, "spring.profiles.active=" + + StringUtils.arrayToCommaDelimitedString(profiles)); + } + + protected Map getEnvironmentProperties( + MergedContextConfiguration config) { + Map properties = new LinkedHashMap(); + // JMX bean names will clash if the same bean is used in multiple contexts + disableJmx(properties); + properties.putAll(TestPropertySourceUtils + .convertInlinedPropertiesToMap(config.getPropertySourceProperties())); + if (!TestAnnotations.isIntegrationTest(config)) { + properties.putAll(getDefaultEnvironmentProperties()); + } + return properties; + } + + private void disableJmx(Map properties) { + properties.put("spring.jmx.enabled", "false"); + } + + private Map getDefaultEnvironmentProperties() { + return Collections.singletonMap("server.port", "-1"); + } + + private void addProperties(ConfigurableEnvironment environment, + Map properties) { + // @IntegrationTest properties go before external configuration and after system + environment.getPropertySources().addAfter( + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, + new MapPropertySource("integrationTest", properties)); + } + + private List> getInitializers( + MergedContextConfiguration mergedConfig, SpringApplication application) { + List> initializers = new ArrayList>(); + initializers.add(new PropertySourceLocationsInitializer( + mergedConfig.getPropertySourceLocations())); + initializers.addAll(application.getInitializers()); + for (Class> initializerClass : mergedConfig + .getContextInitializerClasses()) { + initializers.add(BeanUtils.instantiate(initializerClass)); + } + return initializers; + } + + @Override + public void processContextConfiguration( + ContextConfigurationAttributes configAttributes) { + super.processContextConfiguration(configAttributes); + if (!configAttributes.hasResources()) { + Class[] defaultConfigClasses = detectDefaultConfigurationClasses( + configAttributes.getDeclaringClass()); + configAttributes.setClasses(defaultConfigClasses); + } + } + + /** + * Detect the default configuration classes for the supplied test class. By default + * simply delegates to + * {@link AnnotationConfigContextLoaderUtils#detectDefaultConfigurationClasses} . + * @param declaringClass the test class that declared {@code @ContextConfiguration} + * @return an array of default configuration classes, potentially empty but never + * {@code null} + * @see AnnotationConfigContextLoaderUtils + */ + protected Class[] detectDefaultConfigurationClasses(Class declaringClass) { + return AnnotationConfigContextLoaderUtils + .detectDefaultConfigurationClasses(declaringClass); + } + + @Override + public ApplicationContext loadContext(String... locations) throws Exception { + throw new UnsupportedOperationException("SpringApplicationContextLoader " + + "does not support the loadContext(String...) method"); + } + + @Override + protected String[] getResourceSuffixes() { + return new String[] { "-context.xml", "Context.groovy" }; + } + + @Override + protected String getResourceSuffix() { + throw new IllegalStateException(); + } + + /** + * Inner class to configure {@link WebMergedContextConfiguration}. + */ + private static class WebConfigurer { + + private static final Class WEB_CONTEXT_CLASS = GenericWebApplicationContext.class; + + void configure(MergedContextConfiguration configuration, + SpringApplication application, + List> initializers) { + if (!TestAnnotations.isIntegrationTest(configuration)) { + WebMergedContextConfiguration webConfiguration = (WebMergedContextConfiguration) configuration; + addMockServletContext(initializers, webConfiguration); + application.setApplicationContextClass(WEB_CONTEXT_CLASS); + } + } + + private void addMockServletContext( + List> initializers, + WebMergedContextConfiguration webConfiguration) { + SpringBootMockServletContext servletContext = new SpringBootMockServletContext( + webConfiguration.getResourceBasePath()); + initializers.add(0, + new ServletContextApplicationContextInitializer(servletContext)); + } + + } + + /** + * {@link ApplicationContextInitializer} to setup test property source locations. + */ + private static class PropertySourceLocationsInitializer + implements ApplicationContextInitializer { + + private final String[] propertySourceLocations; + + PropertySourceLocationsInitializer(String[] propertySourceLocations) { + this.propertySourceLocations = propertySourceLocations; + } + + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + TestPropertySourceUtils.addPropertiesFilesToEnvironment(applicationContext, + this.propertySourceLocations); + } + + } + + private static class TestAnnotations { + + public static boolean isIntegrationTest( + MergedContextConfiguration configuration) { + return (hasAnnotation(configuration, IntegrationTest.class) + || hasAnnotation(configuration, WebIntegrationTest.class)); + } + + private static boolean hasAnnotation(MergedContextConfiguration configuration, + Class annotation) { + return (AnnotationUtils.findAnnotation(configuration.getTestClass(), + annotation) != null); + } + + } } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java b/spring-boot-test/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java new file mode 100644 index 00000000000..c80ad9a1bd0 --- /dev/null +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/WebAppIntegrationTestContextBootstrapper.java @@ -0,0 +1,65 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test; + +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.test.context.ContextLoader; +import org.springframework.test.context.MergedContextConfiguration; +import org.springframework.test.context.TestContextBootstrapper; +import org.springframework.test.context.support.DefaultTestContextBootstrapper; +import org.springframework.test.context.web.WebDelegatingSmartContextLoader; +import org.springframework.test.context.web.WebMergedContextConfiguration; + +/** + * {@link TestContextBootstrapper} for Spring Boot web integration tests. + * + * @author Phillip Webb + * @since 1.2.1 + * @deprecated Since 1.4.0 + */ +@Deprecated +class WebAppIntegrationTestContextBootstrapper extends DefaultTestContextBootstrapper { + + @Override + protected Class getDefaultContextLoaderClass( + Class testClass) { + if (AnnotationUtils.findAnnotation(testClass, WebIntegrationTest.class) != null) { + return WebDelegatingSmartContextLoader.class; + } + return super.getDefaultContextLoaderClass(testClass); + } + + @Override + protected MergedContextConfiguration processMergedContextConfiguration( + MergedContextConfiguration mergedConfig) { + WebIntegrationTest annotation = AnnotationUtils + .findAnnotation(mergedConfig.getTestClass(), WebIntegrationTest.class); + if (annotation != null) { + mergedConfig = new WebMergedContextConfiguration(mergedConfig, null); + MergedContextConfigurationProperties properties = new MergedContextConfigurationProperties( + mergedConfig); + if (annotation.randomPort()) { + properties.add(annotation.value(), "server.port:0"); + } + else { + properties.add(annotation.value()); + } + } + return mergedConfig; + } + +} diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java index 6fae84ba2c3..2bc345ee5a5 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/WebIntegrationTest.java @@ -24,8 +24,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.core.annotation.AliasFor; import org.springframework.core.env.Environment; +import org.springframework.test.context.BootstrapWith; /** * Test class annotation signifying that the tests are "web integration tests" and @@ -40,13 +40,14 @@ import org.springframework.core.env.Environment; * @since 1.2.1 * @see IntegrationTest * @deprecated since 1.4.0 in favor of - * {@link org.springframework.boot.test.context.web.WebIntegrationTest} + * {@link org.springframework.boot.test.context.SpringApplicationTest} with + * {@code webEnvironment=RANDOM_PORT} or {@code webEnvironment=DEFINED_PORT}. */ @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -@org.springframework.boot.test.context.web.WebIntegrationTest +@BootstrapWith(WebAppIntegrationTestContextBootstrapper.class) @Deprecated public @interface WebIntegrationTest { @@ -55,7 +56,6 @@ public @interface WebIntegrationTest { * {@link Environment} before the test runs. * @return properties to add to the context */ - @AliasFor(annotation = org.springframework.boot.test.context.web.WebIntegrationTest.class, attribute = "value") String[] value() default {}; /** @@ -65,7 +65,6 @@ public @interface WebIntegrationTest { * test. * @return if a random port should be used */ - @AliasFor(annotation = org.springframework.boot.test.context.web.WebIntegrationTest.class, attribute = "randomPort") boolean randomPort() default false; } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/IntegrationTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/IntegrationTest.java deleted file mode 100644 index 9fd0d43cf38..00000000000 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/IntegrationTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.test.context; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.context.ApplicationContext; -import org.springframework.core.env.Environment; -import org.springframework.test.context.BootstrapWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; - -/** - * Test class annotation signifying that the tests are "integration tests" for a - * {@link org.springframework.boot.SpringApplication Spring Boot Application}. By default - * will load nested {@code @Configuration} classes, or fallback an - * {@link SpringApplicationConfiguration @SpringApplicationConfiguration} search. Unless - * otherwise configured, a {@link SpringApplicationContextLoader} will be used to load the - * {@link ApplicationContext}. Use - * {@link SpringApplicationConfiguration @SpringApplicationConfiguration} or - * {@link ContextConfiguration @ContextConfiguration} if custom configuration is required. - *

- * It's recommended that {@code @IntegrationTest} is used only for non-web applications - * (i.e. not combined with {@link WebAppConfiguration @WebAppConfiguration}). If you want - * to start a real embedded servlet container in the same way as a production application - * (listening on normal ports) use - * {@link org.springframework.boot.test.context.web.WebIntegrationTest @WebIntegrationTest} - * instead. If you are testing a web application and want to mock the servlet environment - * (for example so that you can use {@link MockMvc}) you should switch to the - * {@link SpringApplicationTest @SpringApplicationTest} annotation. - * - * @author Dave Syer - * @author Phillip Webb - * @see SpringApplicationTest - * @see org.springframework.boot.test.context.web.WebIntegrationTest - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -@BootstrapWith(IntegrationTestContextBootstrapper.class) -public @interface IntegrationTest { - - /** - * Properties in form {@literal key=value} that should be added to the Spring - * {@link Environment} before the test runs. - * @return the environment properties - */ - String[] value() default {}; - -} diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/IntegrationTestContextBootstrapper.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/IntegrationTestContextBootstrapper.java deleted file mode 100644 index 23d2595806a..00000000000 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/IntegrationTestContextBootstrapper.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.test.context; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.test.context.MergedContextConfiguration; -import org.springframework.test.context.TestContextBootstrapper; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.context.web.WebMergedContextConfiguration; - -/** - * {@link TestContextBootstrapper} for {@link IntegrationTest}. - * - * @author Phillip Webb - */ -class IntegrationTestContextBootstrapper extends SpringBootTestContextBootstrapper { - - private static final String SERVLET_LISTENER = "org.springframework.test.context.web.ServletTestExecutionListener"; - - @Override - protected List getDefaultTestExecutionListenerClassNames() { - // Remove the ServletTestExecutionListener because it only deals with MockServlet - List classNames = new ArrayList( - super.getDefaultTestExecutionListenerClassNames()); - while (classNames.contains(SERVLET_LISTENER)) { - classNames.remove(SERVLET_LISTENER); - } - return Collections.unmodifiableList(classNames); - } - - @Override - protected MergedContextConfiguration processMergedContextConfiguration( - MergedContextConfiguration mergedConfig) { - mergedConfig = super.processMergedContextConfiguration(mergedConfig); - WebAppConfiguration webAppConfiguration = AnnotatedElementUtils - .getMergedAnnotation(mergedConfig.getTestClass(), - WebAppConfiguration.class); - if (webAppConfiguration != null) { - mergedConfig = new WebMergedContextConfiguration(mergedConfig, - webAppConfiguration.value()); - } - return mergedConfig; - } - - @Override - protected void processPropertySourceProperties( - MergedContextConfiguration mergedConfig, - List propertySourceProperties) { - IntegrationTest annotation = AnnotatedElementUtils - .getMergedAnnotation(mergedConfig.getTestClass(), IntegrationTest.class); - propertySourceProperties.addAll(Arrays.asList(annotation.value())); - } - -} diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationConfiguration.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationConfiguration.java index 83c320b03c7..efde57446bf 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationConfiguration.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationConfiguration.java @@ -36,18 +36,13 @@ import org.springframework.test.context.ContextConfiguration; * Spring Boot's {@link SpringApplicationContextLoader}. *

* Tests that using this annotation only to define {@code classes} should consider using - * {@link SpringApplicationTest @SpringApplicationTest}, - * {@link IntegrationTest @IntegrationTest} or - * {@link org.springframework.boot.test.context.web.WebIntegrationTest @WebIntegrationTest} - * instead. + * {@link SpringApplicationTest @SpringApplicationTest} instead. * * @author Dave Syer * @author Sam Brannen * @author Phillip Webb * @since 1.4.0 * @see SpringApplicationTest - * @see IntegrationTest - * @see org.springframework.boot.test.context.web.WebIntegrationTest * @see SpringApplicationContextLoader * @see ContextConfiguration */ diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationContextLoader.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationContextLoader.java index 7787ea92ebd..47b95e945ae 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationContextLoader.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationContextLoader.java @@ -54,21 +54,12 @@ import org.springframework.web.context.support.GenericWebApplicationContext; /** * A {@link ContextLoader} that can be used to test Spring Boot applications (those that * normally startup using {@link SpringApplication}). Although this loader can be used - * directly, most test will instead want to use one of the following annotations: - *

    - *
  • {@link SpringApplicationTest @SpringApplicationTest} - For non-web applications, or - * web-applications running under a mock servlet environment
  • - *
  • {@link IntegrationTest @IntegrationTest} - To integration test non-web applications - *
  • - *
  • - * {@link org.springframework.boot.test.context.web.WebIntegrationTest @WebIntegrationTest} - * - To integration test web applications (i.e. listening on normal ports).
  • - *
+ * directly, most test will instead want to use it with {@link SpringApplicationTest}. + *

* The loader supports both standard {@link MergedContextConfiguration} as well as * {@link WebMergedContextConfiguration}. If {@link WebMergedContextConfiguration} is used * the context will either use a mock servlet environment, or start the full embedded - * servlet container (depending on the result of {@link #isIntegrationTest - * isIntegrationTest(...)}). + * servlet container. *

* If {@code @ActiveProfiles} are provided in the test class they will be used to create * the application context. @@ -77,8 +68,6 @@ import org.springframework.web.context.support.GenericWebApplicationContext; * @author Phillip Webb * @author Andy Wilkinson * @see SpringApplicationTest - * @see IntegrationTest - * @see org.springframework.boot.test.context.web.WebIntegrationTest */ public class SpringApplicationContextLoader extends AbstractContextLoader { @@ -86,8 +75,6 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { static { Set annotations = new LinkedHashSet(); - annotations.add("org.springframework.boot.test.context.IntegrationTest"); - annotations.add("org.springframework.boot.test.context.web.WebIntegrationTest"); annotations.add("org.springframework.boot.test.IntegrationTest"); annotations.add("org.springframework.boot.test.WebIntegrationTest"); INTEGRATION_TEST_ANNOTATIONS = Collections.unmodifiableSet(annotations); @@ -110,8 +97,9 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { application); if (config instanceof WebMergedContextConfiguration) { application.setWebEnvironment(true); - WebConfigurer configurer = new WebConfigurer(isIntegrationTest(config)); - configurer.configure(config, application, initializers); + if (!isEmbeddedWebEnvironment(config)) { + new WebConfigurer().configure(config, application, initializers); + } } else { application.setWebEnvironment(false); @@ -154,8 +142,8 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { disableJmx(properties); properties.putAll(TestPropertySourceUtils .convertInlinedPropertiesToMap(config.getPropertySourceProperties())); - if (!isIntegrationTest(config)) { - properties.putAll(getDefaultEnvironmentProperties()); + if (!isEmbeddedWebEnvironment(config)) { + properties.put("server.port", "-1"); } return properties; } @@ -164,10 +152,6 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { properties.put("spring.jmx.enabled", "false"); } - private Map getDefaultEnvironmentProperties() { - return Collections.singletonMap("server.port", "-1"); - } - private void addProperties(ConfigurableEnvironment environment, Map properties) { // @IntegrationTest properties go before external configuration and after system @@ -192,18 +176,17 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { return initializers; } - /** - * Return if the test is a full integration test or not. By default this method checks - * for well known integration test annotations. - * @param config the merged context configuration - * @return if the test is an integration test - */ - protected boolean isIntegrationTest(MergedContextConfiguration config) { + private boolean isEmbeddedWebEnvironment(MergedContextConfiguration config) { for (String annotation : INTEGRATION_TEST_ANNOTATIONS) { if (AnnotatedElementUtils.isAnnotated(config.getTestClass(), annotation)) { return true; } } + SpringApplicationTest annotation = AnnotatedElementUtils + .findMergedAnnotation(config.getTestClass(), SpringApplicationTest.class); + if (annotation != null && annotation.webEnvironment().isEmbedded()) { + return true; + } return false; } @@ -255,20 +238,12 @@ public class SpringApplicationContextLoader extends AbstractContextLoader { private static final Class WEB_CONTEXT_CLASS = GenericWebApplicationContext.class; - private final boolean integrationTest; - - WebConfigurer(boolean integrationTest) { - this.integrationTest = integrationTest; - } - void configure(MergedContextConfiguration configuration, SpringApplication application, List> initializers) { - if (!this.integrationTest) { - WebMergedContextConfiguration webConfiguration = (WebMergedContextConfiguration) configuration; - addMockServletContext(initializers, webConfiguration); - application.setApplicationContextClass(WEB_CONTEXT_CLASS); - } + WebMergedContextConfiguration webConfiguration = (WebMergedContextConfiguration) configuration; + addMockServletContext(initializers, webConfiguration); + application.setApplicationContextClass(WEB_CONTEXT_CLASS); } private void addMockServletContext( diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTest.java index 88102f5c7cc..7b9d4e6c9b0 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTest.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTest.java @@ -23,33 +23,36 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; +import org.springframework.boot.context.web.LocalServerPort; import org.springframework.context.ApplicationContext; +import org.springframework.core.annotation.AliasFor; import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.ContextConfiguration; +import org.springframework.web.context.WebApplicationContext; /** * Test class annotation signifying that the tests are for a * {@link org.springframework.boot.SpringApplication Spring Boot Application}. By default - * will load nested {@code @Configuration} classes, or fallback an + * will load nested {@code @Configuration} classes, or fall back on * {@link SpringApplicationConfiguration @SpringApplicationConfiguration} search. Unless * otherwise configured, a {@link SpringApplicationContextLoader} will be used to load the * {@link ApplicationContext}. Use * {@link SpringApplicationConfiguration @SpringApplicationConfiguration} or * {@link ContextConfiguration @ContextConfiguration} if custom configuration is required. *

- * A mock servlet environment will be used when this annotation is used to a test web - * application. If you want to start a real embedded servlet container in the same way as - * a production application (listening on normal ports) the - * {@link org.springframework.boot.test.context.web.WebIntegrationTest @WebIntegrationTest} - * annotation should be used instead. If you are testing a non-web application, and you - * don't need a mock servlet environment you should switch to - * {@link IntegrationTest @IntegrationTest}. + * The environment that will be used can be configured using the {@code mode} attribute. + * By default, a mock servlet environment will be used when this annotation is used to a + * test web application. If you want to start a real embedded servlet container in the + * same way as a production application (listening on normal ports) configure + * {@code mode=EMBEDDED_SERVLET}. If want to disable the creation of the mock servlet + * environment, configure {@code mode=STANDARD}. * * @author Phillip Webb + * @author Andy Wilkinson * @since 1.4.0 - * @see IntegrationTest - * @see org.springframework.boot.test.context.web.WebIntegrationTest */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @@ -58,11 +61,73 @@ import org.springframework.test.context.ContextConfiguration; @BootstrapWith(SpringApplicationTestContextBootstrapper.class) public @interface SpringApplicationTest { + /** + * Alias for {@link #properties()}. + * @return the properties to apply + */ + @AliasFor("properties") + String[] value() default {}; + /** * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add */ - String[] value() default {}; + @AliasFor("value") + String[] properties() default {}; + + /** + * The type of web environment to create when applicable. Defaults to + * {@link WebEnvironment#MOCK}. + * @return the type of web environment + */ + WebEnvironment webEnvironment() default WebEnvironment.MOCK; + + /** + * An enumeration web environment modes. + */ + enum WebEnvironment { + + /** + * Creates a {@link WebApplicationContext} with a mock servlet environment or a + * regular {@link ApplicationContext} if servlet APIs are not on the classpath. + */ + MOCK(false), + + /** + * Creates an {@link EmbeddedWebApplicationContext} and sets a + * {@code server.port=0} {@link Environment} property (which usually triggers + * listening on a random port). Often used in conjunction with a + * {@link LocalServerPort} injected field on the test. + */ + RANDOM_PORT(true), + + /** + * Creates an {@link EmbeddedWebApplicationContext} without defining any + * {@code server.port=0} {@link Environment} property. + */ + DEFINED_PORT(true), + + /** + * Creates an {@link ApplicationContext} and sets + * {@link SpringApplication#setWebEnvironment(boolean)} to {@code false}. + */ + NONE(false); + + private final boolean embedded; + + WebEnvironment(boolean embedded) { + this.embedded = embedded; + } + + /** + * Return if the environment uses an {@link EmbeddedWebApplicationContext}. + * @return if an {@link EmbeddedWebApplicationContext} is used. + */ + public boolean isEmbedded() { + return this.embedded; + } + + } } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextBootstrapper.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextBootstrapper.java index 64eba434dd9..f276b4d9610 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextBootstrapper.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextBootstrapper.java @@ -19,11 +19,11 @@ package org.springframework.boot.test.context; import java.util.Arrays; import java.util.List; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.TestContext; import org.springframework.test.context.TestContextBootstrapper; -import org.springframework.test.context.web.ServletTestExecutionListener; import org.springframework.test.context.web.WebMergedContextConfiguration; import org.springframework.util.ClassUtils; @@ -37,11 +37,20 @@ class SpringApplicationTestContextBootstrapper extends SpringBootTestContextBoot private static final String[] WEB_ENVIRONMENT_CLASSES = { "javax.servlet.Servlet", "org.springframework.web.context.ConfigurableWebApplicationContext" }; + private static final String ACTIVATE_SERVLET_LISTENER = "org.springframework.test." + + "context.web.ServletTestExecutionListener.activateListener"; + @Override public TestContext buildTestContext() { TestContext context = super.buildTestContext(); - if (isWebApplicationTest()) { - context.setAttribute(ServletTestExecutionListener.ACTIVATE_LISTENER, true); + SpringApplicationTest annotation = AnnotatedElementUtils + .getMergedAnnotation(context.getTestClass(), SpringApplicationTest.class); + WebEnvironment webEnvironment = annotation.webEnvironment(); + if (webEnvironment == WebEnvironment.MOCK) { + context.setAttribute(ACTIVATE_SERVLET_LISTENER, true); + } + else if (webEnvironment.isEmbedded()) { + context.setAttribute(ACTIVATE_SERVLET_LISTENER, false); } return context; } @@ -50,14 +59,17 @@ class SpringApplicationTestContextBootstrapper extends SpringBootTestContextBoot protected MergedContextConfiguration processMergedContextConfiguration( MergedContextConfiguration mergedConfig) { mergedConfig = super.processMergedContextConfiguration(mergedConfig); - if (!(mergedConfig instanceof WebMergedContextConfiguration) - && isWebApplicationTest()) { + SpringApplicationTest annotation = AnnotatedElementUtils.getMergedAnnotation( + mergedConfig.getTestClass(), SpringApplicationTest.class); + WebEnvironment webEnvironment = annotation.webEnvironment(); + if (webEnvironment.isEmbedded() || (webEnvironment == WebEnvironment.MOCK + && hasWebEnvironmentClasses())) { mergedConfig = new WebMergedContextConfiguration(mergedConfig, ""); } return mergedConfig; } - private boolean isWebApplicationTest() { + private boolean hasWebEnvironmentClasses() { for (String className : WEB_ENVIRONMENT_CLASSES) { if (!ClassUtils.isPresent(className, null)) { return false; @@ -72,7 +84,10 @@ class SpringApplicationTestContextBootstrapper extends SpringBootTestContextBoot List propertySourceProperties) { SpringApplicationTest annotation = AnnotatedElementUtils.getMergedAnnotation( mergedConfig.getTestClass(), SpringApplicationTest.class); - propertySourceProperties.addAll(Arrays.asList(annotation.value())); + propertySourceProperties.addAll(Arrays.asList(annotation.properties())); + if (annotation.webEnvironment() == WebEnvironment.RANDOM_PORT) { + propertySourceProperties.add("server.port=0"); + } } } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextCustomizer.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextCustomizer.java similarity index 56% rename from spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextCustomizer.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextCustomizer.java index 035cc0774ed..9a28c869939 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextCustomizer.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextCustomizer.java @@ -14,35 +14,35 @@ * limitations under the License. */ -package org.springframework.boot.test.context.web; +package org.springframework.boot.test.context; import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.env.Environment; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.MergedContextConfiguration; +import org.springframework.web.client.RestTemplate; /** - * {@link ContextCustomizer} for {@link WebIntegrationTest} that provides a - * {@link TestRestTemplate} bean that can automatically resolve - * {@literal local.server.port}. + * {@link ContextCustomizer} for {@link SpringApplicationTest}. * * @author Phillip Webb + * @author Andy Wilkinson */ -class WebIntegrationTestContextCustomizer implements ContextCustomizer { +class SpringApplicationTestContextCustomizer implements ContextCustomizer { @Override public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) { - TestRestTemplate restTemplate = getRestTemplate(context.getEnvironment()); - context.getBeanFactory().registerSingleton("testRestTemplate", restTemplate); - } - - private TestRestTemplate getRestTemplate(Environment environment) { - TestRestTemplate template = new TestRestTemplate(); - template.setUriTemplateHandler(new LocalHostUriTemplateHandler(environment)); - return template; + SpringApplicationTest annotation = AnnotatedElementUtils.getMergedAnnotation( + mergedContextConfiguration.getTestClass(), SpringApplicationTest.class); + if (annotation.webEnvironment().isEmbedded()) { + RestTemplate restTemplate = TestRestTemplateFactory + .createRestTemplate(context.getEnvironment()); + context.getBeanFactory().registerSingleton("testRestTemplate", restTemplate); + } } @Override @@ -58,4 +58,15 @@ class WebIntegrationTestContextCustomizer implements ContextCustomizer { return true; } + // Inner class to avoid references to web classes that may not be on the classpath + private static class TestRestTemplateFactory { + + private static TestRestTemplate createRestTemplate(Environment environment) { + TestRestTemplate template = new TestRestTemplate(); + template.setUriTemplateHandler(new LocalHostUriTemplateHandler(environment)); + return template; + } + + } + } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextCustomizerFactory.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextCustomizerFactory.java similarity index 75% rename from spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextCustomizerFactory.java rename to spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextCustomizerFactory.java index d731d8210c2..2607925af00 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextCustomizerFactory.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringApplicationTestContextCustomizerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.test.context.web; +package org.springframework.boot.test.context; import java.util.List; @@ -24,19 +24,19 @@ import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.ContextCustomizerFactory; /** - * {@link ContextCustomizerFactory} for {@link WebIntegrationTest}. + * {@link ContextCustomizerFactory} for {@link SpringApplicationTest}. * - * @author Phillip Webb - * @see WebIntegrationTestContextCustomizer + * @author Andy Wilkinson + * @see SpringApplicationTestContextCustomizer */ -class WebIntegrationTestContextCustomizerFactory implements ContextCustomizerFactory { +class SpringApplicationTestContextCustomizerFactory implements ContextCustomizerFactory { @Override public ContextCustomizer createContextCustomizer(Class testClass, List configAttributes) { if (AnnotatedElementUtils.findMergedAnnotation(testClass, - WebIntegrationTest.class) != null) { - return new WebIntegrationTestContextCustomizer(); + SpringApplicationTest.class) != null) { + return new SpringApplicationTestContextCustomizer(); } return null; } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTest.java deleted file mode 100644 index e00dd00ab79..00000000000 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.test.context.web; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.beans.factory.annotation.Autowire; -import org.springframework.boot.test.context.IntegrationTest; -import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.SpringApplicationContextLoader; -import org.springframework.boot.test.context.SpringApplicationTest; -import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.context.ApplicationContext; -import org.springframework.core.env.Environment; -import org.springframework.test.context.BootstrapWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.web.servlet.MockMvc; - -/** - * Test class annotation signifying that the tests are "web integration tests" for a - * {@link org.springframework.boot.SpringApplication Spring Boot Application} and - * therefore require full startup in the same way as a production application (listening - * on normal ports). By default will load nested {@code @Configuration} classes, or - * fallback an {@link SpringApplicationConfiguration @SpringApplicationConfiguration} - * search. Unless otherwise configured, a {@link SpringApplicationContextLoader} will be - * used to load the {@link ApplicationContext}. Use - * {@link SpringApplicationConfiguration @SpringApplicationConfiguration} or - * {@link ContextConfiguration @ContextConfiguration} if custom configuration is required. - *

- * If you are not testing a web application consider using the - * {@link IntegrationTest @IntegrationTest} annotation instead. If you are testing a web - * application and want to mock the servlet environment (for example so that you can use - * {@link MockMvc}) you should switch to the - * {@link SpringApplicationTest @SpringApplicationTest} annotation. - *

- * Tests that need to make REST calls to the started server can additionally - * {@link Autowire @Autowire} a {@link TestRestTemplate} which will be pre-configured with - * a {@link LocalHostUriTemplateHandler}. - * - * @author Phillip Webb - * @since 1.4.0 - * @see SpringApplicationTest - * @see IntegrationTest - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Inherited -@BootstrapWith(WebIntegrationTestContextBootstrapper.class) -public @interface WebIntegrationTest { - - /** - * Properties in form {@literal key=value} that should be added to the Spring - * {@link Environment} before the test runs. - * @return properties to add to the context - */ - String[] value() default {}; - - /** - * Convenience attribute that can be used to set a {@code server.port=0} - * {@link Environment} property which usually triggers listening on a random port. - * Often used in conjunction with a @Value("${local.server.port}") - * injected field on the test. - * @return if a random port should be used - */ - boolean randomPort() default false; - -} diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextBootstrapper.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextBootstrapper.java deleted file mode 100644 index 1abdd39218d..00000000000 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/WebIntegrationTestContextBootstrapper.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.test.context.web; - -import java.util.Arrays; -import java.util.List; - -import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; -import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.test.context.MergedContextConfiguration; -import org.springframework.test.context.TestContextBootstrapper; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.context.web.WebMergedContextConfiguration; - -/** - * {@link TestContextBootstrapper} for Spring Boot web integration tests. - * - * @author Phillip Webb - */ -class WebIntegrationTestContextBootstrapper extends SpringBootTestContextBootstrapper { - - @Override - protected MergedContextConfiguration processMergedContextConfiguration( - MergedContextConfiguration mergedConfig) { - assertValidAnnotations(mergedConfig.getTestClass()); - mergedConfig = super.processMergedContextConfiguration(mergedConfig); - return new WebMergedContextConfiguration(mergedConfig, null); - } - - private void assertValidAnnotations(Class testClass) { - if (AnnotatedElementUtils.findMergedAnnotation(testClass, - WebAppConfiguration.class) != null - && AnnotatedElementUtils.findMergedAnnotation(testClass, - WebIntegrationTest.class) != null) { - throw new IllegalStateException("@WebIntegrationTest and " - + "@WebAppConfiguration cannot be used together"); - } - } - - @Override - protected void processPropertySourceProperties( - MergedContextConfiguration mergedConfig, - List propertySourceProperties) { - WebIntegrationTest annotation = AnnotatedElementUtils.getMergedAnnotation( - mergedConfig.getTestClass(), WebIntegrationTest.class); - propertySourceProperties.addAll(Arrays.asList(annotation.value())); - if (annotation.randomPort()) { - propertySourceProperties.add("server.port=0"); - } - } - -} diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/package-info.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/package-info.java deleted file mode 100644 index 69157a45519..00000000000 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/web/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Classes and annotations related to configuring Spring's {@code WebApplicationContext} - * for tests. - */ -package org.springframework.boot.test.context.web; diff --git a/spring-boot-test/src/main/resources/META-INF/spring.factories b/spring-boot-test/src/main/resources/META-INF/spring.factories index 3a72cef79f3..913523eb46b 100644 --- a/spring-boot-test/src/main/resources/META-INF/spring.factories +++ b/spring-boot-test/src/main/resources/META-INF/spring.factories @@ -1,8 +1,8 @@ # Spring Test ContextCustomizerFactories org.springframework.test.context.ContextCustomizerFactory=\ org.springframework.boot.test.context.ImportsContextCustomizerFactory,\ +org.springframework.boot.test.context.SpringApplicationTestContextCustomizerFactory,\ org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizerFactory,\ -org.springframework.boot.test.context.web.WebIntegrationTestContextCustomizerFactory,\ org.springframework.boot.test.mock.mockito.MockitoContextCustomizerFactory # Test Execution Listeners diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java index 23851a8abcd..0604d3b4c21 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/SpringApplicationWebIntegrationTestTests.java @@ -26,6 +26,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.web.LocalServerPort; +import org.springframework.boot.test.SpringApplicationWebIntegrationTestTests.Config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @@ -49,8 +50,8 @@ import static org.assertj.core.api.Assertions.assertThat; @SuppressWarnings("deprecation") @RunWith(SpringRunner.class) @DirtiesContext +@SpringApplicationConfiguration(Config.class) @WebIntegrationTest({ "server.port=0", "value=123" }) -@Deprecated public class SpringApplicationWebIntegrationTestTests { @LocalServerPort diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/web/SpringApplicationWebIntegrationTestTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringApplicationTestWebEnvironmentEmbeddedTests.java similarity index 77% rename from spring-boot-test/src/test/java/org/springframework/boot/test/context/web/SpringApplicationWebIntegrationTestTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringApplicationTestWebEnvironmentEmbeddedTests.java index e72c7f43caf..433add6d3d6 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/web/SpringApplicationWebIntegrationTestTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringApplicationTestWebEnvironmentEmbeddedTests.java @@ -14,47 +14,36 @@ * limitations under the License. */ -package org.springframework.boot.test.context.web; +package org.springframework.boot.test.context; import javax.servlet.ServletContext; import org.junit.Test; -import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.IntegrationTest; -import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.SpringApplicationWebIntegrationTestTests.Config; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.servlet.DispatcherServlet; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link IntegrationTest} + * Base class for {@link SpringApplicationTest} tests configured to start an embedded + * servlet container * * @author Phillip Webb + * @author Andy Wilkinson */ -@RunWith(SpringRunner.class) -@DirtiesContext -@SpringApplicationConfiguration(Config.class) -@WebIntegrationTest({ "server.port=0", "value=123" }) -public class SpringApplicationWebIntegrationTestTests { +public abstract class AbstractSpringApplicationTestWebEnvironmentEmbeddedTests { @LocalServerPort private int port = 0; @@ -96,10 +85,7 @@ public class SpringApplicationWebIntegrationTestTests { WebApplicationContextUtils.getWebApplicationContext(this.servletContext)); } - @Configuration - @EnableWebMvc - @RestController - protected static class Config { + protected static class AbstractConfig { @Value("${server.port:8080}") private int port = 8080; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationActiveProfileTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationActiveProfileTests.java index 267e20af4fa..b16b7167a44 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationActiveProfileTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationActiveProfileTests.java @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration -@IntegrationTest("spring.config.name=enableother") +@SpringApplicationTest("spring.config.name=enableother") @ActiveProfiles("override") public class SpringApplicationConfigurationActiveProfileTests { diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationJmxTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationJmxTests.java index 919382a0a81..6a1a8607b12 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationJmxTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationJmxTests.java @@ -36,8 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @DirtiesContext +@SpringApplicationTest @SpringApplicationConfiguration(Config.class) -@IntegrationTest public class SpringApplicationConfigurationJmxTests { @Value("${spring.jmx.enabled}") diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/web/SpringApplicationMockMvcTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationMockMvcTests.java similarity index 93% rename from spring-boot-test/src/test/java/org/springframework/boot/test/context/web/SpringApplicationMockMvcTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationMockMvcTests.java index fc7cb643701..280163a71cd 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/web/SpringApplicationMockMvcTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationConfigurationMockMvcTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.test.context.web; +package org.springframework.boot.test.context; import javax.servlet.ServletContext; @@ -23,8 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringApplicationConfiguration; -import org.springframework.boot.test.context.web.SpringApplicationMockMvcTests.Config; +import org.springframework.boot.test.context.SpringApplicationConfigurationMockMvcTests.Config; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; @@ -51,7 +50,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @DirtiesContext @SpringApplicationConfiguration(classes = Config.class) @WebAppConfiguration -public class SpringApplicationMockMvcTests { +public class SpringApplicationConfigurationMockMvcTests { @Autowired private WebApplicationContext context; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationContextLoaderTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationContextLoaderTests.java index 7a2c389b340..e78b5dd9cd2 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationContextLoaderTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationContextLoaderTests.java @@ -45,6 +45,13 @@ public class SpringApplicationContextLoaderTests { assertKey(config, "anotherKey", "anotherValue"); } + @Test + public void environmentPropertiesSimpleNonAlias() throws Exception { + Map config = getEnvironmentProperties(SimpleConfigNonAlias.class); + assertKey(config, "key", "myValue"); + assertKey(config, "anotherKey", "anotherValue"); + } + @Test public void environmentPropertiesOverrideDefaults() throws Exception { Map config = getEnvironmentProperties(OverrideConfig.class); @@ -97,37 +104,43 @@ public class SpringApplicationContextLoaderTests { assertThat(actual.get(key)).isEqualTo(value); } - @IntegrationTest({ "key=myValue", "anotherKey:anotherValue" }) + @SpringApplicationTest({ "key=myValue", "anotherKey:anotherValue" }) @ContextConfiguration(classes = Config.class) static class SimpleConfig { } - @IntegrationTest({ "server.port=2345" }) + @SpringApplicationTest(properties = { "key=myValue", "anotherKey:anotherValue" }) + @ContextConfiguration(classes = Config.class) + static class SimpleConfigNonAlias { + + } + + @SpringApplicationTest("server.port=2345") @ContextConfiguration(classes = Config.class) static class OverrideConfig { } - @IntegrationTest({ "key=myValue", "otherKey=otherValue" }) + @SpringApplicationTest({ "key=myValue", "otherKey=otherValue" }) @ContextConfiguration(classes = Config.class) static class AppendConfig { } - @IntegrationTest({ "key=my=Value", "anotherKey:another:Value" }) + @SpringApplicationTest({ "key=my=Value", "anotherKey:another:Value" }) @ContextConfiguration(classes = Config.class) static class SameSeparatorInValue { } - @IntegrationTest({ "key=my:Value", "anotherKey:another=Value" }) + @SpringApplicationTest({ "key=my:Value", "anotherKey:another=Value" }) @ContextConfiguration(classes = Config.class) static class AnotherSeparatorInValue { } - @IntegrationTest({ "key=myValue", "variables=foo=FOO\n bar=BAR" }) + @SpringApplicationTest({ "key=myValue", "variables=foo=FOO\n bar=BAR" }) @ContextConfiguration(classes = Config.class) static class NewLineInValue { diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationIntegrationTestTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationIntegrationTestTests.java deleted file mode 100644 index 44aec2ba70a..00000000000 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationIntegrationTestTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.test.context; - -import javax.servlet.ServletContext; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.test.context.SpringApplicationIntegrationTestTests.Config; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; -import org.springframework.web.servlet.DispatcherServlet; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link IntegrationTest} - * - * @author Dave Syer - */ -@RunWith(SpringRunner.class) -@DirtiesContext -@SpringApplicationConfiguration(Config.class) -@WebAppConfiguration -@IntegrationTest({ "server.port=0", "value=123" }) -public class SpringApplicationIntegrationTestTests { - - @Value("${local.server.port}") - private int port = 0; - - @Value("${value}") - private int value = 0; - - @Autowired - private WebApplicationContext context; - - @Autowired - private ServletContext servletContext; - - @Test - public void runAndTestHttpEndpoint() { - assertThat(this.port).isNotEqualTo(8080).isNotEqualTo(0); - String body = new RestTemplate() - .getForObject("http://localhost:" + this.port + "/", String.class); - assertThat(body).isEqualTo("Hello World"); - } - - @Test - public void annotationAttributesOverridePropertiesFile() throws Exception { - assertThat(this.value).isEqualTo(123); - } - - @Test - public void validateWebApplicationContextIsSet() { - assertThat(this.context).isSameAs( - WebApplicationContextUtils.getWebApplicationContext(this.servletContext)); - } - - @Configuration - @EnableWebMvc - @RestController - protected static class Config { - - @Value("${server.port:8080}") - private int port = 8080; - - @Bean - public DispatcherServlet dispatcherServlet() { - return new DispatcherServlet(); - } - - @Bean - public EmbeddedServletContainerFactory embeddedServletContainer() { - TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); - factory.setPort(this.port); - return factory; - } - - @Bean - public static PropertySourcesPlaceholderConfigurer propertyPlaceholder() { - return new PropertySourcesPlaceholderConfigurer(); - } - - @RequestMapping("/") - public String home() { - return "Hello World"; - } - - } - -} diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationIntegrationTestPropertyLocationTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestPropertyLocationTests.java similarity index 74% rename from spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationIntegrationTestPropertyLocationTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestPropertyLocationTests.java index a43619fcce7..7bc67d1a1ff 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationIntegrationTestPropertyLocationTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestPropertyLocationTests.java @@ -23,29 +23,29 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringApplicationIntegrationTestPropertyLocationTests.MoreConfig; -import org.springframework.boot.test.context.SpringApplicationIntegrationTestTests.Config; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; +import org.springframework.boot.test.context.SpringApplicationTestPropertyLocationTests.Config; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.env.Environment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link IntegrationTest} with {@link TestPropertySource} locations. + * Tests for {@link SpringApplicationTest} with {@link TestPropertySource} locations. * * @author Phillip Webb */ @RunWith(SpringRunner.class) @DirtiesContext -@SpringApplicationConfiguration({ Config.class, MoreConfig.class }) -@WebAppConfiguration -@IntegrationTest({ "server.port=0", "value1=123" }) +@SpringApplicationConfiguration(Config.class) +@SpringApplicationTest(webEnvironment = WebEnvironment.NONE, properties = "value1=123") @TestPropertySource(properties = "value2=456", locations = "classpath:/test-property-source-annotation.properties") -public class SpringApplicationIntegrationTestPropertyLocationTests { +public class SpringApplicationTestPropertyLocationTests { @Autowired private Environment environment; @@ -59,7 +59,7 @@ public class SpringApplicationIntegrationTestPropertyLocationTests { } @Configuration - static class MoreConfig { + static class Config { @Value("${value1}") private String value1; @@ -77,6 +77,11 @@ public class SpringApplicationIntegrationTestPropertyLocationTests { assertThat(this.annotationReferenced).isEqualTo("fromfile"); } + @Bean + public static PropertySourcesPlaceholderConfigurer propertyPlaceholder() { + return new PropertySourcesPlaceholderConfigurer(); + } + } } diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentDefinedPortTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentDefinedPortTests.java new file mode 100644 index 00000000000..61029760119 --- /dev/null +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentDefinedPortTests.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.context; + +import org.junit.runner.RunWith; + +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +/** + * Tests for {@link SpringApplicationTest} configured with + * {@link WebEnvironment#DEFINED_PORT}. + * + * @author Phillip Webb + * @author Andy Wilkinson + */ +@RunWith(SpringRunner.class) +@DirtiesContext +@SpringApplicationTest(webEnvironment = WebEnvironment.DEFINED_PORT, properties = { + "server.port=0", "value=123" }) +public class SpringApplicationTestWebEnvironmentDefinedPortTests + extends AbstractSpringApplicationTestWebEnvironmentEmbeddedTests { + + @Configuration + @EnableWebMvc + @RestController + protected static class Config extends AbstractConfig { + + } + +} diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentMockTests.java similarity index 91% rename from spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentMockTests.java index 2b65fe5c3c1..ba86f09f6de 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentMockTests.java @@ -23,6 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @@ -37,14 +38,15 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link SpringApplicationTest} + * Tests for {@link SpringApplicationTest} configured with {@link WebEnvironment#MOCK}. * * @author Phillip Webb + * @author Andy Wilkinson */ @RunWith(SpringRunner.class) @SpringApplicationTest("value=123") @DirtiesContext -public class SpringApplicationTestTests { +public class SpringApplicationTestWebEnvironmentMockTests { @Value("${value}") private int value = 0; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentRandomPortTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentRandomPortTests.java new file mode 100644 index 00000000000..0ea4eec6d53 --- /dev/null +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringApplicationTestWebEnvironmentRandomPortTests.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.context; + +import org.junit.runner.RunWith; + +import org.springframework.boot.test.context.SpringApplicationTest.WebEnvironment; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +/** + * Tests for {@link SpringApplicationTest} configured with + * {@link WebEnvironment#DEFINED_PORT}. + * + * @author Phillip Webb + * @author Andy Wilkinson + */ +@RunWith(SpringRunner.class) +@DirtiesContext +@SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "value=123" }) +public class SpringApplicationTestWebEnvironmentRandomPortTests + extends AbstractSpringApplicationTestWebEnvironmentEmbeddedTests { + + @Configuration + @EnableWebMvc + @RestController + protected static class Config extends AbstractConfig { + + } + +}