use of cn.taketoday.web.reactive.function.client.WebClientResponseException in project today-infrastructure by TAKETODAY.
the class DefaultClientResponseTests method createException.
@Test
public void createException() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
given(mockResponse.getStatusCode()).willReturn(HttpStatus.NOT_FOUND);
given(mockResponse.getRawStatusCode()).willReturn(HttpStatus.NOT_FOUND.value());
given(mockResponse.getBody()).willReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<WebClientResponseException> resultMono = defaultClientResponse.createException();
WebClientResponseException exception = resultMono.block();
assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(exception.getMessage()).isEqualTo("404 Not Found");
assertThat(exception.getHeaders()).containsExactly(entry("Content-Type", Collections.singletonList("text/plain")));
assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes);
}
use of cn.taketoday.web.reactive.function.client.WebClientResponseException in project today-infrastructure by TAKETODAY.
the class DefaultClientResponseTests method createError.
@Test
public void createError() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
given(mockResponse.getStatusCode()).willReturn(HttpStatus.NOT_FOUND);
given(mockResponse.getRawStatusCode()).willReturn(HttpStatus.NOT_FOUND.value());
given(mockResponse.getBody()).willReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<String> resultMono = defaultClientResponse.createError();
StepVerifier.create(resultMono).consumeErrorWith(t -> {
assertThat(t).isInstanceOf(WebClientResponseException.class);
WebClientResponseException exception = (WebClientResponseException) t;
assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(exception.getMessage()).isEqualTo("404 Not Found");
assertThat(exception.getHeaders()).containsExactly(entry("Content-Type", Collections.singletonList("text/plain")));
assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes);
}).verify();
}
use of cn.taketoday.web.reactive.function.client.WebClientResponseException in project today-framework by TAKETODAY.
the class DefaultClientResponseTests method createException.
@Test
public void createException() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
given(mockResponse.getStatusCode()).willReturn(HttpStatus.NOT_FOUND);
given(mockResponse.getRawStatusCode()).willReturn(HttpStatus.NOT_FOUND.value());
given(mockResponse.getBody()).willReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<WebClientResponseException> resultMono = defaultClientResponse.createException();
WebClientResponseException exception = resultMono.block();
assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(exception.getMessage()).isEqualTo("404 Not Found");
assertThat(exception.getHeaders()).containsExactly(entry("Content-Type", Collections.singletonList("text/plain")));
assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes);
}
use of cn.taketoday.web.reactive.function.client.WebClientResponseException in project today-framework by TAKETODAY.
the class DefaultClientResponseTests method createError.
@Test
public void createError() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
given(mockResponse.getStatusCode()).willReturn(HttpStatus.NOT_FOUND);
given(mockResponse.getRawStatusCode()).willReturn(HttpStatus.NOT_FOUND.value());
given(mockResponse.getBody()).willReturn(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<String> resultMono = defaultClientResponse.createError();
StepVerifier.create(resultMono).consumeErrorWith(t -> {
assertThat(t).isInstanceOf(WebClientResponseException.class);
WebClientResponseException exception = (WebClientResponseException) t;
assertThat(exception.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(exception.getMessage()).isEqualTo("404 Not Found");
assertThat(exception.getHeaders()).containsExactly(entry("Content-Type", Collections.singletonList("text/plain")));
assertThat(exception.getResponseBodyAsByteArray()).isEqualTo(bytes);
}).verify();
}
Aggregations