use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CompositeRequestConditionTests method match.
@Test
public void match() {
MockServerWebExchange exchange = MockServerHttpRequest.get("/path?param1=paramValue1").toExchange();
RequestCondition<?> condition1 = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST);
RequestCondition<?> condition2 = new RequestMethodsRequestCondition(RequestMethod.GET);
CompositeRequestCondition composite1 = new CompositeRequestCondition(this.param1, condition1);
CompositeRequestCondition composite2 = new CompositeRequestCondition(this.param1, condition2);
assertEquals(composite2, composite1.getMatchingCondition(exchange));
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceInternalNoMatch.
@Test
public void resolveResourceInternalNoMatch() {
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
assertNull(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT));
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceAcceptEncodingInCacheKey.
@Test
public void resolveResourceAcceptEncodingInCacheKey() {
String file = "bar.css";
MockServerWebExchange exchange = MockServerHttpRequest.get(file).header("Accept-Encoding", "gzip").toExchange();
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file + "+encoding=gzip";
assertEquals(expected, this.cache.get(cacheKey).get());
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceInternal.
@Test
public void resolveResourceInternal() {
String file = "bar.css";
Resource expected = new ClassPathResource("test/" + file, getClass());
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
assertEquals(expected, actual);
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transformExtLinksNotAllowed.
@Test
public void transformExtLinksNotAllowed() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/external.css").toExchange();
ResourceResolverChain resolverChain = Mockito.mock(DefaultResourceResolverChain.class);
ResourceTransformerChain transformerChain = new DefaultResourceTransformerChain(resolverChain, Collections.singletonList(new CssLinkResourceTransformer()));
Resource externalCss = new ClassPathResource("test/external.css", getClass());
StepVerifier.create(transformerChain.transform(exchange, externalCss).cast(TransformedResource.class)).consumeNextWith(resource -> {
String expected = "@import url(\"http://example.org/fonts/css\");\n" + "body { background: url(\"file:///home/spring/image.png\") }\n" + "figure { background: url(\"//example.org/style.css\")}";
String result = new String(resource.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertEquals(expected, result);
}).expectComplete().verify();
Mockito.verify(resolverChain, Mockito.never()).resolveUrlPath("http://example.org/fonts/css", Collections.singletonList(externalCss));
Mockito.verify(resolverChain, Mockito.never()).resolveUrlPath("file:///home/spring/image.png", Collections.singletonList(externalCss));
Mockito.verify(resolverChain, Mockito.never()).resolveUrlPath("//example.org/style.css", Collections.singletonList(externalCss));
}
Aggregations