use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.
the class VacuumdIT method setUp.
@Before
public void setUp() throws Exception {
m_network.createStandardNetwork();
InputStream is = ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/vacuumd/vacuumd-configuration.xml");
try {
VacuumdConfigFactory.setInstance(new VacuumdConfigFactory(is));
} finally {
IOUtils.closeQuietly(is);
}
m_eventdIpcMgr.setEventWriter(m_database);
EventExpander expander = new EventExpander(new MetricRegistry());
expander.setEventConfDao(new EmptyEventConfDao());
m_eventdIpcMgr.setEventExpander(expander);
Vacuumd.destroySingleton();
m_vacuumd = Vacuumd.getSingleton();
m_vacuumd.setEventManager(m_eventdIpcMgr);
m_vacuumd.init();
// Insert some empty nodes to avoid foreign-key violations on subsequent events/alarms
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "default-1");
node.setId(1);
m_nodeDao.save(node);
node = new OnmsNode(m_locationDao.getDefaultLocation(), "default-2");
node.setId(2);
m_nodeDao.save(node);
m_nodeDao.flush();
MockUtil.println("------------ Finished setup for: " + this.getClass().getName() + " --------------------------");
}
use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.
the class EventExpanderTest method testAfterPropertiesSetWithNoEventConfDao.
@Test
public void testAfterPropertiesSetWithNoEventConfDao() {
m_mocks.replayAll();
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new IllegalStateException("property eventConfDao must be set"));
EventExpander expander = new EventExpander(new MetricRegistry());
try {
expander.afterPropertiesSet();
} catch (Throwable t) {
ta.throwableReceived(t);
}
ta.verifyAnticipated();
}
use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.
the class EventExpanderTest method testAfterPropertiesSet.
@Test
public void testAfterPropertiesSet() {
m_mocks.replayAll();
EventExpander expander = new EventExpander(new MetricRegistry());
expander.setEventConfDao(m_eventConfDao);
expander.setEventUtil(m_eventUtil);
expander.afterPropertiesSet();
}
use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.
the class EventExpanderTest method testOptionalParameters.
@Test
public void testOptionalParameters() {
String uei = "uei.opennms.org/testEventWithOptionalParameters";
EventBuilder builder = new EventBuilder(uei, "something");
builder.addParam("worst-framework-ever", "Vaadin");
Event event = builder.getEvent();
EventExpander expander = new EventExpander(new MetricRegistry());
expander.setEventConfDao(m_eventConfDao);
expander.setEventUtil(m_eventUtil);
expander.afterPropertiesSet();
org.opennms.netmgt.xml.eventconf.Event eventConfig = new org.opennms.netmgt.xml.eventconf.Event();
eventConfig.setUei(uei);
org.opennms.netmgt.xml.eventconf.Parameter p1 = new org.opennms.netmgt.xml.eventconf.Parameter();
p1.setName("username");
p1.setValue("agalue");
eventConfig.addParameter(p1);
org.opennms.netmgt.xml.eventconf.Parameter p2 = new org.opennms.netmgt.xml.eventconf.Parameter();
p2.setName("i-hate");
p2.setValue("%parm[#1]%");
p2.setExpand(true);
eventConfig.addParameter(p2);
EasyMock.expect(m_eventConfDao.findByEvent(event)).andReturn(eventConfig);
EasyMock.expect(m_eventConfDao.isSecureTag(EasyMock.anyObject())).andReturn(true).anyTimes();
EasyMock.expect(m_eventUtil.expandParms("%parm[#1]%", event, new HashMap<String, Map<String, String>>())).andReturn("Vaadin");
m_mocks.replayAll();
expander.expandEvent(event);
assertEquals("event UEI", uei, event.getUei());
assertEquals("parameters count", 3, event.getParmCollection().size());
assertNotNull(event.getParm("username"));
assertEquals("parameter value", "agalue", event.getParm("username").getValue().getContent());
assertEquals("parameter value", "Vaadin", event.getParm("i-hate").getValue().getContent());
}
use of org.opennms.netmgt.eventd.EventExpander in project opennms by OpenNMS.
the class EventExpanderTest method testExpandEventWithNoDaoMatches.
@Test
public void testExpandEventWithNoDaoMatches() {
String uei = "uei.opennms.org/internal/capsd/snmpConflictsWithDb";
EventBuilder builder = new EventBuilder(uei, "something");
EventExpander expander = new EventExpander(new MetricRegistry());
expander.setEventConfDao(m_eventConfDao);
expander.setEventUtil(m_eventUtil);
expander.afterPropertiesSet();
Event event = builder.getEvent();
assertNull("event description should be null before expandEvent is called", event.getDescr());
EasyMock.expect(m_eventConfDao.findByEvent(event)).andReturn(null);
EasyMock.expect(m_eventConfDao.findByUei("uei.opennms.org/default/event")).andReturn(null);
m_mocks.replayAll();
expander.expandEvent(event);
assertEquals("event UEI", uei, event.getUei());
// assertNotNull("event description should not be null after expandEvent is called", event.getDescr());
//
// String matchText = "During a rescan";
// assertTrue("event description should contain '" + matchText + "'", event.getDescr().contains(matchText));
}
Aggregations