diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/cors/CorsTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/cors/CorsTests.java index 9d3bee78..b722127c 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/cors/CorsTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/cors/CorsTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.cors; import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.boot.SpringBootConfiguration; @@ -32,13 +31,11 @@ import org.springframework.http.HttpMethod; 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.web.reactive.function.client.ClientResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class CorsTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/cors/SimpleUrlHandlerCorsTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/cors/SimpleUrlHandlerCorsTests.java index f986ee1f..7a6427ec 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/cors/SimpleUrlHandlerCorsTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/cors/SimpleUrlHandlerCorsTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.cors; import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.boot.SpringBootConfiguration; @@ -34,13 +33,11 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.ClientResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT, properties = "spring.cloud.gateway.globalcors.add-to-simple-url-handler-mapping=true") @DirtiesContext diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilterCustomTagsTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilterCustomTagsTests.java index 51e71c38..31b705c4 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilterCustomTagsTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilterCustomTagsTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.filter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -33,7 +32,6 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -42,10 +40,9 @@ import static org.springframework.cloud.gateway.config.GatewayMetricsProperties. /** * @author Ingyu Hwang */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext -public class GatewayMetricsFilterCustomTagsTests extends BaseWebClientTests { +class GatewayMetricsFilterCustomTagsTests extends BaseWebClientTests { private static final String REQUEST_METRICS_NAME = DEFAULT_PREFIX + ".requests"; @@ -56,7 +53,7 @@ public class GatewayMetricsFilterCustomTagsTests extends BaseWebClientTests { private String testUri; @Test - public void gatewayRequestsMeterFilterHasCustomTags() { + void gatewayRequestsMeterFilterHasCustomTags() { testClient.get().uri("/headers").exchange().expectStatus().isOk(); // default tags @@ -79,10 +76,10 @@ public class GatewayMetricsFilterCustomTagsTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class CustomConfig { + static class CustomConfig { @Bean - public GatewayTagsProvider customGatewayTagsProvider() { + GatewayTagsProvider customGatewayTagsProvider() { return exchange -> Tags.of("custom1", "tag1", "custom2", "tag2"); } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilterTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilterTests.java index e2ed2ab7..a75c89d0 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilterTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/GatewayMetricsFilterTests.java @@ -17,8 +17,7 @@ package org.springframework.cloud.gateway.filter; import io.micrometer.core.instrument.MeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -37,7 +36,6 @@ import org.springframework.http.HttpMethod; 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.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -45,7 +43,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.config.GatewayMetricsProperties.DEFAULT_PREFIX; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class GatewayMetricsFilterTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterCompatibleTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterCompatibleTests.java index bde33d62..d2c65518 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterCompatibleTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterCompatibleTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -27,7 +26,6 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.server.ServerWebExchange; import static org.assertj.core.api.Assertions.assertThat; @@ -41,7 +39,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * * @author echooymxq **/ -@RunWith(SpringRunner.class) @SpringBootTest(properties = { "spring.cloud.gateway.routes[0].id=route_connect_timeout", "spring.cloud.gateway.routes[0].uri=http://localhost:32167", "spring.cloud.gateway.routes[0].predicates[0].name=Path", @@ -53,16 +50,16 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen "spring.cloud.gateway.routes[1].filters[0]=StripPrefix=1", "spring.cloud.gateway.routes[1].metadata.response-timeout=1000" }, webEnvironment = RANDOM_PORT) @DirtiesContext -public class NettyRoutingFilterCompatibleTests extends BaseWebClientTests { +class NettyRoutingFilterCompatibleTests extends BaseWebClientTests { @Test - public void shouldApplyConnectTimeoutPerRoute() { + void shouldApplyConnectTimeoutPerRoute() { assertThat(NettyRoutingFilter.getInteger("5")).isEqualTo(5); assertThat(NettyRoutingFilter.getInteger(5)).isEqualTo(5); } @Test - public void shouldApplyResponseTimeoutPerRoute() { + void shouldApplyResponseTimeoutPerRoute() { testClient.get().uri("/route/delay/2").exchange().expectStatus().isEqualTo(HttpStatus.GATEWAY_TIMEOUT) .expectBody().jsonPath("$.status").isEqualTo(String.valueOf(HttpStatus.GATEWAY_TIMEOUT.value())) .jsonPath("$.message").isEqualTo("Response took longer than timeout: PT1S"); @@ -71,7 +68,7 @@ public class NettyRoutingFilterCompatibleTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterIntegrationTests.java index de965257..f86a0219 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterIntegrationTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +32,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.server.ServerWebExchange; @@ -43,7 +41,6 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(properties = "spring.cloud.gateway.httpclient.response-timeout=3s", webEnvironment = RANDOM_PORT) @DirtiesContext public class NettyRoutingFilterIntegrationTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.java index ddde7dcb..0415c332 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/NettyRoutingFilterTests.java @@ -17,11 +17,9 @@ package org.springframework.cloud.gateway.filter; import org.hamcrest.Matchers; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.netty.DisposableServer; import reactor.netty.http.server.HttpServer; @@ -37,33 +35,34 @@ import org.springframework.cloud.gateway.test.PermitAllSecurityConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.util.SocketUtils; -@RunWith(SpringRunner.class) +import static org.assertj.core.api.Assertions.assertThat; + @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class NettyRoutingFilterTests extends BaseWebClientTests { +class NettyRoutingFilterTests extends BaseWebClientTests { private static int port; @Autowired private ApplicationContext context; - @BeforeClass + @BeforeAll public static void beforeAll() { port = SocketUtils.findAvailableTcpPort(); } @Test - @Ignore - public void mockServerWorks() { + @Disabled + void mockServerWorks() { WebTestClient client = WebTestClient.bindToApplicationContext(this.context).build(); client.get().uri("/mockexample").exchange().expectStatus().value(Matchers.lessThan(500)); } - @Test // gh-2207 - public void testCaseInsensitiveScheme() { + @Test + // gh-2207 + void testCaseInsensitiveScheme() { DisposableServer server = HttpServer.create().port(port).host("127.0.0.1").route( routes -> routes.get("/issue", (request, response) -> response.sendString(Mono.just("issue2207")))) .bindNow(); @@ -71,10 +70,10 @@ public class NettyRoutingFilterTests extends BaseWebClientTests { try { testClient.get().uri("/issue").exchange().expectStatus().isOk().expectBody() .consumeWith(entityExchangeResult -> { - Assert.assertNotNull(entityExchangeResult); - Assert.assertNotNull(entityExchangeResult.getResponseBody()); + assertThat(entityExchangeResult).isNotNull(); + assertThat(entityExchangeResult.getResponseBody()).isNotNull(); String content = new String(entityExchangeResult.getResponseBody()); - Assert.assertEquals("issue2207", content); + assertThat(content).isEqualTo("issue2207"); }); } finally { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilterTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilterTests.java index 7770e975..892b339f 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilterTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/WeightCalculatorWebFilterTests.java @@ -22,7 +22,8 @@ import java.util.Map; import java.util.Random; import org.jetbrains.annotations.NotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; import org.springframework.cloud.gateway.event.PredicateArgsEvent; import org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter.GroupWeightConfig; @@ -34,6 +35,7 @@ import org.springframework.web.server.WebFilterChain; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.condition.JRE.JAVA_17; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -95,7 +97,9 @@ public class WeightCalculatorWebFilterTests { return "route" + i; } + // TODO: modify implementation for testability on JDK17 for Spring 6 @Test + @DisabledOnJre(JAVA_17) public void testChooseRouteWithRandom() { WeightCalculatorWebFilter filter = createFilter(); filter.addWeightConfig(new WeightConfig("groupa", "route1", 1)); diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java index f2e3a1b2..4e50b2ab 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.util.Arrays; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -35,7 +34,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -45,7 +43,6 @@ import static org.springframework.cloud.gateway.test.TestUtils.getMap; * @author Spencer Gibb * @author Biju Kunjummen */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @ActiveProfiles(profiles = "request-header-web-filter") diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java index f1332961..cdd5b089 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java @@ -21,8 +21,7 @@ import java.net.URI; import java.net.URLDecoder; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -37,7 +36,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.util.UriComponentsBuilder; import static org.assertj.core.api.Assertions.assertThat; @@ -45,7 +43,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.containsEncodedParts; import static org.springframework.cloud.gateway.test.TestUtils.getMap; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @ActiveProfiles(profiles = "request-parameter-web-filter") diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddResponseHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddResponseHeaderGatewayFilterFactoryTests.java index e050d35f..bc60ec68 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddResponseHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/AddResponseHeaderGatewayFilterFactoryTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.net.URI; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -33,19 +32,17 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.util.UriComponentsBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext -public class AddResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTests { +class AddResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTests { @Test - public void testResposneHeaderFilter() { + void testResposneHeaderFilter() { URI uri = UriComponentsBuilder.fromUriString(this.baseUri + "/headers").build(true).toUri(); String host = "www.addresponseheader.org"; String expectedValue = "Bar"; @@ -54,7 +51,7 @@ public class AddResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTes } @Test - public void testResposneHeaderFilterJavaDsl() { + void testResposneHeaderFilterJavaDsl() { URI uri = UriComponentsBuilder.fromUriString(this.baseUri + "/get").build(true).toUri(); String host = "www.addresponseheaderjava.org"; String expectedValue = "myresponsevalue-www"; @@ -62,7 +59,7 @@ public class AddResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTes } @Test - public void toStringFormat() { + void toStringFormat() { NameValueConfig config = new NameValueConfig().setName("myname").setValue("myvalue"); GatewayFilter filter = new AddResponseHeaderGatewayFilterFactory().apply(config); assertThat(filter.toString()).contains("myname").contains("myvalue"); @@ -71,7 +68,7 @@ public class AddResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTes @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { @Value("${test.uri}") String uri; diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/DedupeResponseHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/DedupeResponseHeaderGatewayFilterFactoryTests.java index 75d268f6..4179fceb 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/DedupeResponseHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/DedupeResponseHeaderGatewayFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -25,17 +24,15 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext -public class DedupeResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTests { +class DedupeResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTests { @Test - public void dedupeResponseHeaderFilterWorks() { + void dedupeResponseHeaderFilterWorks() { testClient.get().uri("/headers").header("Host", "www.deduperesponseheader.org").exchange().expectStatus().isOk() .expectHeader().valueEquals("Access-Control-Allow-Credentials", "true").expectHeader() .valueEquals("Access-Control-Allow-Origin", "https://musk.mars").expectHeader() @@ -46,7 +43,7 @@ public class DedupeResponseHeaderGatewayFilterFactoryTests extends BaseWebClient @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/MapRequestHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/MapRequestHeaderGatewayFilterFactoryTests.java index e9b836e3..65aed5be 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/MapRequestHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/MapRequestHeaderGatewayFilterFactoryTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -35,7 +34,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -44,14 +42,13 @@ import static org.springframework.cloud.gateway.test.TestUtils.getMap; /** * @author Tony Clarke */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @ActiveProfiles(profiles = "request-map-header-web-filter") -public class MapRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTests { +class MapRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTests { @Test - public void mapRequestHeaderFilterWorks() { + void mapRequestHeaderFilterWorks() { testClient.get().uri("/headers").header("Host", "www.maprequestheader.org").header("a", "tome").exchange() .expectBody(Map.class).consumeWith(result -> { Map headers = getMap(result.getResponseBody(), "headers"); @@ -60,7 +57,7 @@ public class MapRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTest } @Test - public void mapRequestHeaderFilterWorksJavaDsl() { + void mapRequestHeaderFilterWorksJavaDsl() { testClient.get().uri("/headers").header("Host", "www.maprequestheaderjava.org").header("b", "tome").exchange() .expectBody(Map.class).consumeWith(result -> { Map headers = getMap(result.getResponseBody(), "headers"); @@ -70,7 +67,7 @@ public class MapRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTest @SuppressWarnings("unchecked") @Test - public void mapRequestHeaderWithMultiValueFilterWorks() { + void mapRequestHeaderWithMultiValueFilterWorks() { testClient.get().uri("/multivalueheaders").header("Host", "www.maprequestheader.org") .header("a", "tome", "toyou").exchange().expectBody(Map.class).consumeWith(result -> { Map headers = getMap(result.getResponseBody(), "headers"); @@ -81,7 +78,7 @@ public class MapRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTest } @Test - public void mapRequestHeaderWithNullValueFilterWorks() { + void mapRequestHeaderWithNullValueFilterWorks() { testClient.get().uri("/headers").header("Host", "www.maprequestheader.org").header("a", (String) null) .exchange().expectBody(Map.class).consumeWith(result -> { Map headers = getMap(result.getResponseBody(), "headers"); @@ -90,7 +87,7 @@ public class MapRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTest } @Test - public void mapRequestHeaderWhenInputHeaderDoesNotExist() { + void mapRequestHeaderWhenInputHeaderDoesNotExist() { testClient.get().uri("/headers").header("Host", "www.maprequestheader.org").exchange().expectBody(Map.class) .consumeWith(result -> { Map headers = getMap(result.getResponseBody(), "headers"); @@ -99,7 +96,7 @@ public class MapRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTest } @Test - public void toStringFormat() { + void toStringFormat() { Config config = new Config().setFromHeader("myfromheader").setToHeader("mytoheader"); GatewayFilter filter = new MapRequestHeaderGatewayFilterFactory().apply(config); assertThat(filter.toString()).contains("myfromheader").contains("mytoheader"); @@ -108,13 +105,13 @@ public class MapRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTest @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { @Value("${test.uri}") String uri; @Bean - public RouteLocator testRouteLocator(RouteLocatorBuilder builder) { + RouteLocator testRouteLocator(RouteLocatorBuilder builder) { return builder.routes().route("map_request_header_java_test", r -> r.path("/headers").and().host("**.maprequestheaderjava.org") .filters(f -> f.prefixPath("/httpbin").mapRequestHeader("b", "X-Request-Example-Java")) diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/PreserveHostHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/PreserveHostHeaderGatewayFilterFactoryTests.java index c1c8e959..710f76e0 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/PreserveHostHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/PreserveHostHeaderGatewayFilterFactoryTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -33,7 +32,6 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -42,7 +40,6 @@ import static org.springframework.cloud.gateway.test.TestUtils.getMap; /** * @author Spencer Gibb */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class PreserveHostHeaderGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RedirectToGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RedirectToGatewayFilterFactoryTests.java index d9e5e0b5..d23f4965 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RedirectToGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RedirectToGatewayFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -32,12 +31,10 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RedirectToGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveRequestHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveRequestHeaderGatewayFilterFactoryTests.java index 349e753a..0da13c06 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveRequestHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveRequestHeaderGatewayFilterFactoryTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -29,13 +28,11 @@ import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFac import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.test.TestUtils.getMap; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RemoveRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveRequestParameterGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveRequestParameterGatewayFilterFactoryIntegrationTests.java index 8851ccf9..a067e12b 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveRequestParameterGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveRequestParameterGatewayFilterFactoryIntegrationTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -33,13 +32,11 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.test.TestUtils.getMap; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RemoveRequestParameterGatewayFilterFactoryIntegrationTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveResponseHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveResponseHeaderGatewayFilterFactoryTests.java index 010237cd..05a0fc4d 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveResponseHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RemoveResponseHeaderGatewayFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -27,12 +26,10 @@ import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFac import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RemoveResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestHeaderSizeGatewayFilterFactoryTest.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestHeaderSizeGatewayFilterFactoryTest.java index a5b0d4ea..c0dcf5d9 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestHeaderSizeGatewayFilterFactoryTest.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestHeaderSizeGatewayFilterFactoryTest.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -32,7 +31,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.unit.DataSize; import org.springframework.util.unit.DataUnit; @@ -43,7 +41,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Sakalya Deshpande */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RequestHeaderSizeGatewayFilterFactoryTest extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests.java index 59d784d1..315f921c 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests.java @@ -20,9 +20,8 @@ import java.net.URI; import java.util.Optional; import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -34,7 +33,6 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -42,7 +40,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen /** * @author Toshiaki Maki */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests extends BaseWebClientTests { @@ -51,7 +48,7 @@ public class RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests exten int port; @Test - @Ignore + @Disabled public void changeUriWorkWithProperties() { testClient.get().uri("/").header("Host", "www.changeuri.org") .header("X-CF-Forwarded-Url", "http://localhost:" + port + "/actuator/health").exchange() @@ -59,7 +56,7 @@ public class RequestHeaderToRequestUriGatewayFilterFactoryIntegrationTests exten } @Test - @Ignore + @Disabled public void changeUriWorkWithDsl() { testClient.get().uri("/").header("Host", "www.changeuri.org") .header("X-Next-Url", "http://localhost:" + port + "/actuator/health").exchange() diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestRateLimiterGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestRateLimiterGatewayFilterFactoryTests.java index 32d4b272..8f7b825b 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestRateLimiterGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestRateLimiterGatewayFilterFactoryTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.util.Collections; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Autowired; @@ -45,7 +44,6 @@ import org.springframework.http.HttpStatus; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.web.server.MockServerWebExchange; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @@ -57,7 +55,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * * @author Spencer Gibb */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RequestRateLimiterGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestSizeGatewayFilterFactoryTest.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestSizeGatewayFilterFactoryTest.java index 2c3b7f2a..2dd2adc3 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestSizeGatewayFilterFactoryTest.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RequestSizeGatewayFilterFactoryTest.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -32,7 +31,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.unit.DataSize; import static org.assertj.core.api.Assertions.assertThat; @@ -42,7 +40,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen * @author Arpan Das */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RequestSizeGatewayFilterFactoryTest extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java index 10a560b9..16b9ad8d 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RetryGatewayFilterFactoryIntegrationTests.java @@ -25,16 +25,16 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hamcrest.CoreMatchers; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.system.OutputCaptureRule; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.client.DefaultServiceInstance; import org.springframework.cloud.gateway.filter.GatewayFilter; @@ -53,7 +53,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -62,7 +61,6 @@ import org.springframework.web.bind.annotation.RestController; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT, properties = { "spring.cloud.gateway.httpclient.connect-timeout=500", "spring.cloud.gateway.httpclient.response-timeout=2s", @@ -72,11 +70,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen // https://github.com/spring-cloud/spring-cloud-gateway/issues/1315, // so we use only PrefixPath filter @ActiveProfiles("retrytests") +@ExtendWith(OutputCaptureExtension.class) public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTests { - @Rule - public final OutputCaptureRule capture = new OutputCaptureRule(); - @Test public void retryFilterGet() { testClient.get().uri("/retry?key=get").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("3"); @@ -110,11 +106,11 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest } @Test - public void retryFilterPost() { + public void retryFilterPost(CapturedOutput output) { testClient.post().uri("/retrypost?key=postconfig&expectedbody=HelloConfig") .header(HttpHeaders.HOST, "www.retrypostconfig.org").bodyValue("HelloConfig").exchange().expectStatus() .isOk().expectBody(String.class).isEqualTo("3"); - assertThat(this.capture.toString()).contains("disposing response connection before next iteration"); + assertThat(output).contains("disposing response connection before next iteration"); } @Test @@ -124,12 +120,12 @@ public class RetryGatewayFilterFactoryIntegrationTests extends BaseWebClientTest } @Test - public void retryFilterPostOneTime() { + public void retryFilterPostOneTime(CapturedOutput output) { testClient.post().uri("/retrypost?key=retryFilterPostOneTime&expectedbody=HelloGateway&count=1") .header(HttpHeaders.HOST, "www.retrypostonceconfig.org").bodyValue("HelloGateway").exchange() .expectStatus().isOk(); - assertThat(this.capture.toString()).contains("setting new iteration in attr 0"); - assertThat(this.capture.toString()).doesNotContain("setting new iteration in attr 1"); + assertThat(output).contains("setting new iteration in attr 0"); + assertThat(output).doesNotContain("setting new iteration in attr 1"); } @Test diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewriteLocationResponseHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewriteLocationResponseHeaderGatewayFilterFactoryTests.java index 01345eca..318a1033 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewriteLocationResponseHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewriteLocationResponseHeaderGatewayFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -25,11 +24,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RewriteLocationResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactoryIntegrationTests.java index 0aa27cdf..414c61a5 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactoryIntegrationTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -25,11 +24,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RewritePathGatewayFilterFactoryIntegrationTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewriteResponseHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewriteResponseHeaderGatewayFilterFactoryTests.java index 6451620e..db65493f 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewriteResponseHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/RewriteResponseHeaderGatewayFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -25,11 +24,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class RewriteResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SaveSessionGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SaveSessionGatewayFilterFactoryTests.java index 5de82d62..74c7aab1 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SaveSessionGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SaveSessionGatewayFilterFactoryTests.java @@ -20,8 +20,7 @@ import java.time.Duration; import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -34,7 +33,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.server.WebSession; import org.springframework.web.server.session.WebSessionManager; @@ -47,7 +45,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen /** * @author Greg Turnquist */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @ActiveProfiles(profiles = "save-session-web-filter") diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SecureHeadersGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SecureHeadersGatewayFilterFactoryTests.java index 8049416b..c2886f74 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SecureHeadersGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SecureHeadersGatewayFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -30,7 +29,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.ClientResponse; import static org.assertj.core.api.Assertions.assertThat; @@ -45,7 +43,6 @@ import static org.springframework.cloud.gateway.filter.factory.SecureHeadersGate import static org.springframework.cloud.gateway.filter.factory.SecureHeadersGatewayFilterFactory.X_XSS_PROTECTION_HEADER; import static org.springframework.cloud.gateway.test.TestUtils.assertStatus; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class SecureHeadersGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactoryIntegrationTests.java index 1fc0c78b..c58a57c6 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactoryIntegrationTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -25,11 +24,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class SetPathGatewayFilterFactoryIntegrationTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetRequestHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetRequestHeaderGatewayFilterFactoryTests.java index fb3fd1f1..f3386d34 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetRequestHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetRequestHeaderGatewayFilterFactoryTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -33,7 +32,6 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -43,7 +41,6 @@ import static org.springframework.cloud.gateway.test.TestUtils.getMap; * @author Spencer Gibb * @author Biju Kunjummen */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class SetRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetRequestHostHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetRequestHostHeaderGatewayFilterFactoryTests.java index 19ba6a1e..416f9ec0 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetRequestHostHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetRequestHostHeaderGatewayFilterFactoryTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.filter.factory; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -28,13 +27,11 @@ import org.springframework.cloud.gateway.filter.GatewayFilter; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.test.TestUtils.getMap; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class SetRequestHostHeaderGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetResponseHeaderGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetResponseHeaderGatewayFilterFactoryTests.java index a31e15ee..8f72d577 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetResponseHeaderGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetResponseHeaderGatewayFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -31,12 +30,10 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class SetResponseHeaderGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetStatusGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetStatusGatewayFilterFactoryTests.java index 3ab2ee7f..59c46287 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetStatusGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SetStatusGatewayFilterFactoryTests.java @@ -17,8 +17,7 @@ package org.springframework.cloud.gateway.filter.factory; import org.hamcrest.Matchers; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -39,13 +38,11 @@ import org.springframework.http.HttpMethod; 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.web.reactive.server.WebTestClient; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class SetStatusGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java index dfd32e63..0923348f 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerFilterFactoryTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.http.HttpStatus; diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java index bb201e41..bdda74aa 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/SpringCloudCircuitBreakerResilience4JFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringBootConfiguration; @@ -34,7 +33,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.function.BodyInserters; @@ -45,7 +43,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen /** * @author Ryan Baxter */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT, properties = { "debug=true", "spring.cloud.circuitbreaker.hystrix.enabled=false" }) @ContextConfiguration(classes = SpringCloudCircuitBreakerResilience4JFilterFactoryTests.Config.class) diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactoryIntegrationTests.java index dc9bb966..cb81dfd9 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/StripPrefixGatewayFilterFactoryIntegrationTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -25,14 +24,12 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; /** * @author Ryan Baxter */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class StripPrefixGatewayFilterFactoryIntegrationTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java index 6c25e6eb..14c7aa70 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactorySslTimeoutTests.java @@ -63,7 +63,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen "spring.main.allow-bean-definition-overriding=true" }) @DirtiesContext @ActiveProfiles("single-cert-ssl") -public class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWebClientTests { +class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWebClientTests { @Autowired AtomicInteger releaseCount; @@ -82,7 +82,7 @@ public class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWe } @Test - public void modifyRequestBodySSLTimeout() { + void modifyRequestBodySSLTimeout() { testClient.post().uri("/post").header("Host", "www.modifyrequestbodyssltimeout.org") .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) .body(BodyInserters.fromValue("request")).exchange().expectStatus() @@ -91,7 +91,7 @@ public class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWe } @RetryingTest(3) - public void modifyRequestBodyRelease() { + void modifyRequestBodyRelease() { releaseCount.set(0); // long initialUsedDirectMemory = PlatformDependent.usedDirectMemory(); for (int i = 0; i < 10; i++) { @@ -107,7 +107,7 @@ public class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWe } @Test - public void modifyRequestBodyHappenedError() { + void modifyRequestBodyHappenedError() { testClient.post().uri("/post").header("Host", "www.modifyrequestbodyexception.org") .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) .body(BodyInserters.fromValue("request")).exchange().expectStatus() @@ -118,14 +118,14 @@ public class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWe @EnableAutoConfiguration @SpringBootConfiguration(proxyBeanMethods = false) @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { @Value("${test.uri}") String uri; @Bean @DependsOn("testModifyRequestBodyGatewayFilterFactory") - public RouteLocator testRouteLocator(RouteLocatorBuilder builder) { + RouteLocator testRouteLocator(RouteLocatorBuilder builder) { return builder.routes() .route("test_modify_request_body_ssl_timeout", r -> r.order(-1).host("**.modifyrequestbodyssltimeout.org") @@ -146,13 +146,13 @@ public class ModifyRequestBodyGatewayFilterFactorySslTimeoutTests extends BaseWe } @Bean - public AtomicInteger count() { + AtomicInteger count() { return new AtomicInteger(); } @Bean @Primary - public ModifyRequestBodyGatewayFilterFactory testModifyRequestBodyGatewayFilterFactory( + ModifyRequestBodyGatewayFilterFactory testModifyRequestBodyGatewayFilterFactory( ServerCodecConfigurer codecConfigurer, AtomicInteger count) { return new ModifyRequestBodyGatewayFilterFactory(codecConfigurer.getReaders()) { @Override diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactoryTests.java index 4fd7660e..90fd2917 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyRequestBodyGatewayFilterFactoryTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.factory.rewrite; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Value; @@ -33,7 +32,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.BodyInserters; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -41,7 +39,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen /** * @author Junghoon Song */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT, properties = "spring.codec.max-in-memory-size=13") @DirtiesContext public class ModifyRequestBodyGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryGzipTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryGzipTests.java index 4962b965..6c871771 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryGzipTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryGzipTests.java @@ -20,8 +20,7 @@ import java.net.URI; import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Value; @@ -35,18 +34,16 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.util.UriComponentsBuilder; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext -public class ModifyResponseBodyGatewayFilterFactoryGzipTests extends BaseWebClientTests { +class ModifyResponseBodyGatewayFilterFactoryGzipTests extends BaseWebClientTests { @Test - public void testModificationOfResponseBody() { + void testModificationOfResponseBody() { URI uri = UriComponentsBuilder.fromUriString(this.baseUri + "/gzip").build(true).toUri(); testClient.get().uri(uri).header("Host", "www.modifyresponsebodyjava.org").accept(MediaType.APPLICATION_JSON) @@ -56,13 +53,13 @@ public class ModifyResponseBodyGatewayFilterFactoryGzipTests extends BaseWebClie @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { @Value("${test.uri}") String uri; @Bean - public RouteLocator testRouteLocator(RouteLocatorBuilder builder) { + RouteLocator testRouteLocator(RouteLocatorBuilder builder) { return builder.routes().route("modify_response_java_test_gzip", r -> r.path("/gzip").and() .host("www.modifyresponsebodyjava.org") .filters(f -> f.modifyResponseBody(String.class, Map.class, (webExchange, originalResponse) -> { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java index 0b71e286..6db20d0b 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/factory/rewrite/ModifyResponseBodyGatewayFilterFactoryTests.java @@ -20,8 +20,7 @@ import java.net.URI; import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Value; @@ -37,13 +36,11 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.util.UriComponentsBuilder; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT, properties = "spring.codec.max-in-memory-size=40") @DirtiesContext public class ModifyResponseBodyGatewayFilterFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/HttpStatusInResponseHeadersFilterTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/HttpStatusInResponseHeadersFilterTests.java index 5909321c..5338b1f9 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/HttpStatusInResponseHeadersFilterTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/HttpStatusInResponseHeadersFilterTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.filter.headers; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -28,7 +27,6 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.server.ServerWebExchange; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +35,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen /** * @author Spencer Gibb */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class HttpStatusInResponseHeadersFilterTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/NonStandardHeadersInResponseTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/NonStandardHeadersInResponseTests.java index a9197483..42cdb6cc 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/NonStandardHeadersInResponseTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/NonStandardHeadersInResponseTests.java @@ -20,8 +20,7 @@ import java.net.URI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Value; @@ -37,14 +36,12 @@ import org.springframework.context.annotation.Import; import org.springframework.core.annotation.Order; import org.springframework.http.HttpHeaders; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.util.UriComponentsBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = DEFINED_PORT, properties = { "server.port=62175" }) @DirtiesContext public class NonStandardHeadersInResponseTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingEmptyPredicatesTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingEmptyPredicatesTests.java index 297dfcc5..b3337410 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingEmptyPredicatesTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingEmptyPredicatesTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.handler; import java.net.URI; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import org.springframework.boot.SpringBootConfiguration; @@ -31,11 +30,9 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT, properties = {}) @DirtiesContext public class RoutePredicateHandlerMappingEmptyPredicatesTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java index eef41bd3..ea3e3338 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java @@ -16,10 +16,9 @@ package org.springframework.cloud.gateway.handler; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -31,7 +30,6 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.SocketUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -39,20 +37,19 @@ import org.springframework.web.bind.annotation.RestController; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT, properties = "management.server.port=${test.port}") @DirtiesContext public class RoutePredicateHandlerMappingIntegrationTests extends BaseWebClientTests { private static int managementPort; - @BeforeClass + @BeforeAll public static void beforeClass() { managementPort = SocketUtils.findAvailableTcpPort(); System.setProperty("test.port", String.valueOf(managementPort)); } - @AfterClass + @AfterAll public static void afterClass() { System.clearProperty("test.port"); } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingSameManagementPortIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingSameManagementPortIntegrationTests.java index 6b51b612..c539666a 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingSameManagementPortIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingSameManagementPortIntegrationTests.java @@ -16,10 +16,9 @@ package org.springframework.cloud.gateway.handler; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -27,26 +26,24 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.SocketUtils; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = DEFINED_PORT) @DirtiesContext public class RoutePredicateHandlerMappingSameManagementPortIntegrationTests extends BaseWebClientTests { private static int samePort; - @BeforeClass + @BeforeAll public static void beforeClass() { samePort = SocketUtils.findAvailableTcpPort(); System.setProperty("server.port", String.valueOf(samePort)); System.setProperty("management.server.port", String.valueOf(samePort)); } - @AfterClass + @AfterAll public static void afterClass() { System.clearProperty("server.port"); System.clearProperty("management.server.port"); diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactoryIntegrationTests.java index bb35cbc9..f312f65d 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/BetweenRoutePredicateFactoryIntegrationTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.handler.predicate; import java.time.ZonedDateTime; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -33,11 +32,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class BetweenRoutePredicateFactoryIntegrationTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CloudFoundryRouteServiceRoutePredicateFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CloudFoundryRouteServiceRoutePredicateFactoryIntegrationTests.java index ca6968b3..a19c1d43 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CloudFoundryRouteServiceRoutePredicateFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CloudFoundryRouteServiceRoutePredicateFactoryIntegrationTests.java @@ -17,8 +17,7 @@ package org.springframework.cloud.gateway.handler.predicate; import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -30,7 +29,6 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -38,7 +36,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen /** * @author Toshiaki Maki */ -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class CloudFoundryRouteServiceRoutePredicateFactoryIntegrationTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java index 14666011..36ff2fa1 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryIntegrationTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.gateway.handler.predicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -25,19 +24,17 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) -public class CookieRoutePredicateFactoryIntegrationTests extends BaseWebClientTests { +class CookieRoutePredicateFactoryIntegrationTests extends BaseWebClientTests { @Test - public void cookieRegexWorks() { + void cookieRegexWorks() { assertCookieValue("helloaaaaa"); assertCookieValue("hello"); @@ -53,10 +50,10 @@ public class CookieRoutePredicateFactoryIntegrationTests extends BaseWebClientTe @SpringBootConfiguration @Import(DefaultTestConfig.class) @RestController - public static class TestConfig { + static class TestConfig { @GetMapping("/httpbin/cookie") - public String cookie(@CookieValue("mycookie") String mycookie) { + String cookie(@CookieValue("mycookie") String mycookie) { return mycookie; } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryTests.java index a959f0ca..94e80fd7 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/CookieRoutePredicateFactoryTests.java @@ -18,7 +18,7 @@ package org.springframework.cloud.gateway.handler.predicate; import java.util.function.Predicate; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.gateway.handler.predicate.CookieRoutePredicateFactory.Config; import org.springframework.cloud.gateway.test.BaseWebClientTests; diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/HeaderRoutePredicateFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/HeaderRoutePredicateFactoryTests.java index 2c134a30..525db877 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/HeaderRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/HeaderRoutePredicateFactoryTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.handler.predicate; import java.util.function.Predicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -33,12 +32,10 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class HeaderRoutePredicateFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/HostRoutePredicateFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/HostRoutePredicateFactoryTests.java index 35b9cd8a..10fb4f85 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/HostRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/HostRoutePredicateFactoryTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate; import java.util.Arrays; import java.util.function.Predicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -34,12 +33,10 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class HostRoutePredicateFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactoryTests.java index 074db693..4f195c8a 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/MethodRoutePredicateFactoryTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.handler.predicate; import java.util.function.Predicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -35,12 +34,10 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class MethodRoutePredicateFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java index 32253ea3..3f4fff11 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/PathRoutePredicateFactoryTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate; import java.util.Arrays; import java.util.function.Predicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; @@ -35,13 +34,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.server.ServerWebExchange; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext public class PathRoutePredicateFactoryTests extends BaseWebClientTests { diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactoryTests.java index 84255516..48892642 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/QueryRoutePredicateFactoryTests.java @@ -18,15 +18,15 @@ package org.springframework.cloud.gateway.handler.predicate; import java.util.function.Predicate; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.system.OutputCaptureRule; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.cloud.gateway.handler.predicate.QueryRoutePredicateFactory.Config; import org.springframework.cloud.gateway.route.RouteLocator; import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; @@ -34,26 +34,20 @@ import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext +@ExtendWith(OutputCaptureExtension.class) public class QueryRoutePredicateFactoryTests extends BaseWebClientTests { - @Rule - public OutputCaptureRule output = new OutputCaptureRule(); - @Test - public void noQueryParamWorks() { + public void noQueryParamWorks(CapturedOutput output) { testClient.get().uri("/get").exchange().expectStatus().isOk().expectHeader().valueEquals(ROUTE_ID_HEADER, "default_path_to_httpbin"); - output.expect(not(containsString("Error applying predicate for route: foo_query_param"))); + assertThat(output).doesNotContain("Error applying predicate for route: foo_query_param"); } @Test @@ -63,10 +57,10 @@ public class QueryRoutePredicateFactoryTests extends BaseWebClientTests { } @Test - public void emptyQueryParamWorks() { + public void emptyQueryParamWorks(CapturedOutput output) { testClient.get().uri("/get?foo").exchange().expectStatus().isOk().expectHeader().valueEquals(ROUTE_ID_HEADER, "default_path_to_httpbin"); - output.expect(not(containsString("Error applying predicate for route: foo_query_param"))); + assertThat(output).doesNotContain("Error applying predicate for route: foo_query_param"); } @Test diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRoutePredicateFactoryTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRoutePredicateFactoryTests.java index 184b65e7..aacb7ebe 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRoutePredicateFactoryTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/RemoteAddrRoutePredicateFactoryTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.gateway.handler.predicate; import java.time.Duration; import java.util.function.Predicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -38,14 +37,12 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.ClientResponse; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.test.TestUtils.assertStatus; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @ActiveProfiles({ "remote-address" }) diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/WeightRoutePredicateFactoryIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/WeightRoutePredicateFactoryIntegrationTests.java index d7e5d2ec..8ad1397d 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/WeightRoutePredicateFactoryIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/WeightRoutePredicateFactoryIntegrationTests.java @@ -19,8 +19,8 @@ package org.springframework.cloud.gateway.handler.predicate; import java.util.Random; import java.util.function.Predicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -36,16 +36,16 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.condition.JRE.JAVA_17; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext +@DisabledOnJre(JAVA_17) public class WeightRoutePredicateFactoryIntegrationTests extends BaseWebClientTests { @Autowired diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/WeightRoutePredicateFactoryYaml404Tests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/WeightRoutePredicateFactoryYaml404Tests.java index 9bb136e3..3c098ca9 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/WeightRoutePredicateFactoryYaml404Tests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/predicate/WeightRoutePredicateFactoryYaml404Tests.java @@ -18,8 +18,8 @@ package org.springframework.cloud.gateway.handler.predicate; import java.util.Random; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnJre; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringBootConfiguration; @@ -31,17 +31,17 @@ import org.springframework.context.annotation.Import; import org.springframework.http.HttpHeaders; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.jupiter.api.condition.JRE.JAVA_17; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @ActiveProfiles("weights-404") @DirtiesContext -public class WeightRoutePredicateFactoryYaml404Tests extends BaseWebClientTests { +@DisabledOnJre(JAVA_17) +class WeightRoutePredicateFactoryYaml404Tests extends BaseWebClientTests { @Autowired private WeightCalculatorWebFilter filter; @@ -53,7 +53,7 @@ public class WeightRoutePredicateFactoryYaml404Tests extends BaseWebClientTests } @Test - public void weightsFromYamlNot404() { + void weightsFromYamlNot404() { filter.setRandom(getRandom(0.5)); testClient.get().uri("/get").header(HttpHeaders.HOST, "www.weight4041.org").exchange().expectStatus().isOk() @@ -63,9 +63,9 @@ public class WeightRoutePredicateFactoryYaml404Tests extends BaseWebClientTests @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { - public TestConfig(WeightCalculatorWebFilter filter) { + TestConfig(WeightCalculatorWebFilter filter) { Random random = getRandom(0.4); filter.setRandom(random); diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java index db8d27ba..f03dd48d 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java @@ -20,7 +20,7 @@ import java.time.Duration; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import reactor.core.publisher.Mono; import org.springframework.boot.SpringBootConfiguration; @@ -68,7 +68,7 @@ public class BaseWebClientTests { protected String baseUri; - @Before + @BeforeEach public void setup() throws Exception { setup(new ReactorClientHttpConnector(), "http://localhost:" + port); } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/CustomBlockHoundIntegration.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/CustomBlockHoundIntegration.java index 89ae2601..7c590933 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/CustomBlockHoundIntegration.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/CustomBlockHoundIntegration.java @@ -86,6 +86,11 @@ public class CustomBlockHoundIntegration implements BlockHoundIntegration { builder.allowBlockingCallsInside( "org.springframework.security.authentication.AbstractUserDetailsReactiveAuthenticationManager", "lambda$authenticate$4"); + + // Uses java.io.RandomAccessFile#readBytes + builder.allowBlockingCallsInside("org.springframework.context.annotation.ConfigurationClassParser", "parse"); + builder.allowBlockingCallsInside( + "org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader", "loadBeanDefinitions"); } } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/FormIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/FormIntegrationTests.java index 5fc08bc1..9a105d6d 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/FormIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/FormIntegrationTests.java @@ -19,8 +19,7 @@ package org.springframework.cloud.gateway.test; import java.nio.charset.StandardCharsets; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -34,7 +33,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.client.MultipartBodyBuilder; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.BodyInserters; @@ -45,17 +43,16 @@ import static org.springframework.cloud.gateway.test.TestUtils.getMap; import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @SuppressWarnings("unchecked") -public class FormIntegrationTests extends BaseWebClientTests { +class FormIntegrationTests extends BaseWebClientTests { public static final MediaType FORM_URL_ENCODED_CONTENT_TYPE = new MediaType(APPLICATION_FORM_URLENCODED, StandardCharsets.UTF_8); @Test - public void formUrlencodedWorks() { + void formUrlencodedWorks() { LinkedMultiValueMap formData = new LinkedMultiValueMap<>(); formData.add("foo", "bar"); formData.add("baz", "bam"); @@ -75,7 +72,7 @@ public class FormIntegrationTests extends BaseWebClientTests { } @Test - public void multipartFormDataWorksWebClient() { + void multipartFormDataWorksWebClient() { MultiValueMap> formData = createMultipartData(); // @formatter:off @@ -89,7 +86,7 @@ public class FormIntegrationTests extends BaseWebClientTests { } @Test - public void multipartFormDataWorksRestTemplate() { + void multipartFormDataWorksRestTemplate() { MultiValueMap> formData = createMultipartData(); TestRestTemplate rest = new TestRestTemplate(); @@ -116,7 +113,7 @@ public class FormIntegrationTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java index b0074e78..5a5620be 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java @@ -24,8 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Autowired; @@ -50,7 +49,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; @@ -59,11 +57,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static org.springframework.cloud.gateway.test.TestUtils.getMap; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @SuppressWarnings("unchecked") -public class GatewayIntegrationTests extends BaseWebClientTests { +class GatewayIntegrationTests extends BaseWebClientTests { @Autowired private GatewayProperties properties; @@ -72,7 +69,7 @@ public class GatewayIntegrationTests extends BaseWebClientTests { private ApplicationContext context; @Test - public void listenersInOrder() { + void listenersInOrder() { assertThat(context).isInstanceOf(AbstractApplicationContext.class); AbstractApplicationContext ctxt = (AbstractApplicationContext) context; List> applicationListeners = new ArrayList<>(ctxt.getApplicationListeners()); @@ -84,7 +81,7 @@ public class GatewayIntegrationTests extends BaseWebClientTests { } @Test - public void complexContentTypeWorks() { + void complexContentTypeWorks() { testClient.post().uri("/headers").contentType(MediaType.APPLICATION_JSON).bodyValue("testdata") .header("Host", "www.complexcontenttype.org").exchange().expectStatus().isOk().expectBody(Map.class) .consumeWith(result -> { @@ -94,7 +91,7 @@ public class GatewayIntegrationTests extends BaseWebClientTests { } @Test - public void forwardedHeadersWork() { + void forwardedHeadersWork() { testClient.get().uri("/headers").exchange().expectStatus().isOk().expectBody(Map.class).consumeWith(result -> { Map headers = getMap(result.getResponseBody(), "headers"); assertThat(headers).containsKeys(ForwardedHeadersFilter.FORWARDED_HEADER, @@ -111,7 +108,7 @@ public class GatewayIntegrationTests extends BaseWebClientTests { } @Test - public void compositeRouteWorks() { + void compositeRouteWorks() { testClient.get().uri("/headers?foo=bar&baz").header("Host", "www.foo.org").header("X-Request-Id", "123") .cookie("chocolate", "chip").exchange().expectStatus().isOk().expectHeader() .valueEquals(HANDLER_MAPPER_HEADER, RoutePredicateHandlerMapping.class.getSimpleName()).expectHeader() @@ -120,7 +117,7 @@ public class GatewayIntegrationTests extends BaseWebClientTests { } @Test - public void defaultFiltersWorks() { + void defaultFiltersWorks() { assertThat(this.properties.getDefaultFilters()).isNotEmpty(); testClient.get().uri("/headers").header("Host", "www.addresponseheader.org").exchange().expectStatus().isOk() @@ -132,13 +129,13 @@ public class GatewayIntegrationTests extends BaseWebClientTests { } @Test - public void loadBalancerFilterWorks() { + void loadBalancerFilterWorks() { testClient.get().uri("/get").header("Host", "www.loadbalancerclient.org").exchange().expectStatus().isOk() .expectHeader().valueEquals(ROUTE_ID_HEADER, "load_balancer_client_test"); } @Test - public void loadBalancerFilterNoClientWorks() { + void loadBalancerFilterNoClientWorks() { testClient.get().uri("/get").header("Host", "www.loadbalancerclientempty.org").exchange().expectStatus() .value(new BaseMatcher() { @Override @@ -159,7 +156,7 @@ public class GatewayIntegrationTests extends BaseWebClientTests { @Test // gh-374 no content type/empty body causes NPR in NettyRoutingFilter - public void noContentType() { + void noContentType() { testClient.get().uri("/nocontenttype").exchange().expectStatus().is2xxSuccessful(); } @@ -167,7 +164,7 @@ public class GatewayIntegrationTests extends BaseWebClientTests { @SpringBootConfiguration @Import(DefaultTestConfig.class) @RestController - public static class TestConfig { + static class TestConfig { private static final Log log = LogFactory.getLog(TestConfig.class); @@ -178,13 +175,13 @@ public class GatewayIntegrationTests extends BaseWebClientTests { } @RequestMapping("/httpbin/nocontenttype") - public ResponseEntity nocontenttype() { + ResponseEntity nocontenttype() { return ResponseEntity.status(204).build(); } @Bean @Order(-1) - public GlobalFilter postFilter() { + GlobalFilter postFilter() { return (exchange, chain) -> { log.info("postFilter start"); return chain.filter(exchange).then(postFilterWork(exchange)); diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/HttpStatusTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/HttpStatusTests.java index 58d3ee11..11b0c574 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/HttpStatusTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/HttpStatusTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.test; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; @@ -30,14 +29,12 @@ 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.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @SuppressWarnings("unchecked") @@ -48,13 +45,13 @@ public class HttpStatusTests extends BaseWebClientTests { } @Test - public void notFoundResponseWorks() { + void notFoundResponseWorks() { testClient.get().uri("/status/404").exchange().expectStatus().isEqualTo(HttpStatus.NOT_FOUND) .expectBody(String.class).isEqualTo("Failed with 404"); } @Test - public void nonStandardCodeWorks() { + void nonStandardCodeWorks() { ResponseEntity response = new TestRestTemplate().getForEntity(baseUri + "/status/432", String.class); assertThat(response.getStatusCodeValue()).isEqualTo(432); assertThat(response.getBody()).isEqualTo("Failed with 432"); @@ -66,13 +63,13 @@ public class HttpStatusTests extends BaseWebClientTests { } @Test - public void serverErrorResponseWorks() { + void serverErrorResponseWorks() { testClient.get().uri("/status/500").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR) .expectBody(String.class).isEqualTo("Failed with 500"); } @Test - public void normalErrorPageWorks() { + void normalErrorPageWorks() { testClient.get().uri("/exception").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR) .expectBody(Map.class) .consumeWith(result -> assertThat(result.getResponseBody()).hasSizeGreaterThanOrEqualTo(5) @@ -83,10 +80,10 @@ public class HttpStatusTests extends BaseWebClientTests { @SpringBootConfiguration @RestController @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { @RequestMapping("/httpbin/exception") - public String exception() { + String exception() { throw new RuntimeException("an error"); } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/PostTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/PostTests.java index 71d1a865..acc260a6 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/PostTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/PostTests.java @@ -18,8 +18,7 @@ package org.springframework.cloud.gateway.test; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -28,20 +27,18 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Import; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @SuppressWarnings("unchecked") // TODO: why does this have to be in a separate test? -public class PostTests extends BaseWebClientTests { +class PostTests extends BaseWebClientTests { @Test - public void postWorks() { + void postWorks() { Mono result = webClient.post().uri("/post").header("Host", "www.example.org").bodyValue("testdata") .retrieve().bodyToMono(Map.class); @@ -52,7 +49,7 @@ public class PostTests extends BaseWebClientTests { @EnableAutoConfiguration @SpringBootConfiguration @Import(DefaultTestConfig.class) - public static class TestConfig { + static class TestConfig { } diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/ClientCertAuthSSLTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/ClientCertAuthSSLTests.java index a2210e49..047215c3 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/ClientCertAuthSSLTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/ClientCertAuthSSLTests.java @@ -25,9 +25,8 @@ import javax.net.ssl.SSLException; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import reactor.netty.http.client.HttpClient; import org.springframework.beans.factory.annotation.Value; @@ -36,12 +35,10 @@ import org.springframework.boot.web.server.WebServerException; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.ResourceUtils; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @ActiveProfiles("client-auth-ssl") @@ -56,7 +53,7 @@ public class ClientCertAuthSSLTests extends SingleCertSSLTests { @Value("${spring.cloud.gateway.httpclient.ssl.key-password}") private String keyPassword; - @Before + @BeforeEach public void setup() throws Exception { KeyStore store = KeyStore.getInstance("JKS"); diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/MultiCertSSLTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/MultiCertSSLTests.java index eff86f34..248c67a7 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/MultiCertSSLTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/MultiCertSSLTests.java @@ -16,16 +16,12 @@ package org.springframework.cloud.gateway.test.ssl; -import org.junit.runner.RunWith; - import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @ActiveProfiles("multi-cert-ssl") diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/SSLHandshakeTimeoutTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/SSLHandshakeTimeoutTests.java index 1947019b..a0f5a479 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/SSLHandshakeTimeoutTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/SSLHandshakeTimeoutTests.java @@ -16,19 +16,16 @@ package org.springframework.cloud.gateway.test.ssl; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.reactive.server.JsonPathAssertions; import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) // this test works because it assumes TLS hand shake cannot be done in 1ms. It takes // closer to 80ms @SpringBootTest(webEnvironment = RANDOM_PORT, diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java index be50ada9..cfc7d11c 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java @@ -21,9 +21,8 @@ import javax.net.ssl.SSLException; import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import reactor.netty.http.client.HttpClient; import org.springframework.boot.SpringBootConfiguration; @@ -35,19 +34,17 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = RANDOM_PORT) @DirtiesContext @ActiveProfiles("single-cert-ssl") public class SingleCertSSLTests extends BaseWebClientTests { - @Before + @BeforeEach public void setup() throws Exception { try { SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE)