Search in sources :

Example 41 with MockService

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

the class MockDatabaseIT method testServiceQuery.

public void testServiceQuery() {
    Querier querier = new Querier(m_db, "select node.nodeid as nodeId, ipinterface.ipaddr as ipAddr, ifServices.status as status, ifServices.serviceId as serviceId, service.serviceName as serviceName from ifServices, ipinterface, node, service where ifServices.serviceId = service.serviceId and ipinterface.id = ifServices.ipInterfaceId and node.nodeid = ipinterface.nodeid;") {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            int nodeId = rs.getInt("nodeId");
            String ipAddr = rs.getString("ipAddr");
            int serviceId = rs.getInt("serviceId");
            String serviceName = rs.getString("serviceName");
            String status = rs.getString("status");
            MockService svc = m_network.getService(nodeId, ipAddr, serviceName);
            assertNotNull(svc);
            assertEquals("Assertion failed: " + svc, svc.getNodeId(), nodeId);
            assertEquals("Assertion failed: " + svc, svc.getIpAddr(), ipAddr);
            assertEquals("Assertion failed: " + svc, svc.getSvcName(), serviceName);
            assertEquals("Assertion failed: " + svc, svc.getSvcId(), serviceId);
            assertEquals("Assertion failed: " + svc, svc.getMgmtStatus().toDbString(), status);
        }
    };
    querier.execute();
    assertEquals(m_network.getServiceCount(), querier.getCount());
}
Also used : Querier(org.opennms.core.utils.Querier) ResultSet(java.sql.ResultSet) MockService(org.opennms.netmgt.mock.MockService)

Example 42 with MockService

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

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

the class PollablesIT method testAddDownServiceToUpNode.

private void testAddDownServiceToUpNode(int nodeId, String nodeLabel, String nodeLocation, String ipAddr, String existingSvcName, String newSvcName) {
    PollableService pExistingSvc = m_network.getService(nodeId, getInetAddress(ipAddr), existingSvcName);
    PollableInterface pIface = pExistingSvc.getInterface();
    PollableNode pNode = pExistingSvc.getNode();
    // first we cause a poll for the up node just be make sure everythings working
    pExistingSvc.doPoll();
    m_network.processStatusChange(new Date());
    verifyAnticipated();
    // no we add the mock serve
    MockService mSvc = m_mockNetwork.addService(nodeId, ipAddr, newSvcName);
    m_db.writeService(mSvc);
    // bring down the service
    mSvc.bringDown();
    // expect a nodeLostService event
    anticipateDown(mSvc);
    // add the service to the PollableNetowrk (simulates nodeGainedService event)
    PollableService pSvc = addServiceToNetwork(nodeId, nodeLabel, nodeLocation, ipAddr, newSvcName);
    assertNotNull(pSvc);
    // before the first call nothing has a cause
    assertElementHasNullCause(pSvc);
    assertElementHasNullCause(pExistingSvc);
    assertElementHasNullCause(pIface);
    assertElementHasNullCause(pNode);
    // and everything is up
    assertUp(pSvc);
    assertUp(pExistingSvc);
    assertUp(pIface);
    assertUp(pNode);
    // now poll
    pSvc.doPoll();
    // expect the svc to be down and everythign else up
    assertDown(pSvc);
    assertUp(pExistingSvc);
    assertUp(pIface);
    assertUp(pNode);
    // no we send the events and update the causes
    m_network.processStatusChange(new Date());
    // only the svc has a cause
    assertNotNull(pSvc.getCause());
    assertElementHasNullCause(pExistingSvc);
    assertElementHasNullCause(pIface);
    assertElementHasNullCause(pNode);
    verifyAnticipated();
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Date(java.util.Date)

Example 44 with MockService

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

the class PollablesIT method testAddUpSvcToUpNode.

private void testAddUpSvcToUpNode(int nodeId, String nodeLabel, String nodeLocation, String ipAddr, String existingSvcName, String newSvcName) {
    PollableService pExistingSvc = m_network.getService(nodeId, getInetAddress(ipAddr), existingSvcName);
    assertNotNull(pExistingSvc);
    PollableInterface pIface = pExistingSvc.getInterface();
    PollableNode pNode = pIface.getNode();
    pExistingSvc.doPoll();
    m_network.processStatusChange(new Date());
    verifyAnticipated();
    MockService mSvc = m_mockNetwork.addService(nodeId, ipAddr, newSvcName);
    m_db.writeService(mSvc);
    PollableService pSvc = addServiceToNetwork(nodeId, nodeLabel, nodeLocation, ipAddr, newSvcName);
    assertNotNull(pSvc);
    assertElementHasNullCause(pSvc);
    assertElementHasNullCause(pExistingSvc);
    assertElementHasNullCause(pIface);
    assertElementHasNullCause(pNode);
    assertUp(pSvc);
    assertUp(pExistingSvc);
    assertUp(pIface);
    assertUp(pNode);
    anticipateDown(mSvc);
    mSvc.bringDown();
    pSvc.doPoll();
    m_network.processStatusChange(new Date());
    verifyAnticipated();
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Date(java.util.Date)

Example 45 with MockService

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

the class MockPollContext method closeOutage.

public void closeOutage(PollableService pSvc, PollEvent svcRegainEvent) {
    MockService mSvc = m_mockNetwork.getService(pSvc.getNodeId(), pSvc.getIpAddr(), pSvc.getSvcName());
    Timestamp eventTime = new Timestamp(svcRegainEvent.getDate().getTime());
    MockUtil.println("Resolving Outage for " + mSvc);
    m_db.resolveOutage(mSvc, svcRegainEvent.getEventId(), eventTime);
}
Also used : MockService(org.opennms.netmgt.mock.MockService) Timestamp(java.sql.Timestamp)

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