use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class GzipResourceResolverTests method resolveGzippedFile.
@Test
public void resolveGzippedFile() throws IOException {
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("Accept-Encoding", "gzip").toExchange();
String file = "js/foo.js";
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
String gzFile = file + ".gz";
Resource resource = new ClassPathResource("test/" + gzFile, getClass());
assertEquals(resource.getDescription(), resolved.getDescription());
assertEquals(new ClassPathResource("test/" + file).getFilename(), resolved.getFilename());
assertTrue("Expected " + resolved + " to be of type " + HttpResource.class, resolved instanceof HttpResource);
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceNoAcceptEncodingInCacheKey.
@Test
public void resolveResourceNoAcceptEncodingInCacheKey() {
String file = "bar.css";
MockServerWebExchange exchange = MockServerHttpRequest.get(file).toExchange();
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file;
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 resolveResourceMatchingEncoding.
@Test
public void resolveResourceMatchingEncoding() {
Resource resource = Mockito.mock(Resource.class);
Resource gzResource = Mockito.mock(Resource.class);
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css", resource);
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css+encoding=gzip", gzResource);
String file = "bar.css";
MockServerWebExchange exchange = MockServerHttpRequest.get(file).toExchange();
assertSame(resource, this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT));
exchange = MockServerHttpRequest.get(file).header("Accept-Encoding", "gzip").toExchange();
assertSame(gzResource, this.chain.resolveResource(exchange, file, 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 resolveResourceInternalFromCache.
@Test
public void resolveResourceInternalFromCache() {
Resource expected = Mockito.mock(Resource.class);
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css", expected);
String file = "bar.css";
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
assertSame(expected, actual);
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transform.
@Test
public void transform() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/main.css").toExchange();
Resource css = new ClassPathResource("test/main.css", getClass());
String expected = "\n" + "@import url(\"/static/bar-11e16cf79faee7ac698c805cf28248d2.css\");\n" + "@import url('/static/bar-11e16cf79faee7ac698c805cf28248d2.css');\n" + "@import url(/static/bar-11e16cf79faee7ac698c805cf28248d2.css);\n\n" + "@import \"/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css\";\n" + "@import '/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css';\n\n" + "body { background: url(\"/static/images/image-f448cd1d5dba82b774f3202c878230b3.png\") }\n";
StepVerifier.create(this.transformerChain.transform(exchange, css).cast(TransformedResource.class)).consumeNextWith(resource -> {
String result = new String(resource.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertEquals(expected, result);
}).expectComplete().verify();
}
Aggregations