@Before public void setUp() throws Exception { MockLogAppender.setupLogging(); MockDatabase db = new MockDatabase(); DataSourceFactory.setInstance(db); RrdUtils.setStrategy(m_strategy); m_provisioner = new OpenNMSProvisioner(); m_eventManager = new MockEventIpcManager(); m_provisioner.setEventManager(m_eventManager); m_capsdConfig = new TestCapsdConfigManager(CAPSD_CONFIG); CapsdConfigFactory.setInstance(m_capsdConfig); m_pollerConfig = new TestPollerConfigManager(POLLER_CONFIG, "localhost", false); PollerConfigFactory.setInstance(m_pollerConfig); m_provisioner.setCapsdConfig(m_capsdConfig); m_provisioner.setPollerConfig(m_pollerConfig); InputStream configStream = ConfigurationTestUtils.getInputStreamForConfigFile("opennms-server.xml"); OpennmsServerConfigFactory onmsSvrConfig = new OpennmsServerConfigFactory(configStream); configStream.close(); OpennmsServerConfigFactory.setInstance(onmsSvrConfig); configStream = ConfigurationTestUtils.getInputStreamForConfigFile("database-schema.xml"); DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(configStream)); configStream.close(); configStream = ConfigurationTestUtils.getInputStreamForResource( this, "/org/opennms/netmgt/capsd/collectd-configuration.xml"); CollectdConfigFactory.setInstance( new CollectdConfigFactory( configStream, onmsSvrConfig.getServerName(), onmsSvrConfig.verifyServer())); configStream.close(); JdbcTemplate jdbcTemplate = new JdbcTemplate(db); m_syncer = new JdbcCapsdDbSyncer(); m_syncer.setJdbcTemplate(jdbcTemplate); m_syncer.setOpennmsServerConfig(OpennmsServerConfigFactory.getInstance()); m_syncer.setCapsdConfig(m_capsdConfig); m_syncer.setPollerConfig(m_pollerConfig); m_syncer.setCollectdConfig(CollectdConfigFactory.getInstance()); m_syncer.setNextSvcIdSql(db.getNextServiceIdStatement()); m_syncer.afterPropertiesSet(); m_syncer.syncServices(); m_provisioner.setCapsdDbSyncer(m_syncer); }
@Before public void setUp() throws Exception { m_assertLevel = Level.WARN; // System.setProperty("mock.logLevel", "DEBUG"); // System.setProperty("mock.debug", "true"); MockUtil.println("------------ Begin Test --------------------------"); MockLogAppender.setupLogging(); m_network = new MockNetwork(); m_network.setCriticalService("ICMP"); m_network.addNode(1, "Router"); m_network.addInterface("192.168.1.1"); m_network.addService("ICMP"); m_network.addService("SMTP"); m_network.addService("SNMP"); m_network.addInterface("192.168.1.2"); m_network.addService("ICMP"); m_network.addService("SMTP"); m_network.addNode(2, "Server"); m_network.addInterface("192.168.1.3"); m_network.addService("ICMP"); m_network.addService("HTTP"); m_network.addService("SMTP"); m_network.addService("SNMP"); m_network.addNode(3, "Firewall"); m_network.addInterface("192.168.1.4"); m_network.addService("SMTP"); m_network.addService("HTTP"); m_network.addInterface("192.168.1.5"); m_network.addService("SMTP"); m_network.addService("HTTP"); m_network.addNode(4, "DownNode"); m_network.addInterface("192.168.1.6"); m_network.addService("SNMP"); // m_network.addInterface("fe80:0000:0000:0000:0231:f982:0123:4567"); // m_network.addService("SNMP"); m_db = new MockDatabase(); m_db.populate(m_network); DataSourceFactory.setInstance(m_db); // DemandPollDao demandPollDao = new DemandPollDaoHibernate(m_db); // demandPollDao.setAllocateIdStmt(m_db // .getNextSequenceValStatement("demandPollNxtId")); // m_demandPollDao = demandPollDao; m_pollerConfig = new MockPollerConfig(m_network); m_pollerConfig.setNextOutageIdSql(m_db.getNextOutageIdStatement()); m_pollerConfig.setNodeOutageProcessingEnabled(true); m_pollerConfig.setCriticalService("ICMP"); m_pollerConfig.addPackage("TestPackage"); m_pollerConfig.addDowntime(1000L, 0L, -1L, false); m_pollerConfig.setDefaultPollInterval(1000L); m_pollerConfig.populatePackage(m_network); m_pollerConfig.addPackage("TestPkg2"); m_pollerConfig.addDowntime(1000L, 0L, -1L, false); m_pollerConfig.setDefaultPollInterval(2000L); m_pollerConfig.addService(m_network.getService(2, "192.168.1.3", "HTTP")); m_anticipator = new EventAnticipator(); m_outageAnticipator = new OutageAnticipator(m_db); m_eventMgr = new MockEventIpcManager(); m_eventMgr.setEventWriter(m_db); m_eventMgr.setEventAnticipator(m_anticipator); m_eventMgr.addEventListener(m_outageAnticipator); m_eventMgr.setSynchronous(false); QueryManager queryManager = new DefaultQueryManager(); queryManager.setDataSource(m_db); DefaultPollContext pollContext = new DefaultPollContext(); pollContext.setEventManager(m_eventMgr); pollContext.setLocalHostName("localhost"); pollContext.setName("Test.DefaultPollContext"); pollContext.setPollerConfig(m_pollerConfig); pollContext.setQueryManager(queryManager); PollableNetwork network = new PollableNetwork(pollContext); m_poller = new Poller(); m_poller.setDataSource(m_db); m_poller.setEventManager(m_eventMgr); m_poller.setNetwork(network); m_poller.setQueryManager(queryManager); m_poller.setPollerConfig(m_pollerConfig); m_poller.setPollOutagesConfig(m_pollerConfig); MockOutageConfig config = new MockOutageConfig(); config.setGetNextOutageID(m_db.getNextOutageIdStatement()); RrdUtils.setStrategy(new NullRrdStrategy()); // m_outageMgr = new OutageManager(); // m_outageMgr.setEventMgr(m_eventMgr); // m_outageMgr.setOutageMgrConfig(config); // m_outageMgr.setDbConnectionFactory(m_db); }