use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runTestForBug3554.
private void runTestForBug3554() throws Exception {
MockLogAppender.resetEvents();
System.err.println("----------------------------------------------------------------------------------- begin test");
String baseIpAddress = "10.0.0.";
int numOfNodes = 5;
// Initialize Mock Network
MockNetwork network = new MockNetwork();
network.setCriticalService("ICMP");
for (int i = 1; i <= numOfNodes; i++) {
String ipAddress = baseIpAddress + i;
network.addNode(i, "testNode-" + ipAddress);
network.addInterface(ipAddress);
network.setIfAlias("eth0");
network.addService("ICMP");
network.addService("SNMP");
}
network.addPathOutage(1, InetAddressUtils.addr("192.168.1.1"), "ICMP");
MockDatabase db = new MockDatabase();
db.populate(network);
db.update("insert into categories (categoryid, categoryname) values (?, ?)", 10, "IPRA");
db.update("insert into categories (categoryid, categoryname) values (?, ?)", 11, "NAS");
for (int i = 1; i <= numOfNodes; i++) {
db.update("update snmpinterface set snmpifname=?, snmpifdescr=? where id=?", "eth0", "eth0", i);
db.update("update node set nodesysoid=? where nodeid=?", ".1.3.6.1.4.1.9.1.222", i);
db.update("insert into category_node values (?, ?)", 10, i);
db.update("insert into category_node values (?, ?)", 11, i);
}
DataSourceFactory.setInstance(db);
// Initialize Filter DAO
System.setProperty("opennms.home", "src/test/resources");
DatabaseSchemaConfigFactory.init();
JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();
jdbcFilterDao.setDataSource(db);
jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());
jdbcFilterDao.afterPropertiesSet();
FilterDaoFactory.setInstance(jdbcFilterDao);
// Initialize Factories
initFactories("/threshd-configuration-bug3554.xml", "/test-thresholds-bug3554.xml");
// Initialize Thresholding Visitors
Map<String, Object> params = new HashMap<String, Object>();
params.put("thresholding-enabled", "true");
ServiceParameters svcParams = new ServiceParameters(params);
for (int i = 1; i <= numOfNodes; i++) {
System.err.println("----------------------------------------------------------------------------------- visitor #" + i);
String ipAddress = baseIpAddress + i;
ThresholdingVisitor visitor = ThresholdingVisitor.create(1, ipAddress, "SNMP", getRepository(), svcParams, m_resourceStorageDao);
assertNotNull(visitor);
// mib2, cisco, ciscoIPRA, ciscoNAS
assertEquals(4, visitor.getThresholdGroups().size());
}
System.err.println("----------------------------------------------------------------------------------- end");
}
Aggregations