use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transformEmptyUrlFunction.
// https://github.com/spring-projects/spring-framework/issues/22602
@Test
public void transformEmptyUrlFunction() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/empty_url_function.css"));
Resource css = getResource("empty_url_function.css");
String expected = ".fooStyle {\n" + "\tbackground: transparent url() no-repeat left top;\n" + "}";
StepVerifier.create(this.transformerChain.transform(exchange, css).cast(TransformedResource.class)).consumeNextWith(transformedResource -> {
String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertThat(result).isEqualTo(expected);
}).expectComplete().verify();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class HandlerMethodMappingTests method ambiguousMatchOnPreFlightRequestWithCorsConfig.
// gh-26490
@Test
public void ambiguousMatchOnPreFlightRequestWithCorsConfig() throws Exception {
this.mapping.registerMapping("/f?o", this.handler, this.method1);
this.mapping.registerMapping("/fo?", this.handler, this.handler.getClass().getMethod("corsHandlerMethod"));
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("https://example.org/foo").header(HttpHeaders.ORIGIN, "https://domain.com").header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"));
this.mapping.getHandler(exchange).block();
MockServerHttpResponse response = exchange.getResponse();
assertThat(response.getStatusCode()).isNull();
assertThat(response.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://domain.com");
assertThat(response.getHeaders().getAccessControlAllowMethods()).containsExactly(HttpMethod.GET);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class HandlerMethodMappingTests method ambiguousMatch.
@Test
public void ambiguousMatch() {
this.mapping.registerMapping("/f?o", this.handler, this.method1);
this.mapping.registerMapping("/fo?", this.handler, this.method2);
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
Mono<Object> result = this.mapping.getHandler(exchange);
StepVerifier.create(result).expectError(IllegalStateException.class).verify();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class HandlerMethodMappingTests method directMatch.
@Test
public void directMatch() {
this.mapping.registerMapping("/foo", this.handler, this.method1);
this.mapping.registerMapping("/fo*", this.handler, this.method2);
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/foo"));
Mono<Object> result = this.mapping.getHandler(exchange);
assertThat(((HandlerMethod) result.block()).getMethod()).isEqualTo(this.method1);
assertThat(this.mapping.getMatches()).containsExactly("/foo");
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method noPathWithinHandlerMappingAttribute.
@Test
public void noPathWithinHandlerMappingAttribute() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
assertThatIllegalArgumentException().isThrownBy(() -> this.handler.handle(exchange).block(TIMEOUT));
}
Aggregations