Search in sources :

Example 1 with ProtocolResolver

use of org.springframework.core.io.ProtocolResolver in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method mockProtocolResolver.

private ProtocolResolver mockProtocolResolver(String path, Resource resource) {
    ProtocolResolver resolver = mock(ProtocolResolver.class);
    given(resolver.resolve(eq(path), any(ResourceLoader.class))).willReturn(resource);
    return resolver;
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) ProtocolResolver(org.springframework.core.io.ProtocolResolver)

Example 2 with ProtocolResolver

use of org.springframework.core.io.ProtocolResolver in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method customProtocolResolverIsUsedInWebApplication.

@Test
void customProtocolResolverIsUsedInWebApplication() {
    GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
    Resource resource = mock(Resource.class);
    ProtocolResolver resolver = mockProtocolResolver("foo:some-file.txt", resource);
    context.addProtocolResolver(resolver);
    this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
    Resource actual = this.resolver.getResource("foo:some-file.txt");
    assertThat(actual).isSameAs(resource);
    then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DeletedClassLoaderFileResource(org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.DeletedClassLoaderFileResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) ProtocolResolver(org.springframework.core.io.ProtocolResolver) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 3 with ProtocolResolver

use of org.springframework.core.io.ProtocolResolver in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method customProtocolResolverIsUsedInNonWebApplication.

@Test
void customProtocolResolverIsUsedInNonWebApplication() {
    GenericApplicationContext context = new GenericApplicationContext();
    Resource resource = mock(Resource.class);
    ProtocolResolver resolver = mockProtocolResolver("foo:some-file.txt", resource);
    context.addProtocolResolver(resolver);
    this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
    Resource actual = this.resolver.getResource("foo:some-file.txt");
    assertThat(actual).isSameAs(resource);
    then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DeletedClassLoaderFileResource(org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.DeletedClassLoaderFileResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) ProtocolResolver(org.springframework.core.io.ProtocolResolver) Test(org.junit.jupiter.api.Test)

Example 4 with ProtocolResolver

use of org.springframework.core.io.ProtocolResolver in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method customProtocolResolverRegisteredAfterCreationIsUsedInNonWebApplication.

@Test
void customProtocolResolverRegisteredAfterCreationIsUsedInNonWebApplication() {
    GenericApplicationContext context = new GenericApplicationContext();
    Resource resource = mock(Resource.class);
    this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
    ProtocolResolver resolver = mockProtocolResolver("foo:some-file.txt", resource);
    context.addProtocolResolver(resolver);
    Resource actual = this.resolver.getResource("foo:some-file.txt");
    assertThat(actual).isSameAs(resource);
    then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DeletedClassLoaderFileResource(org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.DeletedClassLoaderFileResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) ProtocolResolver(org.springframework.core.io.ProtocolResolver) Test(org.junit.jupiter.api.Test)

Example 5 with ProtocolResolver

use of org.springframework.core.io.ProtocolResolver in project spring-boot by spring-projects.

the class ClassLoaderFilesResourcePatternResolverTests method customProtocolResolverRegisteredAfterCreationIsUsedInWebApplication.

@Test
void customProtocolResolverRegisteredAfterCreationIsUsedInWebApplication() {
    GenericWebApplicationContext context = new GenericWebApplicationContext(new MockServletContext());
    Resource resource = mock(Resource.class);
    this.resolver = new ClassLoaderFilesResourcePatternResolver(context, this.files);
    ProtocolResolver resolver = mockProtocolResolver("foo:some-file.txt", resource);
    context.addProtocolResolver(resolver);
    Resource actual = this.resolver.getResource("foo:some-file.txt");
    assertThat(actual).isSameAs(resource);
    then(resolver).should().resolve(eq("foo:some-file.txt"), any(ResourceLoader.class));
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DeletedClassLoaderFileResource(org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.DeletedClassLoaderFileResource) ClassPathResource(org.springframework.core.io.ClassPathResource) ServletContextResource(org.springframework.web.context.support.ServletContextResource) Resource(org.springframework.core.io.Resource) ProtocolResolver(org.springframework.core.io.ProtocolResolver) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

ProtocolResolver (org.springframework.core.io.ProtocolResolver)6 ResourceLoader (org.springframework.core.io.ResourceLoader)6 Test (org.junit.jupiter.api.Test)5 DeletedClassLoaderFileResource (org.springframework.boot.devtools.restart.ClassLoaderFilesResourcePatternResolver.DeletedClassLoaderFileResource)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 Resource (org.springframework.core.io.Resource)4 ServletContextResource (org.springframework.web.context.support.ServletContextResource)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1