use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class JaxbResourceConfigurationTest method testFileSystemResourceExists.
@Test
public void testFileSystemResourceExists() throws ConfigurationResourceException, IOException {
final File configFile = getConfigFile();
final ConfigurationResource<CollectdConfiguration> collectd = new JaxbResourceConfiguration<CollectdConfiguration>(CollectdConfiguration.class, new FileSystemResource(configFile));
assertNotNull(collectd);
final CollectdConfiguration config = collectd.get();
assertNotNull(config);
assertEquals(5, config.getPackages().size());
assertEquals("vmware3", config.getPackages().get(0).getName());
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class ConfigurationTestUtils method getSpringResourceForResourceWithReplacements.
public static Resource getSpringResourceForResourceWithReplacements(final Object obj, final String resource, final String[]... replacements) throws IOException {
try {
String config = getConfigForResourceWithReplacements(obj, resource, replacements);
File tmp = File.createTempFile("testConfigFile", ".xml");
tmp.deleteOnExit();
FileWriter fw = new FileWriter(tmp);
fw.write(config);
fw.close();
return new FileSystemResource(tmp);
} catch (final Throwable t) {
return new InputStreamResource(getInputStreamForResourceWithReplacements(obj, resource, replacements));
}
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class AbstractMergingJaxbConfigDao method reconfigureDaos.
private void reconfigureDaos() {
final Set<File> xmlFilesWithUnusedDaos = new HashSet<>();
xmlFilesWithUnusedDaos.addAll(m_configDaosByPath.keySet());
for (File xmlFile : m_xmlFiles) {
// Try to fetch an existing DAO
JaxbConfigDao dao = m_configDaosByPath.get(xmlFile);
if (dao == null) {
// We need to create one
FileSystemResource fs = new FileSystemResource(xmlFile);
dao = new JaxbConfigDao();
dao.setConfigResource(fs);
dao.afterPropertiesSet();
m_configDaosByPath.put(xmlFile, dao);
} else {
xmlFilesWithUnusedDaos.remove(xmlFilesWithUnusedDaos);
}
}
// Remove any DAOs we don't need anymore
for (File fileWithUnusedDao : xmlFilesWithUnusedDaos) {
m_configDaosByPath.remove(fileWithUnusedDao);
}
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class JdbcDataCollectionConfigDaoJaxbTest method testAfterPropertiesSetWithBogusFileResource.
public void testAfterPropertiesSetWithBogusFileResource() throws Exception {
Resource resource = new FileSystemResource("/bogus-file");
JdbcDataCollectionConfigDaoJaxb dao = new JdbcDataCollectionConfigDaoJaxb();
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 EventConfDaoReloadTest method canReloadEventsOnDisk.
/**
* Verify that the reload operation does not throw any errors
* when reloading event files on disk.
*/
@Test
public void canReloadEventsOnDisk() throws IOException {
// Copy the resources to the file system
File eventconfXml = tempFolder.newFile("eventconf.xml");
File bgp4eventsXml = tempFolder.newFile("BGP4.events.xml");
FileUtils.copyInputStreamToFile(getResourceForRelativePath("reloaded/eventconf.xml").getInputStream(), eventconfXml);
FileUtils.copyInputStreamToFile(getResourceForRelativePath("reloaded/BGP4.events.xml").getInputStream(), bgp4eventsXml);
// Load
DefaultEventConfDao eventConfDao = new DefaultEventConfDao();
eventConfDao.setConfigResource(new FileSystemResource(eventconfXml));
eventConfDao.afterPropertiesSet();
assertEquals(3, eventConfDao.getAllEvents().size());
// Reload
eventConfDao.reload();
assertEquals(3, eventConfDao.getAllEvents().size());
}
Aggregations