use of org.springframework.core.io.Resource 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.Resource 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);
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class GzipResourceResolverTests method resolveGzippedFile.
@Test
public void resolveGzippedFile() throws IOException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Accept-Encoding", "gzip");
String file = "js/foo.js";
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);
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class GzipResourceResolverTests method createGzFile.
private static void createGzFile(String filePath) throws IOException {
Resource location = new ClassPathResource("test/", GzipResourceResolverTests.class);
Resource fileResource = new FileSystemResource(location.createRelative(filePath).getFile());
Path gzFilePath = Paths.get(fileResource.getFile().getAbsolutePath() + ".gz");
Files.deleteIfExists(gzFilePath);
File gzFile = Files.createFile(gzFilePath).toFile();
GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzFile));
FileCopyUtils.copy(fileResource.getInputStream(), out);
gzFile.deleteOnExit();
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class ResourceHttpRequestHandlerTests method getResourceWithMediaTypeResolvedThroughServletContext.
// SPR-14368
@Test
public void getResourceWithMediaTypeResolvedThroughServletContext() throws Exception {
MockServletContext servletContext = new MockServletContext() {
@Override
public String getMimeType(String filePath) {
return "foo/bar";
}
@Override
public String getVirtualServerName() {
return null;
}
};
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setServletContext(servletContext);
handler.setLocations(paths);
handler.afterPropertiesSet();
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css");
handler.handleRequest(this.request, this.response);
assertEquals("foo/bar", this.response.getContentType());
assertEquals("h1 { color:red; }", this.response.getContentAsString());
}
Aggregations