Search in sources :

Example 6 with MockNetwork

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

the class ProvisionerIT method testImportWithNodeCategoryEvents.

@Test(timeout = 300000)
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testImportWithNodeCategoryEvents() 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"));
    m_eventAnticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_UPDATED_EVENT_UEI, "Test").setNodeid(nextNodeId).getEvent());
    // we should not get category update events on a re-import now, that happens during the scan phase
    // m_eventAnticipator.anticipateEvent(getNodeCategoryEvent(nextNodeId, "test"));
    importFromResource("classpath:/requisition_with_node_categories.xml", Boolean.TRUE.toString());
    importFromResource("classpath:/requisition_with_node_categories_changed.xml", Boolean.TRUE.toString());
    m_eventAnticipator.verifyAnticipated();
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockNode(org.opennms.netmgt.mock.MockNode) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 7 with MockNetwork

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

the class PollablesIT method setUp.

@Before
public void setUp() throws Exception {
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockUtil.println("------------ Begin Test --------------------------");
    MockLogAppender.setupLogging();
    m_mockNetwork = new MockNetwork();
    m_mockNetwork.addNode(1, "Router");
    m_mockNetwork.addInterface("192.168.1.1");
    m_mockNetwork.addService("ICMP");
    m_mockNetwork.addService("SMTP");
    m_mockNetwork.addInterface("192.168.1.2");
    m_mockNetwork.addService("ICMP");
    m_mockNetwork.addService("SMTP");
    m_mockNetwork.addNode(2, "Server");
    m_mockNetwork.addInterface("192.168.1.3");
    m_mockNetwork.addService("ICMP");
    m_mockNetwork.addService("HTTP");
    m_mockNetwork.addNode(3, "Firewall");
    m_mockNetwork.addInterface("192.168.1.4");
    m_mockNetwork.addService("SMTP");
    m_mockNetwork.addService("HTTP");
    m_mockNetwork.addInterface("192.168.1.5");
    m_mockNetwork.addService("SMTP");
    m_mockNetwork.addService("SNMP");
    m_db = new MockDatabase();
    m_db.populate(m_mockNetwork);
    m_outageAnticipator = new OutageAnticipator(m_db);
    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_eventMgr.addEventListener(m_outageAnticipator);
    m_pollContext = new MockPollContext();
    m_pollContext.setDatabase(m_db);
    m_pollContext.setCriticalServiceName("ICMP");
    m_pollContext.setNodeProcessingEnabled(true);
    m_pollContext.setPollingAllIfCritServiceUndefined(true);
    m_pollContext.setServiceUnresponsiveEnabled(true);
    m_pollContext.setEventMgr(m_eventMgr);
    m_pollContext.setMockNetwork(m_mockNetwork);
    m_pollerConfig = new MockPollerConfig(m_mockNetwork);
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    m_pollerConfig.setCriticalService("ICMP");
    m_pollerConfig.addPackage("TestPackage");
    m_pollerConfig.addDowntime(100L, 0L, 500L, false);
    m_pollerConfig.addDowntime(200L, 500L, 1500L, false);
    m_pollerConfig.addDowntime(500L, 1500L, -1L, true);
    m_pollerConfig.setDefaultPollInterval(1000L);
    m_pollerConfig.populatePackage(m_mockNetwork);
    m_pollerConfig.addPackage("TestPkg2");
    m_pollerConfig.addDowntime(500L, 0L, 1000L, false);
    m_pollerConfig.addDowntime(500L, 1000L, -1L, true);
    m_pollerConfig.setDefaultPollInterval(2000L);
    m_pollerConfig.addService(m_mockNetwork.getService(2, "192.168.1.3", "HTTP"));
    m_timer = new MockTimer();
    m_scheduler = new MockScheduler(m_timer);
    m_network = createPollableNetwork(m_db, m_scheduler, m_pollerConfig, m_pollerConfig, m_pollContext);
    // set members to make the tests easier
    mNode1 = m_mockNetwork.getNode(1);
    mDot1 = mNode1.getInterface("192.168.1.1");
    mDot1Smtp = mDot1.getService("SMTP");
    mDot1Icmp = mDot1.getService("ICMP");
    mDot2 = mNode1.getInterface("192.168.1.2");
    mDot2Icmp = mDot2.getService("ICMP");
    mNode2 = m_mockNetwork.getNode(2);
    mDot3 = mNode2.getInterface("192.168.1.3");
    mDot3Http = mDot3.getService("HTTP");
    mNode3 = m_mockNetwork.getNode(3);
    mDot4 = mNode3.getInterface("192.168.1.4");
    mDot4Smtp = mDot4.getService("SMTP");
    mDot4Http = mDot4.getService("HTTP");
    assignPollableMembers(m_network);
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) MockScheduler(org.opennms.netmgt.poller.mock.MockScheduler) MockTimer(org.opennms.netmgt.poller.mock.MockTimer) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockPollContext(org.opennms.netmgt.poller.mock.MockPollContext) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) MockDatabase(org.opennms.core.test.db.MockDatabase) OutageAnticipator(org.opennms.netmgt.mock.OutageAnticipator) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) Before(org.junit.Before)

Example 8 with MockNetwork

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

the class PathOutageManagerDaoIT method setUp.

// 
// SetUp and TearDown
// 
@Before
public void setUp() throws Exception {
    MockUtil.println("------------ Begin Test  --------------------------");
    MockLogAppender.setupLogging();
    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface("192.168.1.1");
    m_network.addService("ICMP");
    m_network.addPathOutage(1, InetAddressUtils.addr("192.168.1.1"), "ICMP");
    m_network.addService("SMTP");
    m_network.addService("SNMP");
    m_network.addInterface("192.168.1.2");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addNode(2, "Server");
    m_network.addInterface("192.168.1.3");
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_network.addService("SMTP");
    m_network.addService("SNMP");
    m_network.addNode(3, "Firewall");
    m_network.addInterface("192.168.1.4");
    m_network.addService("SMTP");
    m_network.addPathOutage(3, InetAddressUtils.addr("192.168.1.4"), "SMTP");
    m_network.addService("HTTP");
    m_network.addInterface("192.168.1.5");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addNode(4, "DownNode");
    m_network.addInterface("192.168.1.6");
    m_network.addService("SNMP");
    // m_network.addInterface("fe80:0000:0000:0000:0231:f982:0123:4567");
    // m_network.addService("SNMP");
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    // DemandPollDao demandPollDao = new DemandPollDaoHibernate(m_db);
    // demandPollDao.setAllocateIdStmt(m_db
    // .getNextSequenceValStatement("demandPollNxtId"));
    // m_demandPollDao = demandPollDao;
    m_pollerConfig = new MockPollerConfig(m_network);
    m_pollerConfig.setNextOutageIdSql(m_db.getNextOutageIdStatement());
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    m_pollerConfig.setCriticalService("ICMP");
    m_pollerConfig.addPackage("TestPackage");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(1000L);
    m_pollerConfig.populatePackage(m_network);
    m_pollerConfig.addPackage("TestPkg2");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(2000L);
    m_pollerConfig.addService(m_network.getService(2, "192.168.1.3", "HTTP"));
    DefaultPollContext pollContext = new DefaultPollContext();
    pollContext.setLocalHostName("localhost");
    pollContext.setName("Test.DefaultPollContext");
    pollContext.setPollerConfig(m_pollerConfig);
    pollContext.setQueryManager(m_queryManager);
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) Before(org.junit.Before)

Example 9 with MockNetwork

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

the class PollerQueryManagerDaoIT method setUp.

// 
// SetUp and TearDown
// 
@Before
public void setUp() throws Exception {
    MockUtil.println("------------ Begin Test  --------------------------");
    MockLogAppender.setupLogging();
    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface("192.168.1.1");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addService("SNMP");
    m_network.addInterface("192.168.1.2");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addNode(2, "Server");
    m_network.addInterface("192.168.1.3");
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_network.addService("SMTP");
    m_network.addService("SNMP");
    m_network.addNode(3, "Firewall");
    m_network.addInterface("192.168.1.4");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addInterface("192.168.1.5");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addNode(4, "DownNode");
    m_network.addInterface("192.168.1.6");
    m_network.addService("SNMP");
    // m_network.addInterface("fe80:0000:0000:0000:0231:f982:0123:4567");
    // m_network.addService("SNMP");
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    // DemandPollDao demandPollDao = new DemandPollDaoHibernate(m_db);
    // demandPollDao.setAllocateIdStmt(m_db
    // .getNextSequenceValStatement("demandPollNxtId"));
    // m_demandPollDao = demandPollDao;
    m_pollerConfig = new MockPollerConfig(m_network);
    m_pollerConfig.setNextOutageIdSql(m_db.getNextOutageIdStatement());
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    m_pollerConfig.setCriticalService("ICMP");
    m_pollerConfig.addPackage("TestPackage");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(1000L);
    m_pollerConfig.populatePackage(m_network);
    m_pollerConfig.addPackage("TestPkg2");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(2000L);
    m_pollerConfig.addService(m_network.getService(2, "192.168.1.3", "HTTP"));
    m_outageAnticipator = new OutageAnticipator(m_db);
    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_eventMgr.addEventListener(m_outageAnticipator);
    m_eventMgr.setSynchronous(false);
    m_locationAwarePingClient = mock(LocationAwarePingClient.class);
    DefaultPollContext pollContext = new DefaultPollContext();
    pollContext.setEventManager(m_eventMgr);
    pollContext.setLocalHostName("localhost");
    pollContext.setName("Test.DefaultPollContext");
    pollContext.setPollerConfig(m_pollerConfig);
    pollContext.setQueryManager(m_queryManager);
    pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
    PollableNetwork network = new PollableNetwork(pollContext);
    m_poller = new Poller();
    m_poller.setMonitoredServiceDao(m_monitoredServiceDao);
    m_poller.setTransactionTemplate(m_transactionTemplate);
    m_poller.setEventIpcManager(m_eventMgr);
    m_poller.setNetwork(network);
    m_poller.setQueryManager(m_queryManager);
    m_poller.setPollerConfig(m_pollerConfig);
    m_poller.setPollOutagesConfig(m_pollerConfig);
    m_poller.setLocationAwarePollerClient(m_locationAwarePollerClient);
}
Also used : LocationAwarePingClient(org.opennms.netmgt.icmp.proxy.LocationAwarePingClient) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) OutageAnticipator(org.opennms.netmgt.mock.OutageAnticipator) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) PollableNetwork(org.opennms.netmgt.poller.pollables.PollableNetwork) Before(org.junit.Before)

Example 10 with MockNetwork

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

the class SyslogdConfigFactoryIT method setUp.

@Before
public void setUp() throws Exception {
    DaoTestConfigBean daoTestConfig = new DaoTestConfigBean();
    daoTestConfig.setRelativeHomeDirectory("src/test/resources");
    daoTestConfig.afterPropertiesSet();
    MockNetwork network = new MockNetwork();
    MockDatabase db = new MockDatabase();
    db.populate(network);
    DataSourceFactory.setInstance(db);
    m_factory = new SyslogdConfigFactory(ConfigurationTestUtils.getInputStreamForResource(this, "/etc/syslogd-configuration.xml"));
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockDatabase(org.opennms.core.test.db.MockDatabase) Before(org.junit.Before)

Aggregations

MockNetwork (org.opennms.netmgt.mock.MockNetwork)25 Before (org.junit.Before)11 MockDatabase (org.opennms.core.test.db.MockDatabase)8 Test (org.junit.Test)6 MockPollerConfig (org.opennms.netmgt.mock.MockPollerConfig)6 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)4 OutageAnticipator (org.opennms.netmgt.mock.OutageAnticipator)4 PollableNetwork (org.opennms.netmgt.poller.pollables.PollableNetwork)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)3 LocationAwarePingClient (org.opennms.netmgt.icmp.proxy.LocationAwarePingClient)3 MockNode (org.opennms.netmgt.mock.MockNode)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 FileInputStream (java.io.FileInputStream)2 MibObject (org.opennms.netmgt.config.datacollection.MibObject)2 Package (org.opennms.netmgt.config.poller.Package)2 JdbcFilterDao (org.opennms.netmgt.filter.JdbcFilterDao)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1