@Test
public void PreferenceInjectionAttributeMultipleImplementationSingleInstance_tc025()
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 philipsImpl = waitForImplByName(null, "philipsSwitch");
final Instance philipsInst = philipsImpl.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 philipsSwitch = (Eletronic) philipsInst.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
.getDevicePreference110v());
System.out.println("Injected:" + injectedInstance);
Assert.assertTrue(
String.format(
"The instance injected should be the prefered one (currentVoltage=500), since there exist an instance in which the preference is valid. 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.getDevicePreference110v() == samsungSwitch
|| s1.getDevicePreference110v() == philipsSwitch);