use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method exactStatusTemplateErrorPage.
@Test
void exactStatusTemplateErrorPage() {
this.contextRunner.withPropertyValues("server.error.whitelabel.enabled=false", "spring.mustache.prefix=" + getErrorTemplatesLocation()).run((context) -> {
WebTestClient client = getWebClient(context);
String body = client.get().uri("/notfound").accept(MediaType.TEXT_HTML).exchange().expectStatus().isNotFound().expectBody(String.class).returnResult().getResponseBody();
assertThat(body).contains("404 page");
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method includeStackTraceOnParam.
@Test
void includeStackTraceOnParam() {
this.contextRunner.withPropertyValues("server.error.include-exception=true", "server.error.include-stacktrace=on-param").run((context) -> {
WebTestClient client = getWebClient(context);
client.get().uri("/?trace=true").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("trace").exists().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method alwaysIncludeStackTrace.
@Test
void alwaysIncludeStackTrace() {
this.contextRunner.withPropertyValues("server.error.include-exception=true", "server.error.include-stacktrace=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("trace").exists().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method jsonError.
@Test
void jsonError(CapturedOutput output) {
this.contextRunner.run((context) -> {
WebTestClient client = getWebClient(context);
client.get().uri("/").exchange().expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR).expectBody().jsonPath("status").isEqualTo("500").jsonPath("error").isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()).jsonPath("path").isEqualTo(("/")).jsonPath("message").doesNotExist().jsonPath("exception").doesNotExist().jsonPath("trace").doesNotExist().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
assertThat(output).contains("500 Server Error for HTTP GET \"/\"").contains("java.lang.IllegalStateException: Expected!");
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method defaultErrorView.
@Test
void defaultErrorView() {
this.contextRunner.withPropertyValues("spring.mustache.prefix=classpath:/unknown/", "server.error.include-stacktrace=always", "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("Whitelabel Error Page").contains(this.logIdFilter.getLogId()).contains("<div>Expected!</div>").contains("<div style='white-space:pre-wrap;'>java.lang.IllegalStateException");
});
}
Aggregations