Search in sources :

Example 46 with MockService

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

the class MockPollContext method writeOutage.

private void writeOutage(PollableService pSvc, PollEvent svcLostEvent) {
    MockService mSvc = m_mockNetwork.getService(pSvc.getNodeId(), pSvc.getIpAddr(), pSvc.getSvcName());
    Timestamp eventTime = new Timestamp(svcLostEvent.getDate().getTime());
    MockUtil.println("Opening Outage for " + mSvc);
    m_db.createOutage(mSvc, svcLostEvent.getEventId(), eventTime);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Timestamp(java.sql.Timestamp)

Example 47 with MockService

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

the class PollerIT method createOutages.

private void createOutages(MockElement element, final Event event) {
    MockVisitor outageCreater = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            if (svc.getMgmtStatus().equals(SvcMgmtStatus.ACTIVE)) {
                m_db.createOutage(svc, event);
            }
        }
    };
    element.visit(outageCreater);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockService(org.opennms.netmgt.mock.MockService)

Example 48 with MockService

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

the class PollerIT method testNodeLostServiceIncludesReason.

@Test
public void testNodeLostServiceIncludesReason() throws Exception {
    MockService element = m_network.getService(1, "192.168.1.1", "SMTP");
    String expectedReason = "Oh No!! An Outage!!";
    startDaemons();
    resetAnticipated();
    anticipateDown(element);
    MockUtil.println("Bringing down element: " + element);
    element.bringDown(expectedReason);
    MockUtil.println("Finished bringing down element: " + element);
    verifyAnticipated(8000);
    Collection<Event> receivedEvents = m_eventMgr.getEventAnticipator().getAnticipatedEventsReceived();
    assertEquals(2, receivedEvents.size());
    Iterator<Event> receivedEventsIter = receivedEvents.iterator();
    Event event1 = receivedEventsIter.next();
    assertEquals(expectedReason, EventUtils.getParm(event1, EventConstants.PARM_LOSTSERVICE_REASON));
    Event event2 = receivedEventsIter.next();
    assertNotNull(event2);
    assertEquals(EventConstants.OUTAGE_CREATED_EVENT_UEI, event2.getUei());
    assertEquals("SMTP", event2.getService());
    assertEquals("192.168.1.1", event2.getInterface());
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 49 with MockService

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

the class PollerQueryManagerDaoIT method testNodeGainedServiceWhileNodeDownAndServiceDown.

@Test
public void testNodeGainedServiceWhileNodeDownAndServiceDown() {
    startDaemons();
    MockNode node = m_network.getNode(4);
    MockService svc = m_network.getService(4, "192.168.1.6", "SNMP");
    anticipateDown(node);
    node.bringDown();
    verifyAnticipated(5000);
    resetAnticipated();
    MockService newSvc = m_network.addService(4, "192.168.1.6", "SMTP");
    m_db.writeService(newSvc);
    newSvc.bringDown();
    Event e = MockEventUtil.createNodeGainedServiceEvent("Test", newSvc);
    m_eventMgr.sendEventToListeners(e);
    sleep(5000);
    System.err.println(m_db.getOutages());
    verifyAnticipated(8000);
    anticipateUp(node);
    anticipateDown(svc, true);
    newSvc.bringUp();
    verifyAnticipated(5000);
}
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 50 with MockService

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

the class PollerQueryManagerDaoIT method anticipateServicesUp.

private void anticipateServicesUp(MockElement node) {
    MockVisitor eventCreator = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            anticipateUp(svc);
        }
    };
    node.visit(eventCreator);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockService(org.opennms.netmgt.mock.MockService)

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