Search in sources :

Example 1 with MockNetwork

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

the class CollectdConfigFactoryIT method setUp.

@Before
public void setUp() throws Exception {
    MockNetwork network = new MockNetwork();
    MockDatabase db = new MockDatabase();
    db.populate(network);
    DataSourceFactory.setInstance(db);
    FilterDaoFactory.getInstance();
    InputStream in = ConfigurationTestUtils.getInputStreamForResource(this, "collectd-testdata.xml");
    try {
        m_factory = new CollectdConfigFactory(in, "localhost", false);
    } finally {
        in.close();
    }
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) InputStream(java.io.InputStream) MockDatabase(org.opennms.core.test.db.MockDatabase) Before(org.junit.Before)

Example 2 with MockNetwork

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

the class PollerRpcTimeoutIT method setUp.

@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(str(InetAddressUtils.UNPINGABLE_ADDRESS));
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    // Add a location that no systems are monitoring
    OnmsMonitoringLocation location = new OnmsMonitoringLocation(NONEXISTENT_LOCATION, "Nullsville");
    m_monitoringLocationDao.save(location);
    // Update all of the nodes to have the nonexistent location
    for (OnmsNode node : m_nodeDao.findAll()) {
        node.setLocation(location);
        m_nodeDao.save(node);
    }
    InputStream is = new FileInputStream(new File("src/test/resources/etc/rpctimeout-poller-configuration.xml"));
    PollerConfigFactory factory = new PollerConfigFactory(0, is, "localhost", false);
    PollerConfigFactory.setInstance(factory);
    IOUtils.closeQuietly(is);
    // Sanity check the config
    ServiceMonitor monitor = PollerConfigFactory.getInstance().getServiceMonitor("HTTP");
    Assert.assertNotNull(monitor);
    Package pkg = PollerConfigFactory.getInstance().getPackage("PollerRpcTimeoutIT");
    Assert.assertNotNull(pkg);
    Service svc = pkg.getServices().iterator().next();
    Assert.assertEquals("HTTP", svc.getName());
    DefaultPollContext pollContext = new DefaultPollContext();
    pollContext.setEventManager(m_eventMgr);
    pollContext.setLocalHostName("localhost");
    pollContext.setName("Test.DefaultPollContext");
    pollContext.setPollerConfig(factory);
    pollContext.setQueryManager(m_queryManager);
    pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
    PollableNetwork network = new PollableNetwork(pollContext);
    m_poller = new Poller();
    m_poller.setMonitoredServiceDao(m_monitoredServiceDao);
    m_poller.setOutageDao(m_outageDao);
    m_poller.setTransactionTemplate(m_transactionTemplate);
    m_poller.setEventIpcManager(m_eventMgr);
    m_poller.setNetwork(network);
    m_poller.setQueryManager(m_queryManager);
    m_poller.setPollerConfig(factory);
    m_poller.setPollOutagesConfig(m_pollOutagesConfig);
    m_poller.setLocationAwarePollerClient(m_locationAwarePollerClient);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Service(org.opennms.netmgt.config.poller.Service) FileInputStream(java.io.FileInputStream) PollerConfigFactory(org.opennms.netmgt.config.PollerConfigFactory) MockNetwork(org.opennms.netmgt.mock.MockNetwork) Package(org.opennms.netmgt.config.poller.Package) File(java.io.File) PollableNetwork(org.opennms.netmgt.poller.pollables.PollableNetwork) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Before(org.junit.Before)

Example 3 with MockNetwork

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

the class LatencyStoringServiceMonitorAdaptorIT method setUp.

@Before
public // that uses generics
void setUp() throws Exception {
    BeanUtils.setStaticApplicationContext(m_context);
    m_mocks = new EasyMockUtils();
    m_pollerConfig = m_mocks.createMock(PollerConfig.class);
    MockLogAppender.setupLogging();
    String previousOpennmsHome = System.setProperty("opennms.home", "src/test/resources");
    PollOutagesConfigFactory.init();
    System.setProperty("opennms.home", previousOpennmsHome);
    MockNetwork network = new MockNetwork();
    network.setCriticalService("ICMP");
    network.addNode(1, "testNode");
    network.addInterface("127.0.0.1");
    network.setIfAlias("eth0");
    network.addService("ICMP");
    network.addService("SNMP");
    m_db.populate(network);
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) PollerConfig(org.opennms.netmgt.config.PollerConfig) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) Before(org.junit.Before)

Example 4 with MockNetwork

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

the class PollerConfigFactoryIT method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    MockLogAppender.setupLogging();
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/config/test-database-schema.xml")));
    MockNetwork network = new MockNetwork();
    network.setCriticalService("ICMP");
    network.addNode(1, "Router");
    network.addInterface("192.168.1.1");
    network.addService("ICMP");
    network.addService("SMTP");
    network.addInterface("192.168.1.2");
    network.addService("ICMP");
    network.addService("SMTP");
    network.addNode(2, "Server");
    network.addInterface("192.168.1.3");
    network.addService("ICMP");
    network.addService("HTTP");
    network.addNode(3, "Firewall");
    network.addInterface("192.168.1.4");
    network.addService("SMTP");
    network.addService("HTTP");
    network.addInterface("192.168.1.5");
    network.addService("SMTP");
    network.addService("HTTP");
    network.addInterface("192.169.1.5");
    network.addService("SMTP");
    network.addService("HTTP");
    network.addNode(4, "TestNode121");
    network.addInterface("123.12.123.121");
    network.addService("HTTP");
    network.addNode(5, "TestNode122");
    network.addInterface("123.12.123.122");
    network.addService("HTTP");
    MockDatabase db = new MockDatabase();
    db.populate(network);
    DataSourceFactory.setInstance(db);
    // Make sure it gets *our* MockDatabase
    FilterDaoFactory.setInstance(null);
    FilterDaoFactory.getInstance();
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockDatabase(org.opennms.core.test.db.MockDatabase)

Example 5 with MockNetwork

use of org.opennms.netmgt.mock.MockNetwork 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)

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