Package fr.imag.adele.apam

Examples of fr.imag.adele.apam.Instance


  Implementation impl = waitForImplByName(null, "HouseMeterInstantiable");

  boolean failed = false;

  try {
      Instance inst1 = impl.createInstance(null, null);
  } catch (Exception e) {
      // nothing to do
      failed = true;
  }
View Full Code Here


  Implementation impl = waitForImplByName(null,
    "HouseMeterNotInstantiable");

  boolean failed = false;

  Instance inst1 = null;

  try {
      inst1 = impl.createInstance(null, null);
  } catch (Exception e) {
      // nothing to do
View Full Code Here

    public void NotSingletonNotSharedInstance_tc017() {

  Implementation impl = waitForImplByName(null,
    "HouseMeterNotSingletonNotShared");

  Instance inst1 = impl.createInstance(null, null);
  Instance inst2 = impl.createInstance(null, null);
  Instance inst3 = impl.createInstance(null, null);

  System.out.println("1 ----- " + inst1 + "/" + inst1.getServiceObject());
  System.out.println("2 ----- " + inst2 + "/" + inst2.getServiceObject());
  System.out.println("3 ----- " + inst3 + "/" + inst3.getServiceObject());

  HouseMeterSwitch houseMeter1 = (HouseMeterSwitch) inst1
    .getServiceObject();
  HouseMeterSwitch houseMeter2 = (HouseMeterSwitch) inst2
    .getServiceObject();
  HouseMeterSwitch houseMeter3 = (HouseMeterSwitch) inst3
    .getServiceObject();

  Assert.assertTrue(
    "In case of a not singleton and not shared instance, all instances should be different",
    houseMeter1 != houseMeter2);
View Full Code Here

      return null;
    }
    String instanceName = apfInst.getDeclaration().getName();
    String implementationName = apfInst.getDeclaration().getImplementation().getName();

    Instance instance = getInst(instanceName);
    if (instance != null) {
      logger.error("Error adding instance: already exists " + instanceName);
      return instance;
    }
View Full Code Here

  Assert.assertTrue(
    "In case of a not singleton and shared instance, several instances of the same implementation can be created",
    success);

  Instance inst1 = CST.apamResolver.resolveImpl(rootComposite, impl,
    new HashSet<String>(), new ArrayList<String>());
  Instance inst2 = CST.apamResolver.resolveImpl(rootComposite, impl,
    new HashSet<String>(), new ArrayList<String>());
  Instance inst3 = CST.apamResolver.resolveImpl(rootComposite, impl,
    new HashSet<String>(), new ArrayList<String>());

  final String message = "In case of a not singleton and shared instance, a new instance is never created, always recycled";

  Assert.assertTrue(message, inst1 == inst2);
View Full Code Here

    @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);
View Full Code Here

    @Test
    public void PreferenceInjectionAttributeSingleImplementationMultipleInstance_tc024()
      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");
        }
    });

  final Instance samsungInst2 = 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 samsungSwitch2 = (Eletronic) samsungInst2.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());
  Assert.assertTrue(
    String.format(
      "The instance injected should be the prefered one (currentVoltage=500), \nsince there exist an instance in which the preference is valid. \nThe instance %s (currentVoltage:%s) was injected \ninstead of %s (currentVoltage:%s)",
      injectedInstance.getName(), injectedInstance
        .getAllProperties().get("currentVoltage"),
      samsungInst.getName(), samsungInst.getAllProperties()
        .get("currentVoltage")),
    s1.getDevicePreference110v() == samsungSwitch
      || s1.getDevicePreference110v() == samsungSwitch2);
View Full Code Here

    @Ignore
    public void PreferenceResolutionAfterInjection_tct006()
      throws InvalidSyntaxException {

  Implementation lgImpl = waitForImplByName(null, "LgSwitch");
  final Instance lgInst = lgImpl.createInstance(null,
    new HashMap<String, String>() {
        {
      put("currentVoltage", "100");
        }
    });

  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 lgSwitch = (Eletronic) lgInst.getServiceObject();

  System.out
    .println("Instances after FIRST injection request (preference cannot be resolved)");
  auxListInstances("\t");

  Instance injectedInstance = CST.componentBroker.getInstService(s1
    .getDevicePreference110v());

  System.out.println("Injected:" + injectedInstance);

  Assert.assertTrue(
    String.format(
      "The instance injected cannot be the prefered one (currentVoltage=500), since there exist no 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"),
      lgInst.getName(),
      lgInst.getAllProperties().get("currentVoltage")), s1
      .getDevicePreference110v() == lgSwitch);

  Implementation samsungImpl = waitForImplByName(null, "SamsungSwitch");
  final Instance samsungInst = samsungImpl.createInstance(null,
    new HashMap<String, String>() {
        {
      put("currentVoltage", "500");
        }
    });
  Eletronic samsungSwitch = (Eletronic) samsungInst.getServiceObject();
  Instance injectedInstance2 = CST.componentBroker.getInstService(s1
    .getDevicePreference110v());

  System.out.println("Injected (new resolution) :" + injectedInstance);
  Assert.assertTrue(
    String.format(
View Full Code Here

  String messageTemplate = "In case of a remove callback, when a property of a service A change and the service B use a constraint to inject A on its instance, the link from A->B should be brocken and restablished, thus remove callback should have been called";

  Implementation impl = waitForImplByName(null,
    "S1Impl-removed-callback-with-constraint");

  Instance instance = impl.createInstance(null,
    new HashMap<String, String>());

  S1Impl s1 = (S1Impl) instance.getServiceObject();

  S2 first = s1.getS2();

  // The line s1.getS2() creates the link and sets the
  // UnbindReceivedInstanceParameter to true, so we roll it back to false

  s1.setIsBindUnbindReceivedInstanceParameter(false);

  // after change the variable we expect apam to call the remove method

  instance.getLinkDest("s2").setProperty("defined-property", "invalid");

  S2 second = s1.getS2();

  Assert.assertTrue(messageTemplate,
    s1.getIsBindUnbindReceivedInstanceParameter() == true);
View Full Code Here

  String messageTemplate = "In case of a remove callback, when a property of a service A change and the service B do NOT use a constraint to inject A on its instance, the link from A->B should NOT be brocken and restablished, thus remove callback should NOT have been called";

  Implementation impl = waitForImplByName(null,
    "S1Impl-removed-callback-with-no-constraint");

  Instance instance = impl.createInstance(null,
    new HashMap<String, String>());

  S1Impl s1 = (S1Impl) instance.getServiceObject();

  s1.getS2();

  // The line s1.getS2() creates the link and sets the
  // UnbindReceivedInstanceParameter to true, so we roll it back to false

  s1.setIsBindUnbindReceivedInstanceParameter(false);

  // after change the variable we expect apam NOT to call the remove
  // method

  instance.getLinkDest("s2").setProperty("defined-property", "ups");

  Assert.assertTrue(messageTemplate,
    s1.getIsBindUnbindReceivedInstanceParameter() == false);

    }
View Full Code Here

TOP

Related Classes of fr.imag.adele.apam.Instance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.