use of cn.taketoday.http.HttpStatus in project today-framework by TAKETODAY.
the class WebClientDataBufferAllocatingTests method testOnStatus.
private void testOnStatus(Throwable expected, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
HttpStatus errorStatus = HttpStatus.BAD_GATEWAY;
this.server.enqueue(new MockResponse().setResponseCode(errorStatus.value()).setHeader("Content-Type", "application/json").setChunkedBody("{\"error\" : {\"status\" : 502, \"message\" : \"Bad gateway.\"}}", 5));
Mono<String> mono = this.webClient.get().uri("/json").accept(MediaType.APPLICATION_JSON).retrieve().onStatus(status -> status.equals(errorStatus), exceptionFunction).bodyToMono(String.class);
StepVerifier.create(mono).expectErrorSatisfies(actual -> assertThat(actual).isSameAs(expected)).verify(DELAY);
assertThat(this.server.getRequestCount()).isEqualTo(1);
}
use of cn.taketoday.http.HttpStatus in project today-framework by TAKETODAY.
the class RelativeRedirectFilterTests method doFilterSendRedirectWhenCustomSendRedirectHttpStatusThenLocationAnd301.
@Test
public void doFilterSendRedirectWhenCustomSendRedirectHttpStatusThenLocationAnd301() throws Exception {
String location = "/foo";
HttpStatus status = HttpStatus.MOVED_PERMANENTLY;
this.filter.setRedirectStatus(status);
sendRedirect(location);
InOrder inOrder = Mockito.inOrder(this.response);
inOrder.verify(this.response).setStatus(status.value());
inOrder.verify(this.response).setHeader(HttpHeaders.LOCATION, location);
}
use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.
the class ResponseStatusException method getMessage.
@Override
public String getMessage() {
HttpStatus code = HttpStatus.resolve(getRawStatusCode());
String msg = (code != null ? code : getRawStatusCode()) + (this.reason != null ? " \"" + this.reason + "\"" : "");
return ExceptionUtils.buildMessage(msg, getCause());
}
use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.
the class ExchangeFilterFunctionsTests method statusHandlerMatch.
@Test
public void statusHandlerMatch() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
ClientResponse response = mock(ClientResponse.class);
given(response.statusCode()).willReturn(HttpStatus.NOT_FOUND);
ExchangeFunction exchange = r -> Mono.just(response);
ExchangeFilterFunction errorHandler = ExchangeFilterFunctions.statusError(HttpStatus::is4xxClientError, r -> new MyException());
Mono<ClientResponse> result = errorHandler.filter(request, exchange);
StepVerifier.create(result).expectError(MyException.class).verify();
}
use of cn.taketoday.http.HttpStatus in project today-infrastructure by TAKETODAY.
the class WebClientDataBufferAllocatingTests method testOnStatus.
private void testOnStatus(Throwable expected, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
HttpStatus errorStatus = HttpStatus.BAD_GATEWAY;
this.server.enqueue(new MockResponse().setResponseCode(errorStatus.value()).setHeader("Content-Type", "application/json").setChunkedBody("{\"error\" : {\"status\" : 502, \"message\" : \"Bad gateway.\"}}", 5));
Mono<String> mono = this.webClient.get().uri("/json").accept(MediaType.APPLICATION_JSON).retrieve().onStatus(status -> status.equals(errorStatus), exceptionFunction).bodyToMono(String.class);
StepVerifier.create(mono).expectErrorSatisfies(actual -> assertThat(actual).isSameAs(expected)).verify(DELAY);
assertThat(this.server.getRequestCount()).isEqualTo(1);
}
Aggregations