use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class EventconfFactorySaveTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
m_fa = new FileAnticipator();
// Create a temporary directory
File origHome = new File("src/test/resources");
File origEtc = new File(origHome, "etc");
File origEvents = new File(origEtc, "events");
File tempHome = m_fa.getTempDir();
File tempEtc = m_fa.expecting(tempHome, "etc");
File tempEvents = m_fa.expecting(tempEtc, "events");
File eventConf = createTempCopy(m_fa, origEtc, tempEtc, "eventconf.xml");
createTempCopy(m_fa, origEvents, tempEvents, "Standard.events.xml");
createTempCopy(m_fa, origEvents, tempEvents, "Syslog.test.events.xml");
createTempCopy(m_fa, origEvents, tempEvents, "Syslog.LoadTest.events.xml");
m_eventConfDao = new DefaultEventConfDao();
m_eventConfDao.setConfigResource(new FileSystemResource(eventConf));
m_eventConfDao.afterPropertiesSet();
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class EventConfDaoReloadTest method canReloadEvents.
/**
* Verify that removed event files and modified event files
* are handled properly on reload.
*
* A delay is added when replacing files in order to make
* sure that their lastModifiedTime is different, which
* is used to determine whether or not a file should be
* reloaded.
*/
@Test
public void canReloadEvents() throws Exception {
// 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());
// Replace the eventconf.xml with one that doesn't reference any files
Thread.sleep(1000);
FileUtils.copyInputStreamToFile(getResourceForRelativePath("reloaded/eventconf-nofiles.xml").getInputStream(), eventconfXml);
// Reload
eventConfDao.reload();
assertEquals(1, eventConfDao.getAllEvents().size());
// Put the original eventconf.xml back
FileUtils.copyInputStreamToFile(getResourceForRelativePath("reloaded/eventconf.xml").getInputStream(), eventconfXml);
// Reload
eventConfDao.reload();
assertEquals(3, eventConfDao.getAllEvents().size());
// Replace the BGP4.events.xml with another that has a few more events
Thread.sleep(1000);
FileUtils.copyInputStreamToFile(getResourceForRelativePath("reloaded/BGP4.more.events.xml").getInputStream(), bgp4eventsXml);
// Reload
eventConfDao.reload();
assertEquals(5, eventConfDao.getAllEvents().size());
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class SnmpInterfaceRrdMigratorOnlineTest method setUp.
/**
* Sets up the test.
*
* @throws Exception the exception
*/
@Before
public void setUp() throws Exception {
FileUtils.copyDirectory(new File("src/test/resources/etc"), new File("target/home/etc"));
FileUtils.copyDirectory(new File("src/test/resources/rrd"), new File("target/home/rrd"));
FileUtils.copyDirectory(new File("src/test/resources/jetty-webapps/opennms/WEB-INF"), new File("target/home/jetty-webapps/opennms/WEB-INF/"));
System.setProperty("opennms.home", "target/home");
DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
dao.setConfigResource(new FileSystemResource(new File("target/home/etc/datacollection-config.xml")));
dao.afterPropertiesSet();
DataCollectionConfigFactory.setInstance(dao);
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class DataCollectionConfigMigrator17Offline method isConfigValid.
/**
* Checks if is configuration valid.
*
* @return true, if is configuration valid
* @throws OnmsUpgradeException the OpenNMS upgrade exception
*/
private boolean isConfigValid() throws OnmsUpgradeException {
File configDirectory = new File(sourceFile.getParentFile().getAbsolutePath(), "datacollection");
try {
DefaultDataCollectionConfigDao dao = new DefaultDataCollectionConfigDao();
dao.setConfigDirectory(configDirectory.getAbsolutePath());
dao.setConfigResource(new FileSystemResource(sourceFile));
dao.setReloadCheckInterval(new Long(0));
dao.afterPropertiesSet();
} catch (IllegalArgumentException e) {
log("Found a problem: %s\n", e.getMessage());
Matcher m = pattern.matcher(e.getMessage());
if (m.find()) {
try {
Iterator<Path> paths = Files.list(configDirectory.toPath()).filter(f -> f.getFileName().toString().toLowerCase().endsWith(".xml")).iterator();
for (; paths.hasNext(); ) {
String group = getGroupForResourceType(paths.next().toFile(), m.group(1));
if (group != null) {
updateDataCollectionConfig(m.group(2), group);
return false;
}
}
} catch (Exception ex) {
throw new OnmsUpgradeException("Can't get datacollection-group files", ex);
}
}
} catch (Exception e) {
throw new OnmsUpgradeException("Can't process " + sourceFile, e);
}
return true;
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class MagicUsersMigratorOfflineIT method validateMigration.
/**
* Validate the Migration by checking the updated users.xml
*
* @throws Exception the exception
*/
private void validateMigration() throws Exception {
Userinfo userInfo = JaxbUtils.unmarshal(Userinfo.class, new FileSystemResource(new File("target/home/etc/users.xml")));
final User rtc = getUser(userInfo, "rtc");
Assert.assertNotNull(rtc);
Assert.assertEquals(1, rtc.getRoles().size());
Assert.assertTrue(rtc.getRoles().contains(Authentication.ROLE_RTC));
final User admin = getUser(userInfo, "admin");
Assert.assertNotNull(admin);
Assert.assertEquals(1, admin.getRoles().size());
Assert.assertTrue(admin.getRoles().contains(Authentication.ROLE_ADMIN));
final User jmx = getUser(userInfo, "jmx_operator");
Assert.assertNotNull(jmx);
Assert.assertEquals(1, admin.getRoles().size());
Assert.assertTrue(jmx.getRoles().contains(Authentication.ROLE_JMX));
final User agalue = getUser(userInfo, "agalue");
Assert.assertNotNull(agalue);
Assert.assertEquals(2, agalue.getRoles().size());
Assert.assertTrue(agalue.getRoles().contains(Authentication.ROLE_USER));
Assert.assertTrue(agalue.getRoles().contains("ROLE_MEASUREMENTS"));
final User operator = getUser(userInfo, "operator");
Assert.assertNotNull(operator);
Assert.assertEquals(0, operator.getRoles().size());
final User manager = getUser(userInfo, "manager");
Assert.assertNotNull(manager);
Assert.assertEquals(2, manager.getRoles().size());
Assert.assertTrue(manager.getRoles().contains(Authentication.ROLE_USER));
Assert.assertTrue(manager.getRoles().contains(Authentication.ROLE_READONLY));
}
Aggregations