use of org.springframework.web.testfixture.server.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(resourceKey("bar.css"), expected);
MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
Resource actual = this.chain.resolveResource(exchange, "bar.css", this.locations).block(TIMEOUT);
assertThat(actual).isSameAs(expected);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceMatchingEncoding.
@Test
public void resolveResourceMatchingEncoding() {
Resource resource = Mockito.mock(Resource.class);
Resource gzipped = Mockito.mock(Resource.class);
this.cache.put(resourceKey("bar.css"), resource);
this.cache.put(resourceKey("bar.css+encoding=gzip"), gzipped);
String file = "bar.css";
MockServerWebExchange exchange = MockServerWebExchange.from(get(file));
assertThat(this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT)).isSameAs(resource);
exchange = MockServerWebExchange.from(get(file).header("Accept-Encoding", "gzip"));
assertThat(this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT)).isSameAs(gzipped);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transform.
@Test
public void transform() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/main.css"));
Resource css = getResource("main.css");
String expected = "\n" + "@import url(\"/static/bar-11e16cf79faee7ac698c805cf28248d2.css?#iefix\");\n" + "@import url('/static/bar-11e16cf79faee7ac698c805cf28248d2.css#bla-normal');\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?#iefix\") }\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 CssLinkResourceTransformerTests method transformSkippedForGzippedResource.
@Test
public void transformSkippedForGzippedResource(GzippedFiles gzippedFiles) throws Exception {
gzippedFiles.create("main.css");
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/main.css"));
Resource resource = getResource("main.css");
EncodedResource gzipped = new EncodedResource(resource, "gzip", ".gz");
StepVerifier.create(this.transformerChain.transform(exchange, gzipped)).expectNext(gzipped).expectComplete().verify();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transformNoLinks.
@Test
public void transformNoLinks() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/foo.css"));
Resource expected = getResource("foo.css");
StepVerifier.create(this.transformerChain.transform(exchange, expected)).consumeNextWith(resource -> assertThat(resource).isSameAs(expected)).expectComplete().verify();
}
Aggregations