use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class EventConfDataTest method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging(false);
eventConfDao = new DefaultEventConfDao();
eventConfDao.setConfigResource(new FileSystemResource(ConfigurationTestUtils.getFileForResource(this, "eventconf.xml")));
eventConfDao.afterPropertiesSet();
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class PropertiesGraphDaoIT method testPrefabConfigDirectoryMixedSingleAndMultiReports.
/**
* Test that properties files in an included directory with
* multiple graphs defined in some, and single graphs in others, are loaded correctly
*/
@Test
public void testPrefabConfigDirectoryMixedSingleAndMultiReports() throws IOException {
File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
File multiFile = m_fileAnticipator.tempFile(graphDirectory, "mib2-1.properties");
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();
graphDirectory.mkdir();
m_outputStream = new FileOutputStream(multiFile);
m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
m_writer.write(s_includedMultiGraph1);
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);
//Check the graphs, basically ensuring that a handful of unique but easily checkable
// bits are uniquely what they should be.
//We check all 4 graphs
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());
PrefabGraph mib2Discards = dao.getPrefabGraph("mib2.discards");
assertNotNull(mib2Discards);
assertEquals("mib2.discards", mib2Discards.getName());
assertEquals("Discards In/Out", mib2Discards.getTitle());
String[] columns3 = { "ifInDiscards", "ifOutDiscards" };
Assert.assertArrayEquals(columns3, mib2Discards.getColumns());
PrefabGraph mib2Errors = dao.getPrefabGraph("mib2.errors");
assertNotNull(mib2Errors);
assertEquals("mib2.errors", mib2Errors.getName());
assertEquals("Errors In/Out", mib2Errors.getTitle());
String[] columns4 = { "ifInErrors", "ifOutErrors" };
Assert.assertArrayEquals(columns4, mib2Errors.getColumns());
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class PropertiesGraphDaoIT method testIncludeDirectoryIncludeMissingReportId.
@Test
public void testIncludeDirectoryIncludeMissingReportId() throws Exception {
//We're expecting an ERROR log, and will be most disappointed if
// we don't get it. Turn off the default check in runTest
m_testSpecificLoggingTest = true;
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");
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.replace("report.id", "report.noid"));
m_writer.close();
m_outputStream.close();
HashMap<String, Resource> perfConfig = new HashMap<String, Resource>();
perfConfig.put("performance", new FileSystemResource(rootFile));
PropertiesGraphDao dao = createPropertiesGraphDao(perfConfig, s_emptyMap);
try {
PrefabGraph graph = dao.getPrefabGraph("mib2.bits");
fail("Shouldn't have gotten here; expecting an exception fetching " + graph);
} catch (ObjectRetrievalFailureException e) {
//Expected; no such graph
}
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class FusedForeignSourceRepositoryTest method getSummaryForRequisition.
protected String getSummaryForRequisition(final File file) {
final Requisition requisition = JaxbUtils.unmarshal(Requisition.class, new FileSystemResource(file));
final StringBuilder sb = new StringBuilder();
if (requisition.getNodeCount() > 0) {
sb.append("(");
final Iterator<RequisitionNode> nodeIterator = requisition.getNodes().iterator();
while (nodeIterator.hasNext()) {
sb.append(nodeIterator.next().getNodeLabel());
if (nodeIterator.hasNext())
sb.append(", ");
}
sb.append(")");
}
final String requisitionSummary = file.getPath() + sb.toString() + ": " + requisition.getDate().getTime();
return requisitionSummary;
}
use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.
the class FusedForeignSourceRepositoryTest method multipleSnapshotTest.
@Test
public void multipleSnapshotTest() throws URISyntaxException, InterruptedException {
Requisition pendingReq = new Requisition("test");
pendingReq.putNode(createNode("1"));
m_pending.save(pendingReq);
m_pending.flush();
final String foreignSource = pendingReq.getForeignSource();
pendingReq = m_pending.getRequisition(foreignSource);
final File pendingSnapshotA = RequisitionFileUtils.createSnapshot(m_pending, foreignSource, pendingReq.getDate());
// Now, start a new pending update after the original snapshot is "in progress"
pendingReq.updateDateStamp();
m_pending.save(pendingReq);
m_pending.flush();
final File pendingSnapshotB = RequisitionFileUtils.createSnapshot(m_pending, foreignSource, pendingReq.getDate());
// "import" the A snapshot
m_repository.importResourceRequisition(new FileSystemResource(pendingSnapshotA));
assertFalse(pendingSnapshotA.exists());
assertTrue(pendingSnapshotB.exists());
// since there's still a newer snapshot in-progress, it is safe to delete the pending test.xml
URL pendingUrl = m_pending.getRequisitionURL(foreignSource);
assertNotNull(pendingUrl);
assertFalse(new File(pendingUrl.toURI()).exists());
// then, "import" the B snapshot
final Requisition bReq = m_repository.importResourceRequisition(new FileSystemResource(pendingSnapshotB));
assertFalse(pendingSnapshotA.exists());
assertFalse(pendingSnapshotB.exists());
// now the pending test.xml should be gone
pendingUrl = m_pending.getRequisitionURL(foreignSource);
assertNotNull(pendingUrl);
assertFalse(new File(pendingUrl.toURI()).exists());
// the last (B) pending import should match the deployed
final Requisition deployedRequisition = m_active.getRequisition(foreignSource);
assertEquals(deployedRequisition.getDate().getTime(), bReq.getDate().getTime());
}
Aggregations