Package fr.imag.adele.apam

Examples of fr.imag.adele.apam.Instance


    @Test
    public void RelationLinkResolveInternal_tct002() {
  Implementation implementation = waitForImplByName(null,
    "S07-implementation-14bis");

  Instance instance = implementation.createInstance(null,
    Collections.<String, String> emptyMap());

  org.junit.Assert
    .assertFalse(
      "No exception should be raised as the dependency should be instanciated",
      testResolutionExceptionCase14(instance, 2));
  Assert.assertEquals("One relation should have been created", 1,
    instance.getRawLinks().size());

  Instance instance2 = implementation.createInstance(null,
    Collections.<String, String> emptyMap());

  Implementation implementationdep = waitForImplByName(null,
    "S07-DependencyImpl-02");

  Assert.assertFalse(
    "No exception should be raised as the dependency is already instanciated",
    testResolutionExceptionCase14(instance2, 2));
  auxListInstances();
  Assert.assertEquals("Only one relation should have been created : ", 1,
    instance2.getRawLinks().size());
  Assert.assertEquals(
    "Only one instance of dependency should have been instanciated",
    1, implementationdep.getInsts().size());

  // Test should fail on external bundle resolution
View Full Code Here


        return new Resolved<Implementation>(impl);
      }
      impls = new HashSet<Implementation>();
      impls.add(impl);
    } else if (relToResolve.getTarget() instanceof InstanceReference) {
      Instance inst = CST.componentBroker.getInst(name);
      if (inst == null) {
        return null;
      }
      if (relToResolve.getTargetKind() == ComponentKind.INSTANCE) {
        return new Resolved<Instance>(inst);
      }
      logger.debug("if (relToResolve.getTarget() instanceof InstanceReference) ") ;
      return null;
    } else if (relToResolve.getTarget() instanceof ComponentReference<?>) {
      logger.error("Invalid target reference : " + relToResolve.getTarget());
      return null;
    }

    /*
     * We have computed all component references It is either already
     * resolved, or the implems are in impls. Now Resolve by resource.
     */
    else if (relToResolve.getTarget() instanceof ResourceReference) {
      if (relToResolve.getTargetKind() == ComponentKind.SPECIFICATION) {
        Set<Specification> specs = new HashSet<Specification>();
        for (Specification spec : CST.componentBroker.getSpecs()) {
          if (spec.getProvidedResources().contains(relToResolve.getTarget())) {
            specs.add(spec);
          }
        }
        return relToResolve.getResolved(specs, false);
      }

      /*
       * target Kind is implem or instance get all the implems that
       * implement the resource
       */
      impls = new HashSet<Implementation>();
      for (Implementation impl : CST.componentBroker.getImpls()) {
        if (impl.getProvidedResources().contains((relToResolve.getTarget()))) {
          impls.add(impl);
        }
      }
    }

    // TargetKind is implem or instance, but no implem found.
    if (impls == null || impls.isEmpty()) {
      return null;
    }

    // If TargetKind is implem, select the good one(s)
    if (relToResolve.getTargetKind() == ComponentKind.IMPLEMENTATION) {
      return relToResolve.getResolved(impls, false);
    }

    /*
     * We have in impls all the implementations satisfying the relation
     * target (type and name only). We are looking for instances. Take all
     * the instances of these implementations satisfying the relation
     * constraints and visibility.
     */

    /*
     *  Fast track : if looking for one instance and no preferences, return the first valid instance
     */
    boolean fast = (!relToResolve.isMultiple() && !relToResolve.hasPreferences());

    Set<Instance> insts = new HashSet<Instance>();
    for (Implementation impl : impls) {
      for (Instance inst : impl.getInsts()) {
        if (inst.isSharable() && source.canSee(inst) && inst.matchRelationConstraints(relToResolve)) {
          if (fast) {
            return new Resolved<Instance>(inst);
          }
          insts.add(inst);
        }
View Full Code Here

    "S07-DependencyImpl");

  Implementation implementationTarget = waitForImplByName(null,
    "S07-implementation-17");

  Instance instanceInvalid01 = implementation.createInstance(null,
    new HashMap<String, String>() {
        {
      put("criteria", "do-not-take-this-instance");
        }
    });
  Instance instanceInvalid02 = implementation.createInstance(null,
    new HashMap<String, String>() {
        {
      put("criteria", "neither-this");
        }
    });
  Instance instanceValid01 = implementation.createInstance(null,
    new HashMap<String, String>() {
        {
      put("criteria", "the-chosen-one");
        }
    });
  Instance instanceValid02 = implementation.createInstance(null,
    new HashMap<String, String>() {
        {
      put("criteria", "the-chosen-one");
        }
    });
  Instance instanceInvalid03 = implementation.createInstance(null,
    new HashMap<String, String>() {
        {
      put("criteria", "ignore-this");
        }
    });

  Instance instanceTarget = implementationTarget.createInstance(null,
    null);

  S07ImplementationImporter17 implem = (S07ImplementationImporter17) instanceTarget
    .getServiceObject();

  Instance instanceInjected = auxListInstanceReferencedBy(implem
    .getInjected());

  Assert.assertTrue(
    "Using <relation/> element in metadata to inject a dependency, the preference filter was not respect as expected.",
    instanceInjected == instanceValid01
View Full Code Here

    public void RelationSourceImplementationTargetImplementation_tc097() {

  Implementation implementation = waitForImplByName(null,
    "S07-implementation-01");

  Instance instance = implementation.createInstance(null,
    Collections.<String, String> emptyMap());

  S07ImplementationImporter01 dependency = (S07ImplementationImporter01) instance
    .getServiceObject();

  dependency.getInjected();

  String messageTemplate = "Declaring a relation from source %s to target %s, instantiated object of the type %s which is not the targetKind expected.";

  ComponentImpl ci = (ComponentImpl) implementation;

  Assert.assertTrue(
    String.format(
      "Only one link should have been created, but %s links were found",
      ci.getLocalLinks().size()),
    ci.getLocalLinks().size() == 1);

  for (Link link : ci.getLocalLinks()) {

      validateSourceTargetTypes(link.getSource(), link.getDestination(),
        Implementation.class, Implementation.class);

  }

  Assert.assertTrue(
    String.format(messageTemplate, "Implementation",
      "Implementation", instance.getServiceObject()),
    dependency.getInjected().getProperty("implementation-property") != null
      && dependency.getInjected().getProperty(
        "instance-property") == null);
    }
View Full Code Here

    public void RelationSourceImplementationTargetImplementationOverride_tc100() {

  Implementation implementation = waitForImplByName(null,
    "S07-implementation-04");

  Instance instance = implementation.createInstance(null,
    Collections.<String, String> emptyMap());

  S07ImplementationImporter04 dependency = (S07ImplementationImporter04) instance
    .getServiceObject();

  Assert.assertTrue(
    "Declaring a relation information on the apam specification tag, and just using the id in the apam implementation didnt work, so the dependency was not resolved",
    dependency.getInjected() != null);
View Full Code Here

    public void RelationSourceImplementationTargetInstance_tc099() {

  Implementation implementation = waitForImplByName(null,
    "S07-implementation-03");

  Instance instance = implementation.createInstance(null,
    Collections.<String, String> emptyMap());

  S07ImplementationImporter03 dependency = (S07ImplementationImporter03) instance
    .getServiceObject();

  Instance instanceInjectedReference = auxListInstanceReferencedBy(dependency
    .getInjected());

  auxListProperties(instanceInjectedReference);

  auxListInstances();

  ComponentImpl ci = (ComponentImpl) implementation;

  Assert.assertTrue(
    String.format(
      "Only one link should have been created, but %s links were found",
      ci.getLocalLinks().size()),
    ci.getLocalLinks().size() == 1);

  for (Link link : ci.getLocalLinks()) {

      validateSourceTargetTypes(link.getSource(), link.getDestination(),
        Implementation.class, Instance.class);

  }

  String messageTemplate = "Declaring a relation from source %s to target %s, instantiated object of the type %s which is not the targetKind expected.";

  Assert.assertTrue(
    String.format(messageTemplate, "Implementation", "Instance",
      instance.getServiceObject()),
    instanceInjectedReference
      .getProperty("implementation-property") != null
      && instanceInjectedReference
        .getProperty("specification-property") != null);

    }
View Full Code Here

  target.createInstance(null, null);

  Implementation implementation = waitForImplByName(null,
    "S07-implementation-05");

  Instance instance = implementation.createInstance(null,
    Collections.<String, String> emptyMap());

  auxListInstances();

  ComponentImpl ci = (ComponentImpl) implementation;
View Full Code Here

    public void RelationSourceImplementationTargetInstanceCreationLazy_tc102() {

  Implementation implementation = waitForImplByName(null,
    "S07-implementation-06");

  Instance instance = implementation.createInstance(null,
    Collections.<String, String> emptyMap());

  S07ImplementationImporter06 dependency = (S07ImplementationImporter06) instance
    .getServiceObject();

  ComponentImpl ci = (ComponentImpl) implementation;

  Assert.assertTrue(
View Full Code Here

    public void RelationSourceImplementationTargetSpecification_tc098() {

  Implementation implementation = waitForImplByName(null,
    "S07-implementation-02");

  Instance instance = implementation.createInstance(null, null);

  S07ImplementationImporter02 dependency = (S07ImplementationImporter02) instance
    .getServiceObject();

  auxListProperties(dependency.getInjected());

  auxListInstances();

  ComponentImpl ci = (ComponentImpl) implementation;

  Assert.assertTrue(
    String.format(
      "Only one link should have been created, but %s links were found",
      ci.getLocalLinks().size()),
    ci.getLocalLinks().size() == 1);

  for (Link link : ci.getLocalLinks()) {

      validateSourceTargetTypes(link.getSource(), link.getDestination(),
        Implementation.class, Specification.class);

  }

  String messageTemplate = "Declaring a relation from source %s to target %s, instantiated object of the type %s which is not the targetKind expected.";

  Assert.assertTrue(
    String.format(messageTemplate, "Implementation",
      "Specification", instance.getServiceObject()),
    dependency.getInjected().getProperty("instance-property") == null
      && dependency.getInjected().getProperty(
        "implementation-property") == null
      && dependency.getInjected().getProperty(
        "specification-property") != null);
View Full Code Here

    public void RelationSourceInstanceTargetImplementation_tc119() {

  Implementation implementation = waitForImplByName(null,
    "S07-implementation-18");

  Instance instance = implementation.createInstance(null, new HashMap() {
      {
    put("instance-property", "ok");
      }
  });// Collections.<String, String> emptyMap()

  S07ImplementationImporter18 dependency = (S07ImplementationImporter18) instance
    .getServiceObject();

  auxListProperties(dependency.getInjected());

  auxListInstances();

  ComponentImpl ci = (ComponentImpl) instance;

  Assert.assertTrue(
    String.format(
      "Only one link should have been created, but %s links were found",
      ci.getLocalLinks().size()),
    ci.getLocalLinks().size() == 1);

  for (Link link : ci.getLocalLinks()) {

      validateSourceTargetTypes(link.getSource(), link.getDestination(),
        Instance.class, Implementation.class);

  }

  String messageTemplate = "Declaring a relation from source %s to target %s, instantiated object of the type %s which is not the targetKind expected.";

  Assert.assertTrue(
    String.format(messageTemplate, "Instance", "Implementation",
      instance.getServiceObject()),
    dependency.getInjected().getProperty("instance-property") == null
      && dependency.getInjected().getProperty(
        "implementation-property") != null
      && dependency.getInjected().getProperty(
        "specification-property") != null);
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.