Search in sources :

Example 21 with MockEventIpcManager

use of org.opennms.netmgt.dao.mock.MockEventIpcManager in project opennms by OpenNMS.

the class CollectableServiceTest method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    rrdStrategy = new JRobinRrdStrategy();
    fileAnticipator = new FileAnticipator();
    MockEventIpcManager mockEventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(mockEventIpcManager);
}
Also used : MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) JRobinRrdStrategy(org.opennms.netmgt.rrd.jrobin.JRobinRrdStrategy) FileAnticipator(org.opennms.test.FileAnticipator) Before(org.junit.Before)

Example 22 with MockEventIpcManager

use of org.opennms.netmgt.dao.mock.MockEventIpcManager in project opennms by OpenNMS.

the class CollectdIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_mockUtils = new EasyMockUtils();
    m_filterDao = m_mockUtils.createMock(FilterDao.class);
    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);
    File homeDir = resource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    resource = new ClassPathResource("/test-thresholds.xml");
    ThresholdingConfigFactory.setInstance(new ThresholdingConfigFactory(resource.getInputStream()));
    // set up test using a string key
    m_key = m_testName.getMethodName() + System.nanoTime();
    m_tests.put(m_key, this);
    //create a collector definition
    Collector collector = new Collector();
    collector.setService("SNMP");
    collector.setClassName(MockServiceCollector.class.getName());
    // pass the key to the collector definition so it can look up the associated test
    Parameter param = new Parameter();
    param.setKey(TEST_KEY_PARM_NAME);
    param.setValue(m_key);
    collector.addParameter(param);
    m_collectdConfigFactory = m_mockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class);
    EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(1).anyTimes();
    m_ifaceDao = m_mockUtils.createMock(IpInterfaceDao.class);
    m_nodeDao = m_mockUtils.createMock(NodeDao.class);
    m_collectd = new Collectd() {

        @Override
        protected void handleInsufficientInfo(InsufficientInformationException e) {
            fail("Invalid event received: " + e.getMessage());
        }
    };
    OnmsServiceType snmp = new OnmsServiceType("SNMP");
    NetworkBuilder netBuilder = new NetworkBuilder();
    NodeBuilder nodeBuilder = netBuilder.addNode("node1").setId(1);
    InterfaceBuilder ifaceBlder = netBuilder.addInterface("192.168.1.1").setId(2).setIsSnmpPrimary("P");
    ifaceBlder.addSnmpInterface(1);
    OnmsMonitoredService svc = netBuilder.addService(snmp);
    List<OnmsIpInterface> initialIfs = Collections.emptyList();
    EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expect(m_nodeDao.load(1)).andReturn(nodeBuilder.getNode()).anyTimes();
    createGetPackagesExpectation(svc);
    EasyMock.expect(m_ifaceDao.load(2)).andReturn(ifaceBlder.getInterface()).anyTimes();
    m_mockUtils.replayAll();
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setIpInterfaceDao(m_ifaceDao);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    // Inits the class
    m_collectd.afterPropertiesSet();
//assertNotNull(m_serviceCollector);
}
Also used : DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) InsufficientInformationException(org.opennms.core.utils.InsufficientInformationException) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) NodeBuilder(org.opennms.netmgt.model.NetworkBuilder.NodeBuilder) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) Collector(org.opennms.netmgt.config.collectd.Collector) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) InterfaceBuilder(org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Parameter(org.opennms.netmgt.config.collectd.Parameter) File(java.io.File) ThresholdingConfigFactory(org.opennms.netmgt.config.ThresholdingConfigFactory) Before(org.junit.Before)

Example 23 with MockEventIpcManager

use of org.opennms.netmgt.dao.mock.MockEventIpcManager in project opennms by OpenNMS.

the class DuplicatePrimaryAddressIT method initialize.

/**
     * Initialize.
     *
     * @param scheduleExistingNodes true, to emulate having data on the database
     * @throws Exception the exception
     */
private void initialize(boolean scheduleExistingNodes) throws Exception {
    MockLogAppender.setupLogging();
    m_eventIpcManager = new MockEventIpcManager();
    EventIpcManagerFactory.setIpcManager(m_eventIpcManager);
    m_mockUtils = new EasyMockUtils();
    m_filterDao = m_mockUtils.createMock(FilterDao.class);
    FilterDaoFactory.setInstance(m_filterDao);
    Resource resource = new ClassPathResource("etc/poll-outages.xml");
    PollOutagesConfigFactory factory = new PollOutagesConfigFactory(resource);
    factory.afterPropertiesSet();
    PollOutagesConfigFactory.setInstance(factory);
    File homeDir = resource.getFile().getParentFile().getParentFile();
    System.setProperty("opennms.home", homeDir.getAbsolutePath());
    Collector collector = new Collector();
    collector.setService("SNMP");
    collector.setClassName(MockServiceCollector.class.getName());
    m_collectdConfigFactory = m_mockUtils.createMock(CollectdConfigFactory.class);
    m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class);
    EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes();
    EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(2).anyTimes();
    m_ifaceDao = m_mockUtils.createMock(IpInterfaceDao.class);
    m_nodeDao = m_mockUtils.createMock(NodeDao.class);
    m_collectd = new Collectd() {

        @Override
        protected void handleInsufficientInfo(InsufficientInformationException e) {
            Assert.fail("Invalid event received: " + e.getMessage());
        }
    };
    OnmsServiceType snmp = new OnmsServiceType("SNMP");
    NetworkBuilder netBuilder = new NetworkBuilder();
    OnmsNode n1 = netBuilder.addNode("node1").setId(1).setForeignSource("TestA").setForeignId("node1").getNode();
    OnmsIpInterface ip1 = netBuilder.addSnmpInterface(1).addIpInterface("192.168.1.1").setId(2).setIsSnmpPrimary("P").getInterface();
    netBuilder.addService(snmp);
    OnmsNode n2 = netBuilder.addNode("node2").setId(3).setForeignSource("TestB").setForeignId("node2").getNode();
    OnmsIpInterface ip2 = netBuilder.addSnmpInterface(1).addIpInterface("192.168.1.1").setId(4).setIsSnmpPrimary("P").getInterface();
    netBuilder.addService(snmp);
    Assert.assertNotSame(ip1.getNode().getId(), ip2.getNode().getId());
    List<OnmsIpInterface> initialIfs = new ArrayList<OnmsIpInterface>();
    if (scheduleExistingNodes) {
        initialIfs.add(ip1);
        initialIfs.add(ip2);
    }
    EasyMock.expect(m_ifaceDao.findByServiceType(snmp.getName())).andReturn(initialIfs).anyTimes();
    m_filterDao.flushActiveIpAddressListCache();
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(m_nodeDao.load(1)).andReturn(n1).anyTimes();
    EasyMock.expect(m_nodeDao.load(3)).andReturn(n2).anyTimes();
    createGetPackagesExpectation();
    EasyMock.expect(m_ifaceDao.load(2)).andReturn(ip1).anyTimes();
    EasyMock.expect(m_ifaceDao.load(4)).andReturn(ip2).anyTimes();
    m_mockUtils.replayAll();
    final MockTransactionTemplate transTemplate = new MockTransactionTemplate();
    transTemplate.afterPropertiesSet();
    m_collectd.setCollectdConfigFactory(m_collectdConfigFactory);
    m_collectd.setEventIpcManager(m_eventIpcManager);
    m_collectd.setTransactionTemplate(transTemplate);
    m_collectd.setIpInterfaceDao(m_ifaceDao);
    m_collectd.setNodeDao(m_nodeDao);
    m_collectd.setFilterDao(m_filterDao);
    m_collectd.setPersisterFactory(new MockPersisterFactory());
    m_collectd.setServiceCollectorRegistry(new DefaultServiceCollectorRegistry());
    m_collectd.setLocationAwareCollectorClient(CollectorTestUtils.createLocationAwareCollectorClient());
    m_collectd.afterPropertiesSet();
    m_collectd.start();
}
Also used : DefaultServiceCollectorRegistry(org.opennms.netmgt.collection.support.DefaultServiceCollectorRegistry) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) InsufficientInformationException(org.opennms.core.utils.InsufficientInformationException) ArrayList(java.util.ArrayList) EasyMockUtils(org.opennms.test.mock.EasyMockUtils) NodeDao(org.opennms.netmgt.dao.api.NodeDao) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) Collector(org.opennms.netmgt.config.collectd.Collector) MockPersisterFactory(org.opennms.netmgt.mock.MockPersisterFactory) OnmsNode(org.opennms.netmgt.model.OnmsNode) PollOutagesConfigFactory(org.opennms.netmgt.config.PollOutagesConfigFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) CollectdConfigFactory(org.opennms.netmgt.config.CollectdConfigFactory) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) File(java.io.File)

Example 24 with MockEventIpcManager

use of org.opennms.netmgt.dao.mock.MockEventIpcManager in project opennms by OpenNMS.

the class PollContextIT method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_mNetwork = new MockNetwork();
    m_mNetwork.addNode(1, "Router");
    m_mNetwork.addInterface("192.168.1.1");
    m_mNetwork.addService("ICMP");
    m_mNetwork.addService("SMTP");
    m_mNetwork.addInterface("192.168.1.2");
    m_mNetwork.addService("ICMP");
    m_mNetwork.addService("SMTP");
    m_mNetwork.addNode(2, "Server");
    m_mNetwork.addInterface("192.168.1.3");
    m_mNetwork.addService("ICMP");
    m_mNetwork.addService("HTTP");
    m_mNetwork.addNode(3, "Firewall");
    m_mNetwork.addInterface("192.168.1.4");
    m_mNetwork.addService("SMTP");
    m_mNetwork.addService("HTTP");
    m_mNetwork.addInterface("192.168.1.5");
    m_mNetwork.addService("SMTP");
    m_mNetwork.addService("HTTP");
    m_mSvc = m_mNetwork.getService(1, "192.168.1.1", "ICMP");
    m_db.populate(m_mNetwork);
    m_pollerConfig = new MockPollerConfig(m_mNetwork);
    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_mNetwork);
    m_pollerConfig.addPackage("TestPkg2");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(2000L);
    m_pollerConfig.addService(m_mNetwork.getService(2, "192.168.1.3", "HTTP"));
    m_pollerConfig.setNextOutageIdSql(m_db.getNextOutageIdStatement());
    m_outageAnticipator = new OutageAnticipator(m_db);
    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_eventMgr.addEventListener(m_outageAnticipator);
    m_locationAwarePingClient = mock(LocationAwarePingClient.class);
    m_pollContext = new DefaultPollContext();
    m_pollContext.setEventManager(m_eventMgr);
    m_pollContext.setLocalHostName("localhost");
    m_pollContext.setName("PollContextTest.DefaultPollContext");
    m_pollContext.setPollerConfig(m_pollerConfig);
    m_pollContext.setQueryManager(m_queryManager);
    m_pollContext.setLocationAwarePingClient(m_locationAwarePingClient);
    m_pNetwork = new PollableNetwork(m_pollContext);
    m_pSvc = m_pNetwork.createService(1, "Router", null, InetAddressUtils.addr("192.168.1.1"), "ICMP");
}
Also used : LocationAwarePingClient(org.opennms.netmgt.icmp.proxy.LocationAwarePingClient) MockNetwork(org.opennms.netmgt.mock.MockNetwork) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) OutageAnticipator(org.opennms.netmgt.mock.OutageAnticipator) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) PollableNetwork(org.opennms.netmgt.poller.pollables.PollableNetwork) Before(org.junit.Before)

Example 25 with MockEventIpcManager

use of org.opennms.netmgt.dao.mock.MockEventIpcManager in project opennms by OpenNMS.

the class NotificationsITCase method setUp.

protected void setUp() throws Exception {
    MockUtil.println("################# Running Test ################");
    DaoTestConfigBean bean = new DaoTestConfigBean();
    bean.afterPropertiesSet();
    MockLogAppender.setupLogging();
    m_network = createMockNetwork();
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);
    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_notifdConfig = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
    m_notifdConfig.setNextNotifIdSql(m_db.getNextNotifIdSql());
    m_notifdConfig.setNextUserNotifIdSql(m_db.getNextUserNotifIdSql());
    m_groupManager = createGroupManager();
    m_userManager = createUserManager(m_groupManager);
    m_destinationPathManager = new MockDestinationPathManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "destination-paths.xml"));
    m_notificationCommandManger = new MockNotificationCommandManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notification-commands.xml"));
    m_notificationManager = new MockNotificationManager(m_notifdConfig, m_db, ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifications.xml"));
    m_pollOutagesConfigManager = new MockPollerConfig(m_network);
    m_anticipator = new NotificationAnticipator();
    MockNotificationStrategy.setAnticipator(m_anticipator);
    m_notifd.setConfigManager(m_notifdConfig);
    m_eventProcessor.setEventManager(m_eventMgr);
    m_eventProcessor.setNotifdConfigManager(m_notifdConfig);
    m_eventProcessor.setGroupManager(m_groupManager);
    m_eventProcessor.setUserManager(m_userManager);
    m_eventProcessor.setDestinationPathManager(m_destinationPathManager);
    m_eventProcessor.setNotificationCommandManager(m_notificationCommandManger);
    m_eventProcessor.setNotificationManager(m_notificationManager);
    m_eventProcessor.setPollOutagesConfigManager(m_pollOutagesConfigManager);
    m_notifd.init();
    m_notifd.start();
    //        Date downDate = new Date();
    //        anticipateNotificationsForGroup("node 2 down.", "All services are down on node 2.", "InitialGroup", downDate, 0);
    //    
    //        //bring node down now
    //        m_eventMgr.sendEventToListeners(m_network.getNode(2).createDownEvent(downDate));
    //    
    //        m_anticipator.waitForAnticipated(2000);
    //        
    //        m_anticipator.reset();
    MockUtil.println("################ Finish Setup ################");
}
Also used : DaoTestConfigBean(org.opennms.test.DaoTestConfigBean) MockNotificationManager(org.opennms.netmgt.config.mock.MockNotificationManager) MockDestinationPathManager(org.opennms.netmgt.config.mock.MockDestinationPathManager) MockNotifdConfigManager(org.opennms.netmgt.config.mock.MockNotifdConfigManager) MockEventIpcManager(org.opennms.netmgt.dao.mock.MockEventIpcManager) NotificationAnticipator(org.opennms.netmgt.mock.NotificationAnticipator) MockPollerConfig(org.opennms.netmgt.mock.MockPollerConfig) MockNotificationCommandManager(org.opennms.netmgt.config.mock.MockNotificationCommandManager)

Aggregations

MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)26 Before (org.junit.Before)14 NodeDao (org.opennms.netmgt.dao.api.NodeDao)5 MockPollerConfig (org.opennms.netmgt.mock.MockPollerConfig)5 EasyMockUtils (org.opennms.test.mock.EasyMockUtils)5 EventIpcManager (org.opennms.netmgt.events.api.EventIpcManager)4 MockNetwork (org.opennms.netmgt.mock.MockNetwork)4 OutageAnticipator (org.opennms.netmgt.mock.OutageAnticipator)4 File (java.io.File)3 PollOutagesConfigFactory (org.opennms.netmgt.config.PollOutagesConfigFactory)3 MockNodeDao (org.opennms.netmgt.dao.mock.MockNodeDao)3 FilterDao (org.opennms.netmgt.filter.api.FilterDao)3 LocationAwarePingClient (org.opennms.netmgt.icmp.proxy.LocationAwarePingClient)3 MockPersisterFactory (org.opennms.netmgt.mock.MockPersisterFactory)3 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)3 PollableNetwork (org.opennms.netmgt.poller.pollables.PollableNetwork)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2