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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations