use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class WebMvcEndpointExposureIntegrationTests method createClient.
private WebTestClient createClient(AssertableWebApplicationContext context) {
int port = context.getSourceApplicationContext(ServletWebServerApplicationContext.class).getWebServer().getPort();
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder().codecs((configurer) -> configurer.defaultCodecs().maxInMemorySize(-1)).build();
return WebTestClient.bindToServer().baseUrl("http://localhost:" + port).exchangeStrategies(exchangeStrategies).responseTimeout(Duration.ofMinutes(5)).build();
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class ControllerEndpointWebFluxIntegrationTests method endpointsCanBeAccessed.
@Test
void endpointsCanBeAccessed() {
TestSecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
this.context = new AnnotationConfigReactiveWebApplicationContext();
this.context.register(DefaultConfiguration.class, ExampleController.class);
TestPropertyValues.of("management.endpoints.web.exposure.include=*").applyTo(this.context);
this.context.refresh();
WebTestClient webClient = WebTestClient.bindToApplicationContext(this.context).build();
webClient.get().uri("/actuator/example").exchange().expectStatus().isOk();
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class WebFluxEndpointIntegrationTests method linksAreProvidedToAllEndpointTypes.
@Test
void linksAreProvidedToAllEndpointTypes() {
this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include:*").run((context) -> {
WebTestClient client = createWebTestClient(context);
client.get().uri("/actuator").exchange().expectStatus().isOk().expectBody().jsonPath("_links.beans").isNotEmpty().jsonPath("_links.restcontroller").isNotEmpty().jsonPath("_links.controller").isNotEmpty();
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method bindingResultErrorIncludeMessageAndErrors.
@Test
void bindingResultErrorIncludeMessageAndErrors() {
this.contextRunner.withPropertyValues("server.error.include-message=on-param", "server.error.include-binding-errors=on-param").run((context) -> {
WebTestClient client = getWebClient(context);
client.post().uri("/bind?message=true&errors=true").contentType(MediaType.APPLICATION_JSON).bodyValue("{}").exchange().expectStatus().isBadRequest().expectBody().jsonPath("status").isEqualTo("400").jsonPath("error").isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path").isEqualTo(("/bind")).jsonPath("exception").doesNotExist().jsonPath("errors").isArray().jsonPath("message").isNotEmpty().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 bindingResultError.
@Test
void bindingResultError() {
this.contextRunner.run((context) -> {
WebTestClient client = getWebClient(context);
client.post().uri("/bind").contentType(MediaType.APPLICATION_JSON).bodyValue("{}").exchange().expectStatus().isBadRequest().expectBody().jsonPath("status").isEqualTo("400").jsonPath("error").isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path").isEqualTo(("/bind")).jsonPath("exception").doesNotExist().jsonPath("errors").doesNotExist().jsonPath("message").doesNotExist().jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
});
}
Aggregations