Search in sources :

Example 6 with MockVisitor

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

the class PollablesIT method assertNoPoll.

/**
 * @param network
 */
private void assertNoPoll(MockElement elem) {
    MockVisitor zeroAsserter = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            assertEquals("Unexpected poll count for " + svc, 0, svc.getPollCount());
        }
    };
    elem.visit(zeroAsserter);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockService(org.opennms.netmgt.mock.MockService)

Example 7 with MockVisitor

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

the class PollerIT method sendNodeGainedServices.

private void sendNodeGainedServices(int nodeid, String nodeLabel, String ipAddr, String... svcNames) {
    assertNotNull(svcNames);
    assertTrue(svcNames.length > 0);
    MockNode node = m_network.addNode(nodeid, nodeLabel);
    m_db.writeNode(node);
    MockInterface iface = m_network.addInterface(nodeid, ipAddr);
    m_db.writeInterface(iface);
    List<MockService> services = new ArrayList<>();
    for (String svcName : svcNames) {
        MockService svc = m_network.addService(nodeid, ipAddr, svcName);
        m_db.writeService(svc);
        m_pollerConfig.addService(svc);
        services.add(svc);
    }
    MockVisitor gainSvcSender = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            Event event = MockEventUtil.createNodeGainedServiceEvent("Test", svc);
            m_eventMgr.sendEventToListeners(event);
        }
    };
    node.visit(gainSvcSender);
    MockService svc1 = services.get(0);
    PollAnticipator anticipator = new PollAnticipator();
    svc1.addAnticipator(anticipator);
    anticipator.anticipateAllServices(svc1);
    final StringBuilder didNotOccur = new StringBuilder();
    for (MockService service : anticipator.waitForAnticipated(10000)) {
        didNotOccur.append(service.toString());
    }
    final StringBuilder unanticipatedStuff = new StringBuilder();
    for (MockService service : anticipator.unanticipatedPolls()) {
        unanticipatedStuff.append(service.toString());
    }
    assertEquals(unanticipatedStuff.toString(), "", didNotOccur.toString());
    anticipateDown(svc1);
    svc1.bringDown();
    verifyAnticipated(10000);
}
Also used : PollAnticipator(org.opennms.netmgt.mock.PollAnticipator) MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockInterface(org.opennms.netmgt.mock.MockInterface) MockVisitor(org.opennms.netmgt.mock.MockVisitor) ArrayList(java.util.ArrayList) MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode)

Example 8 with MockVisitor

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

the class PollerQueryManagerDaoIT method testSendNodeGainedServices.

private void testSendNodeGainedServices(int nodeid, String nodeLabel, String ipAddr, String... svcNames) {
    assertNotNull(svcNames);
    assertTrue(svcNames.length > 0);
    MockNode node = m_network.addNode(nodeid, nodeLabel);
    m_db.writeNode(node);
    MockInterface iface = m_network.addInterface(nodeid, ipAddr);
    m_db.writeInterface(iface);
    List<MockService> services = new ArrayList<>();
    for (String svcName : svcNames) {
        MockService svc = m_network.addService(nodeid, ipAddr, svcName);
        m_db.writeService(svc);
        m_pollerConfig.addService(svc);
        services.add(svc);
    }
    MockVisitor gainSvcSender = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            Event event = MockEventUtil.createNodeGainedServiceEvent("Test", svc);
            m_eventMgr.sendEventToListeners(event);
        }
    };
    node.visit(gainSvcSender);
    MockService svc1 = services.get(0);
    PollAnticipator anticipator = new PollAnticipator();
    svc1.addAnticipator(anticipator);
    anticipator.anticipateAllServices(svc1);
    final StringBuilder didNotOccur = new StringBuilder();
    for (MockService service : anticipator.waitForAnticipated(10000)) {
        didNotOccur.append(service.toString());
    }
    final StringBuilder unanticipatedStuff = new StringBuilder();
    for (MockService service : anticipator.unanticipatedPolls()) {
        unanticipatedStuff.append(service.toString());
    }
    assertEquals(unanticipatedStuff.toString(), "", didNotOccur.toString());
    anticipateDown(svc1);
    svc1.bringDown();
    verifyAnticipated(10000);
}
Also used : PollAnticipator(org.opennms.netmgt.mock.PollAnticipator) MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockInterface(org.opennms.netmgt.mock.MockInterface) MockVisitor(org.opennms.netmgt.mock.MockVisitor) ArrayList(java.util.ArrayList) MockService(org.opennms.netmgt.mock.MockService) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode)

Example 9 with MockVisitor

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

the class PollablesIT method anticipateUnresponsive.

private void anticipateUnresponsive(MockElement element) {
    MockVisitor visitor = new MockVisitorAdapter() {

        @Override
        public void visitService(MockService svc) {
            m_eventMgr.getEventAnticipator().anticipateEvent(svc.createUnresponsiveEvent());
        }
    };
    element.visit(visitor);
}
Also used : MockVisitorAdapter(org.opennms.netmgt.mock.MockVisitorAdapter) MockVisitor(org.opennms.netmgt.mock.MockVisitor) MockService(org.opennms.netmgt.mock.MockService)

Example 10 with MockVisitor

use of org.opennms.netmgt.mock.MockVisitor 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)

Aggregations

MockService (org.opennms.netmgt.mock.MockService)14 MockVisitor (org.opennms.netmgt.mock.MockVisitor)14 MockVisitorAdapter (org.opennms.netmgt.mock.MockVisitorAdapter)14 MockInterface (org.opennms.netmgt.mock.MockInterface)3 MockNode (org.opennms.netmgt.mock.MockNode)3 ArrayList (java.util.ArrayList)2 PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)2 Event (org.opennms.netmgt.xml.event.Event)2 MockPathOutage (org.opennms.netmgt.mock.MockPathOutage)1