Search in sources :

Example 6 with VersionResourceResolver

use of org.springframework.web.servlet.resource.VersionResourceResolver in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method resourceHandlerContentStrategyEnabled.

@Test
public void resourceHandlerContentStrategyEnabled() throws Exception {
    load("spring.resources.chain.strategy.content.enabled:true", "spring.resources.chain.strategy.content.paths:/**,/*.png");
    assertThat(getResourceResolvers("/webjars/**")).hasSize(3);
    assertThat(getResourceTransformers("/webjars/**")).hasSize(2);
    assertThat(getResourceResolvers("/**")).extractingResultOf("getClass").containsOnly(CachingResourceResolver.class, VersionResourceResolver.class, PathResourceResolver.class);
    assertThat(getResourceTransformers("/**")).extractingResultOf("getClass").containsOnly(CachingResourceTransformer.class, CssLinkResourceTransformer.class);
    VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers("/**").get(1);
    assertThat(resolver.getStrategyMap().get("/*.png")).isInstanceOf(ContentVersionStrategy.class);
}
Also used : VersionResourceResolver(org.springframework.web.servlet.resource.VersionResourceResolver) Test(org.junit.Test)

Example 7 with VersionResourceResolver

use of org.springframework.web.servlet.resource.VersionResourceResolver in project spring-boot by spring-projects.

the class WebMvcAutoConfigurationTests method resourceHandlerChainCustomized.

@Test
public void resourceHandlerChainCustomized() throws Exception {
    load("spring.resources.chain.enabled:true", "spring.resources.chain.cache:false", "spring.resources.chain.strategy.content.enabled:true", "spring.resources.chain.strategy.content.paths:/**,/*.png", "spring.resources.chain.strategy.fixed.enabled:true", "spring.resources.chain.strategy.fixed.version:test", "spring.resources.chain.strategy.fixed.paths:/**/*.js", "spring.resources.chain.html-application-cache:true", "spring.resources.chain.gzipped:true");
    assertThat(getResourceResolvers("/webjars/**")).hasSize(3);
    assertThat(getResourceTransformers("/webjars/**")).hasSize(2);
    assertThat(getResourceResolvers("/**")).extractingResultOf("getClass").containsOnly(VersionResourceResolver.class, GzipResourceResolver.class, PathResourceResolver.class);
    assertThat(getResourceTransformers("/**")).extractingResultOf("getClass").containsOnly(CssLinkResourceTransformer.class, AppCacheManifestTransformer.class);
    VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers("/**").get(0);
    assertThat(resolver.getStrategyMap().get("/*.png")).isInstanceOf(ContentVersionStrategy.class);
    assertThat(resolver.getStrategyMap().get("/**/*.js")).isInstanceOf(FixedVersionStrategy.class);
}
Also used : VersionResourceResolver(org.springframework.web.servlet.resource.VersionResourceResolver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 VersionResourceResolver (org.springframework.web.servlet.resource.VersionResourceResolver)7 AppCacheManifestTransformer (org.springframework.web.servlet.resource.AppCacheManifestTransformer)4 CachingResourceResolver (org.springframework.web.servlet.resource.CachingResourceResolver)4 CachingResourceTransformer (org.springframework.web.servlet.resource.CachingResourceTransformer)4 CssLinkResourceTransformer (org.springframework.web.servlet.resource.CssLinkResourceTransformer)4 PathResourceResolver (org.springframework.web.servlet.resource.PathResourceResolver)4 ResourceHttpRequestHandler (org.springframework.web.servlet.resource.ResourceHttpRequestHandler)4 ResourceResolver (org.springframework.web.servlet.resource.ResourceResolver)4 ResourceTransformer (org.springframework.web.servlet.resource.ResourceTransformer)4 WebJarsResourceResolver (org.springframework.web.servlet.resource.WebJarsResourceResolver)4 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)2 ContentVersionStrategy (org.springframework.web.servlet.resource.ContentVersionStrategy)2 FixedVersionStrategy (org.springframework.web.servlet.resource.FixedVersionStrategy)2 GzipResourceResolver (org.springframework.web.servlet.resource.GzipResourceResolver)2 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)1