Search in sources :

Example 11 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.

the class EventconfFactoryIT method loadConfiguration.

private DefaultEventConfDao loadConfiguration(String relativeResourcePath, boolean passFile) throws DataAccessException, IOException {
    DefaultEventConfDao dao = new DefaultEventConfDao();
    if (passFile) {
        URL url = getUrlForRelativeResourcePath(relativeResourcePath);
        dao.setConfigResource(new MockFileSystemResourceWithInputStream(new File(url.getFile()), getFilteredInputStreamForConfig(relativeResourcePath)));
    } else {
        dao.setConfigResource(new InputStreamResource(getFilteredInputStreamForConfig(relativeResourcePath)));
    }
    dao.afterPropertiesSet();
    return dao;
}
Also used : File(java.io.File) URL(java.net.URL) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 12 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.

the class XmlDataCollectionConfigDaoJaxbTest method testAfterPropertiesSetWithNestedFiles.

/**
     * Test after properties set with nested files (external references to XML groups).
     * 
     * @throws Exception the exception
     */
@Test
public void testAfterPropertiesSetWithNestedFiles() throws Exception {
    System.setProperty("opennms.home", "src/test/resources");
    XmlDataCollectionConfigDaoJaxb dao = new XmlDataCollectionConfigDaoJaxb();
    File xmlCollectionConfig = new File("src/test/resources/etc", XmlDataCollectionConfig.XML_DATACOLLECTION_CONFIG_FILE);
    assertTrue(XmlDataCollectionConfig.XML_DATACOLLECTION_CONFIG_FILE + " is readable", xmlCollectionConfig.canRead());
    InputStream in = new FileInputStream(xmlCollectionConfig);
    dao.setConfigResource(new InputStreamResource(in));
    dao.afterPropertiesSet();
    XmlDataCollectionConfig config = dao.getConfig();
    Assert.assertNotNull("xml data collection should not be null", config);
    Assert.assertEquals(2, config.getXmlDataCollections().get(0).getXmlSources().get(0).getXmlGroups().size());
    Assert.assertEquals(5, config.getXmlDataCollections().get(1).getXmlSources().get(0).getXmlGroups().size());
}
Also used : XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Example 13 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.

the class DefaultDataCollectionConfigDaoIT method instantiateDao.

private DefaultDataCollectionConfigDao instantiateDao(String fileName, boolean setConfigDirectory) throws Exception {
    DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
    File configFile = new File("src/test/opennms-home/etc", fileName);
    if (setConfigDirectory) {
        File configFolder = new File(configFile.getParentFile(), "datacollection");
        Assert.assertTrue(configFolder.isDirectory());
        dao.setConfigDirectory(configFolder.getAbsolutePath());
    }
    dao.setConfigResource(new InputStreamResource(new FileInputStream(configFile)));
    dao.afterPropertiesSet();
    return dao;
}
Also used : File(java.io.File) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) FileInputStream(java.io.FileInputStream) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 14 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.

the class DefaultStatisticsDaemonConfigDaoTest method testAfterPropertiesSetWithGoodConfigFile.

public void testAfterPropertiesSetWithGoodConfigFile() throws Exception {
    DefaultStatisticsDaemonConfigDao dao = new DefaultStatisticsDaemonConfigDao();
    InputStream in = ConfigurationTestUtils.getInputStreamForConfigFile("statsd-configuration.xml");
    dao.setConfigResource(new InputStreamResource(in));
    dao.afterPropertiesSet();
}
Also used : InputStream(java.io.InputStream) DefaultStatisticsDaemonConfigDao(org.opennms.netmgt.dao.jaxb.DefaultStatisticsDaemonConfigDao) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 15 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.

the class DefaultSurveillanceViewConfigDaoIT method createDaoWithConfigFile.

private void createDaoWithConfigFile(final String configFileName) throws IOException {
    Resource resource = new InputStreamResource(ConfigurationTestUtils.getInputStreamForConfigFile(configFileName));
    m_dao = new DefaultSurveillanceViewConfigDao();
    m_dao.setConfigResource(resource);
    m_dao.afterPropertiesSet();
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) InputStreamResource(org.springframework.core.io.InputStreamResource)

Aggregations

InputStreamResource (org.springframework.core.io.InputStreamResource)32 Test (org.junit.Test)12 InputStream (java.io.InputStream)11 Resource (org.springframework.core.io.Resource)10 FileSystemResource (org.springframework.core.io.FileSystemResource)8 File (java.io.File)6 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)6 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)6 FileInputStream (java.io.FileInputStream)4 ClassPathResource (org.springframework.core.io.ClassPathResource)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 X509Certificate (java.security.cert.X509Certificate)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)2 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)2 DefaultStatisticsDaemonConfigDao (org.opennms.netmgt.dao.jaxb.DefaultStatisticsDaemonConfigDao)2 BeansException (org.springframework.beans.BeansException)2 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)2 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)2