@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); }
@Test public void testNodeGainedDynamicService() throws Exception { m_pollerConfig.setNodeOutageProcessingEnabled(true); startDaemons(); TestCapsdConfigManager capsdConfig = new TestCapsdConfigManager(CAPSD_CONFIG); InputStream configStream = ConfigurationTestUtils.getInputStreamForConfigFile("opennms-server.xml"); OpennmsServerConfigFactory onmsSvrConfig = new OpennmsServerConfigFactory(configStream); configStream.close(); 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 collectdConfig = new CollectdConfigFactory( configStream, onmsSvrConfig.getServerName(), onmsSvrConfig.verifyServer()); configStream.close(); JdbcTemplate jdbcTemplate = new JdbcTemplate(m_db); JdbcCapsdDbSyncer syncer = new JdbcCapsdDbSyncer(); syncer.setJdbcTemplate(jdbcTemplate); syncer.setOpennmsServerConfig(onmsSvrConfig); syncer.setCapsdConfig(capsdConfig); syncer.setPollerConfig(m_pollerConfig); syncer.setCollectdConfig(collectdConfig); syncer.setNextSvcIdSql(m_db.getNextServiceIdStatement()); syncer.afterPropertiesSet(); OpenNMSProvisioner provisioner = new OpenNMSProvisioner(); provisioner.setPollerConfig(m_pollerConfig); provisioner.setCapsdConfig(capsdConfig); provisioner.setCapsdDbSyncer(syncer); provisioner.setEventManager(m_eventMgr); provisioner.addServiceDNS("MyDNS", 3, 100, 1000, 500, 3000, 53, "www.opennms.org"); assertNotNull("The service id for MyDNS is null", m_db.getServiceID("MyDNS")); MockUtil.println("The service id for MyDNS is: " + m_db.getServiceID("MyDNS").toString()); m_anticipator.reset(); testSendNodeGainedService("MyDNS", "HTTP"); }