@Test
public void ConstraintsCheckingInstanceFilteringByInitialProperty_tc010()
throws InvalidSyntaxException {
Implementation samsungImpl = waitForImplByName(null, "SamsungSwitch");
final Instance samsungInst = samsungImpl.createInstance(null,
new HashMap<String, String>() {
{
put("currentVoltage", "95");
}
});
Implementation lgImpl = waitForImplByName(null, "LgSwitch");
final Instance lgInst = lgImpl.createInstance(null,
new HashMap<String, String>() {
{
put("currentVoltage", "100");
}
});
Implementation siemensImpl = waitForImplByName(null, "SiemensSwitch");
final Instance siemensInst = siemensImpl.createInstance(null,
new HashMap<String, String>() {
{
put("currentVoltage", "105");
}
});
Implementation boschImpl = waitForImplByName(null, "BoschSwitch");
final Instance boschInst = boschImpl.createInstance(null,
new HashMap<String, String>() {
{
put("currentVoltage", "110");
}
});
Implementation philipsImpl = waitForImplByName(null, "philipsSwitch");
final Instance philipsInst = philipsImpl.createInstance(null,
new HashMap<String, String>() {
{
put("currentVoltage", "117");
}
});
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");
// apam.waitForIt(Constants.CONST_WAIT_TIME);
Instance s1Inst = s1Impl.createInstance(null, null);
S1Impl s1 = (S1Impl) s1Inst.getServiceObject();
// apam.waitForIt(Constants.CONST_WAIT_TIME);
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("--------------");