Search in sources :

Example 1 with MockService

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

the class MockDatabase method populate.

public void populate(MockNetwork network) {
    MockVisitor dbCreater = new MockVisitorAdapter() {

        @Override
        public void visitNode(MockNode node) {
            writeNode(node);
        }

        @Override
        public void visitInterface(MockInterface iface) {
            writeInterface(iface);
        }

        @Override
        public void visitService(MockService svc) {
            writeService(svc);
        }

        @Override
        public void visitPathOutage(MockPathOutage out) {
            writePathOutage(out);
        }
    };
    network.visit(dbCreater);
    getJdbcTemplate().queryForObject("SELECT setval('nodeNxtId', max(nodeid)) FROM node", Integer.class);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockInterface(org.opennms.netmgt.mock.MockInterface) MockPathOutage(org.opennms.netmgt.mock.MockPathOutage) MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode)

Example 2 with MockService

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

the class PollablesIT method testServiceEvent.

@Test
public void testServiceEvent() throws Exception {
    MockService mSvc = mDot1Smtp;
    PollableService pSvc = pDot1Smtp;
    anticipateDown(mSvc);
    mSvc.bringDown();
    pSvc.doPoll();
    m_network.processStatusChange(new Date());
    verifyAnticipated();
    // anticipate nothin since service is still down
    pSvc.doPoll();
    m_network.processStatusChange(new Date());
    verifyAnticipated();
    anticipateUp(mSvc);
    mSvc.bringUp();
    pSvc.doPoll();
    m_network.processStatusChange(new Date());
    verifyAnticipated();
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Date(java.util.Date) Test(org.junit.Test)

Example 3 with MockService

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

the class PollerQueryManagerDaoIT method testServiceOutagesClosedOnDelete.

@Test
public void testServiceOutagesClosedOnDelete() {
    MockService element = m_network.getService(1, "192.168.1.1", "SMTP");
    testOutagesClosedOnDelete(element);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Test(org.junit.Test)

Example 4 with MockService

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

the class PollerQueryManagerDaoIT method testBug1564.

@Test
@Ignore
public void testBug1564() {
    // 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();
    //
    // Bring Down the HTTP service and expect nodeLostService Event
    //
    resetAnticipated();
    anticipateDown(snmpService);
    // One service works fine
    snmpService.bringDown();
    verifyAnticipated(10000);
    // Now we simulate the restart, the node
    // looses all three at the same time
    resetAnticipated();
    anticipateDown(node);
    icmpService.bringDown();
    smtpService.bringDown();
    snmpService.bringDown();
    verifyAnticipated(10000);
    anticipateDown(smtpService);
    verifyAnticipated(10000);
    anticipateDown(snmpService);
    verifyAnticipated(10000);
    // This is to simulate a restart,
    // where I turn off the node behaviour
    m_pollerConfig.setNodeOutageProcessingEnabled(false);
    anticipateUp(snmpService);
    snmpService.bringUp();
    verifyAnticipated(10000);
    anticipateUp(smtpService);
    smtpService.bringUp();
    verifyAnticipated(10000);
    // Another restart - let's see if this will work?
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    // So everything is down, now
    // SNMP will regain and SMTP will regain
    // will the node come up?
    smtpService.bringDown();
    anticipateUp(smtpService);
    smtpService.bringUp();
    verifyAnticipated(10000, true);
    anticipateUp(snmpService);
    snmpService.bringUp();
    verifyAnticipated(10000);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) MockNode(org.opennms.netmgt.mock.MockNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with MockService

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

the class PollerQueryManagerDaoIT 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)

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