use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method annotatedResponseStatusCodeWithExceptionMessage.
@Test
void annotatedResponseStatusCodeWithExceptionMessage() {
Exception error = new CustomException("Test Message");
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, error), ErrorAttributeOptions.of(Include.MESSAGE));
assertThat(attributes.get("error")).isEqualTo(HttpStatus.I_AM_A_TEAPOT.getReasonPhrase());
assertThat(attributes.get("message")).isEqualTo("Test 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 notIncludeTrace.
@Test
void notIncludeTrace() {
RuntimeException ex = new RuntimeException("Test");
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, ex), ErrorAttributeOptions.defaults());
assertThat(attributes.get("trace")).isNull();
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method excludeMessage.
@Test
void excludeMessage() {
Error error = new OutOfMemoryError("Test error");
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
ServerRequest serverRequest = buildServerRequest(request, error);
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(serverRequest, ErrorAttributeOptions.defaults());
assertThat(this.errorAttributes.getError(serverRequest)).isSameAs(error);
assertThat(attributes).doesNotContainKey("message");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method processResponseStatusException.
@Test
void processResponseStatusException() {
RuntimeException nested = new RuntimeException("Test");
ResponseStatusException error = new ResponseStatusException(HttpStatus.BAD_REQUEST, "invalid request", nested);
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(400);
assertThat(attributes.get("message")).isEqualTo("invalid request");
assertThat(attributes.get("exception")).isEqualTo(RuntimeException.class.getName());
assertThat(this.errorAttributes.getError(serverRequest)).isSameAs(error);
assertThat(serverRequest.attribute(ErrorAttributes.ERROR_ATTRIBUTE)).containsSame(error);
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-boot by spring-projects.
the class WebFluxAutoConfigurationTests method whenAcceptHeaderLocaleContextResolverIsUsedThenAcceptLanguagesHeaderIsHonoured.
@Test
void whenAcceptHeaderLocaleContextResolverIsUsedThenAcceptLanguagesHeaderIsHonoured() {
this.contextRunner.withPropertyValues("spring.web.locale:en_UK").run((context) -> {
MockServerHttpRequest request = MockServerHttpRequest.get("/").acceptLanguageAsLocales(StringUtils.parseLocaleString("nl_NL")).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
LocaleContextResolver localeContextResolver = context.getBean(LocaleContextResolver.class);
assertThat(localeContextResolver).isInstanceOf(AcceptHeaderLocaleContextResolver.class);
LocaleContext localeContext = localeContextResolver.resolveLocaleContext(exchange);
assertThat(localeContext.getLocale()).isEqualTo(StringUtils.parseLocaleString("nl_NL"));
});
}
Aggregations