@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);
  }
예제 #2
0
  @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");
  }
예제 #3
0
  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();
  }
예제 #4
0
  @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")));
  }
예제 #5
0
 public void testUnmarshalResource()
     throws MarshalException, ValidationException, FileNotFoundException, IOException {
   CastorUtils.unmarshal(
       Userinfo.class,
       new InputStreamResource(ConfigurationTestUtils.getInputStreamForConfigFile("users.xml")));
 }