Esempio n. 1
0
  public void setUp() {
    tataFactory = (ComponentFactory) Utils.getFactoryByName(getContext(), "tata");
    totoFactory = (ComponentFactory) Utils.getFactoryByName(getContext(), "toto");
    tataFactory2 = (ComponentFactory) Utils.getFactoryByName(getContext(), "comp-6");
    tataFactory2.stop();
    tataFactory.stop();

    Properties props = new Properties();
    props.put("instance.name", "toto provider");
    try {
      totoProv = totoFactory.createComponentInstance(props);
    } catch (Exception e) {
      e.printStackTrace();
    }

    Properties props3 = new Properties();
    props3.put("instance.name", "toto provider 2");
    try {
      totoProv2 = totoFactory.createComponentInstance(props3);
    } catch (Exception e) {
      e.printStackTrace();
    }

    totoProv.stop();
    totoProv2.stop();

    Factory factory = Utils.getFactoryByName(getContext(), "comp-2");
    Properties props2 = new Properties();
    props2.put("instance.name", "ff");
    try {
      under = factory.createComponentInstance(props2);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /** Check if a pojo can correctly be cast in POJO. Check the getComponentInstance method. */
  @Test
  public void testGetComponentInstance() {
    String factName = "Manipulation-FooProviderType-1";
    String compName = "FooProvider-1";
    ServiceReference ref = null;

    // Get the factory to create a component instance
    Factory fact = ipojoHelper.getFactory(factName);
    assertNotNull("Cannot find the factory FooProvider-1", fact);

    Properties props = new Properties();
    props.put("instance.name", compName);
    ComponentInstance ci = null;
    try {
      ci = fact.createComponentInstance(props);
    } catch (Exception e1) {
      fail(e1.getMessage());
    }

    assertEquals("Check instance name", compName, ci.getInstanceName());

    // Get a FooService provider
    ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), compName);

    assertNotNull("FS not available", ref);

    // Get foo object
    FooService fs = (FooService) osgiHelper.getServiceObject(ref);

    // Cast to POJO
    Pojo pojo = (Pojo) fs;

    // GetComponentInstance
    ComponentInstance instance = pojo.getComponentInstance();
    assertEquals("Check component instance name", instance.getInstanceName(), compName);
    assertEquals("Check component factory name", instance.getFactory().getName(), factName);
    assertNotNull("Instance description not null", instance.getInstanceDescription());
    PrimitiveInstanceDescription id =
        (PrimitiveInstanceDescription) instance.getInstanceDescription();
    assertTrue("Check instance state", id.getState() == ComponentInstance.VALID);
    assertEquals("Check created pojo count", id.getCreatedObjects().length, 1);
    assertEquals("Check instance description name", id.getName(), compName);

    ci.dispose();

    // Check that there is no more FooService
    ref = osgiHelper.getServiceReference(FooService.class.getName());
    assertNull("FS available, but component instance stopped", ref);
  }
Esempio n. 3
0
  @Test
  public void testIP6() {
    ipojoHelper.createComponentInstance(pi6.getName(), "ci");

    ServiceReference ref1 =
        ipojoHelper.getServiceReferenceByName(
            "org.apache.felix.ipojo.runtime.core.components.inherited.ProcessParentImplementation",
            "ci");
    assertNotNull("Check parent-parent", ref1);

    ProcessParentImplementation itself =
        (ProcessParentImplementation) osgiHelper.getServiceObject(ref1);

    itself.processChild();
  }
Esempio n. 4
0
  @Before
  public void setUp() {
    tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
    totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
    tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
    tataFactory2.stop();

    Properties props = new Properties();
    props.put("instance.name", "toto provider");
    try {
      totoProv = totoFactory.createComponentInstance(props);
    } catch (Exception e) {
      e.printStackTrace();
    }

    Properties props3 = new Properties();
    props3.put("instance.name", "toto provider 2");
    try {
      totoProv2 = totoFactory.createComponentInstance(props3);
    } catch (Exception e) {
      e.printStackTrace();
    }

    totoProv.stop();
    totoProv2.stop();

    Factory factory = ipojoHelper.getFactory("comp-7");
    Properties props2 = new Properties();
    props2.put("instance.name", "ff");
    try {
      under = factory.createComponentInstance(props2);
    } catch (Exception e) {
      e.printStackTrace();
    }
    tataFactory.stop();
  }