@Test
public void ConstraintInjectionWhenEmptyPreferenceTagExistsAttribute_tc026()
throws InvalidSyntaxException {
Implementation lgImpl = waitForImplByName(null, "LgSwitch");
final Instance lgInst = lgImpl.createInstance(null,
new HashMap<String, String>() {
{
put("currentVoltage", "100");
}
});
Implementation samsungImpl = waitForImplByName(null, "SamsungSwitch");
final Instance samsungInst = samsungImpl.createInstance(null,
new HashMap<String, String>() {
{
put("currentVoltage", "500");
}
});
Implementation siemensImpl = waitForImplByName(null, "SiemensSwitch");
final Instance siemensInst = siemensImpl.createInstance(null,
new HashMap<String, String>() {
{
put("currentVoltage", "105");
}
});
System.out.println("Instances before injection request");
auxListInstances("\t");
// Creates S1 instance (class that requires the injection)
Implementation s1Impl = waitForImplByName(null,
"fr.imag.adele.apam.pax.test.impl.S1Impl");
Instance s1Inst = s1Impl.createInstance(null, null);
apam.waitForIt(Constants.CONST_WAIT_TIME);
S1Impl s1 = (S1Impl) s1Inst.getServiceObject();
Eletronic samsungSwitch = (Eletronic) samsungInst.getServiceObject();
Eletronic lgSwitch = (Eletronic) lgInst.getServiceObject();
Eletronic siemensSwitch = (Eletronic) siemensInst.getServiceObject();
System.out.println("Instances after injection request");
auxListInstances("\t");
Instance injectedInstance = CST.componentBroker.getInstService(s1
.getDeviceConstraint110v());
Assert.assertTrue(
String.format(
"The instance injected should obey the contraints (currentVoltage=500) given in the xml, this does not happens when there is a <preference> tag with nothing declared inside. The instance %s (currentVoltage:%s) was injected instead of %s (currentVoltage:%s)",
injectedInstance.getName(), injectedInstance
.getAllProperties().get("currentVoltage"),
samsungInst.getName(), samsungInst.getAllProperties()
.get("currentVoltage")), s1
.getDeviceConstraint110v() == samsungSwitch);