diff --git a/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java b/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java index 0ad5f2fc2..c612e360a 100644 --- a/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java +++ b/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java @@ -20,6 +20,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.core.annotation.Order; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; @@ -56,7 +57,7 @@ public class GatewayIntegrationTests { } @LocalServerPort - private int port; + private int port = 0; private WebClient webClient; @@ -78,8 +79,7 @@ public class GatewayIntegrationTests { StepVerifier.create(result) .consumeNextWith( response -> { - assertThat(response).containsKey("headers").isInstanceOf(Map.class); - Map headers = (Map) response.get("headers"); + Map headers = getMap(response, "headers"); assertThat(headers).containsEntry("X-Request-Foo", "Bar"); }) .expectComplete() @@ -106,8 +106,7 @@ public class GatewayIntegrationTests { StepVerifier.create(result) .consumeNextWith( response -> { - assertThat(response).containsKey("args").isInstanceOf(Map.class); - Map args = (Map) response.get("args"); + Map args = getMap(response, "args"); assertThat(args).containsEntry("foo", "bar"); }) .expectComplete() @@ -132,6 +131,25 @@ public class GatewayIntegrationTests { .verify(DURATION); } + @Test + public void complexContentTypeWorks() { + Mono result = webClient.get() + .uri("/headers") + .contentType(MediaType.APPLICATION_JSON_UTF8) + .header("Host", "www.complexcontenttype.org") + .exchange() + .then(response -> response.body(toMono(Map.class))); + + StepVerifier.create(result) + .consumeNextWith( + response -> { + Map headers = getMap(response, "headers"); + assertThat(headers).containsEntry(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE); + }) + .expectComplete() + .verify(DURATION); + } + @Test public void compositeRouteWorks() { Mono result = webClient.get() @@ -274,8 +292,7 @@ public class GatewayIntegrationTests { StepVerifier.create(result) .consumeNextWith( response -> { - assertThat(response).containsKey("headers").isInstanceOf(Map.class); - Map headers = (Map) response.get("headers"); + Map headers = getMap(response, "headers"); assertThat(headers).doesNotContainKey("X-Request-Foo"); }) .expectComplete() @@ -421,6 +438,11 @@ public class GatewayIntegrationTests { .verify(DURATION); } + private Map getMap(Map response, String key) { + assertThat(response).containsKey(key).isInstanceOf(Map.class); + return (Map) response.get(key); + } + private void assertStatus(ClientResponse response, HttpStatus status) { HttpStatus statusCode = response.statusCode(); assertThat(statusCode).isEqualTo(status); diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index e9b99c392..6b317b6e2 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -48,6 +48,13 @@ spring: filters: - AddResponseHeader=X-Request-Foo, Bar + # ===================================== + - id: complex_content_type_test + uri: http://httpbin.org:80 + predicates: + - Host=**.complexcontenttype.org + - Url=/headers + # ===================================== - id: hystrix_failure_test uri: http://httpbin.org:80