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
This commit is contained in:
Andy Wilkinson 2016-03-31 16:55:28 +01:00 committed by Phillip Webb
parent 893a6c32f3
commit 33f0ea3480
122 changed files with 947 additions and 823 deletions

View File

@ -49,8 +49,9 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.web.LocalServerPort; 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.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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; 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.http.converter.HttpMessageConverter;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -74,8 +74,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@IntegrationTest("server.port=0") @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@WebAppConfiguration
@DirtiesContext @DirtiesContext
public class EndpointMvcIntegrationTests { public class EndpointMvcIntegrationTests {

View File

@ -24,8 +24,9 @@ import org.junit.runner.RunWith;
import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication; import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication;
import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpointServerContextPathIntegrationTests.SpringBootHypermediaApplication; import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpointServerContextPathIntegrationTests.SpringBootHypermediaApplication;
import org.springframework.boot.context.web.LocalServerPort; 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.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.boot.test.web.client.TestRestTemplate;
import org.springframework.hateoas.ResourceSupport; import org.springframework.hateoas.ResourceSupport;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
@ -36,7 +37,6 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -52,8 +52,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(SpringBootHypermediaApplication.class) @SpringApplicationConfiguration(SpringBootHypermediaApplication.class)
@WebAppConfiguration @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
@IntegrationTest({ "server.port=0", "server.contextPath=/spring" }) "server.contextPath=/spring" })
@DirtiesContext @DirtiesContext
public class HalBrowserMvcEndpointServerContextPathIntegrationTests { public class HalBrowserMvcEndpointServerContextPathIntegrationTests {

View File

@ -24,8 +24,9 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication; import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication;
import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpointServerPortIntegrationTests.SpringBootHypermediaApplication; 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.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.boot.test.web.client.TestRestTemplate;
import org.springframework.hateoas.ResourceSupport; import org.springframework.hateoas.ResourceSupport;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
@ -36,7 +37,6 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -52,8 +52,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(SpringBootHypermediaApplication.class) @SpringApplicationConfiguration(SpringBootHypermediaApplication.class)
@WebAppConfiguration @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
@IntegrationTest({ "server.port=0", "management.port=0" }) "management.port=0" })
@DirtiesContext @DirtiesContext
public class HalBrowserMvcEndpointServerPortIntegrationTests { public class HalBrowserMvcEndpointServerPortIntegrationTests {

View File

@ -23,8 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.integration.SpringIntegrationMetricReaderTests.TestConfiguration; import org.springframework.boot.actuate.metrics.integration.SpringIntegrationMetricReaderTests.TestConfiguration;
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration; import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; 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.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringApplicationTest;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(TestConfiguration.class) @SpringApplicationConfiguration(TestConfiguration.class)
@IntegrationTest("spring.jmx.enabled=true") @SpringApplicationTest("spring.jmx.enabled=true")
@DirtiesContext @DirtiesContext
public class SpringIntegrationMetricReaderTests { public class SpringIntegrationMetricReaderTests {

View File

@ -23,8 +23,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.MessageSourceAutoConfigurationIntegrationTests.Config; 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.SpringApplicationConfiguration;
import org.springframework.boot.test.context.SpringApplicationTest;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
PropertyPlaceholderAutoConfiguration.class }) PropertyPlaceholderAutoConfiguration.class })
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@IntegrationTest("spring.messages.basename:test/messages") @SpringApplicationTest("spring.messages.basename:test/messages")
public class MessageSourceAutoConfigurationIntegrationTests { public class MessageSourceAutoConfigurationIntegrationTests {
@Autowired @Autowired

View File

@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -56,8 +57,8 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@WebIntegrationTest(randomPort = true, value = {"spring.jersey.type=filter", @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"server.contextPath=/app" }) "spring.jersey.type=filter", "server.contextPath=/app" })
public class JerseyAutoConfigurationCustomFilterContextPathTests { public class JerseyAutoConfigurationCustomFilterContextPathTests {
@Autowired @Autowired
@ -65,8 +66,8 @@ public class JerseyAutoConfigurationCustomFilterContextPathTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate.getForEntity( ResponseEntity<String> entity = this.restTemplate.getForEntity("/app/rest/hello",
"/app/rest/hello", String.class); String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }

View File

@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -56,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@WebIntegrationTest(randomPort = true, value = "spring.jersey.type=filter") @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jersey.type=filter")
public class JerseyAutoConfigurationCustomFilterPathTests { public class JerseyAutoConfigurationCustomFilterPathTests {
@Autowired @Autowired
@ -64,8 +65,8 @@ public class JerseyAutoConfigurationCustomFilterPathTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate.getForEntity( ResponseEntity<String> entity = this.restTemplate.getForEntity("/rest/hello",
"/rest/hello", String.class); String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }

View File

@ -33,7 +33,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.ApplicationContext;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
@ -48,7 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @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 { public class JerseyAutoConfigurationCustomLoadOnStartupTests {
@Autowired @Autowired
@ -56,7 +57,8 @@ public class JerseyAutoConfigurationCustomLoadOnStartupTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
assertThat(new DirectFieldAccessor(this.context.getBean("jerseyServletRegistration")) assertThat(
new DirectFieldAccessor(this.context.getBean("jerseyServletRegistration"))
.getPropertyValue("loadOnStartup")).isEqualTo(5); .getPropertyValue("loadOnStartup")).isEqualTo(5);
} }
@ -72,9 +74,9 @@ public class JerseyAutoConfigurationCustomLoadOnStartupTests {
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@Import({EmbeddedServletContainerAutoConfiguration.class, @Import({ EmbeddedServletContainerAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class, JerseyAutoConfiguration.class, ServerPropertiesAutoConfiguration.class, JerseyAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class}) PropertyPlaceholderAutoConfiguration.class })
protected @interface MinimalWebConfiguration { protected @interface MinimalWebConfiguration {
} }

View File

@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObje
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -56,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @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 { public class JerseyAutoConfigurationCustomObjectMapperProviderTests {
@Autowired @Autowired
@ -64,8 +65,8 @@ public class JerseyAutoConfigurationCustomObjectMapperProviderTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> response = this.restTemplate.getForEntity( ResponseEntity<String> response = this.restTemplate.getForEntity("/rest/message",
"/rest/message", String.class); String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode()); assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
assertThat("{\"subject\":\"Jersey\"}").isEqualTo(response.getBody()); assertThat("{\"subject\":\"Jersey\"}").isEqualTo(response.getBody());
} }

View File

@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -53,10 +54,11 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@WebIntegrationTest(randomPort = true, value = "server.contextPath=/app") @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "server.contextPath=/app")
public class JerseyAutoConfigurationCustomServletContextPathTests { public class JerseyAutoConfigurationCustomServletContextPathTests {
@Autowired @Autowired
@ -64,8 +66,8 @@ public class JerseyAutoConfigurationCustomServletContextPathTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate.getForEntity( ResponseEntity<String> entity = this.restTemplate.getForEntity("/app/rest/hello",
"/app/rest/hello", String.class); String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }

View File

@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -53,10 +54,11 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class JerseyAutoConfigurationCustomServletPathTests { public class JerseyAutoConfigurationCustomServletPathTests {
@Autowired @Autowired
@ -64,8 +66,8 @@ public class JerseyAutoConfigurationCustomServletPathTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate.getForEntity( ResponseEntity<String> entity = this.restTemplate.getForEntity("/rest/hello",
"/rest/hello", String.class); String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }

View File

@ -37,7 +37,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefa
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -55,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@WebIntegrationTest(randomPort = true, value = "spring.jersey.type=filter") @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jersey.type=filter")
public class JerseyAutoConfigurationDefaultFilterPathTests { public class JerseyAutoConfigurationDefaultFilterPathTests {
@Autowired @Autowired
@ -63,8 +64,8 @@ public class JerseyAutoConfigurationDefaultFilterPathTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate ResponseEntity<String> entity = this.restTemplate.getForEntity("/hello",
.getForEntity("/hello", String.class); String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }

View File

@ -37,7 +37,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefa
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -52,10 +53,11 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class JerseyAutoConfigurationDefaultServletPathTests { public class JerseyAutoConfigurationDefaultServletPathTests {
@Autowired @Autowired
@ -63,8 +65,8 @@ public class JerseyAutoConfigurationDefaultServletPathTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate ResponseEntity<String> entity = this.restTemplate.getForEntity("/hello",
.getForEntity("/hello", String.class); String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }

View File

@ -38,7 +38,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObje
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -56,7 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class JerseyAutoConfigurationObjectMapperProviderTests { public class JerseyAutoConfigurationObjectMapperProviderTests {
@Autowired @Autowired
@ -64,8 +65,8 @@ public class JerseyAutoConfigurationObjectMapperProviderTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> response = this.restTemplate.getForEntity( ResponseEntity<String> response = this.restTemplate.getForEntity("/rest/message",
"/rest/message", String.class); String.class);
assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode()); assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode());
assertThat("{\"subject\":\"Jersey\",\"body\":null}") assertThat("{\"subject\":\"Jersey\",\"body\":null}")
.isEqualTo(response.getBody()); .isEqualTo(response.getBody());

View File

@ -35,7 +35,8 @@ import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoCo
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.boot.test.rule.OutputCapture;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -54,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class JerseyAutoConfigurationServletContainerTests { public class JerseyAutoConfigurationServletContainerTests {
@ClassRule @ClassRule

View File

@ -37,7 +37,8 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCust
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -55,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @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 { public class JerseyAutoConfigurationWithoutApplicationPathTests {
@Autowired @Autowired
@ -63,8 +64,8 @@ public class JerseyAutoConfigurationWithoutApplicationPathTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate.getForEntity( ResponseEntity<String> entity = this.restTemplate.getForEntity("/api/hello",
"/api/hello", String.class); String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }

View File

@ -36,15 +36,15 @@ import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfigura
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; 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.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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.RequestMapping;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -57,9 +57,8 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@IntegrationTest({ "server.port:0", @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"spring.mustache.prefix:classpath:/mustache-templates/" }) "spring.mustache.prefix:classpath:/mustache-templates/" })
@WebAppConfiguration
public class MustacheAutoConfigurationIntegrationTests { public class MustacheAutoConfigurationIntegrationTests {
@Autowired @Autowired

View File

@ -25,8 +25,9 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.mustache.MustacheStandaloneIntegrationTests.Application; 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.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.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
@ -42,7 +43,8 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @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 { public class MustacheStandaloneIntegrationTests {
@Autowired @Autowired

View File

@ -41,8 +41,9 @@ import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfigura
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; 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.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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -50,7 +51,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.RequestMapping;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -64,8 +64,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@DirtiesContext @DirtiesContext
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@IntegrationTest("server.port:0") @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@WebAppConfiguration
public class MustacheWebIntegrationTests { public class MustacheWebIntegrationTests {
@Autowired @Autowired

View File

@ -31,7 +31,8 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfi
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.web.LocalServerPort; 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.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@ -59,7 +60,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest({ "server.port=0", @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"security.oauth2.resource.userInfoUri:http://example.com", "security.oauth2.resource.userInfoUri:http://example.com",
"security.oauth2.client.clientId=foo" }) "security.oauth2.client.clientId=foo" })
@DirtiesContext @DirtiesContext

View File

@ -34,8 +34,9 @@ import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.web.BasicErrorControllerIntegrationTests.TestConfiguration; import org.springframework.boot.autoconfigure.web.BasicErrorControllerIntegrationTests.TestConfiguration;
import org.springframework.boot.autoconfigure.web.BasicErrorControllerMockMvcTests.MinimalWebConfiguration; 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.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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -46,7 +47,6 @@ import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.validation.BindException; import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -68,9 +68,8 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(TestConfiguration.class) @SpringApplicationConfiguration(TestConfiguration.class)
@WebAppConfiguration
@DirtiesContext @DirtiesContext
@IntegrationTest("server.port=0") @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class BasicErrorControllerIntegrationTests { public class BasicErrorControllerIntegrationTests {
private ConfigurableApplicationContext context; private ConfigurableApplicationContext context;

View File

@ -26,15 +26,15 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.ErrorPage; import org.springframework.boot.context.embedded.ErrorPage;
import org.springframework.boot.context.web.LocalServerPort; 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.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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; 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.RequestMapping;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -45,8 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@SpringApplicationConfiguration(TestConfiguration.class) @SpringApplicationConfiguration(TestConfiguration.class)
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebAppConfiguration @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "server.servletPath:/spring/*")
@IntegrationTest({ "server.servletPath:/spring/*", "server.port:0" })
@DirtiesContext @DirtiesContext
public class RemappedErrorViewIntegrationTests { public class RemappedErrorViewIntegrationTests {

View File

@ -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.SocketTargetServerConnection;
import org.springframework.boot.devtools.tunnel.server.StaticPortProvider; import org.springframework.boot.devtools.tunnel.server.StaticPortProvider;
import org.springframework.boot.devtools.tunnel.server.TargetServerConnection; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -61,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Phillip Webb * @author Phillip Webb
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class HttpTunnelIntegrationTests { public class HttpTunnelIntegrationTests {
@Autowired @Autowired

View File

@ -23,7 +23,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; 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.MockFilterChain;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; 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; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class HelloWebSecurityApplicationTests { public class HelloWebSecurityApplicationTests {
@Autowired @Autowired

View File

@ -71,7 +71,7 @@
<module name="AvoidStarImport" /> <module name="AvoidStarImport" />
<module name="AvoidStaticImport"> <module name="AvoidStaticImport">
<property name="excludes" <property name="excludes"
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" /> 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.*" />
</module> </module>
<module name="IllegalImport" /> <module name="IllegalImport" />
<module name="RedundantImport" /> <module name="RedundantImport" />

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -37,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleActuatorLog4J2ApplicationTests { public class SampleActuatorLog4J2ApplicationTests {

View File

@ -23,7 +23,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -38,7 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.port:0" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.port:0" })
@DirtiesContext @DirtiesContext
public class SampleActuatorUiApplicationPortTests { public class SampleActuatorUiApplicationPortTests {

View File

@ -23,7 +23,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleActuatorUiApplicationTests { public class SampleActuatorUiApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -40,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
@ActiveProfiles("endpoints") @ActiveProfiles("endpoints")
public class EndpointsPropertiesSampleActuatorApplicationTests { public class EndpointsPropertiesSampleActuatorApplicationTests {

View File

@ -25,7 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -40,8 +41,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.port=0", "management.context-path=/admin", @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.security.enabled=false" }, randomPort = true) "management.port=0", "management.context-path=/admin",
"management.security.enabled=false" })
@DirtiesContext @DirtiesContext
public class InsecureManagementPortAndPathSampleActuatorApplicationTests { public class InsecureManagementPortAndPathSampleActuatorApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -39,7 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.security.enabled:false" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.security.enabled:false" })
@DirtiesContext @DirtiesContext
@ActiveProfiles("unsecure-management") @ActiveProfiles("unsecure-management")
public class InsecureManagementSampleActuatorApplicationTests { public class InsecureManagementSampleActuatorApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -38,7 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "security.basic.enabled:false" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"security.basic.enabled:false" })
@DirtiesContext @DirtiesContext
public class InsecureSampleActuatorApplicationTests { public class InsecureSampleActuatorApplicationTests {

View File

@ -23,7 +23,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -38,8 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.port=0", "management.address=127.0.0.1", @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.context-path:/admin" }, randomPort = true) "management.port=0", "management.address=127.0.0.1",
"management.context-path:/admin" })
@DirtiesContext @DirtiesContext
public class ManagementAddressActuatorApplicationTests { public class ManagementAddressActuatorApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -37,7 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.context_path=/admin" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.context_path=/admin" })
@DirtiesContext @DirtiesContext
public class ManagementPathSampleActuatorApplicationTests { public class ManagementPathSampleActuatorApplicationTests {

View File

@ -25,7 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -40,8 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.port=0", @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.context-path=/admin" }, randomPort = true) "management.port=0", "management.context-path=/admin" })
@DirtiesContext @DirtiesContext
public class ManagementPortAndPathSampleActuatorApplicationTests { public class ManagementPortAndPathSampleActuatorApplicationTests {

View File

@ -25,7 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -40,7 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.port=0" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.port=0" })
@DirtiesContext @DirtiesContext
public class ManagementPortSampleActuatorApplicationTests { public class ManagementPortSampleActuatorApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -39,7 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.port=-1" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.port=-1" })
@DirtiesContext @DirtiesContext
public class NoManagementSampleActuatorApplicationTests { public class NoManagementSampleActuatorApplicationTests {

View File

@ -20,7 +20,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -35,7 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Phillip Webb * @author Phillip Webb
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "endpoints.health.sensitive=false" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"endpoints.health.sensitive=false" })
@DirtiesContext @DirtiesContext
public class NonSensitiveHealthTests { public class NonSensitiveHealthTests {

View File

@ -27,7 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleActuatorApplicationTests { public class SampleActuatorApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -38,8 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "security.basic.enabled:false", @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"server.servletPath:/spring" }, randomPort = true) "security.basic.enabled:false", "server.servletPath:/spring" })
@DirtiesContext @DirtiesContext
public class ServletPathInsecureSampleActuatorApplicationTests { public class ServletPathInsecureSampleActuatorApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -37,7 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "server.servletPath=/spring" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"server.servletPath=/spring" })
@DirtiesContext @DirtiesContext
public class ServletPathSampleActuatorApplicationTests { public class ServletPathSampleActuatorApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class ShutdownSampleActuatorApplicationTests { public class ShutdownSampleActuatorApplicationTests {

View File

@ -31,7 +31,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.context.web.LocalServerPort;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(SampleAtmosphereApplication.class) @SpringApplicationConfiguration(SampleAtmosphereApplication.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleAtmosphereApplicationTests { public class SampleAtmosphereApplicationTests {

View File

@ -22,7 +22,7 @@ import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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.boot.test.rule.OutputCapture;
import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestExecutionListeners.MergeMode; import org.springframework.test.context.TestExecutionListeners.MergeMode;
@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS, listeners = { @TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS, listeners = {
OrderedCassandraTestExecutionListener.class }) OrderedCassandraTestExecutionListener.class })
@IntegrationTest("spring.data.cassandra.port=9142") @SpringApplicationTest("spring.data.cassandra.port=9142")
@CassandraDataSet(keyspace = "mykeyspace", value = "setup.cql") @CassandraDataSet(keyspace = "mykeyspace", value = "setup.cql")
@EmbeddedCassandra(timeout = 60000) @EmbeddedCassandra(timeout = 60000)
public class SampleCassandraApplicationTests { public class SampleCassandraApplicationTests {

View File

@ -20,7 +20,7 @@ import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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.boot.test.rule.OutputCapture;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@IntegrationTest @SpringApplicationTest
public class SampleMongoApplicationTests { public class SampleMongoApplicationTests {
@ClassRule @ClassRule

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
@ -35,7 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleHateoasApplicationTests { public class SampleHateoasApplicationTests {
@LocalServerPort @LocalServerPort

View File

@ -23,7 +23,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
@ -35,7 +36,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = { "management.context-path=" }, randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.context-path=" })
public class SampleHypermediaUiApplicationTests { public class SampleHypermediaUiApplicationTests {
@LocalServerPort @LocalServerPort

View File

@ -23,7 +23,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
@ -35,7 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleHypermediaApplicationHomePageTests { public class SampleHypermediaApplicationHomePageTests {
@LocalServerPort @LocalServerPort

View File

@ -20,7 +20,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -30,7 +31,7 @@ import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleJerseyApplicationTests { public class SampleJerseyApplicationTests {
@LocalServerPort @LocalServerPort

View File

@ -20,14 +20,15 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleJersey1ApplicationTests { public class SampleJersey1ApplicationTests {
@LocalServerPort @LocalServerPort

View File

@ -25,7 +25,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -41,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleJettySslApplicationTests { public class SampleJettySslApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleJettyApplicationTests { public class SampleJettyApplicationTests {

View File

@ -25,7 +25,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -41,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleJetty8SslApplicationTests { public class SampleJetty8SslApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleJetty8ApplicationTests { public class SampleJetty8ApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleJetty93ApplicationTests { public class SampleJetty93ApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.GaugeService; 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.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@ -34,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleDropwizardMetricsApplicationTests { public class SampleDropwizardMetricsApplicationTests {

View File

@ -19,7 +19,8 @@ package sample.metrics.opentsdb;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@ -29,7 +30,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleOpenTsdbExportApplicationTests { public class SampleOpenTsdbExportApplicationTests {

View File

@ -19,7 +19,8 @@ package sample.metrics.redis;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@ -29,7 +30,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(value = "spring.jmx.enabled=true", randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.jmx.enabled=true")
@DirtiesContext @DirtiesContext
public class SampleRedisExportApplicationTests { public class SampleRedisExportApplicationTests {

View File

@ -21,7 +21,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; 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.hateoas.MediaTypes;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.FilterChainProxy; import org.springframework.security.web.FilterChainProxy;
@ -41,7 +42,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC
* @author Greg Turnquist * @author Greg Turnquist
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleSecureOAuth2ResourceApplicationTests { public class SampleSecureOAuth2ResourceApplicationTests {
@Autowired @Autowired

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; 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.hateoas.MediaTypes;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.codec.Base64; import org.springframework.security.crypto.codec.Base64;
@ -49,7 +50,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC
* @author Greg Turnquist * @author Greg Turnquist
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleSecureOAuth2ApplicationTests { public class SampleSecureOAuth2ApplicationTests {
@Autowired @Autowired

View File

@ -22,7 +22,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -37,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleServletApplicationTests { public class SampleServletApplicationTests {

View File

@ -20,7 +20,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; 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.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@IntegrationTest @SpringApplicationTest
public class SpringTestSampleSimpleApplicationTests { public class SpringTestSampleSimpleApplicationTests {
@Autowired @Autowired

View File

@ -25,7 +25,8 @@ import sample.test.service.VehicleDetailsService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestDatabase; 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.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@ -38,7 +39,7 @@ import static org.mockito.BDDMockito.given;
* @author Phillip Webb * @author Phillip Webb
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureTestDatabase @AutoConfigureTestDatabase
public class SampleTestApplicationWebIntegrationTests { public class SampleTestApplicationWebIntegrationTests {

View File

@ -19,7 +19,8 @@ package sample.testng;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -33,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
@WebIntegrationTest("server.port:0") @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTests { public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTests {

View File

@ -20,7 +20,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Phillip Webb * @author Phillip Webb
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebJspApplicationTests { public class SampleWebJspApplicationTests {

View File

@ -32,7 +32,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.web.LocalServerPort; 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.context.ApplicationContext;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -50,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleTomcatTwoConnectorsApplicationTests { public class SampleTomcatTwoConnectorsApplicationTests {

View File

@ -25,7 +25,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -36,7 +37,7 @@ import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleTomcatSslApplicationTests { public class SampleTomcatSslApplicationTests {

View File

@ -29,7 +29,8 @@ import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfi
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class NonAutoConfigurationSampleTomcatApplicationTests { public class NonAutoConfigurationSampleTomcatApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleTomcatApplicationTests { public class SampleTomcatApplicationTests {

View File

@ -20,7 +20,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Phillip Webb * @author Phillip Webb
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebJspApplicationTests { public class SampleWebJspApplicationTests {

View File

@ -20,7 +20,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleTraditionalApplicationTests { public class SampleTraditionalApplicationTests {

View File

@ -25,7 +25,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -41,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Ivan Sopov * @author Ivan Sopov
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleUndertowSslApplicationTests { public class SampleUndertowSslApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleUndertowApplicationTests { public class SampleUndertowApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebFreeMarkerApplicationTests { public class SampleWebFreeMarkerApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleGroovyTemplateApplicationTests { public class SampleGroovyTemplateApplicationTests {

View File

@ -20,7 +20,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -35,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Phillip Webb * @author Phillip Webb
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebJspApplicationTests { public class SampleWebJspApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleMethodSecurityApplicationTests { public class SampleMethodSecurityApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebMustacheApplicationTests { public class SampleWebMustacheApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebSecureCustomApplicationTests { public class SampleWebSecureCustomApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -38,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleGithubApplicationTests { public class SampleGithubApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebSecureCustomApplicationTests { public class SampleWebSecureCustomApplicationTests {

View File

@ -24,7 +24,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -45,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleSecureApplicationTests { public class SampleSecureApplicationTests {

View File

@ -20,7 +20,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -36,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebStaticApplicationTests { public class SampleWebStaticApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Dave Syer * @author Dave Syer
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebUiApplicationTests { public class SampleWebUiApplicationTests {

View File

@ -22,7 +22,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -42,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson * @author Andy Wilkinson
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebVelocityApplicationTests { public class SampleWebVelocityApplicationTests {

View File

@ -34,7 +34,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.context.web.LocalServerPort;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(SampleJettyWebSocketsApplication.class) @SpringApplicationConfiguration(SampleJettyWebSocketsApplication.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebSocketsApplicationTests { public class SampleWebSocketsApplicationTests {

View File

@ -37,7 +37,8 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration({ SampleJettyWebSocketsApplication.class, @SpringApplicationConfiguration({ SampleJettyWebSocketsApplication.class,
CustomContainerConfiguration.class }) CustomContainerConfiguration.class })
@WebIntegrationTest @SpringApplicationTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@DirtiesContext @DirtiesContext
public class CustomContainerWebSocketsApplicationTests { public class CustomContainerWebSocketsApplicationTests {

View File

@ -34,7 +34,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.context.web.LocalServerPort;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(SampleTomcatWebSocketApplication.class) @SpringApplicationConfiguration(SampleTomcatWebSocketApplication.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebSocketsApplicationTests { public class SampleWebSocketsApplicationTests {

View File

@ -37,7 +37,8 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration({ SampleTomcatWebSocketApplication.class, @SpringApplicationConfiguration({ SampleTomcatWebSocketApplication.class,
CustomContainerConfiguration.class }) CustomContainerConfiguration.class })
@WebIntegrationTest @SpringApplicationTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@DirtiesContext @DirtiesContext
public class CustomContainerWebSocketsApplicationTests { public class CustomContainerWebSocketsApplicationTests {

View File

@ -34,7 +34,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.context.web.LocalServerPort;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -47,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration(SampleUndertowWebSocketsApplication.class) @SpringApplicationConfiguration(SampleUndertowWebSocketsApplication.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext @DirtiesContext
public class SampleWebSocketsApplicationTests { public class SampleWebSocketsApplicationTests {

View File

@ -37,7 +37,8 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.boot.test.context.SpringApplicationConfiguration; 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.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -52,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringApplicationConfiguration({ SampleUndertowWebSocketsApplication.class, @SpringApplicationConfiguration({ SampleUndertowWebSocketsApplication.class,
CustomContainerConfiguration.class }) CustomContainerConfiguration.class })
@WebIntegrationTest @SpringApplicationTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@DirtiesContext @DirtiesContext
public class CustomContainerWebSocketsApplicationTests { public class CustomContainerWebSocketsApplicationTests {

View File

@ -27,7 +27,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.context.web.LocalServerPort; 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.boot.test.rule.OutputCapture;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.ws.client.core.WebServiceTemplate; 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; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebIntegrationTest(randomPort = true) @SpringApplicationTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleWsApplicationTests { public class SampleWsApplicationTests {
@Rule @Rule

View File

@ -23,8 +23,13 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; 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.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 * 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 * @author Dave Syer
* @see WebIntegrationTest * @see WebIntegrationTest
* @deprecated since 1.4.0 in favor of * @deprecated since 1.4.0 in favor of {@link SpringApplicationTest}
* {@link org.springframework.boot.test.context.IntegrationTest}
*/ */
@Documented @Documented
@Inherited @Inherited
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @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 @Deprecated
public @interface IntegrationTest { public @interface IntegrationTest {
@ -52,7 +61,6 @@ public @interface IntegrationTest {
* {@link Environment} before the test runs. * {@link Environment} before the test runs.
* @return the environment properties * @return the environment properties
*/ */
@AliasFor(annotation = org.springframework.boot.test.context.IntegrationTest.class, attribute = "value")
String[] value() default {}; String[] value() default {};
} }

View File

@ -16,7 +16,6 @@
package org.springframework.boot.test; package org.springframework.boot.test;
import org.springframework.boot.test.context.IntegrationTest;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationAttributes;

View File

@ -20,7 +20,6 @@ import java.util.Arrays;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import org.springframework.boot.test.context.web.WebIntegrationTest;
import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;

View File

@ -42,11 +42,11 @@ import org.springframework.test.context.ContextConfiguration;
* @deprecated since 1.4.0 in favor of * @deprecated since 1.4.0 in favor of
* {@link org.springframework.boot.test.context.SpringApplicationConfiguration} * {@link org.springframework.boot.test.context.SpringApplicationConfiguration}
*/ */
@ContextConfiguration(loader = SpringApplicationContextLoader.class)
@Documented @Documented
@Inherited @Inherited
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@org.springframework.boot.test.context.SpringApplicationConfiguration
@Deprecated @Deprecated
public @interface SpringApplicationConfiguration { public @interface SpringApplicationConfiguration {
@ -55,7 +55,7 @@ public @interface SpringApplicationConfiguration {
* @see ContextConfiguration#classes() * @see ContextConfiguration#classes()
* @return the context configuration classes * @return the context configuration classes
*/ */
@AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "value") @AliasFor("classes")
Class<?>[] value() default {}; Class<?>[] value() default {};
/** /**
@ -63,7 +63,7 @@ public @interface SpringApplicationConfiguration {
* @see ContextConfiguration#locations() * @see ContextConfiguration#locations()
* @return the context configuration 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 {}; String[] locations() default {};
/** /**
@ -71,7 +71,7 @@ public @interface SpringApplicationConfiguration {
* @see ContextConfiguration#classes() * @see ContextConfiguration#classes()
* @return the context configuration classes * @return the context configuration classes
*/ */
@AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "classes") @AliasFor("value")
Class<?>[] classes() default {}; Class<?>[] classes() default {};
/** /**
@ -79,7 +79,7 @@ public @interface SpringApplicationConfiguration {
* @see ContextConfiguration#initializers() * @see ContextConfiguration#initializers()
* @return the context configuration initializers * @return the context configuration initializers
*/ */
@AliasFor(annotation = org.springframework.boot.test.context.SpringApplicationConfiguration.class, attribute = "initializers") @AliasFor(annotation = ContextConfiguration.class, attribute = "initializers")
Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers() default {}; Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers() default {};
/** /**
@ -87,7 +87,7 @@ public @interface SpringApplicationConfiguration {
* @see ContextConfiguration#inheritLocations() * @see ContextConfiguration#inheritLocations()
* @return {@code true} if context locations should be inherited * @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; boolean inheritLocations() default true;
/** /**
@ -95,7 +95,7 @@ public @interface SpringApplicationConfiguration {
* @see ContextConfiguration#inheritInitializers() * @see ContextConfiguration#inheritInitializers()
* @return {@code true} if context initializers should be inherited * @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; boolean inheritInitializers() default true;
/** /**
@ -103,7 +103,7 @@ public @interface SpringApplicationConfiguration {
* @see ContextConfiguration#name() * @see ContextConfiguration#name()
* @return the name of the context hierarchy level * @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 ""; String name() default "";
} }

View File

@ -16,15 +16,46 @@
package org.springframework.boot.test; 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.SpringApplication;
import org.springframework.boot.context.web.ServletContextApplicationContextInitializer;
import org.springframework.boot.test.context.SpringApplicationTest; 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.mock.web.MockServletContext;
import org.springframework.test.context.ContextConfigurationAttributes;
import org.springframework.test.context.ContextLoader; 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 * 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 * 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.
* <p> * <p>
* Use {@code @WebIntegrationTest} (or {@code @IntegrationTest} with * Use {@code @WebIntegrationTest} (or {@code @IntegrationTest} with
* {@code @WebAppConfiguration}) to indicate that you want to use a real servlet container * {@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 Phillip Webb
* @author Andy Wilkinson * @author Andy Wilkinson
* @see org.springframework.boot.test.context.SpringApplicationTest * @see org.springframework.boot.test.context.SpringApplicationTest
* @see org.springframework.boot.test.context.IntegrationTest * @see org.springframework.boot.test.IntegrationTest
* @see org.springframework.boot.test.context.web.WebIntegrationTest * @see org.springframework.boot.test.WebIntegrationTest
* @deprecated since 1.4.0 in favor of * @deprecated since 1.4.0 in favor of
* {@link SpringApplicationTest @SpringApplicationTest}, * {@link SpringApplicationTest @SpringApplicationTest}
* {@link org.springframework.boot.test.context.IntegrationTest @IntegrationTest},
* {@link org.springframework.boot.test.context.web.WebIntegrationTest @WebIntegrationTest}
* annotations.
* {@link org.springframework.boot.test.context.SpringApplicationContextLoader} can also * {@link org.springframework.boot.test.context.SpringApplicationContextLoader} can also
* be considered if absolutely necessary. * be considered if absolutely necessary.
*/ */
@Deprecated @Deprecated
public class SpringApplicationContextLoader public class SpringApplicationContextLoader extends AbstractContextLoader {
extends org.springframework.boot.test.context.SpringApplicationContextLoader {
@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<String, Object> properties = getEnvironmentProperties(config);
addProperties(environment, properties);
application.setEnvironment(environment);
List<ApplicationContextInitializer<?>> 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<Object> getSources(MergedContextConfiguration mergedConfig) {
Set<Object> sources = new LinkedHashSet<Object>();
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<String, Object> getEnvironmentProperties(
MergedContextConfiguration config) {
Map<String, Object> properties = new LinkedHashMap<String, Object>();
// 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<String, Object> properties) {
properties.put("spring.jmx.enabled", "false");
}
private Map<String, String> getDefaultEnvironmentProperties() {
return Collections.singletonMap("server.port", "-1");
}
private void addProperties(ConfigurableEnvironment environment,
Map<String, Object> 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<ApplicationContextInitializer<?>> getInitializers(
MergedContextConfiguration mergedConfig, SpringApplication application) {
List<ApplicationContextInitializer<?>> initializers = new ArrayList<ApplicationContextInitializer<?>>();
initializers.add(new PropertySourceLocationsInitializer(
mergedConfig.getPropertySourceLocations()));
initializers.addAll(application.getInitializers());
for (Class<? extends ApplicationContextInitializer<?>> 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<GenericWebApplicationContext> WEB_CONTEXT_CLASS = GenericWebApplicationContext.class;
void configure(MergedContextConfiguration configuration,
SpringApplication application,
List<ApplicationContextInitializer<?>> initializers) {
if (!TestAnnotations.isIntegrationTest(configuration)) {
WebMergedContextConfiguration webConfiguration = (WebMergedContextConfiguration) configuration;
addMockServletContext(initializers, webConfiguration);
application.setApplicationContextClass(WEB_CONTEXT_CLASS);
}
}
private void addMockServletContext(
List<ApplicationContextInitializer<?>> 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<ConfigurableApplicationContext> {
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<? extends Annotation> annotation) {
return (AnnotationUtils.findAnnotation(configuration.getTestClass(),
annotation) != null);
}
}
} }

View File

@ -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<? extends ContextLoader> 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;
}
}

View File

@ -24,8 +24,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.boot.context.web.LocalServerPort; import org.springframework.boot.context.web.LocalServerPort;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.test.context.BootstrapWith;
/** /**
* Test class annotation signifying that the tests are "web integration tests" and * 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 * @since 1.2.1
* @see IntegrationTest * @see IntegrationTest
* @deprecated since 1.4.0 in favor of * @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 @Documented
@Inherited @Inherited
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@org.springframework.boot.test.context.web.WebIntegrationTest @BootstrapWith(WebAppIntegrationTestContextBootstrapper.class)
@Deprecated @Deprecated
public @interface WebIntegrationTest { public @interface WebIntegrationTest {
@ -55,7 +56,6 @@ public @interface WebIntegrationTest {
* {@link Environment} before the test runs. * {@link Environment} before the test runs.
* @return properties to add to the context * @return properties to add to the context
*/ */
@AliasFor(annotation = org.springframework.boot.test.context.web.WebIntegrationTest.class, attribute = "value")
String[] value() default {}; String[] value() default {};
/** /**
@ -65,7 +65,6 @@ public @interface WebIntegrationTest {
* test. * test.
* @return if a random port should be used * @return if a random port should be used
*/ */
@AliasFor(annotation = org.springframework.boot.test.context.web.WebIntegrationTest.class, attribute = "randomPort")
boolean randomPort() default false; boolean randomPort() default false;
} }

View File

@ -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.
* <p>
* 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 {};
}

Some files were not shown because too many files have changed in this diff Show More