Search in sources :

Example 66 with ClassPathResource

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"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 67 with ClassPathResource

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);
}
Also used : UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 68 with ClassPathResource

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);
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 69 with ClassPathResource

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));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 70 with ClassPathResource

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());
}
Also used : ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) ContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Aggregations

ClassPathResource (org.springframework.core.io.ClassPathResource)628 Test (org.junit.Test)404 Resource (org.springframework.core.io.Resource)182 DhisSpringTest (org.hisp.dhis.DhisSpringTest)85 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)80 List (java.util.List)63 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)62 Before (org.junit.Before)55 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)54 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)39 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)36 ArrayList (java.util.ArrayList)35 DataElement (org.hisp.dhis.dataelement.DataElement)32 File (java.io.File)29 UrlResource (org.springframework.core.io.UrlResource)29 TestBean (org.springframework.tests.sample.beans.TestBean)27 IOException (java.io.IOException)26 InputStream (java.io.InputStream)23 FileSystemResource (org.springframework.core.io.FileSystemResource)23 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19