Asynchronous ResourceResolver + ResourceTransformer
Issue: SPR-14521
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -74,18 +75,18 @@ public class AppCacheManifestTransformerTests {
|
||||
public void noTransformIfExtensionNoMatch() throws Exception {
|
||||
Resource resource = mock(Resource.class);
|
||||
given(resource.getFilename()).willReturn("foobar.file");
|
||||
given(this.chain.transform(this.exchange, resource)).willReturn(resource);
|
||||
given(this.chain.transform(this.exchange, resource)).willReturn(Mono.just(resource));
|
||||
|
||||
Resource result = this.transformer.transform(this.exchange, resource, this.chain);
|
||||
Resource result = this.transformer.transform(this.exchange, resource, this.chain).blockMillis(5000);
|
||||
assertEquals(resource, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void syntaxErrorInManifest() throws Exception {
|
||||
Resource resource = new ClassPathResource("test/error.appcache", getClass());
|
||||
given(this.chain.transform(this.exchange, resource)).willReturn(resource);
|
||||
given(this.chain.transform(this.exchange, resource)).willReturn(Mono.just(resource));
|
||||
|
||||
Resource result = this.transformer.transform(this.exchange, resource, this.chain);
|
||||
Resource result = this.transformer.transform(this.exchange, resource, this.chain).blockMillis(5000);
|
||||
assertEquals(resource, result);
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ public class AppCacheManifestTransformerTests {
|
||||
this.chain = new DefaultResourceTransformerChain(resolverChain, transformers);
|
||||
|
||||
Resource resource = new ClassPathResource("test/test.appcache", getClass());
|
||||
Resource result = this.transformer.transform(this.exchange, resource, this.chain);
|
||||
Resource result = this.transformer.transform(this.exchange, resource, this.chain).blockMillis(5000);
|
||||
byte[] bytes = FileCopyUtils.copyToByteArray(result.getInputStream());
|
||||
String content = new String(bytes, "UTF-8");
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public class CachingResourceResolverTests {
|
||||
public void resolveResourceInternal() {
|
||||
String file = "bar.css";
|
||||
Resource expected = new ClassPathResource("test/" + file, getClass());
|
||||
Resource actual = this.chain.resolveResource(this.exchange, file, this.locations);
|
||||
Resource actual = this.chain.resolveResource(this.exchange, file, this.locations).blockMillis(5000);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
@@ -93,20 +93,20 @@ public class CachingResourceResolverTests {
|
||||
this.cache.put(CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + "bar.css", expected);
|
||||
|
||||
String file = "bar.css";
|
||||
Resource actual = this.chain.resolveResource(this.exchange, file, this.locations);
|
||||
Resource actual = this.chain.resolveResource(this.exchange, file, this.locations).blockMillis(5000);
|
||||
|
||||
assertSame(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceInternalNoMatch() {
|
||||
assertNull(this.chain.resolveResource(this.exchange, "invalid.css", this.locations));
|
||||
assertNull(this.chain.resolveResource(this.exchange, "invalid.css", this.locations).blockMillis(5000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolverUrlPath() {
|
||||
String expected = "/foo.css";
|
||||
String actual = this.chain.resolveUrlPath(expected, this.locations);
|
||||
String actual = this.chain.resolveUrlPath(expected, this.locations).blockMillis(5000);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
@@ -115,14 +115,14 @@ public class CachingResourceResolverTests {
|
||||
public void resolverUrlPathFromCache() {
|
||||
String expected = "cached-imaginary.css";
|
||||
this.cache.put(CachingResourceResolver.RESOLVED_URL_PATH_CACHE_KEY_PREFIX + "imaginary.css", expected);
|
||||
String actual = this.chain.resolveUrlPath("imaginary.css", this.locations);
|
||||
String actual = this.chain.resolveUrlPath("imaginary.css", this.locations).blockMillis(5000);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolverUrlPathNoMatch() {
|
||||
assertNull(this.chain.resolveUrlPath("invalid.css", this.locations));
|
||||
assertNull(this.chain.resolveUrlPath("invalid.css", this.locations).blockMillis(5000));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,7 +130,7 @@ public class CachingResourceResolverTests {
|
||||
String file = "bar.css";
|
||||
this.request.setUri(file).setHeader("Accept-Encoding", "gzip");
|
||||
|
||||
Resource expected = this.chain.resolveResource(this.exchange, file, this.locations);
|
||||
Resource expected = this.chain.resolveResource(this.exchange, file, this.locations).blockMillis(5000);
|
||||
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file + "+encoding=gzip";
|
||||
|
||||
assertEquals(expected, this.cache.get(cacheKey).get());
|
||||
@@ -141,7 +141,7 @@ public class CachingResourceResolverTests {
|
||||
String file = "bar.css";
|
||||
this.request.setUri(file);
|
||||
|
||||
Resource expected = this.chain.resolveResource(this.exchange, file, this.locations);
|
||||
Resource expected = this.chain.resolveResource(this.exchange, file, this.locations).blockMillis(5000);
|
||||
String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file;
|
||||
|
||||
assertEquals(expected, this.cache.get(cacheKey).get());
|
||||
@@ -156,10 +156,10 @@ public class CachingResourceResolverTests {
|
||||
|
||||
String file = "bar.css";
|
||||
this.request.setUri(file);
|
||||
assertSame(resource, this.chain.resolveResource(this.exchange, file, this.locations));
|
||||
assertSame(resource, this.chain.resolveResource(this.exchange, file, this.locations).blockMillis(5000));
|
||||
|
||||
request.addHeader("Accept-Encoding", "gzip");
|
||||
assertSame(gzResource, this.chain.resolveResource(this.exchange, file, this.locations));
|
||||
assertSame(gzResource, this.chain.resolveResource(this.exchange, file, this.locations).blockMillis(5000));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,9 @@ public class CssLinkResourceTransformerTests {
|
||||
@Test
|
||||
public void transform() throws Exception {
|
||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||
TransformedResource actual = (TransformedResource) this.transformerChain.transform(this.exchange, css);
|
||||
TransformedResource actual =
|
||||
(TransformedResource) this.transformerChain.transform(this.exchange, css)
|
||||
.blockMillis(5000);
|
||||
|
||||
String expected = "\n" +
|
||||
"@import url(\"bar-11e16cf79faee7ac698c805cf28248d2.css\");\n" +
|
||||
@@ -92,7 +94,7 @@ public class CssLinkResourceTransformerTests {
|
||||
@Test
|
||||
public void transformNoLinks() throws Exception {
|
||||
Resource expected = new ClassPathResource("test/foo.css", getClass());
|
||||
Resource actual = this.transformerChain.transform(this.exchange, expected);
|
||||
Resource actual = this.transformerChain.transform(this.exchange, expected).blockMillis(5000);
|
||||
assertSame(expected, actual);
|
||||
}
|
||||
|
||||
@@ -103,7 +105,7 @@ public class CssLinkResourceTransformerTests {
|
||||
Collections.singletonList(new CssLinkResourceTransformer()));
|
||||
|
||||
Resource externalCss = new ClassPathResource("test/external.css", getClass());
|
||||
Resource resource = transformerChain.transform(this.exchange, externalCss);
|
||||
Resource resource = transformerChain.transform(this.exchange, externalCss).blockMillis(5000);
|
||||
TransformedResource transformedResource = (TransformedResource) resource;
|
||||
|
||||
String expected = "@import url(\"http://example.org/fonts/css\");\n" +
|
||||
@@ -124,7 +126,7 @@ public class CssLinkResourceTransformerTests {
|
||||
@Test
|
||||
public void transformWithNonCssResource() throws Exception {
|
||||
Resource expected = new ClassPathResource("test/images/image.png", getClass());
|
||||
Resource actual = this.transformerChain.transform(this.exchange, expected);
|
||||
Resource actual = this.transformerChain.transform(this.exchange, expected).blockMillis(5000);
|
||||
assertSame(expected, actual);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ public class GzipResourceResolverTests {
|
||||
public void resolveGzippedFile() throws IOException {
|
||||
this.request.addHeader("Accept-Encoding", "gzip");
|
||||
String file = "js/foo.js";
|
||||
Resource resolved = this.resolver.resolveResource(this.exchange, file, this.locations);
|
||||
Resource resolved = this.resolver.resolveResource(this.exchange, file, this.locations).blockMillis(5000);
|
||||
|
||||
String gzFile = file+".gz";
|
||||
Resource resource = new ClassPathResource("test/" + gzFile, getClass());
|
||||
@@ -131,7 +131,7 @@ public class GzipResourceResolverTests {
|
||||
public void resolveFingerprintedGzippedFile() throws IOException {
|
||||
this.request.addHeader("Accept-Encoding", "gzip");
|
||||
String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css";
|
||||
Resource resolved = this.resolver.resolveResource(this.exchange, file, this.locations);
|
||||
Resource resolved = this.resolver.resolveResource(this.exchange, file, this.locations).blockMillis(5000);
|
||||
|
||||
String gzFile = file + ".gz";
|
||||
Resource resource = new ClassPathResource("test/" + gzFile, getClass());
|
||||
@@ -145,7 +145,7 @@ public class GzipResourceResolverTests {
|
||||
public void resolveFromCacheWithEncodingVariants() throws IOException {
|
||||
this.request.addHeader("Accept-Encoding", "gzip");
|
||||
String file = "js/foo.js";
|
||||
Resource resolved = this.resolver.resolveResource(this.exchange, file, this.locations);
|
||||
Resource resolved = this.resolver.resolveResource(this.exchange, file, this.locations).blockMillis(5000);
|
||||
|
||||
String gzFile = file+".gz";
|
||||
Resource gzResource = new ClassPathResource("test/"+gzFile, getClass());
|
||||
@@ -160,7 +160,7 @@ public class GzipResourceResolverTests {
|
||||
MockServerHttpResponse response = new MockServerHttpResponse();
|
||||
this.exchange = new DefaultServerWebExchange(this.request, response, new DefaultWebSessionManager());
|
||||
|
||||
resolved = this.resolver.resolveResource(this.exchange, file, this.locations);
|
||||
resolved = this.resolver.resolveResource(this.exchange, file, this.locations).blockMillis(5000);
|
||||
|
||||
Resource resource = new ClassPathResource("test/"+file, getClass());
|
||||
assertEquals(resource.getDescription(), resolved.getDescription());
|
||||
@@ -172,7 +172,7 @@ public class GzipResourceResolverTests {
|
||||
@Test // SPR-13149
|
||||
public void resolveWithNullRequest() throws IOException {
|
||||
String file = "js/foo.js";
|
||||
Resource resolved = this.resolver.resolveResource(null, file, this.locations);
|
||||
Resource resolved = this.resolver.resolveResource(null, file, this.locations).blockMillis(5000);
|
||||
|
||||
String gzFile = file+".gz";
|
||||
Resource gzResource = new ClassPathResource("test/" + gzFile, getClass());
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.web.reactive.resource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -43,7 +44,8 @@ public class PathResourceResolverTests {
|
||||
public void resolveFromClasspath() throws IOException {
|
||||
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
|
||||
String path = "bar.css";
|
||||
Resource actual = this.resolver.resolveResource(null, path, singletonList(location), null);
|
||||
List<Resource> locations = singletonList(location);
|
||||
Resource actual = this.resolver.resolveResource(null, path, locations, null).blockMillis(5000);
|
||||
assertEquals(location.createRelative(path), actual);
|
||||
}
|
||||
|
||||
@@ -51,7 +53,8 @@ public class PathResourceResolverTests {
|
||||
public void resolveFromClasspathRoot() throws IOException {
|
||||
Resource location = new ClassPathResource("/");
|
||||
String path = "org/springframework/web/reactive/resource/test/bar.css";
|
||||
Resource actual = this.resolver.resolveResource(null, path, singletonList(location), null);
|
||||
List<Resource> locations = singletonList(location);
|
||||
Resource actual = this.resolver.resolveResource(null, path, locations, null).blockMillis(5000);
|
||||
assertNotNull(actual);
|
||||
}
|
||||
|
||||
@@ -75,7 +78,8 @@ public class PathResourceResolverTests {
|
||||
}
|
||||
|
||||
private void testCheckResource(Resource location, String requestPath) throws IOException {
|
||||
Resource actual = this.resolver.resolveResource(null, requestPath, singletonList(location), null);
|
||||
List<Resource> locations = singletonList(location);
|
||||
Resource actual = this.resolver.resolveResource(null, requestPath, locations, null).blockMillis(5000);
|
||||
if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) {
|
||||
fail(requestPath + " doesn't actually exist as a relative path");
|
||||
}
|
||||
@@ -90,7 +94,9 @@ public class PathResourceResolverTests {
|
||||
);
|
||||
|
||||
Resource location = new ClassPathResource("test/main.css", PathResourceResolver.class);
|
||||
String actual = this.resolver.resolveUrlPath("../testalternatepath/bar.css", singletonList(location), null);
|
||||
String actual = this.resolver.resolveUrlPath("../testalternatepath/bar.css",
|
||||
singletonList(location), null).blockMillis(5000);
|
||||
|
||||
assertEquals("../testalternatepath/bar.css", actual);
|
||||
}
|
||||
|
||||
@@ -98,7 +104,8 @@ public class PathResourceResolverTests {
|
||||
public void checkRelativeLocation() throws Exception {
|
||||
String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
|
||||
Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework"));
|
||||
assertNotNull(this.resolver.resolveResource(null, "main.css", singletonList(location), null));
|
||||
List<Resource> locations = singletonList(location);
|
||||
assertNotNull(this.resolver.resolveResource(null, "main.css", locations, null).blockMillis(5000));
|
||||
}
|
||||
|
||||
@Test // SPR-12747
|
||||
@@ -110,7 +117,9 @@ public class PathResourceResolverTests {
|
||||
@Test // SPR-13241
|
||||
public void resolvePathRootResource() throws Exception {
|
||||
Resource webjarsLocation = new ClassPathResource("/META-INF/resources/webjars/", PathResourceResolver.class);
|
||||
String path = this.resolver.resolveUrlPathInternal("", singletonList(webjarsLocation), null);
|
||||
String path = this.resolver.resolveUrlPathInternal(
|
||||
"", singletonList(webjarsLocation), null).blockMillis(5000);
|
||||
|
||||
assertNull(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -85,7 +86,9 @@ public class ResourceTransformerSupportTests {
|
||||
this.request.setUri("/resources/main.css");
|
||||
String resourcePath = "/resources/bar.css";
|
||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||
String actual = this.transformer.resolveUrlPath(resourcePath, this.exchange, css, this.transformerChain);
|
||||
String actual = this.transformer.resolveUrlPath(
|
||||
resourcePath, this.exchange, css, this.transformerChain).blockMillis(5000);
|
||||
|
||||
assertEquals("/resources/bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
|
||||
assertEquals("/resources/bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
|
||||
}
|
||||
@@ -93,14 +96,18 @@ public class ResourceTransformerSupportTests {
|
||||
@Test
|
||||
public void resolveUrlPathWithRelativePath() throws Exception {
|
||||
Resource css = new ClassPathResource("test/main.css", getClass());
|
||||
String actual = this.transformer.resolveUrlPath("bar.css", this.exchange, css, this.transformerChain);
|
||||
String actual = this.transformer.resolveUrlPath(
|
||||
"bar.css", this.exchange, css, this.transformerChain).blockMillis(5000);
|
||||
|
||||
assertEquals("bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveUrlPathWithRelativePathInParentDirectory() throws Exception {
|
||||
Resource imagePng = new ClassPathResource("test/images/image.png", getClass());
|
||||
String actual = this.transformer.resolveUrlPath("../bar.css", this.exchange, imagePng, this.transformerChain);
|
||||
String actual = this.transformer.resolveUrlPath(
|
||||
"../bar.css", this.exchange, imagePng, this.transformerChain).blockMillis(5000);
|
||||
|
||||
assertEquals("../bar-11e16cf79faee7ac698c805cf28248d2.css", actual);
|
||||
}
|
||||
|
||||
@@ -108,8 +115,10 @@ public class ResourceTransformerSupportTests {
|
||||
private static class TestResourceTransformerSupport extends ResourceTransformerSupport {
|
||||
|
||||
@Override
|
||||
public Resource transform(ServerWebExchange exchange, Resource resource, ResourceTransformerChain chain) {
|
||||
throw new IllegalStateException("Should never be called");
|
||||
public Mono<Resource> transform(ServerWebExchange exchange, Resource resource,
|
||||
ResourceTransformerChain chain) {
|
||||
|
||||
return Mono.error(new IllegalStateException("Should never be called"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ResourceUrlProviderTests {
|
||||
|
||||
@Test
|
||||
public void getStaticResourceUrl() {
|
||||
String url = this.urlProvider.getForLookupPath("/resources/foo.css");
|
||||
String url = this.urlProvider.getForLookupPath("/resources/foo.css").blockMillis(5000);
|
||||
assertEquals("/resources/foo.css", url);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ResourceUrlProviderTests {
|
||||
ServerWebExchange exchange = new DefaultServerWebExchange(request, response, manager);
|
||||
|
||||
String url = "/resources/foo.css?foo=bar&url=http://example.org";
|
||||
String resolvedUrl = this.urlProvider.getForRequestUrl(exchange, url);
|
||||
String resolvedUrl = this.urlProvider.getForRequestUrl(exchange, url).blockMillis(5000);
|
||||
assertEquals(url, resolvedUrl);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class ResourceUrlProviderTests {
|
||||
resolvers.add(new PathResourceResolver());
|
||||
this.handler.setResourceResolvers(resolvers);
|
||||
|
||||
String url = this.urlProvider.getForLookupPath("/resources/foo.css");
|
||||
String url = this.urlProvider.getForLookupPath("/resources/foo.css").blockMillis(5000);
|
||||
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class ResourceUrlProviderTests {
|
||||
this.handlerMap.put("/resources/*.css", otherHandler);
|
||||
this.urlProvider.setHandlerMap(this.handlerMap);
|
||||
|
||||
String url = this.urlProvider.getForLookupPath("/resources/foo.css");
|
||||
String url = this.urlProvider.getForLookupPath("/resources/foo.css").blockMillis(5000);
|
||||
assertEquals("/resources/foo-e36d2e05253c6c7085a91522ce43a0b4.css", url);
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ public class ResourceWebHandlerTests {
|
||||
|
||||
this.request.addHeader("Accept", "application/json,text/plain,*/*");
|
||||
this.exchange.getAttributes().put(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.html");
|
||||
handler.handle(this.exchange);
|
||||
handler.handle(this.exchange).blockMillis(5000);
|
||||
|
||||
assertEquals(MediaType.TEXT_HTML, this.response.getHeaders().getContentType());
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -76,10 +77,13 @@ public class VersionResourceResolverTests {
|
||||
public void resolveResourceExisting() throws Exception {
|
||||
String file = "bar.css";
|
||||
Resource expected = new ClassPathResource("test/" + file, getClass());
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(expected);
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.just(expected));
|
||||
|
||||
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
|
||||
Resource actual = this.resolver.resolveResourceInternal(null, file, this.locations, this.chain);
|
||||
Resource actual = this.resolver
|
||||
.resolveResourceInternal(null, file, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
verify(this.chain, times(1)).resolveResource(null, file, this.locations);
|
||||
verify(this.versionStrategy, never()).extractVersion(file);
|
||||
@@ -88,10 +92,13 @@ public class VersionResourceResolverTests {
|
||||
@Test
|
||||
public void resolveResourceNoVersionStrategy() throws Exception {
|
||||
String file = "missing.css";
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
this.resolver.setStrategyMap(Collections.emptyMap());
|
||||
Resource actual = this.resolver.resolveResourceInternal(null, file, this.locations, this.chain);
|
||||
Resource actual = this.resolver
|
||||
.resolveResourceInternal(null, file, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertNull(actual);
|
||||
verify(this.chain, times(1)).resolveResource(null, file, this.locations);
|
||||
}
|
||||
@@ -99,11 +106,14 @@ public class VersionResourceResolverTests {
|
||||
@Test
|
||||
public void resolveResourceNoVersionInPath() throws Exception {
|
||||
String file = "bar.css";
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.empty());
|
||||
given(this.versionStrategy.extractVersion(file)).willReturn("");
|
||||
|
||||
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
|
||||
Resource actual = this.resolver.resolveResourceInternal(null, file, this.locations, this.chain);
|
||||
Resource actual = this.resolver
|
||||
.resolveResourceInternal(null, file, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertNull(actual);
|
||||
verify(this.chain, times(1)).resolveResource(null, file, this.locations);
|
||||
verify(this.versionStrategy, times(1)).extractVersion(file);
|
||||
@@ -114,13 +124,16 @@ public class VersionResourceResolverTests {
|
||||
String versionFile = "bar-version.css";
|
||||
String version = "version";
|
||||
String file = "bar.css";
|
||||
given(this.chain.resolveResource(null, versionFile, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveResource(null, versionFile, this.locations)).willReturn(Mono.empty());
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.empty());
|
||||
given(this.versionStrategy.extractVersion(versionFile)).willReturn(version);
|
||||
given(this.versionStrategy.removeVersion(versionFile, version)).willReturn(file);
|
||||
|
||||
this.resolver.setStrategyMap(Collections.singletonMap("/**", this.versionStrategy));
|
||||
Resource actual = this.resolver.resolveResourceInternal(null, versionFile, this.locations, this.chain);
|
||||
Resource actual = this.resolver
|
||||
.resolveResourceInternal(null, versionFile, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertNull(actual);
|
||||
verify(this.versionStrategy, times(1)).removeVersion(versionFile, version);
|
||||
}
|
||||
@@ -131,14 +144,17 @@ public class VersionResourceResolverTests {
|
||||
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.chain.resolveResource(null, versionFile, this.locations)).willReturn(Mono.empty());
|
||||
given(this.chain.resolveResource(null, file, this.locations)).willReturn(Mono.just(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);
|
||||
Resource actual = this.resolver
|
||||
.resolveResourceInternal(null, versionFile, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertNull(actual);
|
||||
verify(this.versionStrategy, times(1)).getResourceVersion(expected);
|
||||
}
|
||||
@@ -153,14 +169,17 @@ public class VersionResourceResolverTests {
|
||||
MockServerHttpResponse response = new MockServerHttpResponse();
|
||||
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
|
||||
ServerWebExchange exchange = new DefaultServerWebExchange(request, response, sessionManager);
|
||||
given(this.chain.resolveResource(exchange, versionFile, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveResource(exchange, file, this.locations)).willReturn(expected);
|
||||
given(this.chain.resolveResource(exchange, versionFile, this.locations)).willReturn(Mono.empty());
|
||||
given(this.chain.resolveResource(exchange, file, this.locations)).willReturn(Mono.just(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(exchange, versionFile, this.locations, this.chain);
|
||||
Resource actual = this.resolver
|
||||
.resolveResourceInternal(exchange, versionFile, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertEquals(expected.getFilename(), actual.getFilename());
|
||||
verify(this.versionStrategy, times(1)).getResourceVersion(expected);
|
||||
assertThat(actual, instanceOf(HttpResource.class));
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.springframework.web.reactive.resource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -33,6 +33,7 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange;
|
||||
import org.springframework.web.server.session.DefaultWebSessionManager;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -61,7 +62,7 @@ public class WebJarsResourceResolverTests {
|
||||
@Before
|
||||
public void setup() {
|
||||
// for this to work, an actual WebJar must be on the test classpath
|
||||
this.locations = Collections.singletonList(new ClassPathResource("/META-INF/resources/webjars"));
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars"));
|
||||
this.resolver = new WebJarsResourceResolver();
|
||||
this.chain = mock(ResourceResolverChain.class);
|
||||
|
||||
@@ -74,11 +75,11 @@ public class WebJarsResourceResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveUrlExisting() {
|
||||
this.locations = Collections.singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
String file = "/foo/2.3/foo.txt";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(file);
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.just(file));
|
||||
|
||||
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain);
|
||||
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).blockMillis(5000);
|
||||
|
||||
assertEquals(file, actual);
|
||||
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
|
||||
@@ -86,11 +87,11 @@ public class WebJarsResourceResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveUrlExistingNotInJarFile() {
|
||||
this.locations = Collections.singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
String file = "foo/foo.txt";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain);
|
||||
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).blockMillis(5000);
|
||||
|
||||
assertNull(actual);
|
||||
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
|
||||
@@ -101,10 +102,10 @@ public class WebJarsResourceResolverTests {
|
||||
public void resolveUrlWebJarResource() {
|
||||
String file = "underscorejs/underscore.js";
|
||||
String expected = "underscorejs/1.8.3/underscore.js";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveUrlPath(expected, this.locations)).willReturn(expected);
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
|
||||
given(this.chain.resolveUrlPath(expected, this.locations)).willReturn(Mono.just(expected));
|
||||
|
||||
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain);
|
||||
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).blockMillis(5000);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
|
||||
@@ -114,9 +115,9 @@ public class WebJarsResourceResolverTests {
|
||||
@Test
|
||||
public void resolveUrlWebJarResourceNotFound() {
|
||||
String file = "something/something.js";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain);
|
||||
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain).blockMillis(5000);
|
||||
|
||||
assertNull(actual);
|
||||
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
|
||||
@@ -126,11 +127,13 @@ public class WebJarsResourceResolverTests {
|
||||
@Test
|
||||
public void resolveResourceExisting() {
|
||||
Resource expected = mock(Resource.class);
|
||||
this.locations = Collections.singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
String file = "foo/2.3/foo.txt";
|
||||
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(expected);
|
||||
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.just(expected));
|
||||
|
||||
Resource actual = this.resolver.resolveResource(this.exchange, file, this.locations, this.chain);
|
||||
Resource actual = this.resolver
|
||||
.resolveResource(this.exchange, file, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
|
||||
@@ -139,9 +142,11 @@ public class WebJarsResourceResolverTests {
|
||||
@Test
|
||||
public void resolveResourceNotFound() {
|
||||
String file = "something/something.js";
|
||||
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(null);
|
||||
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
Resource actual = this.resolver.resolveResource(this.exchange, file, this.locations, this.chain);
|
||||
Resource actual = this.resolver
|
||||
.resolveResource(this.exchange, file, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertNull(actual);
|
||||
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
|
||||
@@ -150,13 +155,20 @@ public class WebJarsResourceResolverTests {
|
||||
|
||||
@Test
|
||||
public void resolveResourceWebJar() {
|
||||
Resource expected = mock(Resource.class);
|
||||
String file = "underscorejs/underscore.js";
|
||||
String expectedPath = "underscorejs/1.8.3/underscore.js";
|
||||
this.locations = Collections.singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
given(this.chain.resolveResource(this.exchange, expectedPath, this.locations)).willReturn(expected);
|
||||
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars/", getClass()));
|
||||
|
||||
Resource actual = this.resolver.resolveResource(this.exchange, file, this.locations, this.chain);
|
||||
String file = "underscorejs/underscore.js";
|
||||
given(this.chain.resolveResource(this.exchange, file, this.locations)).willReturn(Mono.empty());
|
||||
|
||||
Resource expected = mock(Resource.class);
|
||||
String expectedPath = "underscorejs/1.8.3/underscore.js";
|
||||
given(this.chain.resolveResource(this.exchange, expectedPath, this.locations))
|
||||
.willReturn(Mono.just(expected));
|
||||
|
||||
|
||||
Resource actual = this.resolver
|
||||
.resolveResource(this.exchange, file, this.locations, this.chain)
|
||||
.blockMillis(5000);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
verify(this.chain, times(1)).resolveResource(this.exchange, file, this.locations);
|
||||
|
||||
Reference in New Issue
Block a user