Search in sources :

Example 16 with MockDatabase

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");
}
Also used : MockNetwork(org.opennms.netmgt.mock.MockNetwork) HashMap(java.util.HashMap) MockDatabase(org.opennms.core.test.db.MockDatabase) MibObject(org.opennms.netmgt.config.datacollection.MibObject) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao)

Aggregations

MockDatabase (org.opennms.core.test.db.MockDatabase)16 MockNetwork (org.opennms.netmgt.mock.MockNetwork)8 Before (org.junit.Before)5 InputStream (java.io.InputStream)4 DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)4 HashMap (java.util.HashMap)3 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)3 GregorianCalendar (java.util.GregorianCalendar)2 ServletException (javax.servlet.ServletException)2 Test (org.junit.Test)2 DatabaseSchemaConfigFactory (org.opennms.netmgt.config.DatabaseSchemaConfigFactory)2 MibObject (org.opennms.netmgt.config.datacollection.MibObject)2 JdbcFilterDao (org.opennms.netmgt.filter.JdbcFilterDao)2 MockCategoryFactory (org.opennms.netmgt.mock.MockCategoryFactory)2 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)2 MockServletConfig (org.springframework.mock.web.MockServletConfig)2 OpenSessionInViewFilter (org.springframework.orm.hibernate3.support.OpenSessionInViewFilter)2 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ServletContextEvent (javax.servlet.ServletContextEvent)1