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();
}
}
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);
}
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);
}
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();
}
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());
}
Aggregations