Search in sources :

Example 76 with Resource

use of org.springframework.core.io.Resource 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 77 with Resource

use of org.springframework.core.io.Resource 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 78 with Resource

use of org.springframework.core.io.Resource in project cas by apereo.

the class CasCoreBootstrapStandaloneConfiguration method loadEmbeddedYamlOverriddenProperties.

private void loadEmbeddedYamlOverriddenProperties(final Properties props) {
    final Resource resource = resourceLoader.getResource("classpath:/application.yml");
    if (resource != null && resource.exists()) {
        final Map pp = loadYamlProperties(resource);
        if (pp.isEmpty()) {
            LOGGER.debug("No properties were located inside [{}]", resource);
        } else {
            LOGGER.debug("Found settings [{}] in YAML file [{}]", pp.keySet(), resource);
            props.putAll(pp);
        }
    }
}
Also used : Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) Map(java.util.Map)

Example 79 with Resource

use of org.springframework.core.io.Resource in project head by mifos.

the class ApplicationInitializer method copyLogo.

private void copyLogo(ServletContext servletContext) throws IOException {
    ConfigurationLocator configurationLocator = new ConfigurationLocator();
    Resource logoResource = configurationLocator.getUploadedMifosLogo();
    if (!logoResource.exists()) {
        InputStream defaultLogoStream = servletContext.getResourceAsStream("/pages/framework/images/logo.jpg");
        File logoDir = new File(configurationLocator.getConfigurationDirectory() + File.separator + configurationLocator.getLogoDirectory());
        logoDir.mkdir();
        File logo = new File(logoDir, configurationLocator.getLogoName());
        FileUtils.copyInputStreamToFile(defaultLogoStream, logo);
        logger.info("Copy default logo to: " + logo.getAbsolutePath());
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) ConfigurationLocator(org.mifos.framework.util.ConfigurationLocator) File(java.io.File)

Example 80 with Resource

use of org.springframework.core.io.Resource in project head by mifos.

the class MifosMockStrutsTestCase method setStrutsConfig.

protected void setStrutsConfig() throws IOException {
    /*
         * Add a pointer to the context directory so that the web.xml file can be located when running test cases using
         * the junit plugin inside Eclipse.
         * 
         * Find the Web Resources dir (where WEB-INF lives) via Classpath, not hard-coded filenames.
         */
    Resource r = new ClassPathResource("META-INF/resources/WEB-INF/struts-config.xml");
    if (!r.exists() || !r.isReadable()) {
        fail(r.getDescription() + " does not exist or is not readable");
    }
    File webResourcesDirectory = r.getFile().getParentFile().getParentFile();
    mockStruts.setContextDirectory(webResourcesDirectory);
    setConfigFile("/WEB-INF/struts-config.xml,/WEB-INF/other-struts-config.xml");
    /*
         * Because there is no more old-style web.xml as strutstest expects, we simply hard-code our ActionServlet
         * (actually our new ActionServlet30).
         * 
         * Because web.xml (now web-fragment.xml) isn't actually read, the ActionServlet is not initialized with servlet
         * init-params config for all /WEB-INF/*-struts-config.xml listed in web(-fragment).xml, nor are the
         * context-param read into config initParameter from web.xml by the MockStrutsTestCase. All Mifos *StrutsTest
         * don't seem to need that though, and pass with this.
         */
    mockStruts.setActionServlet(new ActionServlet30());
    request = mockStruts.getMockRequest();
    context = mockStruts.getMockContext();
}
Also used : ActionServlet30(org.mifos.framework.struts.ActionServlet30) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

Resource (org.springframework.core.io.Resource)610 Test (org.junit.Test)257 ClassPathResource (org.springframework.core.io.ClassPathResource)231 IOException (java.io.IOException)103 FileSystemResource (org.springframework.core.io.FileSystemResource)77 UrlResource (org.springframework.core.io.UrlResource)68 File (java.io.File)64 ArrayList (java.util.ArrayList)58 ByteArrayResource (org.springframework.core.io.ByteArrayResource)49 InputStream (java.io.InputStream)46 InputStreamResource (org.springframework.core.io.InputStreamResource)31 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)30 URL (java.net.URL)25 HashMap (java.util.HashMap)20 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)18 ServletContextResource (org.springframework.web.context.support.ServletContextResource)18 Map (java.util.Map)17 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)17 ResourceLoader (org.springframework.core.io.ResourceLoader)16 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)16