use of alma.acs.alarmsystem.generated.FaultCode in project ACS by ACS-Community.
the class ACSAlarmDAOImplTest method testRemoveFaultFamily.
public void testRemoveFaultFamily() {
Alarm al1;
boolean exception;
//Delete Entry if it exists due to an error in previous test
{
FaultFamily ff = new FaultFamily();
ff.setName("ffTest1");
try {
_alarmDAO.removeFaultFamily(ff);
} catch (Exception e) {
//This happens when FaultFamily "ffTest1" doesn't exist
}
}
//Check null argument
exception = false;
try {
_alarmDAO.removeFaultFamily(null);
} catch (Exception e) {
exception = true;
}
assertTrue(exception);
//Check Remove FF that doesn't exist
FaultFamily ff = new FaultFamily();
ff.setName("ffTest1");
exception = false;
try {
_alarmDAO.removeFaultFamily(ff);
} catch (Exception e) {
exception = true;
}
assertTrue(exception);
//Check Remove FF
ff.setAlarmSource("ALARM_SYSTEM_SOURCES");
ff.setHelpUrl("http://www.test.com");
Contact ct = new Contact();
ct.setEmail("em1");
ct.setGsm("gsm1");
ct.setName("cont1");
ff.setContact(ct);
FaultCode fc = new FaultCode();
fc.setValue(1);
fc.setPriority(0);
fc.setAction("action1");
fc.setCause("cause1");
fc.setConsequence("conseq1");
fc.setProblemDescription("problem1");
ff.addFaultCode(fc);
FaultMemberDefault fmd = new FaultMemberDefault();
Location lc = new Location();
lc.setBuilding("b1");
lc.setFloor("f1");
lc.setMnemonic("m1");
lc.setPosition("p1");
lc.setRoom("r1");
fmd.setLocation(lc);
ff.setFaultMemberDefault(fmd);
FaultMember fm = new FaultMember();
fm.setName("fmTest1");
lc = new Location();
lc.setBuilding("b2");
lc.setFloor("f2");
lc.setMnemonic("m2");
lc.setPosition("p2");
lc.setRoom("r2");
fm.setLocation(lc);
ff.addFaultMember(fm);
exception = false;
try {
_alarmDAO.addFaultFamily(ff);
} catch (Exception e) {
exception = true;
}
assertFalse(exception);
al1 = _alarmDAO.getAlarm("ffTest1:fmTest1:1");
assertNotNull(al1);
try {
_alarmDAO.removeFaultFamily(ff);
} catch (Exception e) {
exception = true;
}
assertFalse(exception);
al1 = _alarmDAO.getAlarm("ffTest1:fmTest1:1");
assertNull(al1);
}
use of alma.acs.alarmsystem.generated.FaultCode in project ACS by ACS-Community.
the class AlarmManagerTest method testSaveToCDB.
public void testSaveToCDB() {
boolean exception;
_am = AlarmManager.getInstance(_daoManager.getAlarmDAO());
_am.loadFromCDB();
List<FaultFamily> ff1 = _am.getAllAlarms();
assertNotNull(ff1);
int size1 = ff1.size();
int size2;
exception = false;
FaultFamily ff = new FaultFamily();
size1 = ff1.size();
ff.setName("foobar");
ff.setHelpUrl("http://www.foobar.cl/");
Contact ct = new Contact();
ct.setEmail("test@foobar.cl");
ct.setGsm("da");
ct.setName("Foobar");
ff.setContact(ct);
FaultCode fc = new FaultCode();
fc.setValue(1);
fc.setAction("a1");
fc.setCause("c1");
fc.setConsequence("co1");
fc.setPriority(1);
fc.setProblemDescription("pd1");
ff.addFaultCode(fc);
FaultMember fm = new FaultMember();
fm.setName("fmFoobar");
Location lc = new Location();
lc.setBuilding("b1");
lc.setFloor("f1");
lc.setMnemonic("m1");
lc.setPosition("p1");
lc.setRoom("r1");
fm.setLocation(lc);
try {
_am.addFaultFamily(ff);
} catch (Exception e) {
exception = true;
}
assertFalse(exception);
size2 = ff1.size();
assertEquals(size1, size2 - 1);
_am.saveToCDB();
_am.loadFromCDB();
FaultFamily fft = _am.getFaultFamily("foobar");
assertNotNull(fft);
assertEquals(fft.getName(), ff.getName());
assertEquals(fft.getHelpUrl(), ff.getHelpUrl());
exception = false;
try {
_am.deleteFaultFamily(fft);
} catch (Exception e) {
exception = true;
}
assertFalse(exception);
_am.saveToCDB();
_am.loadFromCDB();
fft = _am.getFaultFamily("foobar");
assertNull(fft);
}
use of alma.acs.alarmsystem.generated.FaultCode in project ACS by ACS-Community.
the class AlarmManagerTest method testUpdateFaultCode.
public void testUpdateFaultCode() throws Exception {
boolean exception = false;
_am = AlarmManager.getInstance(_daoManager.getAlarmDAO());
_am.loadFromCDB();
List<FaultFamily> ff1 = _am.getAllAlarms();
assertNotNull(ff1);
FaultFamily ff;
FaultCode fc, fcm;
int size1;
int size2;
ff = new FaultFamily();
size1 = ff1.get(0).getFaultCodeCount();
try {
_am.updateFaultCode(null, null, null);
} catch (NullPointerException e) {
exception = true;
}
assertTrue(exception);
size2 = ff1.get(0).getFaultCodeCount();
assertEquals(size1, size2);
exception = false;
size1 = ff1.get(0).getFaultCodeCount();
try {
_am.updateFaultCode(ff, null, null);
} catch (NullPointerException e) {
exception = true;
}
assertTrue(exception);
size2 = ff1.get(0).getFaultCodeCount();
assertEquals(size1, size2);
ff.setName("foo");
fc = new FaultCode();
exception = false;
size1 = ff1.get(0).getFaultCodeCount();
try {
_am.updateFaultCode(ff, fc, null);
} catch (NullPointerException e) {
exception = true;
}
assertTrue(exception);
size2 = ff1.get(0).getFaultCodeCount();
assertEquals(size1, size2);
fcm = new FaultCode();
exception = false;
size1 = ff1.get(0).getFaultCodeCount();
try {
_am.updateFaultCode(ff, null, fcm);
} catch (NullPointerException e) {
exception = true;
}
assertTrue(exception);
size2 = ff1.get(0).getFaultCodeCount();
assertEquals(size1, size2);
exception = false;
ff.setName(ff1.get(0).getName());
fc.setValue(10342);
fcm.setValue(10343);
size1 = ff1.get(0).getFaultCodeCount();
try {
_am.updateFaultCode(ff, fc, fcm);
} catch (IllegalOperationException e) {
exception = true;
}
assertTrue(exception);
size2 = ff1.get(0).getFaultCodeCount();
assertEquals(size1, size2);
exception = false;
size1 = ff1.get(0).getFaultCodeCount();
try {
_am.addFaultCode(ff, fc);
} catch (IllegalOperationException e) {
exception = true;
}
assertFalse(exception);
size2 = ff1.get(0).getFaultCodeCount();
assertEquals(size1, size2 - 1);
exception = false;
size1 = ff1.get(0).getFaultCodeCount();
try {
_am.updateFaultCode(ff, fc, fcm);
} catch (IllegalOperationException e) {
exception = true;
}
assertFalse(exception);
size2 = ff1.get(0).getFaultCodeCount();
assertEquals(size1, size2);
assertNotNull(_am.getFaultCode(ff1.get(0).getName(), 10343));
}
use of alma.acs.alarmsystem.generated.FaultCode in project ACS by ACS-Community.
the class CDBSender method readAlarmsFromCDB.
/**
* Read alarms from the TM/CDB with the help of {@link ACSAlarmDAOImpl}.
* <P>
* This method can be quite slow so it would be better to run
* in a dedicated thread.
*
* @throws Exception
*/
private void readAlarmsFromCDB() throws Exception {
ConfigurationAccessor conf;
conf = ConfigurationAccessorFactory.getInstance(contSvcs);
ACSAlarmDAOImpl alarmDAO = new ACSAlarmDAOImpl(contSvcs.getLogger());
alarmDAO.setConfAccessor(conf);
List<FaultFamily> FFs = alarmDAO.loadAlarms();
synchronized (alarms) {
for (FaultFamily ff : FFs) {
String faultFamily = ff.getName();
for (FaultMember fm : ff.getFaultMember()) {
for (FaultCode fc : ff.getFaultCode()) {
alarms.add(new AlarmRead(faultFamily + "," + fm.getName() + "," + fc.getValue(), null));
}
}
// Has this FF a default fault member?
if (ff.getFaultMemberDefault() != null) {
System.out.println("Found a default fault member for " + ff.getName());
for (FaultCode fc : ff.getFaultCode()) {
alarms.add(new AlarmRead(faultFamily + ",*," + fc.getValue(), null));
}
}
}
}
}
use of alma.acs.alarmsystem.generated.FaultCode in project ACS by ACS-Community.
the class AlarmManager method checkCDB.
public String checkCDB() {
List<FaultFamily> ffs = _ffList;
String error = "";
for (FaultFamily ff : ffs) {
if (ff.getName() == null || ff.getName().length() == 0)
error += "Fault Family " + ff.getName() + " doesn't have a name.\n";
try {
new URI(ff.getHelpUrl());
} catch (MalformedURIException e1) {
error += "Fault Family " + ff.getName() + " has malformed URL.\n";
}
if (ff.getContact() == null)
error += "Fault Family " + ff.getName() + " doesn't define Contact entity.\n";
if (ff.getContact().getName() == null || ff.getContact().getName().length() == 0)
error += "Fault Family " + ff.getName() + " doesn't define Contact name.\n";
if (ff.getAlarmSource().compareTo("ALARM_SYSTEM_SOURCES") != 0)
error += "Fault Family " + ff.getName() + " has wrong Source defined.\n";
if (ff.getFaultMemberCount() == 0 && ff.getFaultMemberDefault() == null)
error += "Fault Family " + ff.getName() + " doesn't define any Fault Member and doesn't have a Default Fault Member.\n";
FaultMember[] fms = ff.getFaultMember();
for (FaultMember fm : fms) {
if (fm.getName() == null || fm.getName().length() == 0)
error += "Fault Member " + fm.getName() + " defined in Fault Family " + ff.getName() + " doesn't have a name.\n";
}
FaultCode[] fcs = ff.getFaultCode();
for (FaultCode fc : fcs) {
if (fc.getValue() <= 0)
error += "Fault Code " + fc.getValue() + " defined in Fault Family " + ff.getName() + " has an invalid value (Must be > 0).\n";
if (!fc.hasPriority())
error += "Fault Code " + fc.getValue() + " defined in Fault Family " + ff.getName() + " doesn't define a priority.\n";
if (fc.getPriority() < 0 || fc.getPriority() > 3)
error += "Fault Code " + fc.getValue() + " defined in Fault Family " + ff.getName() + " has an invalid a priority (Must be in [0;3]).\n";
if (fc.getProblemDescription() == null || fc.getProblemDescription().length() == 0)
error += "Fault Code " + fc.getValue() + " defined in Fault Family " + ff.getName() + " doesn't define a problem description.\n";
}
}
return error;
}
Aggregations