Search in sources :

Example 1 with MockInterfaceToNodeCache

use of org.opennms.netmgt.dao.mock.MockInterfaceToNodeCache in project opennms by OpenNMS.

the class ConvertToEventTest method testConvertToEvent.

/**
     * Test method which calls the ConvertToEvent constructor.
     *
     * @throws IOException
     */
@Test
public void testConvertToEvent() throws IOException {
    InterfaceToNodeCacheDaoImpl.setInstance(new MockInterfaceToNodeCache());
    // 10000 sample syslogmessages from xml file are taken and passed as
    // Inputstream to create syslogdconfiguration
    InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-loadtest-configuration.xml");
    SyslogdConfig config = new SyslogdConfigFactory(stream);
    // Sample message which is embedded in packet and passed as parameter
    // to
    // ConvertToEvent constructor
    byte[] bytes = "<34> 2010-08-19 localhost foo10000: load test 10000 on tty1".getBytes(StandardCharsets.US_ASCII);
    // Datagram packet which is passed as parameter for ConvertToEvent
    // constructor
    DatagramPacket pkt = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(), SyslogClient.PORT);
    ByteBuffer data = ByteBuffer.wrap(pkt.getData());
    // @param len The length of the XML data in the buffer
    try {
        ConvertToEvent convertToEvent = new ConvertToEvent(DistPollerDao.DEFAULT_DIST_POLLER_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, pkt.getAddress(), pkt.getPort(), data, config);
        LOG.info("Generated event: {}", convertToEvent.getEvent().toString());
    } catch (MessageDiscardedException e) {
        LOG.error("Message Parsing failed", e);
        fail("Message Parsing failed: " + e.getMessage());
    }
}
Also used : InputStream(java.io.InputStream) DatagramPacket(java.net.DatagramPacket) MockInterfaceToNodeCache(org.opennms.netmgt.dao.mock.MockInterfaceToNodeCache) SyslogdConfig(org.opennms.netmgt.config.SyslogdConfig) ByteBuffer(java.nio.ByteBuffer) SyslogdConfigFactory(org.opennms.netmgt.config.SyslogdConfigFactory) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)1 DatagramPacket (java.net.DatagramPacket)1 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1 SyslogdConfig (org.opennms.netmgt.config.SyslogdConfig)1 SyslogdConfigFactory (org.opennms.netmgt.config.SyslogdConfigFactory)1 MockInterfaceToNodeCache (org.opennms.netmgt.dao.mock.MockInterfaceToNodeCache)1