Search in sources :

Example 56 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 57 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 58 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)

Example 59 with MockService

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

the class MockPollContext method writeOutage.

private void writeOutage(PollableService pSvc, PollEvent svcLostEvent) {
    MockService mSvc = m_mockNetwork.getService(pSvc.getNodeId(), pSvc.getIpAddr(), pSvc.getSvcName());
    Timestamp eventTime = new Timestamp(svcLostEvent.getDate().getTime());
    MockUtil.println("Opening Outage for " + mSvc);
    m_db.createOutage(mSvc, svcLostEvent.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