Search in sources :

Example 1 with ResourceResolverChain

use of org.springframework.web.servlet.resource.ResourceResolverChain in project spring-boot-admin by codecentric.

the class PreferMinifiedFilteringResourceResolverTest method test_resolveResource.

@Test
public void test_resolveResource() {
    List<? extends Resource> resources = asList(new ClassPathResource("testResource.txt"), new ClassPathResource("application.properties"));
    new PreferMinifiedFilteringResourceResolver(".min").resolveResource(null, null, resources, new ResourceResolverChain() {

        @Override
        public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations) {
            assertThat(locations.size(), is(2));
            assertThat(locations, contains((Resource) new ClassPathResource("testResource.min.txt"), (Resource) new ClassPathResource("application.properties")));
            return null;
        }

        @Override
        public String resolveUrlPath(String resourcePath, List<? extends Resource> locations) {
            return null;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 2 with ResourceResolverChain

use of org.springframework.web.servlet.resource.ResourceResolverChain in project spring-boot-admin by codecentric.

the class ResourcePatternResolvingResourceResolverTest method test_resolveResource.

@Test
public void test_resolveResource() {
    ResourceResolver resolver = new ResourcePatternResolvingResourceResolver(new PathMatchingResourcePatternResolver(), "classpath:/t*Resource.txt");
    resolver.resolveResource(null, null, null, new ResourceResolverChain() {

        @Override
        public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations) {
            assertThat(locations.size(), is(1));
            assertThat(locations.get(0).getFilename(), is("testResource.txt"));
            return null;
        }

        @Override
        public String resolveUrlPath(String resourcePath, List<? extends Resource> locations) {
            return null;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceResolver(org.springframework.web.servlet.resource.ResourceResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) Test(org.junit.Test)

Example 3 with ResourceResolverChain

use of org.springframework.web.servlet.resource.ResourceResolverChain in project spring-boot-admin by codecentric.

the class ConcatenatingResourceResolverTest method test_resolveUrl.

@Test
public void test_resolveUrl() {
    ResourceResolverChain chain = mock(ResourceResolverChain.class);
    when(chain.resolveUrlPath(null, null)).thenReturn("/resources/resource.txt");
    String url = new ConcatenatingResourceResolver(";".getBytes()).resolveUrlPath(null, null, chain);
    assertThat(url, is("/resources/resource.txt"));
}
Also used : ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) Test(org.junit.Test)

Example 4 with ResourceResolverChain

use of org.springframework.web.servlet.resource.ResourceResolverChain in project spring-boot-admin by codecentric.

the class PreferMinifiedFilteringResourceResolverTest method test_resolveUrl.

@Test
public void test_resolveUrl() {
    ResourceResolverChain chain = mock(ResourceResolverChain.class);
    when(chain.resolveUrlPath(null, null)).thenReturn("/resources/resource.txt");
    String url = new PreferMinifiedFilteringResourceResolver("").resolveUrlPath(null, null, chain);
    assertThat(url, is("/resources/resource.txt"));
}
Also used : ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) Test(org.junit.Test)

Example 5 with ResourceResolverChain

use of org.springframework.web.servlet.resource.ResourceResolverChain in project spring-boot-admin by codecentric.

the class ResourcePatternResolvingResourceResolverTest method test_resolveUrl.

@Test
public void test_resolveUrl() {
    ResourceResolverChain chain = mock(ResourceResolverChain.class);
    when(chain.resolveUrlPath(null, null)).thenReturn("/resources/resource.txt");
    String url = new ResourcePatternResolvingResourceResolver(null, null).resolveUrlPath(null, null, chain);
    assertThat(url, is("/resources/resource.txt"));
}
Also used : ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ResourceResolverChain (org.springframework.web.servlet.resource.ResourceResolverChain)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Resource (org.springframework.core.io.Resource)2 ClassPathResource (org.springframework.core.io.ClassPathResource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourceResolver (org.springframework.web.servlet.resource.ResourceResolver)1