@Test
public void ConstraintsCheckingInstanceFilteringBySetProperty_tc011()
throws InvalidSyntaxException {
Implementation samsungImpl = waitForImplByName(null, "SamsungSwitch");
final Instance samsungInst = samsungImpl.createInstance(null, null);
Implementation lgImpl = waitForImplByName(null, "LgSwitch");
final Instance lgInst = lgImpl.createInstance(null, null);
Implementation siemensImpl = waitForImplByName(null, "SiemensSwitch");
final Instance siemensInst = siemensImpl.createInstance(null, null);
Implementation boschImpl = waitForImplByName(null, "BoschSwitch");
final Instance boschInst = boschImpl.createInstance(null, null);
Implementation philipsImpl = waitForImplByName(null, "philipsSwitch");
final Instance philipsInst = philipsImpl.createInstance(null, null);
samsungInst.setProperty("currentVoltage", "95");
lgInst.setProperty("currentVoltage", "100");
siemensInst.setProperty("currentVoltage", "105");
boschInst.setProperty("currentVoltage", "110");
philipsInst.setProperty("currentVoltage", "117");
apam.waitForIt(Constants.CONST_WAIT_TIME);
Set<Instance> validInstances = new HashSet<Instance>() {
{
add(siemensInst);
add(lgInst);
add(boschInst);
add(samsungInst);
}
};
Implementation s1Impl = waitForImplByName(null, "fr.imag.adele.apam.pax.test.impl.S1Impl");
Instance s1Inst = s1Impl.createInstance(null, null);
S1Impl s1 = (S1Impl) s1Inst.getServiceObject();
// auxListInstanceReferencedBy("#################",s1.getEletronicInstancesConstraintsInstance());
auxListInstances("-------Available instances before using the list-------");
System.out.println("Size of the injected list:" + s1.getEletronicInstancesConstraintsInstance().size());
for (Eletronic e : s1.getEletronicInstancesConstraintsInstance()) {
Instance p = CST.componentBroker.getInstService(e);
System.out.println("---- Voltage:"
+ p.getProperty("currentVoltage") + " / Name:"
+ p.getName());
boolean found = false;
for (Instance l : validInstances) {
if (l.getName().equals(p.getName())) {
found = true;
break;
}
}
// Check if all valid instances were injected
Assert.assertTrue(
String.format(
"Instance %s (currentVoltage:%s) was injected even if its does not obey the constraint (currentVoltage <= 110)",
p.getName(), p.getProperty("currentVoltage")), p
.match("(currentVoltage <= 110)"));
Assert.assertTrue(
String.format(
"Instance %s (currentVoltage:%s) was not found in the list of valid instances for the constraint (currentVoltage <= 110)",
p.getName(), p.getProperty("currentVoltage")),
found);
}
auxListInstances("-------Available instances after using the list-------");