use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class RSocketWebSocketNettyRouteProviderTests method webEndpointsShouldWork.
@Test
void webEndpointsShouldWork() {
new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(HttpHandlerAutoConfiguration.class, WebFluxAutoConfiguration.class, ErrorWebFluxAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, JacksonAutoConfiguration.class, CodecsAutoConfiguration.class, RSocketStrategiesAutoConfiguration.class, RSocketServerAutoConfiguration.class, RSocketMessagingAutoConfiguration.class, RSocketRequesterAutoConfiguration.class)).withUserConfiguration(WebConfiguration.class).withPropertyValues("spring.rsocket.server.transport=websocket", "spring.rsocket.server.mapping-path=/rsocket").run((context) -> {
ReactiveWebServerApplicationContext serverContext = (ReactiveWebServerApplicationContext) context.getSourceApplicationContext();
RSocketRequester requester = createRSocketRequester(context, serverContext.getWebServer());
TestProtocol rsocketResponse = requester.route("websocket").data(new TestProtocol("rsocket")).retrieveMono(TestProtocol.class).block(Duration.ofSeconds(3));
assertThat(rsocketResponse.getName()).isEqualTo("rsocket");
WebTestClient client = createWebTestClient(serverContext.getWebServer());
client.get().uri("/protocol").exchange().expectStatus().isOk().expectBody().jsonPath("name", "http");
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class WebTestClientAutoConfigurationTests method shouldApplySpringSecurityConfigurer.
@Test
@SuppressWarnings("unchecked")
void shouldApplySpringSecurityConfigurer() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class).run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class);
WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils.getField(webTestClient, "builder");
WebHttpHandlerBuilder httpHandlerBuilder = (WebHttpHandlerBuilder) ReflectionTestUtils.getField(builder, "httpHandlerBuilder");
List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils.getField(httpHandlerBuilder, "filters");
assertThat(filters.get(0).getClass().getName()).isEqualTo("org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers$MutatorFilter");
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class WebTestClientAutoConfigurationTests method shouldCustomizeTimeout.
@Test
void shouldCustomizeTimeout() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class).withPropertyValues("spring.test.webtestclient.timeout=15m").run((context) -> {
WebTestClient webTestClient = context.getBean(WebTestClient.class);
assertThat(webTestClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofMinutes(15));
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method testExceptionWithNullMessage.
@Test
void testExceptionWithNullMessage() {
this.contextRunner.withPropertyValues("spring.mustache.prefix=classpath:/unknown/").run((context) -> {
WebTestClient client = getWebClient(context);
String body = client.get().uri("/notfound").accept(MediaType.TEXT_HTML).exchange().expectStatus().isNotFound().expectHeader().contentType(TEXT_HTML_UTF8).expectBody(String.class).returnResult().getResponseBody();
assertThat(body).contains("Whitelabel Error Page").contains(this.logIdFilter.getLogId()).contains("type=Not Found, status=404");
});
}
use of org.springframework.test.web.reactive.server.WebTestClient in project spring-boot by spring-projects.
the class DefaultErrorWebExceptionHandlerIntegrationTests method whitelabelDisabled.
@Test
void whitelabelDisabled() {
this.contextRunner.withPropertyValues("server.error.whitelabel.enabled=false", "spring.mustache.prefix=classpath:/unknown/").run((context) -> {
WebTestClient client = getWebClient(context);
client.get().uri("/notfound").accept(MediaType.TEXT_HTML).exchange().expectStatus().isNotFound().expectBody().isEmpty();
});
}
Aggregations