use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class AppCacheManifestTransformerTests method transformManifest.
@Test
public void transformManifest() throws Exception {
this.request = new MockHttpServletRequest("GET", "/static/test.appcache");
Resource resource = new ClassPathResource("test/test.appcache", getClass());
Resource result = this.transformer.transform(this.request, resource, this.chain);
byte[] bytes = FileCopyUtils.copyToByteArray(result.getInputStream());
String content = new String(bytes, "UTF-8");
assertThat("should rewrite resource links", content, Matchers.containsString("/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css"));
assertThat("should rewrite resource links", content, Matchers.containsString("/static/bar-11e16cf79faee7ac698c805cf28248d2.css"));
assertThat("should rewrite resource links", content, Matchers.containsString("/static/js/bar-bd508c62235b832d960298ca6c0b7645.js"));
assertThat("should not rewrite external resources", content, Matchers.containsString("//example.org/style.css"));
assertThat("should not rewrite external resources", content, Matchers.containsString("http://example.org/image.png"));
assertThat("should generate fingerprint", content, Matchers.containsString("# Hash: 4bf0338bcbeb0a5b3a4ec9ed8864107d"));
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class PathResourceResolverTests method resolveFromClasspath.
@Test
public void resolveFromClasspath() throws IOException {
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
String requestPath = "bar.css";
Resource actual = this.resolver.resolveResource(null, requestPath, Arrays.asList(location), null);
assertEquals(location.createRelative(requestPath), actual);
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class PathResourceResolverTests method checkResource.
@Test
public void checkResource() throws IOException {
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
testCheckResource(location, "../testsecret/secret.txt");
testCheckResource(location, "test/../../testsecret/secret.txt");
location = new UrlResource(getClass().getResource("./test/"));
String secretPath = new UrlResource(getClass().getResource("testsecret/secret.txt")).getURL().getPath();
testCheckResource(location, "file:" + secretPath);
testCheckResource(location, "/file:" + secretPath);
testCheckResource(location, "/" + secretPath);
testCheckResource(location, "////../.." + secretPath);
testCheckResource(location, "/%2E%2E/testsecret/secret.txt");
testCheckResource(location, "/%2e%2e/testsecret/secret.txt");
testCheckResource(location, " " + secretPath);
testCheckResource(location, "/ " + secretPath);
testCheckResource(location, "url:" + secretPath);
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class PathResourceResolverTests method checkFileLocation.
// SPR-12747
@Test
public void checkFileLocation() throws Exception {
Resource resource = new ClassPathResource("test/main.css", PathResourceResolver.class);
assertTrue(this.resolver.checkResource(resource, resource));
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class ResourceHttpRequestHandlerTests method getMediaTypeWithFavorPathExtensionOff.
// SPR-14577
@Test
public void getMediaTypeWithFavorPathExtensionOff() throws Exception {
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
factory.setFavorPathExtension(false);
factory.afterPropertiesSet();
ContentNegotiationManager manager = factory.getObject();
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setServletContext(new MockServletContext());
handler.setLocations(paths);
handler.setContentNegotiationManager(manager);
handler.afterPropertiesSet();
this.request.addHeader("Accept", "application/json,text/plain,*/*");
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.html");
handler.handleRequest(this.request, this.response);
assertEquals("text/html", this.response.getContentType());
}
Aggregations