use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class PropertiesGraphDaoIT method testBasicPrefabConfigDirectorySingleReports.
/**
* Test that individual graph files in an include directory are loaded as expected
*/
@Test
public void testBasicPrefabConfigDirectorySingleReports() throws IOException {
File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
File graphBits = m_fileAnticipator.tempFile(graphDirectory, "mib2.bits.properties");
File graphHCbits = m_fileAnticipator.tempFile(graphDirectory, "mib2.HCbits.properties");
m_outputStream = new FileOutputStream(rootFile);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_baseIncludePrefab);
m_writer.close();
m_outputStream.close();
graphDirectory.mkdir();
m_outputStream = new FileOutputStream(graphBits);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_separateBitsGraph);
m_writer.close();
m_outputStream.close();
m_outputStream = new FileOutputStream(graphHCbits);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_separateHCBitsGraph);
m_writer.close();
m_outputStream.close();
HashMap<String, Resource> prefabConfigs = new HashMap<String, Resource>();
prefabConfigs.put("performance", new FileSystemResource(rootFile));
PropertiesGraphDao dao = createPropertiesGraphDao(prefabConfigs, s_emptyMap);
PrefabGraph mib2Bits = dao.getPrefabGraph("mib2.bits");
assertNotNull(mib2Bits);
assertEquals("mib2.bits", mib2Bits.getName());
assertEquals("Bits In/Out", mib2Bits.getTitle());
String[] columns1 = { "ifInOctets", "ifOutOctets" };
Assert.assertArrayEquals(columns1, mib2Bits.getColumns());
PrefabGraph mib2HCBits = dao.getPrefabGraph("mib2.HCbits");
assertNotNull(mib2HCBits);
assertEquals("mib2.HCbits", mib2HCBits.getName());
assertEquals("Bits In/Out", mib2HCBits.getTitle());
String[] columns2 = { "ifHCInOctets", "ifHCOutOctets" };
Assert.assertArrayEquals(columns2, mib2HCBits.getColumns());
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class LatencyStoringServiceMonitorAdaptorIT method testThresholdsWithScheduledOutage.
// TODO: This test will fail if you have a default locale with >3 characters for month, e.g. Locale.FRENCH
@Test
@JUnitTemporaryDatabase(tempDbClass = MockDatabase.class)
public void testThresholdsWithScheduledOutage() throws Exception {
DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
final StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
sb.append("<outages>");
sb.append("<outage name=\"junit outage\" type=\"specific\">");
sb.append("<time begins=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
sb.append("\" ends=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
sb.append("\"/>");
sb.append("<interface address=\"match-any\"/>");
sb.append("</outage>");
sb.append("</outages>");
File file = new File("target/poll-outages.xml");
FileWriter writer = new FileWriter(file);
writer.write(sb.toString());
writer.close();
PollOutagesConfigFactory oldFactory = PollOutagesConfigFactory.getInstance();
PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
PollOutagesConfigFactory.getInstance().afterPropertiesSet();
executeThresholdTest(new Double[] { 100.0 });
m_eventIpcManager.getEventAnticipator().verifyAnticipated();
// Reset the state of the PollOutagesConfigFactory for any subsequent tests
PollOutagesConfigFactory.setInstance(oldFactory);
file.delete();
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class LatencyThresholdingSetIT method setUp.
@Before
public void setUp() throws Exception {
BeanUtils.setStaticApplicationContext(m_context);
// Resets Counters Cache Data
CollectionResourceWrapper.s_cache.clear();
MockLogAppender.setupLogging();
m_fileAnticipator = new FileAnticipator();
m_resourceStorageDao = new FilesystemResourceStorageDao();
m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir());
// Use a mock FilterDao that always returns 127.0.0.1 in the active IP list
FilterDao filterDao = EasyMock.createMock(FilterDao.class);
EasyMock.expect(filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
filterDao.flushActiveIpAddressListCache();
EasyMock.expectLastCall().anyTimes();
FilterDaoFactory.setInstance(filterDao);
EasyMock.replay(filterDao);
DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
final StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
sb.append("<outages>");
sb.append("<outage name=\"junit outage\" type=\"specific\">");
sb.append("<time begins=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
sb.append("\" ends=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
sb.append("\"/>");
sb.append("<interface address=\"match-any\"/>");
sb.append("</outage>");
sb.append("</outages>");
File file = new File("target/poll-outages.xml");
FileWriter writer = new FileWriter(file);
writer.write(sb.toString());
writer.close();
PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
PollOutagesConfigFactory.getInstance().afterPropertiesSet();
initFactories("/threshd-configuration.xml", "/test-thresholds.xml");
m_anticipatedEvents = new ArrayList<>();
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class ThresholdingVisitorIT method setUp.
@Before
public void setUp() throws Exception {
// Resets Counters Cache Data
CollectionResourceWrapper.s_cache.clear();
MockLogAppender.setupLogging();
m_fileAnticipator = new FileAnticipator();
m_hrStorageProperties = new HashMap<Integer, File>();
m_resourceStorageDao = new FilesystemResourceStorageDao();
m_resourceStorageDao.setRrdDirectory(new File(m_fileAnticipator.getTempDir(), "snmp"));
m_filterDao = EasyMock.createMock(FilterDao.class);
EasyMock.expect(m_filterDao.getActiveIPAddressList((String) EasyMock.anyObject())).andReturn(Collections.singletonList(addr("127.0.0.1"))).anyTimes();
m_filterDao.flushActiveIpAddressListCache();
EasyMock.expectLastCall().anyTimes();
FilterDaoFactory.setInstance(m_filterDao);
EasyMock.replay(m_filterDao);
m_anticipator = new EventAnticipator();
MockEventIpcManager eventMgr = new MockEventIpcManager();
eventMgr.setEventAnticipator(m_anticipator);
eventMgr.setSynchronous(true);
EventIpcManager eventdIpcMgr = (EventIpcManager) eventMgr;
EventIpcManagerFactory.setIpcManager(eventdIpcMgr);
DateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
final StringBuilder sb = new StringBuilder("<?xml version=\"1.0\"?>");
sb.append("<outages>");
sb.append("<outage name=\"junit outage\" type=\"specific\">");
sb.append("<time begins=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() - 3600000)));
sb.append("\" ends=\"");
sb.append(formatter.format(new Date(System.currentTimeMillis() + 3600000)));
sb.append("\"/>");
sb.append("<interface address=\"match-any\"/>");
sb.append("</outage>");
sb.append("</outages>");
File file = new File("target/poll-outages.xml");
FileWriter writer = new FileWriter(file);
writer.write(sb.toString());
writer.close();
PollOutagesConfigFactory.setInstance(new PollOutagesConfigFactory(new FileSystemResource(file)));
PollOutagesConfigFactory.getInstance().afterPropertiesSet();
initFactories("/threshd-configuration.xml", "/test-thresholds.xml");
m_anticipatedEvents = new ArrayList<>();
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class Normalizer method unmarshal.
/**
* Unmarshall.
*
* @param source the source
*/
public static void unmarshal(Source source) {
try {
System.out.println("Normalizing " + source.configFile);
final Resource resource = new FileSystemResource(source.configFile);
Object result = null;
result = JaxbUtils.unmarshal(source.clazz, resource);
JaxbUtils.marshal(result, new FileWriter(source.configFile));
// Double check the newly generated file can be processed correctly.
result = JaxbUtils.unmarshal(source.clazz, resource);
if (result == null) {
throw new IllegalArgumentException("Something went wrong in JAXB.");
}
} catch (Exception ex) {
System.err.println("Cannot normalize file: " + ex);
}
}
Aggregations