From 54bea725543c37d1659b9a033e835fa717d20fea Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 29 Mar 2016 14:36:52 +0200 Subject: [PATCH] Polish Jersey integration tests --- ...nfigurationCustomFilterContextPathTests.java | 17 ++++++----------- ...yAutoConfigurationCustomFilterPathTests.java | 17 ++++++----------- ...gurationCustomObjectMapperProviderTests.java | 17 ++++++----------- ...figurationCustomServletContextPathTests.java | 17 ++++++----------- ...AutoConfigurationCustomServletPathTests.java | 17 ++++++----------- ...AutoConfigurationDefaultFilterPathTests.java | 17 ++++++----------- ...utoConfigurationDefaultServletPathTests.java | 17 ++++++----------- ...oConfigurationObjectMapperProviderTests.java | 17 ++++++----------- ...yAutoConfigurationServletContainerTests.java | 10 ++-------- ...onfigurationWithoutApplicationPathTests.java | 17 ++++++----------- 10 files changed, 56 insertions(+), 107 deletions(-) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java index e48dc3f0d2..7d2d395b5d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java @@ -30,22 +30,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomFilterContextPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -58,20 +56,17 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest({ "server.port=0", "spring.jersey.type=filter", +@WebIntegrationTest(randomPort = true, value = {"spring.jersey.type=filter", "server.contextPath=/app" }) -@WebAppConfiguration public class JerseyAutoConfigurationCustomFilterContextPathTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/app/rest/hello", String.class); + "/app/rest/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java index c93fe107ac..75b2b874aa 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java @@ -30,22 +30,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomFilterPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -58,19 +56,16 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest({ "server.port=0", "spring.jersey.type=filter" }) -@WebAppConfiguration +@WebIntegrationTest(randomPort = true, value = "spring.jersey.type=filter") public class JerseyAutoConfigurationCustomFilterPathTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/rest/hello", String.class); + "/rest/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java index c3da9f7ca3..385a375cca 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java @@ -30,22 +30,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObjectMapperProviderTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -58,19 +56,16 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest({ "server.port=0", "spring.jackson.serialization-inclusion=non_null" }) -@WebAppConfiguration +@WebIntegrationTest(randomPort = true, value = "spring.jackson.serialization-inclusion=non_null") public class JerseyAutoConfigurationCustomObjectMapperProviderTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity response = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/rest/message", String.class); + "/rest/message", String.class); assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode()); assertThat("{\"subject\":\"Jersey\"}").isEqualTo(response.getBody()); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java index 5a5148e76c..6d996c9121 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java @@ -30,22 +30,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletContextPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -58,19 +56,16 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest({ "server.port=0", "server.contextPath=/app" }) -@WebAppConfiguration +@WebIntegrationTest(randomPort = true, value = "server.contextPath=/app") public class JerseyAutoConfigurationCustomServletContextPathTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/app/rest/hello", String.class); + "/app/rest/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java index 5dd6211311..6ecb35fca7 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java @@ -30,22 +30,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -58,19 +56,16 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest("server.port=0") -@WebAppConfiguration +@WebIntegrationTest(randomPort = true) public class JerseyAutoConfigurationCustomServletPathTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/rest/hello", String.class); + "/rest/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java index eb72e41398..c576b1ecc6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java @@ -29,22 +29,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefaultFilterPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -57,19 +55,16 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest({ "server.port=0", "spring.jersey.type=filter" }) -@WebAppConfiguration +@WebIntegrationTest(randomPort = true, value = "spring.jersey.type=filter") public class JerseyAutoConfigurationDefaultFilterPathTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity entity = this.restTemplate - .getForEntity("http://localhost:" + this.port + "/hello", String.class); + .getForEntity("/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java index f9de343157..2d99e6c8dc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java @@ -29,22 +29,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationDefaultServletPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -57,19 +55,16 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest("server.port=0") -@WebAppConfiguration +@WebIntegrationTest(randomPort = true) public class JerseyAutoConfigurationDefaultServletPathTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity entity = this.restTemplate - .getForEntity("http://localhost:" + this.port + "/hello", String.class); + .getForEntity("/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java index dd286c4dd4..597cf17694 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java @@ -30,22 +30,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationObjectMapperProviderTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -58,19 +56,16 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest("server.port=0") -@WebAppConfiguration +@WebIntegrationTest(randomPort = true) public class JerseyAutoConfigurationObjectMapperProviderTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity response = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/rest/message", String.class); + "/rest/message", String.class); assertThat(HttpStatus.OK).isEqualTo(response.getStatusCode()); assertThat("{\"subject\":\"Jersey\",\"body\":null}") .isEqualTo(response.getBody()); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java index 54dcc4f8c1..852efe8d27 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java @@ -34,16 +34,14 @@ import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationServ import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.web.LocalServerPort; -import org.springframework.boot.test.context.IntegrationTest; import org.springframework.boot.test.context.SpringApplicationConfiguration; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -56,16 +54,12 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest("server.port=0") -@WebAppConfiguration +@WebIntegrationTest(randomPort = true) public class JerseyAutoConfigurationServletContainerTests { @ClassRule public static OutputCapture output = new OutputCapture(); - @LocalServerPort - private int port; - @Test public void existingJerseyServletIsAmended() { assertThat(output.toString()) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java index e38768ddc7..d173d2dd87 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java @@ -29,22 +29,20 @@ import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationCustomServletPathTests.Application; import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -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.web.client.TestRestTemplate; +import org.springframework.boot.test.context.web.WebIntegrationTest; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -57,19 +55,16 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @DirtiesContext @SpringApplicationConfiguration(Application.class) -@IntegrationTest({ "server.port=0", "spring.jersey.application-path=/api" }) -@WebAppConfiguration +@WebIntegrationTest(randomPort = true, value = "spring.jersey.application-path=/api") public class JerseyAutoConfigurationWithoutApplicationPathTests { - @LocalServerPort - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); + @Autowired + private RestTemplate restTemplate; @Test public void contextLoads() { ResponseEntity entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/api/hello", String.class); + "/api/hello", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); }