Search in sources :

Example 6 with MockVisitorAdapter

use of org.opennms.netmgt.mock.MockVisitorAdapter 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 7 with MockVisitorAdapter

use of org.opennms.netmgt.mock.MockVisitorAdapter 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 8 with MockVisitorAdapter

use of org.opennms.netmgt.mock.MockVisitorAdapter 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<MockService>();
    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);
    StringBuffer didNotOccur = new StringBuffer();
    for (MockService service : anticipator.waitForAnticipated(10000)) {
        didNotOccur.append(service.toString());
    }
    StringBuffer unanticipatedStuff = new StringBuffer();
    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 MockVisitorAdapter

use of org.opennms.netmgt.mock.MockVisitorAdapter 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<MockService>();
    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);
    StringBuffer didNotOccur = new StringBuffer();
    for (MockService service : anticipator.waitForAnticipated(10000)) {
        didNotOccur.append(service.toString());
    }
    StringBuffer unanticipatedStuff = new StringBuffer();
    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 10 with MockVisitorAdapter

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