@Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testAuthorizedAlarms() {

    Collection<OnmsAlarm> matching = m_alarmDao.findAll();

    assertNotNull(matching);
    assertEquals(1, matching.size());

    System.err.println(matching);

    enableAuthorizationFilter("NonExistentGroup");

    Collection<OnmsAlarm> matching2 = m_alarmDao.findAll();

    assertNotNull(matching2);
    assertEquals(0, matching2.size());

    System.err.println(matching2);

    disableAuthorizationFilter();

    Collection<OnmsAlarm> matching3 = m_alarmDao.findAll();

    assertNotNull(matching3);
    assertEquals(1, matching3.size());

    System.err.println(matching3);
  }
 @Test
 @Transactional
 public void testAlarmSummary_WithEmptyNodeIdsArray() {
   List<AlarmSummary> summary = m_alarmDao.getNodeAlarmSummaries();
   Assert.assertNotNull(summary); // the result does not really matter, as long as we get a result
   summary = null;
   summary = m_alarmDao.getNodeAlarmSummaries();
   Assert.assertNotNull(summary);
 }
 @Test
 @Transactional
 public void testSortOnNodeLabel() {
   Criteria criteria = new Criteria(OnmsAlarm.class);
   criteria.setAliases(Arrays.asList(new Alias[] {new Alias("node", "node", JoinType.LEFT_JOIN)}));
   criteria.setOrders(Arrays.asList(new Order[] {Order.asc("node.label")}));
   m_alarmDao.findMatching(criteria);
 }
  @Test
  @Transactional
  public void testActions() {
    OnmsEvent event = new OnmsEvent();
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventCreateTime(new Date());
    event.setDistPoller(m_distPollerDao.load("localhost"));
    event.setEventTime(new Date());
    event.setEventSeverity(Integer.valueOf(6));
    event.setEventUei("uei://org/opennms/test/EventDaoTest");
    event.setEventSource("test");
    m_eventDao.save(event);

    OnmsNode node = m_nodeDao.findAll().iterator().next();

    OnmsAlarm alarm = new OnmsAlarm();

    alarm.setNode(node);
    alarm.setUei(event.getEventUei());
    alarm.setSeverity(OnmsSeverity.get(event.getEventSeverity()));
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.load("localhost"));

    m_alarmDao.save(alarm);

    OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());

    assertEquals(OnmsSeverity.MAJOR, newAlarm.getSeverity());

    newAlarm.escalate("admin");
    assertEquals(OnmsSeverity.CRITICAL, newAlarm.getSeverity());

    newAlarm.clear("admin");
    assertEquals(OnmsSeverity.CLEARED, newAlarm.getSeverity());

    newAlarm.unacknowledge("admin");
    assertNull(newAlarm.getAckUser());
    assertNull(newAlarm.getAlarmAckTime());
  }
  @Test
  @Transactional
  public void testSave() {
    OnmsEvent event = new OnmsEvent();
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventCreateTime(new Date());
    event.setDistPoller(m_distPollerDao.load("localhost"));
    event.setEventTime(new Date());
    event.setEventSeverity(new Integer(7));
    event.setEventUei("uei://org/opennms/test/EventDaoTest");
    event.setEventSource("test");
    m_eventDao.save(event);

    OnmsNode node = m_nodeDao.findAll().iterator().next();

    OnmsAlarm alarm = new OnmsAlarm();

    alarm.setNode(node);
    alarm.setUei(event.getEventUei());
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.load("localhost"));

    m_alarmDao.save(alarm);
    // It works we're so smart! hehe

    OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());

    Collection<OnmsAlarm> alarms;
    Criteria criteria = new Criteria(OnmsAlarm.class);
    criteria.addRestriction(new EqRestriction("node.id", node.getId()));
    alarms = m_alarmDao.findMatching(criteria);
    assertEquals(1, alarms.size());
    newAlarm = alarms.iterator().next();
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
  }
  @Test
  @Transactional
  public void testAlarmSummary_AlarmWithNoEvent() {
    OnmsNode node = m_nodeDao.findAll().iterator().next();

    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setNode(node);
    alarm.setUei("uei://org/opennms/test/badAlarmTest");
    alarm.setSeverityId(new Integer(7));
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.load("localhost"));

    m_alarmDao.save(alarm);

    List<AlarmSummary> summary = m_alarmDao.getNodeAlarmSummaries();
    Assert.assertNotNull(summary);
    Assert.assertEquals(1, summary.size());
    AlarmSummary sum = summary.get(0);
    Assert.assertEquals(node.getLabel(), sum.getNodeLabel());
    Assert.assertEquals(alarm.getSeverity().getId(), sum.getMaxSeverity().getId());
    Assert.assertEquals("N/A", sum.getFuzzyTimeDown());
  }
  @Test
  @Transactional
  public void testAlarmSummary() {
    OnmsEvent event = new OnmsEvent();
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventCreateTime(new Date());
    event.setDistPoller(m_distPollerDao.load("localhost"));
    event.setEventTime(new Date());
    event.setEventSeverity(new Integer(7));
    event.setEventUei("uei://org/opennms/test/EventDaoTest");
    event.setEventSource("test");
    m_eventDao.save(event);

    OnmsNode node = m_nodeDao.findAll().iterator().next();

    OnmsAlarm alarm = new OnmsAlarm();

    alarm.setNode(node);
    alarm.setUei(event.getEventUei());
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.load("localhost"));

    m_alarmDao.save(alarm);

    List<AlarmSummary> summary = m_alarmDao.getNodeAlarmSummaries();
    Assert.assertNotNull(summary);
    Assert.assertEquals(1, summary.size());
    AlarmSummary sum = summary.get(0);
    Assert.assertEquals(node.getLabel(), sum.getNodeLabel());
    Assert.assertEquals(alarm.getSeverity().getId(), sum.getMaxSeverity().getId());
    Assert.assertNotSame("N/A", sum.getFuzzyTimeDown());
  }
  @Test
  public void testGetOspfLinkStatusDown() {
    EasyMock.expect(
            m_alarmDao.findMatching(EasyMock.anyObject(org.opennms.core.criteria.Criteria.class)))
        .andReturn(createDownAlarm());
    EasyMock.expect(
            m_ospfLinkDao.findMatching(EasyMock.<org.opennms.core.criteria.Criteria>anyObject()))
        .andReturn(createOspfLinks());

    EasyMock.replay(m_alarmDao, m_ospfLinkDao);

    List<EdgeRef> edges = createEdges();
    Map<EdgeRef, Status> statusMap =
        m_statusProvider.getStatusForEdges(m_edgeProvider, edges, new Criteria[0]);

    assertEquals(1, statusMap.size());
    assertEquals(edges.get(0), new ArrayList<EdgeRef>(statusMap.keySet()).get(0));
    Status status = statusMap.get(edges.get(0));
    assertEquals("down", status.computeStatus());
  }
  @Test
  @Transactional
  @Ignore
  public void testWithoutDistPoller() {
    OnmsEvent event = new OnmsEvent();
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventCreateTime(new Date());
    event.setDistPoller(m_distPollerDao.load("localhost"));
    event.setEventTime(new Date());
    event.setEventSeverity(new Integer(7));
    event.setEventUei("uei://org/opennms/test/EventDaoTest");
    event.setEventSource("test");
    m_eventDao.save(event);

    OnmsNode node = m_nodeDao.findAll().iterator().next();

    OnmsAlarm alarm = new OnmsAlarm();

    alarm.setNode(node);
    alarm.setUei(event.getEventUei());
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);

    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(
        new DataIntegrityViolationException(
            "not-null property references a null or transient value: org.opennms.netmgt.model.OnmsAlarm.distPoller; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: org.opennms.netmgt.model.OnmsAlarm.distPoller"));

    try {
      m_alarmDao.save(alarm);
    } catch (Throwable t) {
      ta.throwableReceived(t);
    }

    ta.verifyAnticipated();
  }
Example #10
0
  public void resetDatabase() {
    LOG.debug("==== DatabasePopulator Reset ====");
    for (final DataLinkInterface iface : m_dataLinkInterfaceDao.findAll()) {
      m_dataLinkInterfaceDao.delete(iface);
    }
    for (final OnmsOutage outage : m_outageDao.findAll()) {
      m_outageDao.delete(outage);
    }
    for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
      m_userNotificationDao.delete(not);
    }
    for (final OnmsNotification not : m_notificationDao.findAll()) {
      m_notificationDao.delete(not);
    }
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
      m_alarmDao.delete(alarm);
    }
    for (final OnmsEvent event : m_eventDao.findAll()) {
      m_eventDao.delete(event);
    }
    for (final OnmsSnmpInterface iface : m_snmpInterfaceDao.findAll()) {
      m_snmpInterfaceDao.delete(iface);
    }
    for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
      m_ipInterfaceDao.delete(iface);
    }
    for (final OnmsNode node : m_nodeDao.findAll()) {
      m_nodeDao.delete(node);
    }
    for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
      m_serviceTypeDao.delete(service);
    }

    LOG.debug("= DatabasePopulatorExtension Reset Starting =");
    for (Extension eachExtension : extensions) {
      DaoSupport daoSupport = eachExtension.getDaoSupport();
      OnmsDao dao =
          daoSupport != null && daoSupport.getDaoClass() != null
              ? lookupDao(daoSupport.getDaoClass())
              : null;

      eachExtension.onShutdown(this, dao);
      if (dao != null) {
        dao.flush();
      }
    }
    LOG.debug("= DatabasePopulatorExtension Reset Finished =");

    m_dataLinkInterfaceDao.flush();
    m_outageDao.flush();
    m_userNotificationDao.flush();
    m_notificationDao.flush();
    m_alarmDao.flush();
    m_eventDao.flush();
    m_snmpInterfaceDao.flush();
    m_ipInterfaceDao.flush();
    m_nodeDao.flush();
    m_serviceTypeDao.flush();

    LOG.debug("==== DatabasePopulator Reset Finished ====");
  }