use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class ThymeleafReactiveAutoConfigurationTests method useSecurityDialect.
@Test
void useSecurityDialect() {
this.contextRunner.run((context) -> {
ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class);
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test").build());
exchange.getAttributes().put(SpringSecurityContextUtils.SECURITY_CONTEXT_MODEL_ATTRIBUTE_NAME, new SecurityContextImpl(new TestingAuthenticationToken("alice", "admin")));
WebContext attrs = new WebContext(SpringWebFluxWebApplication.buildApplication(null).buildExchange(exchange, Locale.US, MediaType.TEXT_HTML, StandardCharsets.UTF_8));
String result = engine.process("security-dialect", attrs);
assertThat(result).isEqualTo("<html><body><div>alice</div></body></html>" + System.lineSeparator());
});
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class FreeMarkerAutoConfigurationReactiveIntegrationTests method customSuffix.
@Test
void customSuffix() {
this.contextRunner.withPropertyValues("spring.freemarker.suffix:.freemarker").run((context) -> {
MockServerWebExchange exchange = render(context, "suffixed");
String result = exchange.getResponse().getBodyAsString().block(Duration.ofSeconds(30));
assertThat(result).contains("suffixed");
});
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class MetricsWebFilterTests method filterAddsTagsToRegistryForHandledExceptions.
@Test
void filterAddsTagsToRegistryForHandledExceptions() {
MockServerWebExchange exchange = createExchange("/projects/spring-boot", "/projects/{project}");
this.webFilter.filter(exchange, (serverWebExchange) -> {
exchange.getAttributes().put(ErrorAttributes.ERROR_ATTRIBUTE, new IllegalStateException("test error"));
return exchange.getResponse().setComplete();
}).block(Duration.ofSeconds(30));
assertMetricsContainsTag("uri", "/projects/{project}");
assertMetricsContainsTag("status", "200");
assertMetricsContainsTag("exception", "IllegalStateException");
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class MetricsWebFilterTests method filterAddsStandardTags.
@Test
void filterAddsStandardTags() {
MockServerWebExchange exchange = createTimedHandlerMethodExchange("timed");
this.webFilter.filter(exchange, (serverWebExchange) -> exchange.getResponse().setComplete()).block(Duration.ofSeconds(30));
assertMetricsContainsTag("uri", "/projects/{project}");
assertMetricsContainsTag("status", "200");
}
use of org.springframework.mock.web.server.MockServerWebExchange in project spring-boot by spring-projects.
the class MetricsWebFilterTests method whenMetricsRecordingFailsThenExchangeFilteringSucceeds.
@Test
void whenMetricsRecordingFailsThenExchangeFilteringSucceeds() {
MockServerWebExchange exchange = createExchange("/projects/spring-boot", "/projects/{project}");
this.tagsProvider.failOnce();
this.webFilter.filter(exchange, (serverWebExchange) -> exchange.getResponse().setComplete()).block(Duration.ofSeconds(30));
}
Aggregations