示例#1
0
 private OnmsNotification buildTestNotification(
     final NetworkBuilder builder, final OnmsEvent event) {
   final OnmsNotification notif = new OnmsNotification();
   notif.setEvent(event);
   notif.setTextMsg("This is a test notification");
   notif.setIpAddress(InetAddressUtils.getInetAddress("192.168.1.1"));
   notif.setNode(m_node1);
   notif.setServiceType(getService("ICMP"));
   return notif;
 }
  @Test
  @Transactional
  public void testNotificationSave() {
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_distPollerDao.load("localhost"));
    event.setEventCreateTime(new Date());
    event.setEventDescr("event dao test");
    event.setEventHost("localhost");
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventLogGroup("event dao test log group");
    event.setEventLogMsg("event dao test log msg");
    event.setEventSeverity(7);
    event.setEventSource("EventDaoTest");
    event.setEventTime(new Date());
    event.setEventUei("uei://org/opennms/test/NotificationDaoTest");
    //        OnmsAlarm alarm = new OnmsAlarm();
    //        event.setAlarm(alarm);

    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsIpInterface iface = node.getIpInterfaces().iterator().next();
    OnmsMonitoredService service = iface.getMonitoredServices().iterator().next();
    event.setNode(node);
    event.setServiceType(service.getServiceType());
    event.setIpAddr(iface.getIpAddress());
    m_eventDao.save(event);
    OnmsEvent newEvent = m_eventDao.load(event.getId());
    assertEquals("uei://org/opennms/test/NotificationDaoTest", newEvent.getEventUei());

    OnmsNotification notification = new OnmsNotification();
    notification.setEvent(newEvent);
    notification.setTextMsg("Tests are fun!");
    m_notificationDao.save(notification);

    OnmsNotification newNotification = m_notificationDao.load(notification.getNotifyId());
    assertEquals(
        "uei://org/opennms/test/NotificationDaoTest", newNotification.getEvent().getEventUei());
  }