Search in sources :

Example 71 with ClassPathResource

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();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ArrayList(java.util.ArrayList) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SimpleDateFormat(java.text.SimpleDateFormat) ClassPathResource(org.springframework.core.io.ClassPathResource) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 72 with ClassPathResource

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

Example 73 with ClassPathResource

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);
}
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 74 with ClassPathResource

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();
}
Also used : Path(java.nio.file.Path) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 75 with ClassPathResource

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