use of alma.acsplugins.alarmsystem.gui.table.AlarmGUIType in project ACS by ACS-Community.
the class AlarmContainerTest method testRemoveInactivAls.
/**
* Test the removal of inactive alarms
*
* @throws Exception
*/
public void testRemoveInactivAls() throws Exception {
final Vector<Alarm> alarms = new Vector<Alarm>();
int notReduced;
// Stores for each priority the number of inactive alarms
final int[] priorities = new int[AlarmGUIType.values().length - 1];
// The test is done for each AlarmGUIType corresponding to a priority
for (AlarmGUIType alarmType : AlarmGUIType.values()) {
// Add some alarms
alarms.clear();
assertEquals(0, alarms.size());
EDTExecutor.instance().executeSync(new Runnable() {
@Override
public void run() {
container.clear();
assertEquals(0, container.size(false));
}
});
for (int t = 0; t < 4; t++) {
priorities[t] = 0;
}
notReduced = populateContainer(CONTAINER_SIZE / 2, "TEST", alarms, null);
class EDTReader implements Runnable {
// The value to check after reading from EDT
private final int value;
EDTReader(int val) {
value = val;
}
public void run() {
assertEquals("Wrong not reduced size", CONTAINER_SIZE / 2, container.size(false));
assertEquals("Wrong reduced size", value, container.size(true));
}
}
EDTExecutor.instance().executeSync(new EDTReader(notReduced));
for (Alarm al : alarms) {
if (!al.getStatus().isActive()) {
priorities[al.getPriority()]++;
}
}
class Checker implements Runnable {
private final AlarmGUIType alarmType;
public Checker(AlarmGUIType alarmType) {
this.alarmType = alarmType;
}
public void run() {
try {
container.removeInactiveAlarms(alarmType);
} catch (Throwable t) {
System.out.println("Error removing inactive alarms for " + alarmType);
t.printStackTrace();
return;
}
if (alarmType != AlarmGUIType.INACTIVE) {
assertEquals(alarms.size() - priorities[alarmType.ordinal()], container.size(false));
} else {
int newSize = alarms.size() - priorities[0] - priorities[1] - priorities[2] - priorities[3];
assertEquals(newSize, container.size(false));
}
}
}
EDTExecutor.instance().executeSync(new Checker(alarmType));
}
}
Aggregations