use of org.springframework.core.io.Resource 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.Resource 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.Resource 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.Resource 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);
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class VersionResourceResolverTests method resolveResourceSuccess.
@Test
public void resolveResourceSuccess() throws Exception {
String versionFile = "bar-version.css";
String version = "version";
String file = "bar.css";
Resource expected = new ClassPathResource("test/" + file, getClass());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/resources/bar-version.css");
given(this.chain.resolveResource(request, versionFile, this.locations)).willReturn(null);
given(this.chain.resolveResource(request, 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(version);
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
Resource actual = this.resolver.resolveResourceInternal(request, versionFile, this.locations, this.chain);
assertEquals(expected.getFilename(), actual.getFilename());
verify(this.versionStrategy, times(1)).getResourceVersion(expected);
assertThat(actual, instanceOf(HttpResource.class));
assertEquals("\"" + version + "\"", ((HttpResource) actual).getResponseHeaders().getETag());
}
Aggregations