Search in sources :

Example 56 with FileSystemResource

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

the class NMS7963IT method setUp.

/**
 * Sets the up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
    dao.setConfigDirectory("src/test/resources/etc/datacollection");
    dao.setConfigResource(new FileSystemResource("src/test/resources/etc/datacollection-config.xml"));
    dao.afterPropertiesSet();
    DataCollectionConfigFactory.setInstance(dao);
    m_rrdStrategy = new JRobinRrdStrategy();
    m_resourceStorageDao = new FilesystemResourceStorageDao();
    m_resourceStorageDao.setRrdDirectory(m_temporaryFolder.getRoot());
    m_temporaryFolder.newFolder("snmp");
    m_persisterFactory = new RrdPersisterFactory();
    m_persisterFactory.setResourceStorageDao(m_resourceStorageDao);
    m_persisterFactory.setRrdStrategy(m_rrdStrategy);
    m_collectionAgent = new MockCollectionAgent(1, "mynode.local", InetAddrUtils.addr("127.0.0.1"));
    m_nodeDao = EasyMock.createMock(NodeDao.class);
    OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("mynode.local");
    node.setAssetRecord(new OnmsAssetRecord());
    EasyMock.expect(m_nodeDao.get(1)).andReturn(node).anyTimes();
    EasyMock.replay(m_nodeDao);
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) FilesystemResourceStorageDao(org.opennms.netmgt.dao.support.FilesystemResourceStorageDao) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) FileSystemResource(org.springframework.core.io.FileSystemResource) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao) Before(org.junit.Before)

Example 57 with FileSystemResource

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

the class XmlDataCollectionConfigDaoJaxbTest method testAfterPropertiesSetWithBogusFileResource.

/**
 * Test after properties set with bogus file resource.
 *
 * @throws Exception the exception
 */
@Test
public void testAfterPropertiesSetWithBogusFileResource() throws Exception {
    Resource resource = new FileSystemResource("/bogus-file");
    XmlDataCollectionConfigDaoJaxb dao = new XmlDataCollectionConfigDaoJaxb();
    dao.setConfigResource(resource);
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new MarshallingResourceFailureException(ThrowableAnticipator.IGNORE_MESSAGE));
    try {
        dao.afterPropertiesSet();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : MarshallingResourceFailureException(org.opennms.core.xml.MarshallingResourceFailureException) InputStreamResource(org.springframework.core.io.InputStreamResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Example 58 with FileSystemResource

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

the class Provisioner method doImport.

/**
 * <p>doImport</p>
 *
 * @param url a {@link java.lang.String} object.
 */
public void doImport(final String url, final String rescanExisting) {
    try {
        LOG.info("doImport: importing from url: {}, rescanExisting ? {}", url, rescanExisting);
        final Resource resource;
        final URL u = new URL(url);
        if ("file".equals(u.getProtocol())) {
            final File file = new File(u.toURI());
            LOG.debug("doImport: file = {}", file);
            if (file.exists()) {
                resource = new FileSystemResource(file);
            } else {
                final String filename = file.getName();
                if (filename.contains("%20")) {
                    resource = new FileSystemResource(new File(file.getParentFile(), filename.replace("%20", " ")));
                } else {
                    resource = new UrlResource(url);
                }
            }
        } else {
            resource = new UrlResource(url);
        }
        m_stats = new TimeTrackingMonitor();
        send(importStartedEvent(resource, rescanExisting));
        importModelFromResource(resource, rescanExisting, m_stats);
        LOG.info("Finished Importing: {}", m_stats);
        send(importSuccessEvent(m_stats, url, rescanExisting));
    } catch (final Throwable t) {
        final String msg = "Exception importing " + url;
        LOG.error("Exception importing {} using rescanExisting={}", url, rescanExisting, t);
        send(importFailedEvent((msg + ": " + t.getMessage()), url, rescanExisting));
    }
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) URL(java.net.URL)

Example 59 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project waltz by khartec.

the class IOUtilities method getFileResource.

public static Resource getFileResource(String fileName) {
    Resource resource = new ClassPathResource(fileName);
    if (!resource.exists()) {
        String home = System.getProperty("user.home");
        resource = new FileSystemResource(home + "/.waltz/" + fileName);
    }
    return resource;
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 60 with FileSystemResource

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

the class AddPropertiesToConfigurationCommand method loadYamlPropertiesFromConfigurationFile.

private Properties loadYamlPropertiesFromConfigurationFile(final File filePath) {
    final YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResolutionMethod(YamlProcessor.ResolutionMethod.OVERRIDE);
    factory.setResources(new FileSystemResource(filePath));
    factory.setSingleton(true);
    factory.afterPropertiesSet();
    return factory.getObject();
}
Also used : YamlPropertiesFactoryBean(org.springframework.beans.factory.config.YamlPropertiesFactoryBean) FileSystemResource(org.springframework.core.io.FileSystemResource)

Aggregations

FileSystemResource (org.springframework.core.io.FileSystemResource)148 File (java.io.File)77 Test (org.junit.Test)44 Resource (org.springframework.core.io.Resource)42 Before (org.junit.Before)27 ClassPathResource (org.springframework.core.io.ClassPathResource)16 IOException (java.io.IOException)12 FileWriter (java.io.FileWriter)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Properties (java.util.Properties)8 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)8 FileOutputStream (java.io.FileOutputStream)7 URL (java.net.URL)7 InputStreamResource (org.springframework.core.io.InputStreamResource)7 UrlResource (org.springframework.core.io.UrlResource)7 Date (java.util.Date)5 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)5 FileReader (java.io.FileReader)4 OutputStreamWriter (java.io.OutputStreamWriter)4