use of org.springframework.core.io.Resource 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);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "bar.css");
assertSame(resource, this.chain.resolveResource(request, "bar.css", this.locations));
request = new MockHttpServletRequest("GET", "bar.css");
request.addHeader("Accept-Encoding", "gzip");
assertSame(gzResource, this.chain.resolveResource(request, "bar.css", this.locations));
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceAcceptEncodingInCacheKey.
@Test
public void resolveResourceAcceptEncodingInCacheKey() {
String file = "bar.css";
MockHttpServletRequest request = new MockHttpServletRequest("GET", file);
request.addHeader("Accept-Encoding", "gzip");
Resource expected = this.chain.resolveResource(request, file, this.locations);
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file + "+encoding=gzip";
assertEquals(expected, this.cache.get(cacheKey).get());
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceNoAcceptEncodingInCacheKey.
@Test
public void resolveResourceNoAcceptEncodingInCacheKey() {
String file = "bar.css";
MockHttpServletRequest request = new MockHttpServletRequest("GET", file);
Resource expected = this.chain.resolveResource(request, file, this.locations);
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file;
assertEquals(expected, this.cache.get(cacheKey).get());
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class ContentBasedVersionStrategyTests method getResourceVersion.
@Test
public void getResourceVersion() throws Exception {
Resource expected = new ClassPathResource("test/bar.css", getClass());
String hash = DigestUtils.md5DigestAsHex(FileCopyUtils.copyToByteArray(expected.getInputStream()));
assertEquals(hash, this.versionStrategy.getResourceVersion(expected));
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transform.
@Test
public void transform() throws Exception {
this.request = new MockHttpServletRequest("GET", "/static/main.css");
Resource css = new ClassPathResource("test/main.css", getClass());
TransformedResource actual = (TransformedResource) this.transformerChain.transform(this.request, css);
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";
String result = new String(actual.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertEquals(expected, result);
}
Aggregations