use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method htmlError.
@Test
void htmlError() {
this.contextRunner.withPropertyValues("server.error.include-message=always").run((context) -> {
WebTestClient client = getWebClient(context);
String body = client.get().uri("/").accept(MediaType.TEXT_HTML).exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectHeader().contentType(TEXT_HTML_UTF8).expectBody(String.class).returnResult().getResponseBody();
assertThat(body).contains("status: 500").contains("message: Expected!");
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method escapeHtmlInDefaultErrorView.
@Test
void escapeHtmlInDefaultErrorView() {
this.contextRunner.withPropertyValues("spring.mustache.prefix=classpath:/unknown/", "server.error.include-message=always").run((context) -> {
WebTestClient client = getWebClient(context);
String body = client.get().uri("/html").accept(MediaType.TEXT_HTML).exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectHeader().contentType(TEXT_HTML_UTF8).expectBody(String.class).returnResult().getResponseBody();
assertThat(body).contains("Whitelabel Error Page").contains(this.logIdFilter.getLogId()).doesNotContain("<script>").contains("<script>");
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method invalidAcceptMediaType.
@Test
void invalidAcceptMediaType() {
this.contextRunner.run((context) -> {
WebTestClient client = getWebClient(context);
client.get().uri("/notfound").header("Accept", "v=3.0").exchange().expectStatus().isEqualTo(HttpStatus.NOT_FOUND);
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method defaultErrorAttributesSubclassWithoutDelegation.
@Test
void defaultErrorAttributesSubclassWithoutDelegation() {
this.contextRunner.withUserConfiguration(CustomErrorAttributesWithoutDelegation.class).run((context) -> {
WebTestClient client = getWebClient(context);
client.get().uri("/badRequest").exchange().expectStatus().isBadRequest().expectBody().jsonPath("status").isEqualTo("400").jsonPath("timestamp").doesNotExist().jsonPath("error").isEqualTo("custom error").jsonPath("path").doesNotExist();
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method alwaysIncludeMessage.
@Test
void alwaysIncludeMessage() {
this.contextRunner.withPropertyValues("server.error.include-exception=true", "server.error.include-message=always").run((context) -> {
WebTestClient client = getWebClient(context);
client.get().uri("/?trace=false").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody().jsonPath("status").isEqualTo("500").jsonPath("error").isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()).jsonPath("exception").isEqualTo(IllegalStateException.class.getName()).jsonPath("message").isNotEmpty().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
});
}
Aggregations