Search in sources :

Example 81 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class ResourceTransformerSupportTests method resolveUrlPath.

@Test
public void resolveUrlPath() throws Exception {
    this.request.setRequestURI("/context/servlet/resources/main.css");
    this.request.setContextPath("/context");
    this.request.setServletPath("/servlet");
    String resourcePath = "/context/servlet/resources/bar.css";
    Resource css = new ClassPathResource("test/main.css", getClass());
    String actual = this.transformer.resolveUrlPath(resourcePath, this.request, css, this.transformerChain);
    assertEquals("/context/servlet/resources/bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
}
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 82 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class ResourceTransformerSupportTests method resolveUrlPathWithRelativePathInParentDirectory.

@Test
public void resolveUrlPathWithRelativePathInParentDirectory() throws Exception {
    Resource imagePng = new ClassPathResource("test/images/image.png", getClass());
    String actual = this.transformer.resolveUrlPath("../bar.css", this.request, imagePng, this.transformerChain);
    assertEquals("../bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
}
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 83 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class ResourceTransformerSupportTests method resolveUrlPathWithRelativePath.

@Test
public void resolveUrlPathWithRelativePath() throws Exception {
    Resource css = new ClassPathResource("test/main.css", getClass());
    String actual = this.transformer.resolveUrlPath("bar.css", this.request, css, this.transformerChain);
    assertEquals("bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
}
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 84 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class ResourceUrlEncodingFilterTests method createFilter.

@Before
public void createFilter() throws Exception {
    VersionResourceResolver versionResolver = new VersionResourceResolver();
    versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));
    PathResourceResolver pathResolver = new PathResourceResolver();
    pathResolver.setAllowedLocations(new ClassPathResource("test/", getClass()));
    List<ResourceResolver> resolvers = Arrays.asList(versionResolver, pathResolver);
    this.filter = new ResourceUrlEncodingFilter();
    this.resourceUrlProvider = createResourceUrlProvider(resolvers);
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Example 85 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class VersionResourceResolverTests method resolveResourceVersionDoesNotMatch.

@Test
public void resolveResourceVersionDoesNotMatch() throws Exception {
    String versionFile = "bar-version.css";
    String version = "version";
    String file = "bar.css";
    Resource expected = new ClassPathResource("test/" + file, getClass());
    given(this.chain.resolveResource(null, versionFile, this.locations)).willReturn(null);
    given(this.chain.resolveResource(null, file, this.locations)).willReturn(expected);
    given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
    given(this.versionStrategy.removeVersion(versionFile, version)).willReturn(file);
    given(this.versionStrategy.getResourceVersion(expected)).willReturn("newer-version");
    this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
    Resource actual = this.resolver.resolveResourceInternal(null, versionFile, this.locations, this.chain);
    assertNull(actual);
    verify(this.versionStrategy, times(1)).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)

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