Ejemplo n.º 1
0
  @Test
  public void testCounters() throws Exception {
    AlarmPoint underTest = createAlarm("testCounters");
    AlarmHistory hist = underTest.history();
    Map<String, Integer> counters = hist.counters().get();

    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    verifyCounters(counters, 1, 0);

    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    verifyCounters(counters, 1, 1);

    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    verifyCounters(counters, 2, 1);

    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    verifyCounters(counters, 2, 2);

    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    verifyCounters(counters, 2, 2);

    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    verifyCounters(counters, 3, 2);

    int activateCounters = hist.activateCounter();
    assertEquals(3, activateCounters);

    hist.resetActivateCounter();
    verifyCounters(counters, 0, 2);

    hist.resetAllCounters();
    verifyCounters(counters, 0, 0);
  }
Ejemplo n.º 2
0
 @Test
 public void testEmpty() throws Exception {
   AlarmPoint underTest = createAlarm("testEmpty");
   AlarmHistory hist = underTest.history();
   AlarmEvent event1 = hist.firstEvent();
   AlarmEvent event2 = hist.lastEvent();
   assertNull(event1);
   assertNull(event2);
   assertEquals("Activate Counter", 0, hist.activateCounter());
 }
Ejemplo n.º 3
0
  @Test
  public void testGetPosition() throws Exception {
    AlarmPoint underTest = createAlarm("testGetPosition");
    alarmSystem.addAlarmListener(this);
    AlarmHistory hist = underTest.history();
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);

    assertEquals(5, eventCounter);
    assertEquals(5, hist.allAlarmEvents().get().size());

    AlarmEvent event = hist.eventAt(-1);
    assertNull(event);
    event = hist.eventAt(5);
    assertNull(event);
    event = hist.eventAt(0);
    assertEquals("activation", event.systemName().get());
    event = hist.eventAt(1);
    assertEquals("deactivation", event.systemName().get());
    event = hist.eventAt(2);
    assertEquals("activation", event.systemName().get());
    event = hist.eventAt(3);
    assertEquals("deactivation", event.systemName().get());
    event = hist.eventAt(4);
    assertEquals("activation", event.systemName().get());
  }
Ejemplo n.º 4
0
 @Test
 public void testFirstNotLast() throws Exception {
   AlarmPoint underTest = createAlarm("testFirstNotLast");
   underTest.updateCondition(true);
   underTest.updateCondition(false);
   AlarmHistory hist = underTest.history();
   AlarmEvent event1 = hist.firstEvent();
   AlarmEvent event2 = hist.lastEvent();
   assertFalse(event1.equals(event2));
   Assert.assertEquals(AlarmPoint.STATUS_ACTIVATED, event1.newStatus().get().name(null));
   Assert.assertEquals(AlarmPoint.STATUS_NORMAL, event2.newStatus().get().name(null));
 }
Ejemplo n.º 5
0
  @Test
  public void testSetMaxSize() throws Exception {
    AlarmPoint underTest = createAlarm("testSetMaxSize");
    alarmSystem.addAlarmListener(this);
    AlarmHistory hist = underTest.history();
    assertEquals(0, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(1, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    assertEquals(2, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(3, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    assertEquals(4, hist.allAlarmEvents().get().size());

    int maxsize = hist.maxSize().get();
    assertEquals(30, maxsize);

    hist.maxSize()
        .set(3); // The Qi4j version doesn't intercept the maxSize().set() method and purge the old
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE); // so we do another event to purge.
    assertEquals(3, hist.allAlarmEvents().get().size());

    hist.maxSize().set(0);
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE); // so we do another event to purge.
    assertEquals(0, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(0, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    assertEquals(0, hist.allAlarmEvents().get().size());
    hist.maxSize().set(2);
    assertEquals(0, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(1, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_DEACTIVATE);
    assertEquals(2, hist.allAlarmEvents().get().size());
    underTest.trigger(AlarmPoint.TRIGGER_ACTIVATE);
    assertEquals(2, hist.allAlarmEvents().get().size());
    assertEquals(11, eventCounter);
  }