Search in sources :

Example 26 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class PollerQueryManagerDaoIT method bringDownCritSvcs.

private void bringDownCritSvcs(MockElement element) {
    MockVisitor markCritSvcDown = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            if ("ICMP".equals(svc.getSvcName())) {
                svc.bringDown();
            }
        }
    };
    element.visit(markCritSvcDown);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockService(org.opennms.netmgt.mock.MockService)

Example 27 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class PollerIT method testNullInterfaceOnNodeDown.

@Test
public void testNullInterfaceOnNodeDown() {
    // NODE processing = true;
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockNode node = m_network.getNode(2);
    MockService icmpService = m_network.getService(2, "192.168.1.3", "ICMP");
    MockService smtpService = m_network.getService(2, "192.168.1.3", "SMTP");
    MockService snmpService = m_network.getService(2, "192.168.1.3", "SNMP");
    // start the poller
    startDaemons();
    anticipateDown(node);
    icmpService.bringDown();
    smtpService.bringDown();
    snmpService.bringDown();
    verifyAnticipated(10000);
    // node is down at this point
    boolean foundNodeDown = false;
    for (final Event event : m_eventMgr.getEventAnticipator().getAnticipatedEventsReceived()) {
        if (EventConstants.NODE_DOWN_EVENT_UEI.equals(event.getUei())) {
            foundNodeDown = true;
            assertNull(event.getInterfaceAddress());
        }
    }
    assertTrue(foundNodeDown);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 28 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class PollerIT method testNodeLostServiceWithReason.

@Test
public void testNodeLostServiceWithReason() {
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    MockService svc = m_network.getService(1, "192.168.1.1", "ICMP");
    Event e = svc.createDownEvent();
    String reasonParm = "eventReason";
    String val = (String) AbstractEventUtil.getInstance().getNamedParmValue("parm[" + reasonParm + "]", e);
    assertEquals("Service Not Responding.", val);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 29 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class NotifdIT method testBug1114.

@Test
public void testBug1114() throws Exception {
    // XXX Needing to bump up this number is bogus
    m_anticipator.setExpectedDifference(5000);
    MockService svc = m_network.getService(1, "192.168.1.1", "ICMP");
    long interval = computeInterval();
    Event event = MockEventUtil.createServiceEvent("Test", "uei.opennms.org/tests/nodeTimeTest", svc, null);
    Date date = event.getTime();
    String dateString = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(date);
    long endTime = anticipateNotificationsForGroup("time " + dateString + ".", "Timestamp: " + dateString + ".", "InitialGroup", date, interval);
    m_eventMgr.sendEventToListeners(event);
    // XXX Needing to decrease the end time is bogus
    verifyAnticipated(endTime - 5000, 1000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) Date(java.util.Date) Test(org.junit.Test)

Example 30 with MockService

use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.

the class BroadcastEventProcessorIT method testExpandNoticeId_Bug1745.

/**
     * Trip a notification and see if the %noticeid% token gets expanded to a numeric
     * value in the subject and text message
     * 
     * @author Jeff Gehlbach <jeffg@jeffg.org>
     */
@Test
public void testExpandNoticeId_Bug1745() throws Exception {
    MockService svc = m_network.getService(1, "192.168.1.1", "ICMP");
    Event event = MockEventUtil.createServiceEvent("Test", "uei.opennms.org/test/noticeIdExpansion", svc, null);
    // We need to know what noticeID to expect -- whatever the NotificationManager
    // gives us, the next notice to come out will have noticeID n+1.  This isn't
    // foolproof, but it should work within the confines of JUnit as long as all
    // previous cases have torn down the mock Notifd.
    String antNID = Integer.toString(m_notificationManager.getNoticeId() + 1);
    Date testDate = new Date();
    long finishedNotifs = anticipateNotificationsForGroup("notification '" + antNID + "'", "Notification '" + antNID + "'", "InitialGroup", testDate, 0);
    MockEventUtil.setEventTime(event, testDate);
    m_eventMgr.sendEventToListeners(event);
    verifyAnticipated(finishedNotifs, 1000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MockService (org.opennms.netmgt.mock.MockService)59 Test (org.junit.Test)36 Event (org.opennms.netmgt.xml.event.Event)19 MockNode (org.opennms.netmgt.mock.MockNode)16 MockVisitor (org.opennms.netmgt.mock.MockVisitor)14 MockVisitorAdapter (org.opennms.netmgt.mock.MockVisitorAdapter)14 Date (java.util.Date)8 MockInterface (org.opennms.netmgt.mock.MockInterface)8 Timestamp (java.sql.Timestamp)3 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)3 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 Querier (org.opennms.core.utils.Querier)2 PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)2 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)1 LocationAwarePingClient (org.opennms.netmgt.icmp.proxy.LocationAwarePingClient)1 MockNetwork (org.opennms.netmgt.mock.MockNetwork)1