use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.
the class WebFluxTagsTests method uriTagValueIsRootWhenRequestHasNoPatternAndSlashPathInfo.
@Test
void uriTagValueIsRootWhenRequestHasNoPatternAndSlashPathInfo() {
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
ServerWebExchange exchange = MockServerWebExchange.from(request);
Tag tag = WebFluxTags.uri(exchange);
assertThat(tag.getValue()).isEqualTo("root");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.
the class WebFluxTagsTests method uriTagValueIsUnknownWhenRequestHasNoPatternAndNonRootPathInfo.
@Test
void uriTagValueIsUnknownWhenRequestHasNoPatternAndNonRootPathInfo() {
MockServerHttpRequest request = MockServerHttpRequest.get("/example").build();
ServerWebExchange exchange = MockServerWebExchange.from(request);
Tag tag = WebFluxTags.uri(exchange);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class HttpHandlerConnectorTests method adaptRequest.
@Test
public void adaptRequest() {
TestHttpHandler handler = new TestHttpHandler(response -> {
response.setStatusCode(HttpStatus.OK);
return response.setComplete();
});
new HttpHandlerConnector(handler).connect(HttpMethod.POST, URI.create("/custom-path"), request -> {
request.getHeaders().put("custom-header", Arrays.asList("h0", "h1"));
request.getCookies().add("custom-cookie", new HttpCookie("custom-cookie", "c0"));
return request.writeWith(Mono.just(toDataBuffer("Custom body")));
}).block(Duration.ofSeconds(5));
MockServerHttpRequest request = (MockServerHttpRequest) handler.getSavedRequest();
assertThat(request.getMethod()).isEqualTo(HttpMethod.POST);
assertThat(request.getURI().toString()).isEqualTo("/custom-path");
HttpHeaders headers = request.getHeaders();
assertThat(headers.get("custom-header")).isEqualTo(Arrays.asList("h0", "h1"));
assertThat(request.getCookies().getFirst("custom-cookie")).isEqualTo(new HttpCookie("custom-cookie", "c0"));
assertThat(headers.get(HttpHeaders.COOKIE)).isEqualTo(Collections.singletonList("custom-cookie=c0"));
DataBuffer buffer = request.getBody().blockFirst(Duration.ZERO);
assertThat(buffer.toString(UTF_8)).isEqualTo("Custom body");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method annotatedResponseStatusCode.
@Test
void annotatedResponseStatusCode() {
Exception error = new CustomException();
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, error), ErrorAttributeOptions.defaults());
assertThat(attributes.get("error")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.getReasonPhrase());
assertThat(attributes).doesNotContainKey("message");
assertThat(attributes.get("status")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.value());
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method processResponseStatusExceptionWithNoNestedCause.
@Test
void processResponseStatusExceptionWithNoNestedCause() {
ResponseStatusException error = new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "could not process request");
this.errorAttributes = new DefaultErrorAttributes();
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
ServerRequest serverRequest = buildServerRequest(request, error);
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(serverRequest, ErrorAttributeOptions.of(Include.EXCEPTION, Include.MESSAGE));
assertThat(attributes.get("status")).isEqualTo(406);
assertThat(attributes.get("message")).isEqualTo("could not process request");
assertThat(attributes.get("exception")).isEqualTo(ResponseStatusException.class.getName());
assertThat(this.errorAttributes.getError(serverRequest)).isSameAs(error);
assertThat(serverRequest.attribute(ErrorAttributes.ERROR_ATTRIBUTE)).containsSame(error);
}
Aggregations