use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class ResourceHttpRequestHandlerTests method setUp.
@Before
public void setUp() throws Exception {
dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
List<Resource> paths = new ArrayList<>(2);
paths.add(new ClassPathResource("test/", getClass()));
paths.add(new ClassPathResource("testalternatepath/", getClass()));
paths.add(new ClassPathResource("META-INF/resources/webjars/"));
this.handler = new ResourceHttpRequestHandler();
this.handler.setLocations(paths);
this.handler.setCacheSeconds(3600);
this.handler.setServletContext(new TestServletContext());
this.handler.afterPropertiesSet();
this.request = new MockHttpServletRequest("GET", "");
this.response = new MockHttpServletResponse();
}
use of org.springframework.core.io.ClassPathResource 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.ClassPathResource 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);
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method createTempCopy.
private void createTempCopy(String filePath, String copyFilePath) throws IOException {
Resource location = new ClassPathResource("test/", CssLinkResourceTransformerTests.class);
Path original = Paths.get(location.getFile().getAbsolutePath(), filePath);
Path copy = Paths.get(location.getFile().getAbsolutePath(), copyFilePath);
Files.deleteIfExists(copy);
Files.copy(original, copy);
copy.toFile().deleteOnExit();
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class GzipResourceResolverTests method resolveFingerprintedGzippedFile.
@Test
public void resolveFingerprintedGzippedFile() throws IOException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Accept-Encoding", "gzip");
String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css";
Resource resolved = this.resolver.resolveResource(request, file, this.locations);
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);
}
Aggregations