コード例 #1
0
ファイル: AlarmdTest.java プロジェクト: lunar999/opennms
 @Test
 public void testNullEvent() throws Exception {
   ThrowableAnticipator ta = new ThrowableAnticipator();
   ta.anticipate(new IllegalArgumentException("event argument must not be null"));
   try {
     m_alarmd.getPersister().persist(null);
   } catch (Throwable t) {
     ta.throwableReceived(t);
   }
   ta.verifyAnticipated();
 }
  public void testConstructorThresholdNull() {
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("threshold argument cannot be null"));

    try {
      new ThresholdEvaluatorStateRelativeChange(null);
    } catch (Throwable t) {
      ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
  }
コード例 #3
0
  public void testGetIpcManagerNotInitialized() {
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalStateException("this factory has not been initialized"));

    try {
      EventIpcManagerFactory.getIpcManager();
    } catch (Throwable t) {
      ta.throwableReceived(t);
    }

    ta.verifyAnticipated();
  }
コード例 #4
0
  public void testSetIpcManagerNull() {
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("argument ipcManager must not be null"));

    try {
      EventIpcManagerFactory.setIpcManager(null);
    } catch (Throwable t) {
      ta.throwableReceived(t);
    }

    ta.verifyAnticipated();
  }
コード例 #5
0
ファイル: AlarmdTest.java プロジェクト: lunar999/opennms
  @Test
  public void testNoLogmsg() throws Exception {
    EventBuilder bldr = new EventBuilder("testNoLogmsg", "AlarmdTest");
    bldr.setAlarmData(new AlarmData());

    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("Incoming event has an illegal dbid (0), aborting"));
    try {
      m_alarmd.getPersister().persist(bldr.getEvent());
    } catch (Throwable t) {
      ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
  }
  public void testGetUnknownUser() {
    SpringSecurityUserDao userDao = createMock(SpringSecurityUserDao.class);
    OpenNMSUserDetailsService detailsService = new OpenNMSUserDetailsService();
    detailsService.setUserDao(userDao);

    expect(userDao.getByUsername("test_user")).andReturn(null);

    replay(userDao);

    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new UsernameNotFoundException("Unable to locate test_user in the userDao"));

    try {
      detailsService.loadUserByUsername("test_user");
    } catch (Throwable t) {
      ta.throwableReceived(t);
    }
    verify(userDao);
    ta.verifyAnticipated();
  }
コード例 #7
0
  @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();
  }