use of org.springframework.test.web.reactive.server.HttpHandlerConnector in project spring-integration by spring-projects.
the class WebFluxRequestExecutingMessageHandlerTests method testServiceUnavailableWithoutBody.
@Test
public void testServiceUnavailableWithoutBody() {
ClientHttpConnector httpConnector = new HttpHandlerConnector((request, response) -> {
response.setStatusCode(HttpStatus.SERVICE_UNAVAILABLE);
return Mono.defer(response::setComplete);
});
WebClient webClient = WebClient.builder().clientConnector(httpConnector).build();
String destinationUri = "http://www.springsource.org/spring-integration";
QueueChannel replyChannel = new QueueChannel();
QueueChannel errorChannel = new QueueChannel();
WebFluxRequestExecutingMessageHandler messageHandler = new WebFluxRequestExecutingMessageHandler(destinationUri, webClient);
messageHandler.setOutputChannel(replyChannel);
Message<String> requestMessage = MessageBuilder.withPayload("test").setErrorChannel(errorChannel).build();
messageHandler.handleMessage(requestMessage);
Message<?> errorMessage = errorChannel.receive(10000);
assertNotNull(errorMessage);
Object payload = errorMessage.getPayload();
assertThat(payload, instanceOf(MessageHandlingException.class));
Exception exception = (Exception) payload;
assertThat(exception.getCause(), instanceOf(WebClientResponseException.class));
assertThat(exception.getMessage(), containsString("503 Service Unavailable"));
Message<?> replyMessage = errorChannel.receive(10);
assertNull(replyMessage);
}
use of org.springframework.test.web.reactive.server.HttpHandlerConnector in project spring-integration by spring-projects.
the class WebFluxRequestExecutingMessageHandlerTests method testReactiveErrorOneWay.
@Test
public void testReactiveErrorOneWay() {
ClientHttpConnector httpConnector = new HttpHandlerConnector((request, response) -> {
response.setStatusCode(HttpStatus.UNAUTHORIZED);
return Mono.defer(response::setComplete);
});
WebClient webClient = WebClient.builder().clientConnector(httpConnector).build();
String destinationUri = "http://www.springsource.org/spring-integration";
WebFluxRequestExecutingMessageHandler reactiveHandler = new WebFluxRequestExecutingMessageHandler(destinationUri, webClient);
reactiveHandler.setExpectReply(false);
QueueChannel errorChannel = new QueueChannel();
reactiveHandler.handleMessage(MessageBuilder.withPayload("hello, world").setErrorChannel(errorChannel).build());
Message<?> errorMessage = errorChannel.receive(10000);
assertNotNull(errorMessage);
assertThat(errorMessage, instanceOf(ErrorMessage.class));
Throwable throwable = (Throwable) errorMessage.getPayload();
assertThat(throwable.getMessage(), containsString("401 Unauthorized"));
}
use of org.springframework.test.web.reactive.server.HttpHandlerConnector in project spring-integration by spring-projects.
the class WebFluxDslTests method testWebFluxFlowWithReplyPayloadToFlux.
@Test
public void testWebFluxFlowWithReplyPayloadToFlux() {
ClientHttpConnector httpConnector = new HttpHandlerConnector((request, response) -> {
response.setStatusCode(HttpStatus.OK);
response.getHeaders().setContentType(MediaType.TEXT_PLAIN);
DataBufferFactory bufferFactory = response.bufferFactory();
return response.writeWith(Mono.just(bufferFactory.wrap("FOO\nBAR\n".getBytes()))).then(Mono.defer(response::setComplete));
});
WebClient webClient = WebClient.builder().clientConnector(httpConnector).build();
new DirectFieldAccessor(this.webFluxWithReplyPayloadToFlux).setPropertyValue("webClient", webClient);
QueueChannel replyChannel = new QueueChannel();
Message<String> testMessage = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
this.webFluxFlowWithReplyPayloadToFluxInput.send(testMessage);
Message<?> receive = replyChannel.receive(10_000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(Flux.class));
@SuppressWarnings("unchecked") Flux<String> response = (Flux<String>) receive.getPayload();
StepVerifier.create(response).expectNext("FOO", "BAR").verifyComplete();
}
Aggregations