Search in sources :

Example 51 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class VacuumdIT method setUp.

/**
 * Sets up the test.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_ancitipator = ((MockEventIpcManager) m_eventProxy).getEventAnticipator();
    m_location = new OnmsMonitoringLocation("Default", "Default");
    m_distPoller = new OnmsDistPoller("00000000-0000-0000-0000-000000000000");
    m_distPoller.setLabel("localhost");
    m_distPoller.setLocation("Default");
    m_distPoller.setType(OnmsMonitoringSystem.TYPE_OPENNMS);
    OnmsNode node = createNode();
    m_down = new NorthboundAlarm(createDownAlarm(node, new Date()));
    System.err.println(JaxbUtils.marshal(m_down));
    m_up = new NorthboundAlarm(createUpAlarm(node, new Date(m_down.getLastOccurrence().getTime() + DELAY)));
    System.err.println(JaxbUtils.marshal(m_up));
    // Setup the Drools northbounder configuration DAO
    DroolsNorthbounderConfigDao configDao = new DroolsNorthbounderConfigDao();
    configDao.setConfigResource(new FileSystemResource(new File("src/test/resources/etc/vacuumd/drools-northbounder-configuration.xml")));
    configDao.afterPropertiesSet();
    Assert.assertNotNull(configDao.getConfig().getEngine("Vacuumd"));
    // Setup the northbounder
    nbi = new DroolsNorthbounder(m_appContext, configDao, m_eventProxy, "Vacuumd");
    nbi.afterPropertiesSet();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) DroolsNorthbounderConfigDao(org.opennms.netmgt.alarmd.northbounder.drools.DroolsNorthbounderConfigDao) DroolsNorthbounder(org.opennms.netmgt.alarmd.northbounder.drools.DroolsNorthbounder) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Example 52 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class SyslogConfigDaoTest method testFiltersAndReload.

/**
 * Test filters and reload.
 *
 * @throws Exception the exception
 */
@Test
public void testFiltersAndReload() throws Exception {
    File configFile = new File("target/syslog-northbounder-test.xml");
    FileWriter writer = new FileWriter(configFile);
    writer.write(xmlWithFilters);
    writer.close();
    Resource resource = new FileSystemResource(configFile);
    SyslogNorthbounderConfigDao dao = new SyslogNorthbounderConfigDao();
    dao.setConfigResource(resource);
    dao.afterPropertiesSet();
    assertNotNull(dao.getConfig());
    SyslogDestination dst = dao.getConfig().getSyslogDestination("test-host");
    assertNotNull(dst);
    assertEquals(2, dst.getFilters().size());
    assertEquals(true, dst.getFilters().get(0).isEnabled());
    assertEquals(false, dst.getFilters().get(1).isEnabled());
    writer = new FileWriter(configFile);
    writer.write(xmlNoUeis);
    writer.close();
    dao.reload();
    dst = dao.getConfig().getSyslogDestination("test-host");
    assertNotNull(dst);
    assertTrue(dst.getFilters().isEmpty());
    configFile.delete();
}
Also used : FileWriter(java.io.FileWriter) FileSystemResource(org.springframework.core.io.FileSystemResource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 53 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project opennms by OpenNMS.

the class SnmpDataCollectionTest method verifySnmpCollectionIncludeOrder.

/**
 * Verify that the order of the includes in the default 'datacollection-config.xml'
 * file are listed in alphabetical order, with the exception of MIB2 which should
 * always come first.
 *
 * See https://issues.opennms.org/browse/NMS-9643
 */
@Test
public void verifySnmpCollectionIncludeOrder() {
    final DatacollectionConfig config = JaxbUtils.unmarshal(DatacollectionConfig.class, new FileSystemResource(ConfigurationTestUtils.getFileForConfigFile("datacollection-config.xml")));
    final SnmpCollection snmpCollection = config.getSnmpCollection("default");
    assertNotNull("'default' snmp-collection should exist.", snmpCollection);
    // Current order
    final List<String> includesInOrderSpecified = snmpCollection.getIncludeCollections().stream().map(inc -> inc.getDataCollectionGroup().toLowerCase()).collect(Collectors.toList());
    // Exepected order
    final List<String> includesInNaturalOrder = snmpCollection.getIncludeCollections().stream().map(inc -> inc.getDataCollectionGroup().toLowerCase()).sorted(Comparator.naturalOrder()).collect(Collectors.toList());
    // Special handling for the "MIB2" include, if present
    if (includesInOrderSpecified.indexOf("mib2") == 0) {
        includesInNaturalOrder.remove("mib2");
        includesInNaturalOrder.add(0, "mib2");
    }
    assertEquals("One or more SNMP data collections included in the default configuration are not listed in alphabetical order." + " Please sort and try again.", includesInNaturalOrder, includesInOrderSpecified);
}
Also used : DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) List(java.util.List) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) ConfigurationTestUtils(org.opennms.core.test.ConfigurationTestUtils) JaxbUtils(org.opennms.core.xml.JaxbUtils) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) DatacollectionConfig(org.opennms.netmgt.config.datacollection.DatacollectionConfig) SnmpCollection(org.opennms.netmgt.config.datacollection.SnmpCollection) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test)

Example 54 with FileSystemResource

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());
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) FileSystemResource(org.springframework.core.io.FileSystemResource) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.springframework.core.io.Resource) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 55 with FileSystemResource

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
    }
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) FileSystemResource(org.springframework.core.io.FileSystemResource) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.springframework.core.io.Resource) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Aggregations

FileSystemResource (org.springframework.core.io.FileSystemResource)148 File (java.io.File)77 Test (org.junit.Test)44 Resource (org.springframework.core.io.Resource)42 Before (org.junit.Before)27 ClassPathResource (org.springframework.core.io.ClassPathResource)16 IOException (java.io.IOException)12 FileWriter (java.io.FileWriter)10 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 Properties (java.util.Properties)8 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)8 FileOutputStream (java.io.FileOutputStream)7 URL (java.net.URL)7 InputStreamResource (org.springframework.core.io.InputStreamResource)7 UrlResource (org.springframework.core.io.UrlResource)7 Date (java.util.Date)5 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)5 FileReader (java.io.FileReader)4 OutputStreamWriter (java.io.OutputStreamWriter)4