org.springframework.web.reactive.resource.ResourceTransformer Java Examples
The following examples show how to use
org.springframework.web.reactive.resource.ResourceTransformer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceHandlerRegistryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void resourceChain() throws Exception { ResourceUrlProvider resourceUrlProvider = Mockito.mock(ResourceUrlProvider.class); this.registry.setResourceUrlProvider(resourceUrlProvider); ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class); ResourceTransformerSupport mockTransformer = Mockito.mock(ResourceTransformerSupport.class); this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer); ResourceWebHandler handler = getHandler("/resources/**"); List<ResourceResolver> resolvers = handler.getResourceResolvers(); assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4)); assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class)); CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0); assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class)); assertThat(resolvers.get(1), Matchers.equalTo(mockResolver)); assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class)); assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class)); List<ResourceTransformer> transformers = handler.getResourceTransformers(); assertThat(transformers, Matchers.hasSize(2)); assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class)); assertThat(transformers.get(1), Matchers.equalTo(mockTransformer)); Mockito.verify(mockTransformer).setResourceUrlProvider(resourceUrlProvider); }
Example #2
Source File: ResourceHandlerRegistryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void resourceChainWithVersionResolver() throws Exception { VersionResourceResolver versionResolver = new VersionResourceResolver() .addFixedVersionStrategy("fixed", "/**/*.js") .addContentVersionStrategy("/**"); this.registration.resourceChain(true).addResolver(versionResolver) .addTransformer(new AppCacheManifestTransformer()); ResourceWebHandler handler = getHandler("/resources/**"); List<ResourceResolver> resolvers = handler.getResourceResolvers(); assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4)); assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class)); assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver)); assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class)); assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class)); List<ResourceTransformer> transformers = handler.getResourceTransformers(); assertThat(transformers, Matchers.hasSize(3)); assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class)); assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class)); assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class)); }
Example #3
Source File: ResourceHandlerRegistryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void resourceChain() throws Exception { ResourceUrlProvider resourceUrlProvider = Mockito.mock(ResourceUrlProvider.class); this.registry.setResourceUrlProvider(resourceUrlProvider); ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class); ResourceTransformerSupport mockTransformer = Mockito.mock(ResourceTransformerSupport.class); this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer); ResourceWebHandler handler = getHandler("/resources/**"); List<ResourceResolver> resolvers = handler.getResourceResolvers(); assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4)); assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class)); CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0); assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class)); assertThat(resolvers.get(1), Matchers.equalTo(mockResolver)); assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class)); assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class)); List<ResourceTransformer> transformers = handler.getResourceTransformers(); assertThat(transformers, Matchers.hasSize(2)); assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class)); assertThat(transformers.get(1), Matchers.equalTo(mockTransformer)); Mockito.verify(mockTransformer).setResourceUrlProvider(resourceUrlProvider); }
Example #4
Source File: ResourceHandlerRegistryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void resourceChainWithVersionResolver() throws Exception { VersionResourceResolver versionResolver = new VersionResourceResolver() .addFixedVersionStrategy("fixed", "/**/*.js") .addContentVersionStrategy("/**"); this.registration.resourceChain(true).addResolver(versionResolver) .addTransformer(new AppCacheManifestTransformer()); ResourceWebHandler handler = getHandler("/resources/**"); List<ResourceResolver> resolvers = handler.getResourceResolvers(); assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4)); assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class)); assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver)); assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class)); assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class)); List<ResourceTransformer> transformers = handler.getResourceTransformers(); assertThat(transformers, Matchers.hasSize(3)); assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class)); assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class)); assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class)); }
Example #5
Source File: ResourceChainRegistration.java From spring-analysis-note with MIT License | 5 votes |
/** * Add a resource transformer to the chain. * @param transformer the transformer to add * @return the current instance for chained method invocation */ public ResourceChainRegistration addTransformer(ResourceTransformer transformer) { Assert.notNull(transformer, "The provided ResourceTransformer should not be null"); this.transformers.add(transformer); if (transformer instanceof CssLinkResourceTransformer) { this.hasCssLinkTransformer = true; } return this; }
Example #6
Source File: ResourceChainRegistration.java From spring-analysis-note with MIT License | 5 votes |
protected List<ResourceTransformer> getResourceTransformers() { if (this.hasVersionResolver && !this.hasCssLinkTransformer) { List<ResourceTransformer> result = new ArrayList<>(this.transformers); boolean hasTransformers = !this.transformers.isEmpty(); boolean hasCaching = hasTransformers && this.transformers.get(0) instanceof CachingResourceTransformer; result.add(hasCaching ? 1 : 0, new CssLinkResourceTransformer()); return result; } return this.transformers; }
Example #7
Source File: ResourceHandlerRegistryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void resourceChainWithoutCaching() throws Exception { this.registration.resourceChain(false); ResourceWebHandler handler = getHandler("/resources/**"); List<ResourceResolver> resolvers = handler.getResourceResolvers(); assertThat(resolvers, Matchers.hasSize(2)); assertThat(resolvers.get(0), Matchers.instanceOf(WebJarsResourceResolver.class)); assertThat(resolvers.get(1), Matchers.instanceOf(PathResourceResolver.class)); List<ResourceTransformer> transformers = handler.getResourceTransformers(); assertThat(transformers, Matchers.hasSize(0)); }
Example #8
Source File: ResourceHandlerRegistryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void resourceChainWithOverrides() throws Exception { CachingResourceResolver cachingResolver = Mockito.mock(CachingResourceResolver.class); VersionResourceResolver versionResolver = Mockito.mock(VersionResourceResolver.class); WebJarsResourceResolver webjarsResolver = Mockito.mock(WebJarsResourceResolver.class); PathResourceResolver pathResourceResolver = new PathResourceResolver(); CachingResourceTransformer cachingTransformer = Mockito.mock(CachingResourceTransformer.class); AppCacheManifestTransformer appCacheTransformer = Mockito.mock(AppCacheManifestTransformer.class); CssLinkResourceTransformer cssLinkTransformer = new CssLinkResourceTransformer(); this.registration.setCacheControl(CacheControl.maxAge(3600, TimeUnit.MILLISECONDS)) .resourceChain(false) .addResolver(cachingResolver) .addResolver(versionResolver) .addResolver(webjarsResolver) .addResolver(pathResourceResolver) .addTransformer(cachingTransformer) .addTransformer(appCacheTransformer) .addTransformer(cssLinkTransformer); ResourceWebHandler handler = getHandler("/resources/**"); List<ResourceResolver> resolvers = handler.getResourceResolvers(); assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4)); assertThat(resolvers.get(0), Matchers.sameInstance(cachingResolver)); assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver)); assertThat(resolvers.get(2), Matchers.sameInstance(webjarsResolver)); assertThat(resolvers.get(3), Matchers.sameInstance(pathResourceResolver)); List<ResourceTransformer> transformers = handler.getResourceTransformers(); assertThat(transformers, Matchers.hasSize(3)); assertThat(transformers.get(0), Matchers.sameInstance(cachingTransformer)); assertThat(transformers.get(1), Matchers.sameInstance(appCacheTransformer)); assertThat(transformers.get(2), Matchers.sameInstance(cssLinkTransformer)); }
Example #9
Source File: ResourceChainRegistration.java From java-technology-stack with MIT License | 5 votes |
/** * Add a resource transformer to the chain. * @param transformer the transformer to add * @return the current instance for chained method invocation */ public ResourceChainRegistration addTransformer(ResourceTransformer transformer) { Assert.notNull(transformer, "The provided ResourceTransformer should not be null"); this.transformers.add(transformer); if (transformer instanceof CssLinkResourceTransformer) { this.hasCssLinkTransformer = true; } return this; }
Example #10
Source File: ResourceChainRegistration.java From java-technology-stack with MIT License | 5 votes |
protected List<ResourceTransformer> getResourceTransformers() { if (this.hasVersionResolver && !this.hasCssLinkTransformer) { List<ResourceTransformer> result = new ArrayList<>(this.transformers); boolean hasTransformers = !this.transformers.isEmpty(); boolean hasCaching = hasTransformers && this.transformers.get(0) instanceof CachingResourceTransformer; result.add(hasCaching ? 1 : 0, new CssLinkResourceTransformer()); return result; } return this.transformers; }
Example #11
Source File: ResourceHandlerRegistryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void resourceChainWithoutCaching() throws Exception { this.registration.resourceChain(false); ResourceWebHandler handler = getHandler("/resources/**"); List<ResourceResolver> resolvers = handler.getResourceResolvers(); assertThat(resolvers, Matchers.hasSize(2)); assertThat(resolvers.get(0), Matchers.instanceOf(WebJarsResourceResolver.class)); assertThat(resolvers.get(1), Matchers.instanceOf(PathResourceResolver.class)); List<ResourceTransformer> transformers = handler.getResourceTransformers(); assertThat(transformers, Matchers.hasSize(0)); }
Example #12
Source File: ResourceHandlerRegistryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void resourceChainWithOverrides() throws Exception { CachingResourceResolver cachingResolver = Mockito.mock(CachingResourceResolver.class); VersionResourceResolver versionResolver = Mockito.mock(VersionResourceResolver.class); WebJarsResourceResolver webjarsResolver = Mockito.mock(WebJarsResourceResolver.class); PathResourceResolver pathResourceResolver = new PathResourceResolver(); CachingResourceTransformer cachingTransformer = Mockito.mock(CachingResourceTransformer.class); AppCacheManifestTransformer appCacheTransformer = Mockito.mock(AppCacheManifestTransformer.class); CssLinkResourceTransformer cssLinkTransformer = new CssLinkResourceTransformer(); this.registration.setCacheControl(CacheControl.maxAge(3600, TimeUnit.MILLISECONDS)) .resourceChain(false) .addResolver(cachingResolver) .addResolver(versionResolver) .addResolver(webjarsResolver) .addResolver(pathResourceResolver) .addTransformer(cachingTransformer) .addTransformer(appCacheTransformer) .addTransformer(cssLinkTransformer); ResourceWebHandler handler = getHandler("/resources/**"); List<ResourceResolver> resolvers = handler.getResourceResolvers(); assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4)); assertThat(resolvers.get(0), Matchers.sameInstance(cachingResolver)); assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver)); assertThat(resolvers.get(2), Matchers.sameInstance(webjarsResolver)); assertThat(resolvers.get(3), Matchers.sameInstance(pathResourceResolver)); List<ResourceTransformer> transformers = handler.getResourceTransformers(); assertThat(transformers, Matchers.hasSize(3)); assertThat(transformers.get(0), Matchers.sameInstance(cachingTransformer)); assertThat(transformers.get(1), Matchers.sameInstance(appCacheTransformer)); assertThat(transformers.get(2), Matchers.sameInstance(cssLinkTransformer)); }