Search in sources :

Example 1 with MockNotifdConfigManager

use of org.opennms.netmgt.config.mock.MockNotifdConfigManager in project opennms by OpenNMS.

the class NotificationManagerIT method setUp.

@Before
public void setUp() throws Exception {
    // Initialize Filter DAO
    DatabaseSchemaConfigFactory.init();
    JdbcFilterDao jdbcFilterDao = new JdbcFilterDao();
    jdbcFilterDao.setDataSource(m_dataSource);
    jdbcFilterDao.setDatabaseSchemaConfigFactory(DatabaseSchemaConfigFactory.getInstance());
    jdbcFilterDao.afterPropertiesSet();
    FilterDaoFactory.setInstance(jdbcFilterDao);
    m_configManager = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
    m_notificationManager = new NotificationManagerIT.NotificationManagerImpl(m_configManager, m_dataSource);
    OnmsNode node;
    OnmsIpInterface ipInterface;
    OnmsMonitoredService service;
    OnmsServiceType serviceType;
    OnmsCategory category1 = new OnmsCategory("CategoryOne");
    m_categoryDao.save(category1);
    OnmsCategory category2 = new OnmsCategory("CategoryTwo");
    m_categoryDao.save(category2);
    OnmsCategory category3 = new OnmsCategory("CategoryThree");
    m_categoryDao.save(category3);
    OnmsCategory category4 = new OnmsCategory("CategoryFour");
    m_categoryDao.save(category4);
    m_categoryDao.flush();
    serviceType = new OnmsServiceType("ICMP");
    m_serviceTypeDao.save(serviceType);
    serviceType = new OnmsServiceType("HTTP");
    m_serviceTypeDao.save(serviceType);
    // node 1
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 1");
    node.addCategory(category1);
    node.addCategory(category2);
    node.addCategory(category3);
    node1 = node;
    ipInterface = new OnmsIpInterface(addr("192.168.1.1"), node);
    ipInterfaceOnNode1 = ipInterface;
    service = new OnmsMonitoredService(ipInterface, serviceType);
    m_nodeDao.save(node);
    // node 2
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 2");
    node.addCategory(category1);
    node.addCategory(category2);
    node.addCategory(category4);
    m_nodeDao.save(node);
    ipInterface = new OnmsIpInterface(addr("192.168.1.1"), node);
    m_ipInterfaceDao.save(ipInterface);
    service = new OnmsMonitoredService(ipInterface, serviceType);
    m_serviceDao.save(service);
    ipInterface = new OnmsIpInterface(addr("0.0.0.0"), node);
    m_ipInterfaceDao.save(ipInterface);
    // node 3
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 3");
    m_nodeDao.save(node);
    ipInterface = new OnmsIpInterface(addr("192.168.1.2"), node);
    m_ipInterfaceDao.save(ipInterface);
    service = new OnmsMonitoredService(ipInterface, serviceType);
    m_serviceDao.save(service);
    // node 4 has an interface, but no services
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 4");
    m_nodeDao.save(node);
    ipInterface = new OnmsIpInterface(addr("192.168.1.3"), node);
    m_ipInterfaceDao.save(ipInterface);
    // node 5 has no interfaces
    node = new OnmsNode(m_locationDao.getDefaultLocation(), "node 5");
    m_nodeDao.save(node);
    m_nodeDao.flush();
    m_ipInterfaceDao.flush();
    m_serviceDao.flush();
    m_serviceTypeDao.flush();
    m_categoryDao.flush();
}
Also used : MockNotifdConfigManager(org.opennms.netmgt.config.mock.MockNotifdConfigManager) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) JdbcFilterDao(org.opennms.netmgt.filter.JdbcFilterDao) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

Example 2 with MockNotifdConfigManager

use of org.opennms.netmgt.config.mock.MockNotifdConfigManager in project opennms by OpenNMS.

the class NotificationsConfigTest method testFormattedNotificationsXml.

@Test
public void testFormattedNotificationsXml() throws Exception {
    MockUtil.println("################# Running Test ################");
    MockLogAppender.setupLogging();
    MockNotifdConfigManager notifdConfig = new MockNotifdConfigManager(ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifd-configuration.xml"));
    NotificationManager manager = new MockNotificationManager(notifdConfig, null, ConfigurationTestUtils.getConfigForResourceWithReplacements(this, "notifications-config-test.xml"));
    Notification n = manager.getNotification("crazyTestNotification");
    assertTrue(n.getTextMessage().contains("\n"));
}
Also used : MockNotificationManager(org.opennms.netmgt.config.mock.MockNotificationManager) MockNotifdConfigManager(org.opennms.netmgt.config.mock.MockNotifdConfigManager) NotificationManager(org.opennms.netmgt.config.NotificationManager) MockNotificationManager(org.opennms.netmgt.config.mock.MockNotificationManager) Notification(org.opennms.netmgt.config.notifications.Notification) Test(org.junit.Test)

Example 3 with MockNotifdConfigManager

use of org.opennms.netmgt.config.mock.MockNotifdConfigManager 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

MockNotifdConfigManager (org.opennms.netmgt.config.mock.MockNotifdConfigManager)3 MockNotificationManager (org.opennms.netmgt.config.mock.MockNotificationManager)2 Before (org.junit.Before)1 Test (org.junit.Test)1 NotificationManager (org.opennms.netmgt.config.NotificationManager)1 MockDestinationPathManager (org.opennms.netmgt.config.mock.MockDestinationPathManager)1 MockNotificationCommandManager (org.opennms.netmgt.config.mock.MockNotificationCommandManager)1 Notification (org.opennms.netmgt.config.notifications.Notification)1 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)1 JdbcFilterDao (org.opennms.netmgt.filter.JdbcFilterDao)1 MockPollerConfig (org.opennms.netmgt.mock.MockPollerConfig)1 NotificationAnticipator (org.opennms.netmgt.mock.NotificationAnticipator)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)1 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)1 DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)1