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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations