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);
}
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);
}
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();
}
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");
}
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 ################");
}
Aggregations