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);
}
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();
}
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));
}
}
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;
}
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();
}
Aggregations