From 8c724ea051048650b77b04ed9237e334d30d40a6 Mon Sep 17 00:00:00 2001 From: Anastasiia Smirnova Date: Fri, 8 Feb 2019 00:34:39 +0200 Subject: [PATCH 1/2] light tests cleanup --- .../cloud/gateway/test/BaseWebClientTests.java | 15 +++++++++------ .../gateway/test/ssl/SingleCertSSLTests.java | 18 +++++------------- .../src/test/resources/application-logging.yml | 8 ++++++++ .../resources/application-multi-cert-ssl.yml | 9 --------- .../application-redis-rate-limiter-config.yml | 3 --- ...ation-redis-rate-limiter-default-config.yml | 3 --- .../resources/application-remote-address.yml | 3 --- .../application-removenonproxyheaders.yml | 1 - .../application-request-header-web-filter.yml | 4 ---- ...pplication-request-parameter-web-filter.yml | 4 ---- .../application-save-session-web-filter.yml | 4 ---- .../resources/application-single-cert-ssl.yml | 9 --------- .../test/resources/application-weights-404.yml | 3 --- .../src/test/resources/application.yml | 15 ++++----------- 14 files changed, 26 insertions(+), 73 deletions(-) create mode 100644 spring-cloud-gateway-core/src/test/resources/application-logging.yml diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java index c7020fd0b..66c7f3c59 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java @@ -66,18 +66,21 @@ public class BaseWebClientTests { @Before public void setup() { - ClientHttpConnector httpConnector = new ReactorClientHttpConnector(); + setup(new ReactorClientHttpConnector(), "http://localhost:" + port); + } - baseUri = "http://localhost:" + port; + protected void setup(ClientHttpConnector httpConnector, String baseUri) { + this.baseUri = baseUri; this.webClient = WebClient.builder().clientConnector(httpConnector) - .baseUrl(baseUri).build(); - this.testClient = WebTestClient.bindToServer().baseUrl(baseUri).build(); + .baseUrl(this.baseUri).build(); + this.testClient = WebTestClient.bindToServer(httpConnector) + .baseUrl(this.baseUri).build(); } @Configuration @RibbonClients({ - @RibbonClient(name = "testservice", configuration = TestRibbonConfig.class), - @RibbonClient(name = "myservice", configuration = TestRibbonConfig.class) }) + @RibbonClient(name = "testservice", configuration = TestRibbonConfig.class) + }) @Import(PermitAllSecurityConfiguration.class) public static class DefaultTestConfig { diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java index d45101850..54d068709 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java @@ -55,20 +55,12 @@ public class SingleCertSSLTests extends BaseWebClientTests { try { SslContext sslContext = SslContextBuilder.forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE).build(); - HttpClient httpClient = HttpClient.create().secure(ssl -> { - ssl.sslContext(sslContext); - }); - ClientHttpConnector httpConnector = new ReactorClientHttpConnector( - httpClient); - baseUri = "https://localhost:" + port; - this.webClient = WebClient.builder().clientConnector(httpConnector) - .baseUrl(baseUri).build(); - this.testClient = WebTestClient.bindToServer(httpConnector).baseUrl(baseUri) - .build(); - } - catch (SSLException e) { + HttpClient httpClient = HttpClient.create() + .secure(ssl -> ssl.sslContext(sslContext)); + setup(new ReactorClientHttpConnector(httpClient), "https://localhost:" + port); + } catch (SSLException e) { throw new RuntimeException(e); - } + } } @Test diff --git a/spring-cloud-gateway-core/src/test/resources/application-logging.yml b/spring-cloud-gateway-core/src/test/resources/application-logging.yml new file mode 100644 index 000000000..c07e955ae --- /dev/null +++ b/spring-cloud-gateway-core/src/test/resources/application-logging.yml @@ -0,0 +1,8 @@ +logging: + level: + org.springframework.cloud.gateway: TRACE + org.springframework.http.server.reactive: DEBUG + org.springframework.web.reactive: DEBUG + org.springframework.boot.autoconfigure.web: DEBUG + reactor.netty: DEBUG + redisratelimiter: DEBUG \ No newline at end of file diff --git a/spring-cloud-gateway-core/src/test/resources/application-multi-cert-ssl.yml b/spring-cloud-gateway-core/src/test/resources/application-multi-cert-ssl.yml index 60c3d3637..5ab3bed37 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-multi-cert-ssl.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-multi-cert-ssl.yml @@ -1,5 +1,4 @@ test: - hostport: httpbin.org:80 uri: lb:https://testservice server: @@ -28,11 +27,3 @@ spring: args: pattern: /** -logging: - level: - org.springframework.cloud.gateway: TRACE - org.springframework.http.server.reactive: DEBUG - org.springframework.web.reactive: DEBUG - reactor.ipc.netty: DEBUG - redisratelimiter: DEBUG - diff --git a/spring-cloud-gateway-core/src/test/resources/application-redis-rate-limiter-config.yml b/spring-cloud-gateway-core/src/test/resources/application-redis-rate-limiter-config.yml index 1fd28017e..85ac957d9 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-redis-rate-limiter-config.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-redis-rate-limiter-config.yml @@ -1,6 +1,3 @@ -test: - uri: lb://myservice - spring: cloud: gateway: diff --git a/spring-cloud-gateway-core/src/test/resources/application-redis-rate-limiter-default-config.yml b/spring-cloud-gateway-core/src/test/resources/application-redis-rate-limiter-default-config.yml index 603bd9b35..e1ba40799 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-redis-rate-limiter-default-config.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-redis-rate-limiter-default-config.yml @@ -1,6 +1,3 @@ -test: - uri: lb://myservice - spring: cloud: gateway: diff --git a/spring-cloud-gateway-core/src/test/resources/application-remote-address.yml b/spring-cloud-gateway-core/src/test/resources/application-remote-address.yml index 0fdef541f..12795440c 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-remote-address.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-remote-address.yml @@ -1,6 +1,3 @@ -test: - uri: lb://myservice - spring: cloud: gateway: diff --git a/spring-cloud-gateway-core/src/test/resources/application-removenonproxyheaders.yml b/spring-cloud-gateway-core/src/test/resources/application-removenonproxyheaders.yml index d4fa27325..f95895dbb 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-removenonproxyheaders.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-removenonproxyheaders.yml @@ -7,7 +7,6 @@ spring: routes: # ===================================== - id: remove_request_header_test - # uri: http://httpbin.org:80 uri: lb://testservice predicates: - Host=**.removenonproxyheaders.org diff --git a/spring-cloud-gateway-core/src/test/resources/application-request-header-web-filter.yml b/spring-cloud-gateway-core/src/test/resources/application-request-header-web-filter.yml index 73cd8ad3e..3778f9a44 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-request-header-web-filter.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-request-header-web-filter.yml @@ -1,7 +1,3 @@ -test: - hostport: httpbin.org:80 - uri: lb://testservice - spring: cloud: gateway: diff --git a/spring-cloud-gateway-core/src/test/resources/application-request-parameter-web-filter.yml b/spring-cloud-gateway-core/src/test/resources/application-request-parameter-web-filter.yml index 2a23b506f..b0190007d 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-request-parameter-web-filter.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-request-parameter-web-filter.yml @@ -1,7 +1,3 @@ -test: - hostport: httpbin.org:80 - uri: lb://testservice - spring: cloud: gateway: diff --git a/spring-cloud-gateway-core/src/test/resources/application-save-session-web-filter.yml b/spring-cloud-gateway-core/src/test/resources/application-save-session-web-filter.yml index 2bb160083..110bb930d 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-save-session-web-filter.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-save-session-web-filter.yml @@ -1,7 +1,3 @@ -test: - hostport: httpbin.org:80 - uri: lb://testservice - spring: cloud: gateway: diff --git a/spring-cloud-gateway-core/src/test/resources/application-single-cert-ssl.yml b/spring-cloud-gateway-core/src/test/resources/application-single-cert-ssl.yml index 7c184e4f2..61866d25b 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-single-cert-ssl.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-single-cert-ssl.yml @@ -1,5 +1,4 @@ test: - hostport: httpbin.org:80 uri: lb:https://testservice server: @@ -28,11 +27,3 @@ spring: args: pattern: /** -logging: - level: - org.springframework.cloud.gateway: TRACE - org.springframework.http.server.reactive: DEBUG - org.springframework.web.reactive: DEBUG - reactor.ipc.netty: DEBUG - redisratelimiter: DEBUG - diff --git a/spring-cloud-gateway-core/src/test/resources/application-weights-404.yml b/spring-cloud-gateway-core/src/test/resources/application-weights-404.yml index 95b460841..49ffb6d5b 100644 --- a/spring-cloud-gateway-core/src/test/resources/application-weights-404.yml +++ b/spring-cloud-gateway-core/src/test/resources/application-weights-404.yml @@ -1,6 +1,3 @@ -test: - uri: lb://testservice - spring: cloud: gateway: diff --git a/spring-cloud-gateway-core/src/test/resources/application.yml b/spring-cloud-gateway-core/src/test/resources/application.yml index 0a0b2491b..8b2933954 100644 --- a/spring-cloud-gateway-core/src/test/resources/application.yml +++ b/spring-cloud-gateway-core/src/test/resources/application.yml @@ -5,6 +5,9 @@ test: uri: lb://testservice spring: + profiles: + include: logging + cloud: gateway: globalcors: @@ -141,7 +144,7 @@ spring: # ===================================== - id: load_balancer_client_test - uri: lb://myservice + uri: lb://testservice predicates: - Host=**.loadbalancerclient.org @@ -346,17 +349,7 @@ spring: hystrix.command.successcmd.execution.isolation.thread.timeoutInMilliseconds: 5000 -logging: - level: - org.springframework.cloud.gateway: TRACE - org.springframework.http.server.reactive: DEBUG - org.springframework.web.reactive: DEBUG - org.springframework.boot.autoconfigure.web: DEBUG - reactor.netty: DEBUG - redisratelimiter: DEBUG - eureka: client: enabled: false -# port: 8081 From 87bea41c8364de3e703d6defe79ae296751b1de6 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Mon, 4 Mar 2019 15:46:05 -0500 Subject: [PATCH 2/2] Fixing checkstyle --- .../cloud/gateway/test/BaseWebClientTests.java | 7 +++---- .../cloud/gateway/test/ssl/SingleCertSSLTests.java | 11 +++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java index 66c7f3c59..31c95cc22 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java @@ -73,14 +73,13 @@ public class BaseWebClientTests { this.baseUri = baseUri; this.webClient = WebClient.builder().clientConnector(httpConnector) .baseUrl(this.baseUri).build(); - this.testClient = WebTestClient.bindToServer(httpConnector) - .baseUrl(this.baseUri).build(); + this.testClient = WebTestClient.bindToServer(httpConnector).baseUrl(this.baseUri) + .build(); } @Configuration @RibbonClients({ - @RibbonClient(name = "testservice", configuration = TestRibbonConfig.class) - }) + @RibbonClient(name = "testservice", configuration = TestRibbonConfig.class) }) @Import(PermitAllSecurityConfiguration.class) public static class DefaultTestConfig { diff --git a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java index 54d068709..6af15d4d9 100644 --- a/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java +++ b/spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/test/ssl/SingleCertSSLTests.java @@ -32,15 +32,12 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.gateway.test.BaseWebClientTests; import org.springframework.context.annotation.Import; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.reactive.ClientHttpConnector; 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.test.web.reactive.server.WebTestClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.reactive.function.client.WebClient; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -57,10 +54,12 @@ public class SingleCertSSLTests extends BaseWebClientTests { .trustManager(InsecureTrustManagerFactory.INSTANCE).build(); HttpClient httpClient = HttpClient.create() .secure(ssl -> ssl.sslContext(sslContext)); - setup(new ReactorClientHttpConnector(httpClient), "https://localhost:" + port); - } catch (SSLException e) { + setup(new ReactorClientHttpConnector(httpClient), + "https://localhost:" + port); + } + catch (SSLException e) { throw new RuntimeException(e); - } + } } @Test