Search in sources :

Example 1 with NotificationAnticipator

use of org.opennms.netmgt.mock.NotificationAnticipator in project opennms by OpenNMS.

the class MockNotificationStrategy method send.

/* (non-Javadoc)
     * @see org.opennms.netmgt.notifd.NotificationStrategy#send(java.util.List)
     */
@Override
public int send(List<Argument> arguments) {
    MockUtil.println("Message sent with arguments:" + arguments);
    MockNotification notification = new MockNotification();
    Iterator<Argument> it = arguments.iterator();
    while (it.hasNext()) {
        Argument arg = it.next();
        if (arg.getSwitch().equals(NotificationManager.PARAM_SUBJECT)) {
            notification.setSubject(arg.getValue());
        } else if (arg.getSwitch().equals(NotificationManager.PARAM_EMAIL)) {
            notification.setEmail(arg.getValue());
        } else if (arg.getSwitch().equals(NotificationManager.PARAM_TEXT_MSG)) {
            notification.setTextMsg(arg.getValue());
        }
    }
    notification.setExpectedTime(System.currentTimeMillis());
    NotificationAnticipator anticipator = getAnticipator();
    if (anticipator != null) {
        anticipator.notificationReceived(notification);
    } else {
        throw new NullPointerException("anticipator is null");
    }
    return 0;
}
Also used : MockNotification(org.opennms.netmgt.mock.MockNotification) Argument(org.opennms.netmgt.model.notifd.Argument) NotificationAnticipator(org.opennms.netmgt.mock.NotificationAnticipator)

Example 2 with NotificationAnticipator

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

NotificationAnticipator (org.opennms.netmgt.mock.NotificationAnticipator)2 MockDestinationPathManager (org.opennms.netmgt.config.mock.MockDestinationPathManager)1 MockNotifdConfigManager (org.opennms.netmgt.config.mock.MockNotifdConfigManager)1 MockNotificationCommandManager (org.opennms.netmgt.config.mock.MockNotificationCommandManager)1 MockNotificationManager (org.opennms.netmgt.config.mock.MockNotificationManager)1 MockEventIpcManager (org.opennms.netmgt.dao.mock.MockEventIpcManager)1 MockNotification (org.opennms.netmgt.mock.MockNotification)1 MockPollerConfig (org.opennms.netmgt.mock.MockPollerConfig)1 Argument (org.opennms.netmgt.model.notifd.Argument)1 DaoTestConfigBean (org.opennms.test.DaoTestConfigBean)1