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());
}
}
Aggregations