@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"); }
public void testExceptionContainsFileNameUnmarshalResourceWithBadResource() throws MarshalException, ValidationException, FileNotFoundException, IOException { /* * We are going to attempt to unmarshal groups.xml with the wrong * class so we get a MarshalException and we can then test to see if the * file name is embedded in the exception. */ boolean gotException = false; File file = ConfigurationTestUtils.getFileForConfigFile("groups.xml"); try { CastorUtils.unmarshal(Userinfo.class, new FileSystemResource(file)); } catch (MarshalException e) { String matchString = file.getAbsolutePath().replace('\\', '/'); if (e.toString().contains(matchString)) { gotException = true; } else { AssertionFailedError ae = new AssertionFailedError( "Got an exception, but not one containing the message we were expecting ('" + matchString + "'): " + e); ae.initCause(e); throw ae; } } if (!gotException) { fail("Did not get a MarshalException, but we were expecting one."); } }
protected void initializeDatabase() throws Exception { // Create a ByteArrayOutputSteam to effectively throw away output. resetOutputStream(); m_installerDb.setDatabaseName(getTestDatabase()); m_installerDb.setDataSource(getDataSource()); m_installerDb.setAdminDataSource(getAdminDataSource()); m_installerDb.setPostgresOpennmsUser(getAdminUser()); m_installerDb.setCreateSqlLocation( ConfigurationTestUtils.getFileForConfigFile("create.sql").getAbsolutePath()); m_installerDb.setStoredProcedureDirectory( ConfigurationTestUtils.getFileForConfigFile("getPercentAvailabilityInWindow.sql") .getParentFile() .getAbsolutePath()); // m_installerDb.setDebug(true); m_installerDb.readTables(); m_installerDb.createSequences(); m_installerDb.updatePlPgsql(); m_installerDb.addStoredProcedures(); /* * Here's an example of an iplike function that always returns true. * CREATE OR REPLACE FUNCTION iplike(text, text) RETURNS bool AS ' BEGIN RETURN true; END; ' LANGUAGE 'plpgsql'; * * Found this in BaseIntegrationTestCase. */ if (m_setupIpLike) { m_installerDb.setPostgresIpLikeLocation(null); m_installerDb.updateIplike(); } m_installerDb.createTables(); if (m_insertData) { m_installerDb.insertData(); } }
public void testUnmarshallInputStreamWithUtf8() throws MarshalException, ValidationException, IOException { Userinfo users = CastorUtils.unmarshal( Userinfo.class, ConfigurationTestUtils.getInputStreamForResource(this, "/users-utf8.xml")); assertEquals("user count", 1, users.getUsers().getUserCount()); // \u00f1 is unicode for n~ assertEquals("user name", "Admi\u00f1istrator", users.getUsers().getUser(0).getFullName()); }
public void testUnmarshalReaderQuietly() throws MarshalException, ValidationException, FileNotFoundException, IOException { CastorUtils.unmarshal( Userinfo.class, ConfigurationTestUtils.getInputStreamForConfigFile("users.xml")); /* * Ensure that nothing was logged. * In particular, we want to make sure that we don't see this message: * 2008-07-28 16:04:53,260 DEBUG [main] org.exolab.castor.xml.Unmarshaller: *static* unmarshal method called, this will ignore any mapping files or changes made to an Unmarshaller instance. */ MockLogAppender.assertNoLogging(); }
@Override protected void setUp() throws Exception { EventIpcManager m_eventIpcManager; NodeDao m_nodeDao; MockLogAppender.setupLogging(); Resource threshdResource = new ClassPathResource("/etc/thresholds.xml"); File homeDir = threshdResource.getFile().getParentFile().getParentFile(); System.setProperty("opennms.home", homeDir.getAbsolutePath()); // Test setup m_eventIpcManager = m_easyMockUtils.createMock(EventIpcManager.class); EventIpcManagerFactory.setIpcManager(m_eventIpcManager); m_nodeDao = m_easyMockUtils.createMock(NodeDao.class); m_ipIfDao = m_easyMockUtils.createMock(IpInterfaceDao.class); m_scheduler = new MockScheduler(); m_eventIpcManager.addEventListener(isA(EventListener.class)); expectLastCall().anyTimes(); m_eventIpcManager.addEventListener(isA(EventListener.class), isACollection(String.class)); expectLastCall().anyTimes(); m_eventIpcManager.addEventListener(isA(EventListener.class), isA(String.class)); expectLastCall().anyTimes(); m_eventIpcManager.removeEventListener(isA(EventListener.class)); expectLastCall().anyTimes(); // MockNetwork 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.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.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"); // // MockDatabase m_db = new MockDatabase(); // m_db.populate(m_network); // // DataSourceFactory.setInstance(m_db); // Mock the FilterDao without using EasyMockUtils so that it can be verified separately m_filterDao = EasyMock.createMock(FilterDao.class); List<InetAddress> allIps = new ArrayList<InetAddress>(); allIps.add(addr("192.168.1.1")); allIps.add(addr("192.168.1.2")); allIps.add(addr("192.168.1.3")); allIps.add(addr("192.168.1.4")); allIps.add(addr("192.168.1.5")); expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE *.*.*.*")) .andReturn(allIps) .anyTimes(); expect(m_filterDao.getActiveIPAddressList("IPADDR IPLIKE 1.1.1.1")) .andReturn(new ArrayList<InetAddress>(0)) .anyTimes(); EasyMock.replay(m_filterDao); FilterDaoFactory.setInstance(m_filterDao); // This call will also ensure that the poll-outages.xml file can parse IPv4 // and IPv6 addresses. Resource resource = new ClassPathResource("etc/poll-outages.xml"); PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource); factory.afterPropertiesSet(); PollOutagesConfigFactory.setInstance(factory); final MockTransactionTemplate transTemplate = new MockTransactionTemplate(); transTemplate.afterPropertiesSet(); m_collectd = new Collectd(); m_collectd.setEventIpcManager(m_eventIpcManager); // m_collectd.setCollectdConfigFactory(m_collectdConfigFactory); m_collectd.setNodeDao(m_nodeDao); m_collectd.setIpInterfaceDao(m_ipIfDao); m_collectd.setFilterDao(m_filterDao); m_collectd.setScheduler(m_scheduler); m_collectd.setTransactionTemplate(transTemplate); // m_collectd.afterPropertiesSet(); ThresholdingConfigFactory.setInstance( new ThresholdingConfigFactory( ConfigurationTestUtils.getInputStreamForConfigFile("thresholds.xml"))); }
public void testUnmarshalResource() throws MarshalException, ValidationException, FileNotFoundException, IOException { CastorUtils.unmarshal( Userinfo.class, new InputStreamResource(ConfigurationTestUtils.getInputStreamForConfigFile("users.xml"))); }
protected File findIpLikeLibrary() { File topDir = ConfigurationTestUtils.getTopProjectDirectory(); File ipLikeDir = new File(topDir, "opennms-iplike"); assertTrue( "iplike directory exists at ../opennms-iplike: " + ipLikeDir.getAbsolutePath(), ipLikeDir.exists()); File[] ipLikePlatformDirs = ipLikeDir.listFiles( new FileFilter() { @Override public boolean accept(File file) { if (file.getName().matches("opennms-iplike-.*") && file.isDirectory()) { return true; } else { return false; } } }); assertTrue( "expecting at least one opennms iplike platform directory in " + ipLikeDir.getAbsolutePath() + "; got: " + StringUtils.arrayToDelimitedString(ipLikePlatformDirs, ", "), ipLikePlatformDirs.length > 0); File ipLikeFile = null; for (File ipLikePlatformDir : ipLikePlatformDirs) { assertTrue( "iplike platform directory does not exist but was listed in directory listing: " + ipLikePlatformDir.getAbsolutePath(), ipLikePlatformDir.exists()); File ipLikeTargetDir = new File(ipLikePlatformDir, "target"); if (!ipLikeTargetDir.exists() || !ipLikeTargetDir.isDirectory()) { // Skip this one continue; } File[] ipLikeFiles = ipLikeTargetDir.listFiles( new FileFilter() { @Override public boolean accept(File file) { if (file.isFile() && file.getName().matches("opennms-iplike-.*\\.(so|dylib)")) { return true; } else { return false; } } }); assertFalse( "expecting zero or one iplike file in " + ipLikeTargetDir.getAbsolutePath() + "; got: " + StringUtils.arrayToDelimitedString(ipLikeFiles, ", "), ipLikeFiles.length > 1); if (ipLikeFiles.length == 1) { ipLikeFile = ipLikeFiles[0]; } } assertNotNull( "Could not find iplike shared object in a target directory in any of these directories: " + StringUtils.arrayToDelimitedString(ipLikePlatformDirs, ", "), ipLikeFile); return ipLikeFile; }