/** 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);
  }