Search in sources :

Example 1 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-boot-admin by codecentric.

the class ConcatenatingResourceResolverTest method test_concatenation.

@Test
public void test_concatenation() throws IOException {
    Resource testResource = new ClassPathResource("/testResource.txt");
    List<Resource> resources = asList(testResource, testResource, testResource);
    Resource resolvedResource = new ConcatenatingResourceResolver(";".getBytes()).resolveResource(null, "/foo.txt", resources, null);
    assertThat(resolvedResource.getFilename(), is("foo.txt"));
    assertThat(resolvedResource.lastModified(), is(testResource.lastModified()));
    assertThat(resolvedResource.getDescription(), is("Byte array resource [(class path resource [testResource.txt], class path resource [testResource.txt], class path resource [testResource.txt])]"));
    assertThat(copyToByteArray(resolvedResource.getInputStream()), is("Foobar;Foobar;Foobar".getBytes()));
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 2 with ClassPathResource

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

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

the class Text method getNonLocalizedFileLookupDatabase.

private static Properties getNonLocalizedFileLookupDatabase() throws TableTagException {
    Properties resource = null;
    if (null == nonLocalizedFileLookupDatabase) {
        ClassPathResource fileLookupDatabase = new ClassPathResource(FilePaths.TABLE_TAG_PATH_DATABASE);
        resource = new Properties();
        try {
            resource.load(fileLookupDatabase.getInputStream());
        } catch (IOException e) {
            throw new TableTagException(e);
        }
    }
    return resource;
}
Also used : TableTagException(org.mifos.framework.exceptions.TableTagException) IOException(java.io.IOException) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 4 with ClassPathResource

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

the class TableTag method getNonLocalizedFileLookupDatabase.

private Properties getNonLocalizedFileLookupDatabase() {
    Properties resource = null;
    if (null == nonLocalizedFileLookupDatabase) {
        ClassPathResource fileLookupDatabase = new ClassPathResource(FilePaths.TABLE_TAG_PATH_DATABASE);
        resource = new Properties();
        try {
            resource.load(fileLookupDatabase.getInputStream());
        } catch (IOException e) {
            throw new MifosRuntimeException(e);
        }
    }
    return resource;
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with ClassPathResource

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

the class ChartOfAccountsConfig method load.

/**
     * Factory method which loads the Chart of Accounts configuration from the
     * given filename. Given XML filename will be validated against
     * {@link FilePaths#CHART_OF_ACCOUNTS_SCHEMA}.
     *
     * @param chartOfAccountsXml
     *            a relative path to the Chart of Accounts configuration file.
     */
public static ChartOfAccountsConfig load(String chartOfAccountsXml) throws ConfigurationException {
    ChartOfAccountsConfig instance = null;
    Document document = null;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = dbf.newDocumentBuilder();
        if (FilePaths.CHART_OF_ACCOUNTS_DEFAULT.equals(chartOfAccountsXml)) {
            // default chart of accounts
            document = parser.parse(MifosResourceUtil.getClassPathResourceAsStream(chartOfAccountsXml));
        } else {
            // custom chart of accounts
            document = parser.parse(MifosResourceUtil.getFile(chartOfAccountsXml));
        }
        // create a SchemaFactory capable of understanding XML schemas
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        // load an XML schema
        ClassPathResource schemaFileResource = new ClassPathResource(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
        Source schemaFile = null;
        if (schemaFileResource.exists()) {
            InputStream in = ChartOfAccountsConfig.class.getClassLoader().getResourceAsStream(FilePaths.CHART_OF_ACCOUNTS_SCHEMA);
            schemaFile = new StreamSource(in);
        } else {
            schemaFile = new StreamSource(MifosResourceUtil.getFile(FilePaths.CHART_OF_ACCOUNTS_SCHEMA));
        }
        Schema schema = factory.newSchema(schemaFile);
        // create a Validator instance and validate document
        Validator validator = schema.newValidator();
        validator.validate(new DOMSource(document));
    } catch (IOException e) {
        throw new ConfigurationException(e);
    } catch (SAXException e) {
        throw new ConfigurationException(e);
    } catch (ParserConfigurationException e) {
        throw new ConfigurationException(e);
    }
    instance = new ChartOfAccountsConfig();
    instance.coaDocument = document;
    return instance;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) IOException(java.io.IOException) Document(org.w3c.dom.Document) ClassPathResource(org.springframework.core.io.ClassPathResource) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Validator(javax.xml.validation.Validator)

Aggregations

ClassPathResource (org.springframework.core.io.ClassPathResource)1437 Test (org.junit.jupiter.api.Test)558 Resource (org.springframework.core.io.Resource)314 Test (org.junit.Test)274 lombok.val (lombok.val)159 List (java.util.List)137 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)129 IOException (java.io.IOException)118 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)104 InputStream (java.io.InputStream)103 File (java.io.File)91 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)87 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)78 ArrayList (java.util.ArrayList)77 FileSystemResource (org.springframework.core.io.FileSystemResource)61 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)60 Bean (org.springframework.context.annotation.Bean)60 Path (java.nio.file.Path)51 Map (java.util.Map)47 BeforeEach (org.junit.jupiter.api.BeforeEach)45