use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class CorsUrlHandlerMappingTests method preFlightRequestWithGlobalCorsConfig.
@Test
public void preFlightRequestWithGlobalCorsConfig() throws Exception {
CorsConfiguration mappedConfig = new CorsConfiguration();
mappedConfig.addAllowedOrigin("*");
this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/welcome.html", mappedConfig));
String origin = "http://domain2.com";
ServerWebExchange exchange = createExchange(HttpMethod.OPTIONS, "/welcome.html", origin);
Object actual = this.handlerMapping.getHandler(exchange).block();
assertNotNull(actual);
assertNotSame(this.welcomeController, actual);
assertEquals("*", exchange.getResponse().getHeaders().getFirst(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class SimpleUrlHandlerMappingTests method testUrl.
private void testUrl(String url, Object bean, HandlerMapping handlerMapping, String pathWithinMapping) {
ServerWebExchange exchange = MockServerHttpRequest.method(HttpMethod.GET, URI.create(url)).toExchange();
Object actual = handlerMapping.getHandler(exchange).block();
if (bean != null) {
assertNotNull(actual);
assertSame(bean, actual);
//noinspection OptionalGetWithoutIsPresent
assertEquals(pathWithinMapping, exchange.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).get());
} else {
assertNull(actual);
}
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class VersionResourceResolverTests method resolveResourceSuccess.
@Test
public void resolveResourceSuccess() throws Exception {
String versionFile = "bar-version.css";
String version = "version";
String file = "bar.css";
Resource expected = new ClassPathResource("test/" + file, getClass());
ServerWebExchange exchange = MockServerHttpRequest.get("/resources/bar-version.css").toExchange();
given(this.chain.resolveResource(exchange, versionFile, this.locations)).willReturn(Mono.empty());
given(this.chain.resolveResource(exchange, file, this.locations)).willReturn(Mono.just(expected));
given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
given(this.versionStrategy.removeVersion(versionFile, version)).willReturn(file);
given(this.versionStrategy.getResourceVersion(expected)).willReturn(version);
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
Resource actual = this.resolver.resolveResourceInternal(exchange, versionFile, this.locations, this.chain).block(Duration.ofMillis(5000));
assertEquals(expected.getFilename(), actual.getFilename());
verify(this.versionStrategy, times(1)).getResourceVersion(expected);
assertThat(actual, instanceOf(HttpResource.class));
assertEquals("\"" + version + "\"", ((HttpResource) actual).getResponseHeaders().getETag());
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class PatternsRequestConditionTests method compareNumberOfMatchingPatterns.
@Test
public void compareNumberOfMatchingPatterns() throws Exception {
ServerWebExchange exchange = get("/foo.html").toExchange();
PatternsRequestCondition c1 = new PatternsRequestCondition("/foo", "*.jpeg");
PatternsRequestCondition c2 = new PatternsRequestCondition("/foo", "*.html");
PatternsRequestCondition match1 = c1.getMatchingCondition(exchange);
PatternsRequestCondition match2 = c2.getMatchingCondition(exchange);
assertNotNull(match1);
assertEquals(1, match1.compareTo(match2, exchange));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class PatternsRequestConditionTests method matchSuffixPattern.
@Test
public void matchSuffixPattern() throws Exception {
ServerWebExchange exchange = get("/foo.html").toExchange();
PatternsRequestCondition condition = new PatternsRequestCondition("/{foo}");
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertNotNull(match);
assertEquals("/{foo}.*", match.getPatterns().iterator().next());
condition = new PatternsRequestCondition(new String[] { "/{foo}" }, null, null, false, false, null);
match = condition.getMatchingCondition(exchange);
assertNotNull(match);
assertEquals("/{foo}", match.getPatterns().iterator().next());
}
Aggregations