Search in sources :

Example 21 with MockNode

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

the class PollerIT method testNullInterfaceOnNodeDown.

@Test
public void testNullInterfaceOnNodeDown() {
    // 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();
    anticipateDown(node);
    icmpService.bringDown();
    smtpService.bringDown();
    snmpService.bringDown();
    verifyAnticipated(10000);
    // node is down at this point
    boolean foundNodeDown = false;
    for (final Event event : m_eventMgr.getEventAnticipator().getAnticipatedEventsReceived()) {
        if (EventConstants.NODE_DOWN_EVENT_UEI.equals(event.getUei())) {
            foundNodeDown = true;
            assertNull(event.getInterfaceAddress());
        }
    }
    assertTrue(foundNodeDown);
}
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 22 with MockNode

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

the class ProvisionerIT method testRequisitionedCategoriesNoPolicies.

@Test(timeout = 300000)
public void testRequisitionedCategoriesNoPolicies() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    final MockNetwork network = new MockNetwork();
    final MockNode node = network.addNode(nextNodeId, "test");
    network.addInterface("172.16.1.1");
    network.addService("ICMP");
    anticipateCreationEvents(node);
    m_eventAnticipator.anticipateEvent(getNodeCategoryEvent(nextNodeId, "test"));
    // we should not get new update events on a re-import now, that happens during the scan phase
    //m_eventAnticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_UPDATED_EVENT_UEI, "Test").setNodeid(nextNodeId).getEvent());
    //m_eventAnticipator.anticipateEvent(getNodeCategoryEvent(nextNodeId, "test"));
    importFromResource("classpath:/provisioner-testCategories-oneCategory.xml", Boolean.TRUE.toString());
    m_eventAnticipator.verifyAnticipated();
    assertEquals(0, m_eventAnticipator.getUnanticipatedEvents().size());
    m_eventAnticipator.reset();
    m_eventAnticipator.anticipateEvent(nodeScanCompleted(nextNodeId));
    m_eventAnticipator.setDiscardUnanticipated(true);
    runPendingScans();
    m_eventAnticipator.verifyAnticipated();
    m_eventAnticipator.reset();
    OnmsNode n = getNodeDao().get(nextNodeId);
    assertEquals(1, n.getCategories().size());
    assertEquals("TotallyMadeUpCategoryName", n.getCategories().iterator().next().getName());
    // import again, should be the same
    importFromResource("classpath:/provisioner-testCategories-oneCategory.xml", Boolean.TRUE.toString());
    n = getNodeDao().get(nextNodeId);
    assertEquals(1, n.getCategories().size());
    assertEquals("TotallyMadeUpCategoryName", n.getCategories().iterator().next().getName());
    runPendingScans();
    n = getNodeDao().get(nextNodeId);
    assertEquals(1, n.getCategories().size());
    assertEquals("TotallyMadeUpCategoryName", n.getCategories().iterator().next().getName());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 23 with MockNode

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

the class NotifdIT method testManualAcknowledge1.

@Test
public void testManualAcknowledge1() throws Exception {
    m_destinationPathManager.getPath("NoEscalate").setInitialDelay("2000ms");
    MockNode node = m_network.getNode(1);
    Event e = node.createDownEvent();
    m_eventMgr.sendEventToListeners(e);
    m_db.acknowledgeNoticesForEvent(e);
    verifyAnticipated(0, 0, 7000);
}
Also used : Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test)

Example 24 with MockNode

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

the class NotifdIT method testRoleNotification.

@Test
public void testRoleNotification() throws Exception {
    MockNode node = m_network.getNode(1);
    Date downDate = new Date();
    long finishedDowns = anticipateNotificationsForRole("notification test", "Notification Test", "oncall", downDate, 0);
    m_eventMgr.sendEventToListeners(MockEventUtil.createNodeEvent("Test", "uei.opennms.org/test/roleTestEvent", node));
    verifyAnticipated(finishedDowns, 1000);
    m_anticipator.reset();
}
Also used : MockNode(org.opennms.netmgt.mock.MockNode) Date(java.util.Date) Test(org.junit.Test)

Example 25 with MockNode

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

the class NotifdIT method testAutoAcknowledge1.

@Test
public void testAutoAcknowledge1() throws Exception {
    m_destinationPathManager.getPath("NoEscalate").setInitialDelay("2000ms");
    MockNode node = m_network.getNode(1);
    Event downEvent = node.createDownEvent();
    Tticket tticket = new Tticket();
    tticket.setContent("777");
    tticket.setState("1");
    downEvent.setTticket(tticket);
    m_eventMgr.sendEventToListeners(downEvent);
    sleep(1000);
    Date date = new Date();
    Event upEvent = node.createUpEvent(date);
    long endTime = anticipateNotificationsForGroup("node 1 up.", "The node which was previously down is now up.", "UpGroup", date, 0);
    m_eventMgr.sendEventToListeners(upEvent);
    verifyAnticipated(endTime, 1000, 5000);
}
Also used : Tticket(org.opennms.netmgt.xml.event.Tticket) Event(org.opennms.netmgt.xml.event.Event) MockNode(org.opennms.netmgt.mock.MockNode) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MockNode (org.opennms.netmgt.mock.MockNode)52 Test (org.junit.Test)42 Event (org.opennms.netmgt.xml.event.Event)21 MockService (org.opennms.netmgt.mock.MockService)16 MockInterface (org.opennms.netmgt.mock.MockInterface)7 Date (java.util.Date)5 ResultSet (java.sql.ResultSet)4 PollAnticipator (org.opennms.netmgt.mock.PollAnticipator)4 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 MockNetwork (org.opennms.netmgt.mock.MockNetwork)3 MockVisitor (org.opennms.netmgt.mock.MockVisitor)3 MockVisitorAdapter (org.opennms.netmgt.mock.MockVisitorAdapter)3 Ignore (org.junit.Ignore)2 Querier (org.opennms.core.utils.Querier)2 RowCallbackHandler (org.springframework.jdbc.core.RowCallbackHandler)2 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1