|
|
@ -59,40 +59,50 @@ public class GatewayIntegrationTests { |
|
|
|
AssertionError error = null; |
|
|
|
AssertionError error = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@FunctionalInterface |
|
|
|
public void urlRouteWorks() { |
|
|
|
interface ResultVerifier { |
|
|
|
Mono<ClientResponse> result = webClient.exchange( |
|
|
|
void verify(); |
|
|
|
GET("http://localhost:" + port + "/get").build() |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Result testResult = new Result(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IntStream.range(0, 3).forEach(i -> { |
|
|
|
private void verify(ResultVerifier verifier) { |
|
|
|
|
|
|
|
Result result = new Result(); |
|
|
|
|
|
|
|
IntStream.range(0, 3).forEach( i -> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
StepVerifier.create(result) |
|
|
|
verifier.verify(); |
|
|
|
.consumeNextWith( |
|
|
|
result.passedOnce = true; |
|
|
|
response -> { |
|
|
|
|
|
|
|
HttpHeaders httpHeaders = response.headers().asHttpHeaders(); |
|
|
|
|
|
|
|
HttpStatus statusCode = response.statusCode(); |
|
|
|
|
|
|
|
assertThat(httpHeaders.getFirst(HANDLER_MAPPER_HEADER)) |
|
|
|
|
|
|
|
.isEqualTo(GatewayPredicateHandlerMapping.class.getSimpleName()); |
|
|
|
|
|
|
|
assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER)) |
|
|
|
|
|
|
|
.isEqualTo("default_path_to_httpbin"); |
|
|
|
|
|
|
|
assertThat(statusCode).isEqualTo(HttpStatus.OK); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expectComplete() |
|
|
|
|
|
|
|
.verify(Duration.ofSeconds(3)); |
|
|
|
|
|
|
|
testResult.passedOnce = true; |
|
|
|
|
|
|
|
} catch (AssertionError e) { |
|
|
|
} catch (AssertionError e) { |
|
|
|
testResult.error = e; |
|
|
|
result.error = e; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (!testResult.passedOnce && testResult.error != null) { |
|
|
|
if (!result.passedOnce && result.error != null) { |
|
|
|
throw testResult.error; |
|
|
|
throw result.error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void urlRouteWorks() { |
|
|
|
|
|
|
|
Mono<ClientResponse> result = webClient.exchange( |
|
|
|
|
|
|
|
GET("http://localhost:" + port + "/get").build() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify( () -> |
|
|
|
|
|
|
|
StepVerifier.create(result) |
|
|
|
|
|
|
|
.consumeNextWith( |
|
|
|
|
|
|
|
response -> { |
|
|
|
|
|
|
|
HttpHeaders httpHeaders = response.headers().asHttpHeaders(); |
|
|
|
|
|
|
|
HttpStatus statusCode = response.statusCode(); |
|
|
|
|
|
|
|
assertThat(httpHeaders.getFirst(HANDLER_MAPPER_HEADER)) |
|
|
|
|
|
|
|
.isEqualTo(GatewayPredicateHandlerMapping.class.getSimpleName()); |
|
|
|
|
|
|
|
assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER)) |
|
|
|
|
|
|
|
.isEqualTo("default_path_to_httpbin"); |
|
|
|
|
|
|
|
assertThat(statusCode).isEqualTo(HttpStatus.OK); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expectComplete() |
|
|
|
|
|
|
|
.verify(Duration.ofSeconds(3)) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void hostRouteWorks() { |
|
|
|
public void hostRouteWorks() { |
|
|
|
Mono<ClientResponse> result = webClient.exchange( |
|
|
|
Mono<ClientResponse> result = webClient.exchange( |
|
|
@ -101,38 +111,42 @@ public class GatewayIntegrationTests { |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
StepVerifier.create(result) |
|
|
|
verify( () -> |
|
|
|
.consumeNextWith( |
|
|
|
StepVerifier.create(result) |
|
|
|
response -> { |
|
|
|
.consumeNextWith( |
|
|
|
HttpHeaders httpHeaders = response.headers().asHttpHeaders(); |
|
|
|
response -> { |
|
|
|
HttpStatus statusCode = response.statusCode(); |
|
|
|
HttpHeaders httpHeaders = response.headers().asHttpHeaders(); |
|
|
|
assertThat(httpHeaders.getFirst(HANDLER_MAPPER_HEADER)) |
|
|
|
HttpStatus statusCode = response.statusCode(); |
|
|
|
.isEqualTo(GatewayPredicateHandlerMapping.class.getSimpleName()); |
|
|
|
assertThat(httpHeaders.getFirst(HANDLER_MAPPER_HEADER)) |
|
|
|
assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER)) |
|
|
|
.isEqualTo(GatewayPredicateHandlerMapping.class.getSimpleName()); |
|
|
|
.isEqualTo("host_example_to_httpbin"); |
|
|
|
assertThat(httpHeaders.getFirst(ROUTE_ID_HEADER)) |
|
|
|
assertThat(statusCode).isEqualTo(HttpStatus.OK); |
|
|
|
.isEqualTo("host_example_to_httpbin"); |
|
|
|
}) |
|
|
|
assertThat(statusCode).isEqualTo(HttpStatus.OK); |
|
|
|
.expectComplete() |
|
|
|
}) |
|
|
|
.verify(Duration.ofSeconds(3)); |
|
|
|
.expectComplete() |
|
|
|
|
|
|
|
.verify(Duration.ofSeconds(3)) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void appendRequestHeaderFilterWorks() { |
|
|
|
public void addRequestHeaderFilterWorks() { |
|
|
|
Mono<Map> result = webClient.exchange( |
|
|
|
Mono<Map> result = webClient.exchange( |
|
|
|
GET("http://localhost:" + port + "/headers") |
|
|
|
GET("http://localhost:" + port + "/headers") |
|
|
|
.header("Host", "www.bar.org") |
|
|
|
.header("Host", "www.bar.org") |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
).then(response -> response.body(toMono(Map.class))); |
|
|
|
).then(response -> response.body(toMono(Map.class))); |
|
|
|
|
|
|
|
|
|
|
|
StepVerifier.create(result) |
|
|
|
verify( () -> |
|
|
|
.consumeNextWith( |
|
|
|
StepVerifier.create(result) |
|
|
|
response -> { |
|
|
|
.consumeNextWith( |
|
|
|
assertThat(response).containsKey("headers").isInstanceOf(Map.class); |
|
|
|
response -> { |
|
|
|
Map<String, Object> headers = (Map<String, Object>) response.get("headers"); |
|
|
|
assertThat(response).containsKey("headers").isInstanceOf(Map.class); |
|
|
|
assertThat(headers).containsEntry("X-Request-Foo", "Bar"); |
|
|
|
Map<String, Object> headers = (Map<String, Object>) response.get("headers"); |
|
|
|
}) |
|
|
|
assertThat(headers).containsEntry("X-Request-Foo", "Bar"); |
|
|
|
.expectComplete() |
|
|
|
}) |
|
|
|
.verify(Duration.ofSeconds(3)); |
|
|
|
.expectComplete() |
|
|
|
|
|
|
|
.verify(Duration.ofSeconds(3)) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -143,23 +157,13 @@ public class GatewayIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
Mono<Map> result = webClient.exchange(request) |
|
|
|
Mono<Map> result = webClient.exchange(request) |
|
|
|
.then(response -> response.body(toMono(Map.class))); |
|
|
|
.then(response -> response.body(toMono(Map.class))); |
|
|
|
final Result testResult = new Result(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IntStream.range(0, 3).forEach(i -> { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
StepVerifier.create(result) |
|
|
|
|
|
|
|
.consumeNextWith(map -> assertThat(map).containsEntry("data", "testdata")) |
|
|
|
|
|
|
|
.expectComplete() |
|
|
|
|
|
|
|
.verify(Duration.ofSeconds(3)); |
|
|
|
|
|
|
|
testResult.passedOnce = true; |
|
|
|
|
|
|
|
} catch (AssertionError e) { |
|
|
|
|
|
|
|
testResult.error = e; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!testResult.passedOnce && testResult.error != null) { |
|
|
|
verify( () -> |
|
|
|
throw testResult.error; |
|
|
|
StepVerifier.create(result) |
|
|
|
} |
|
|
|
.consumeNextWith(map -> assertThat(map).containsEntry("data", "testdata")) |
|
|
|
|
|
|
|
.expectComplete() |
|
|
|
|
|
|
|
.verify(Duration.ofSeconds(3)) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -172,6 +176,7 @@ public class GatewayIntegrationTests { |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify( () -> |
|
|
|
StepVerifier.create(result) |
|
|
|
StepVerifier.create(result) |
|
|
|
.consumeNextWith( |
|
|
|
.consumeNextWith( |
|
|
|
response -> { |
|
|
|
response -> { |
|
|
@ -186,7 +191,8 @@ public class GatewayIntegrationTests { |
|
|
|
assertThat(statusCode).isEqualTo(HttpStatus.OK); |
|
|
|
assertThat(statusCode).isEqualTo(HttpStatus.OK); |
|
|
|
}) |
|
|
|
}) |
|
|
|
.expectComplete() |
|
|
|
.expectComplete() |
|
|
|
.verify(); |
|
|
|
.verify() |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@EnableAutoConfiguration |
|
|
|
@EnableAutoConfiguration |
|
|
|