Browse Source

Verify that complex content-types work

pull/41/head
Spencer Gibb 8 years ago
parent
commit
7458db74e3
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 36
      src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java
  2. 7
      src/test/resources/application.yml

36
src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java

@ -20,6 +20,7 @@ import org.springframework.context.annotation.Bean; @@ -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 { @@ -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 { @@ -78,8 +79,7 @@ public class GatewayIntegrationTests {
StepVerifier.create(result)
.consumeNextWith(
response -> {
assertThat(response).containsKey("headers").isInstanceOf(Map.class);
Map<String, Object> headers = (Map<String, Object>) response.get("headers");
Map<String, Object> headers = getMap(response, "headers");
assertThat(headers).containsEntry("X-Request-Foo", "Bar");
})
.expectComplete()
@ -106,8 +106,7 @@ public class GatewayIntegrationTests { @@ -106,8 +106,7 @@ public class GatewayIntegrationTests {
StepVerifier.create(result)
.consumeNextWith(
response -> {
assertThat(response).containsKey("args").isInstanceOf(Map.class);
Map<String, Object> args = (Map<String, Object>) response.get("args");
Map<String, Object> args = getMap(response, "args");
assertThat(args).containsEntry("foo", "bar");
})
.expectComplete()
@ -132,6 +131,25 @@ public class GatewayIntegrationTests { @@ -132,6 +131,25 @@ public class GatewayIntegrationTests {
.verify(DURATION);
}
@Test
public void complexContentTypeWorks() {
Mono<Map> 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<String, Object> headers = getMap(response, "headers");
assertThat(headers).containsEntry(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
})
.expectComplete()
.verify(DURATION);
}
@Test
public void compositeRouteWorks() {
Mono<ClientResponse> result = webClient.get()
@ -274,8 +292,7 @@ public class GatewayIntegrationTests { @@ -274,8 +292,7 @@ public class GatewayIntegrationTests {
StepVerifier.create(result)
.consumeNextWith(
response -> {
assertThat(response).containsKey("headers").isInstanceOf(Map.class);
Map<String, Object> headers = (Map<String, Object>) response.get("headers");
Map<String, Object> headers = getMap(response, "headers");
assertThat(headers).doesNotContainKey("X-Request-Foo");
})
.expectComplete()
@ -421,6 +438,11 @@ public class GatewayIntegrationTests { @@ -421,6 +438,11 @@ public class GatewayIntegrationTests {
.verify(DURATION);
}
private Map<String, Object> getMap(Map response, String key) {
assertThat(response).containsKey(key).isInstanceOf(Map.class);
return (Map<String, Object>) response.get(key);
}
private void assertStatus(ClientResponse response, HttpStatus status) {
HttpStatus statusCode = response.statusCode();
assertThat(statusCode).isEqualTo(status);

7
src/test/resources/application.yml

@ -48,6 +48,13 @@ spring: @@ -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

Loading…
Cancel
Save