Search in sources :

Example 6 with MockDatabase

use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.

the class AvailabilityCalculatorIT method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // Reset the FilterDaoFactory so we don't get screwed by having the JdbcFilterDao be connected to an older database
    FilterDaoFactory.setInstance(null);
    Locale.setDefault(Locale.US);
    m_calendar = new GregorianCalendar();
    // date for report run is 18th May 2005
    m_calendar.set(2005, Calendar.MAY, 18);
    MockLogAppender.setupLogging();
    m_categories = new Categories();
    m_db = new MockDatabase();
    DataSourceFactory.setInstance(m_db);
    InputStream is = ConfigurationTestUtils.getInputStreamForConfigFile("database-schema.xml");
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(is));
    is.close();
    m_catFactory = new MockCategoryFactory();
    CategoryFactory.setInstance(m_catFactory);
    m_db.update("insert into node (location, nodeID, nodelabel, nodeCreateTime, nodeType) values ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 1,'test1.availability.opennms.org','2004-03-01 09:00:00','A')");
    m_db.update("insert into node (location, nodeID, nodelabel, nodeCreateTime, nodeType) values ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 2,'test2.availability.opennms.org','2004-03-01 09:00:00','A')");
    m_db.update("insert into service (serviceid, servicename) values\n" + "(1, 'ICMP');");
    m_db.update("insert into service (serviceid, servicename) values\n" + "(2, 'HTTP');");
    m_db.update("insert into service (serviceid, servicename) values\n" + "(3, 'SNMP');");
    m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(1, 1,'192.168.100.1','M');");
    m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(2, 2,'192.168.100.2','M');");
    m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(3, 2,'192.168.100.3','M');");
    m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 1:192.168.100.1:1
    "(1, 1,'A', 1);");
    m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 2:192.168.100.2:1
    "(2, 1,'A', 2);");
    /*
         * m_db.update("insert into ifservices (serviceid, status, ipInterfaceId) values " + "(2,'A', 2);"); //2:192.168.100.2:2
         */
    m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 2:192.168.100.3:1
    "(3, 1,'A', 3);");
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(1,1,'2005-05-01 09:00:00','2005-05-01 09:30:00');");
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(2,2,'2005-05-01 10:00:00','2005-05-02 10:00:00');");
    // test data for LastMonthsDailyAvailability report
    // insert 30 minute outage on one node - 99.3056% availability
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(3,1,'2005-04-02 10:00:00','2005-04-02 10:30:00');");
    // insert 60 minute outage on one interface and 59 minute outages on
    // another - 97.2454
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(4,1,'2005-04-03 11:30:00','2005-04-03 12:30:00');");
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(5,2,'2005-04-03 23:00:00','2005-04-03 23:59:00');");
    // test an outage that spans 60 minutes across midnight - 99.3056% on
    // each day, well, not exactly
    // its 29 minutes 99.3059 on the fist day and 31 minutes 99.3052 on
    // the second.
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(6,3,'2005-04-04 23:30:00','2005-04-05 00:30:00');");
}
Also used : InputStream(java.io.InputStream) GregorianCalendar(java.util.GregorianCalendar) MockDatabase(org.opennms.core.test.db.MockDatabase) MockCategoryFactory(org.opennms.netmgt.mock.MockCategoryFactory) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory)

Example 7 with MockDatabase

use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.

the class AvailabilityReportIT method setUp.

@Override
protected void setUp() throws Exception {
    System.err.println("------------------- begin " + getName() + " ---------------------");
    // Reset the FilterDaoFactory so we don't get screwed by having the JdbcFilterDao be connected to an older database
    FilterDaoFactory.setInstance(null);
    super.setUp();
    Locale.setDefault(Locale.US);
    calendar = new GregorianCalendar();
    // date for report run is 18th May 2005
    calendar.set(2005, 4, 18);
    MockLogAppender.setupLogging();
    m_categories = new Categories();
    m_db = new MockDatabase();
    DataSourceFactory.setInstance(m_db);
    InputStream is = ConfigurationTestUtils.getInputStreamForConfigFile("database-schema.xml");
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(is));
    is.close();
    m_catFactory = new MockCategoryFactory();
    CategoryFactory.setInstance(m_catFactory);
    m_db.update("insert into node (location, nodeID, nodelabel, nodeCreateTime, nodeType) values ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 1,'test1.availability.opennms.org','2004-03-01 09:00:00','A')");
    m_db.update("insert into node (location, nodeID, nodelabel, nodeCreateTime, nodeType) values ('" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID + "', 2,'test2.availability.opennms.org','2004-03-01 09:00:00','A')");
    m_db.update("insert into service (serviceid, servicename) values\n" + "(1, 'ICMP');");
    m_db.update("insert into service (serviceid, servicename) values\n" + "(2, 'HTTP');");
    m_db.update("insert into service (serviceid, servicename) values\n" + "(3, 'SNMP');");
    m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(1, 1,'192.168.100.1','M');");
    m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(2, 2,'192.168.100.2','M');");
    m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n" + "(3, 2,'192.168.100.3','M');");
    m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 1:192.168.100.1:1
    "(1,1,'A',1);");
    m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 2:192.168.100.2:1
    "(2,1,'A',2);");
    /*
        m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " +
        "(3,2,'A',2);"); // 2:192.168.100.2:2
        */
    m_db.update("insert into ifservices (id, serviceid, status, ipInterfaceId) values " + // 2:192.168.100.3:1
    "(4,1,'A',3);");
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(1,1,'2005-05-01 09:00:00','2005-05-01 09:30:00');");
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(2,2,'2005-05-01 10:00:00','2005-05-02 10:00:00');");
    // test data for LastMonthsDailyAvailability report
    // insert 30 minute outage on one node - 99.3056% availability
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(3,1,'2005-04-02 10:00:00','2005-04-02 10:30:00');");
    // insert 60 minute outage on one interface and 59 minute outages on another - 97.2454
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(4,1,'2005-04-03 11:30:00','2005-04-03 12:30:00');");
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(5,2,'2005-04-03 23:00:00','2005-04-03 23:59:00');");
    // test an outage that spans 60 minutes across midnight - 99.3056% on each day, well, not exactly
    // its 29 minutes 99.3059 on the fist day and 31 minutes 99.3052 on the second.
    m_db.update("insert into outages (outageid, ifServiceId, ifLostService, ifRegainedService) values " + "(6,4,'2005-04-04 23:30:00','2005-04-05 00:30:00');");
}
Also used : InputStream(java.io.InputStream) GregorianCalendar(java.util.GregorianCalendar) MockDatabase(org.opennms.core.test.db.MockDatabase) MockCategoryFactory(org.opennms.netmgt.mock.MockCategoryFactory) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory)

Example 8 with MockDatabase

use of org.opennms.core.test.db.MockDatabase 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 9 with MockDatabase

use of org.opennms.core.test.db.MockDatabase in project opennms by OpenNMS.

the class CollectorConfigDaoImplIT method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    MockUtil.println("------------ Begin Test " + getName() + " --------------------------");
    MockLogAppender.setupLogging();
    MockDatabase m_db = new MockDatabase();
    // m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
}
Also used : MockDatabase(org.opennms.core.test.db.MockDatabase)

Example 10 with MockDatabase

use of org.opennms.core.test.db.MockDatabase 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

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