Search in sources :

Example 16 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project uPortal by Jasig.

the class IdentityImportExportTest method testSubscribedFragment40ImportExport.

@Test
public void testSubscribedFragment40ImportExport() throws Exception {
    runSql("INSERT INTO UP_USER (USER_ID, USER_NAME, USER_DFLT_USR_ID, USER_DFLT_LAY_ID, NEXT_STRUCT_ID, LST_CHAN_UPDT_DT) " + "VALUES (1, 'admin', 0, 0, 0, null)");
    runSql("INSERT INTO UP_USER (USER_ID, USER_NAME, USER_DFLT_USR_ID, USER_DFLT_LAY_ID, NEXT_STRUCT_ID, LST_CHAN_UPDT_DT) " + "VALUES (2, 'mum-lo-campus-apps', 0, 0, 0, null)");
    runSql("INSERT INTO UP_USER (USER_ID, USER_NAME, USER_DFLT_USR_ID, USER_DFLT_LAY_ID, NEXT_STRUCT_ID, LST_CHAN_UPDT_DT) " + "VALUES (3, 'mum-lo-cg', 0, 0, 0, null)");
    final ClassPathResource permissionOwnerResource = new ClassPathResource("/org/apereo/portal/io/xml/subscribed-fragment/test_4-0.subscribed-fragment.xml");
    IdentityImportExportTestUtilities.testIdentityImportExport(this.transactionOperations, this.subscribedFragmentImporter, this.subscribedFragmentExporter, permissionOwnerResource, new Function<ExternalSubscribedFragments, String>() {

        @Override
        public String apply(ExternalSubscribedFragments input) {
            return input.getUsername();
        }
    });
}
Also used : ExternalSubscribedFragments(org.apereo.portal.io.xml.subscribedfragment.ExternalSubscribedFragments) Matchers.anyString(org.mockito.Matchers.anyString) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) BasePortalJpaDaoTest(org.apereo.portal.test.BasePortalJpaDaoTest)

Example 17 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project uPortal by Jasig.

the class SitemapTest method testStylesheetCompilation.

@Test
public void testStylesheetCompilation() throws IOException {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    Resource resource = new ClassPathResource(STYLESHEET_LOCATION);
    Source source = new StreamSource(resource.getInputStream(), resource.getURI().toASCIIString());
    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer(source);
        transformer.setParameter(SitemapPortletController.USE_TAB_GROUPS, useTabGroups);
        transformer.setParameter(SitemapPortletController.USER_LANG, "en_US");
        transformer.setParameter(XsltPortalUrlProvider.CURRENT_REQUEST, request);
        transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, this.xsltPortalUrlProvider);
        Source xmlSource = new StreamSource(new ClassPathResource(XML_LOCATION).getFile());
        CharArrayWriter buffer = new CharArrayWriter();
        TransformerUtils.enableIndenting(transformer);
        transformer.transform(xmlSource, new StreamResult(buffer));
        if (logger.isTraceEnabled()) {
            logger.trace("XML: " + new String(buffer.toCharArray()));
        }
    } catch (TransformerConfigurationException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    } catch (TransformerException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) StreamSource(javax.xml.transform.stream.StreamSource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) MessageSource(org.springframework.context.MessageSource) StaticMessageSource(org.springframework.context.support.StaticMessageSource) CharArrayWriter(java.io.CharArrayWriter) TransformerException(javax.xml.transform.TransformerException) Test(org.junit.Test)

Example 18 with ClassPathResource

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

the class InitializrServiceMetadataTests method readJson.

private static JSONObject readJson(String version) throws IOException, JSONException {
    Resource resource = new ClassPathResource("metadata/service-metadata-" + version + ".json");
    InputStream stream = resource.getInputStream();
    try {
        return new JSONObject(StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
    } finally {
        stream.close();
    }
}
Also used : JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 19 with ClassPathResource

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

the class SpringConfiguration method init.

@PostConstruct
public void init() throws IOException {
    Properties props = new Properties();
    props.load(new ClassPathResource("application.properties").getInputStream());
    String value = props.getProperty("message");
    if (value != null) {
        this.message = value;
    }
}
Also used : Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) PostConstruct(javax.annotation.PostConstruct)

Example 20 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class Jaxb2CollectionHttpMessageConverterTests method readXmlRootElementExternalEntityDisabled.

@Test
@SuppressWarnings("unchecked")
public void readXmlRootElementExternalEntityDisabled() throws Exception {
    Resource external = new ClassPathResource("external.txt", getClass());
    String content = "<!DOCTYPE root [" + "  <!ELEMENT external ANY >\n" + "  <!ENTITY ext SYSTEM \"" + external.getURI() + "\" >]>" + "  <list><rootElement><type s=\"1\"/><external>&ext;</external></rootElement></list>";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
    converter = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>() {

        @Override
        protected XMLInputFactory createXmlInputFactory() {
            XMLInputFactory inputFactory = super.createXmlInputFactory();
            inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
            return inputFactory;
        }
    };
    try {
        Collection<RootElement> result = converter.read(rootElementListType, null, inputMessage);
        assertEquals(1, result.size());
        assertEquals("", result.iterator().next().external);
    } catch (HttpMessageNotReadableException ex) {
    // Some parsers raise an exception
    }
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) Collection(java.util.Collection) ClassPathResource(org.springframework.core.io.ClassPathResource) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Aggregations

ClassPathResource (org.springframework.core.io.ClassPathResource)1441 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 InputStream (java.io.InputStream)105 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)104 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 Bean (org.springframework.context.annotation.Bean)61 FileSystemResource (org.springframework.core.io.FileSystemResource)61 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)60 Path (java.nio.file.Path)51 Map (java.util.Map)47 BeforeEach (org.junit.jupiter.api.BeforeEach)45