Search in sources :

Example 1 with ComponentTypeDescription

use of org.apache.felix.ipojo.architecture.ComponentTypeDescription in project felix by apache.

the class EmptyCompositeTest method testEmptyCompositeCreation.

@Test
public void testEmptyCompositeCreation() {
    Factory factory = ipojoHelper.getFactory("composite.empty");
    Properties props = new Properties();
    props.put("instance.name", "empty");
    ComponentInstance ci = null;
    try {
        ci = factory.createComponentInstance(props);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Unacceptable configuration : " + e.getMessage());
    }
    ComponentTypeDescription cd = ci.getFactory().getComponentDescription();
    assertEquals("Check component type name", cd.getName(), "composite.empty");
    // assertEquals("Check class name (" + cd.getClassName() + ")", cd.getClassName(), "composite");
    assertEquals("Check offered service", cd.getprovidedServiceSpecification().length, 0);
    assertEquals("Check configurable properties", cd.getProperties().length, 0);
    CompositeInstanceDescription id = (CompositeInstanceDescription) ci.getInstanceDescription();
    assertEquals("Check composite instance name", id.getName(), "empty");
    assertEquals("Check composite instance state (" + id.getState() + ")", id.getState(), ComponentInstance.VALID);
    assertEquals("Check contained instance", id.getContainedInstances().length, 0);
    assertTrue("Check composite manager", ci instanceof CompositeManager);
    CompositeManager cm = (CompositeManager) ci;
    ServiceContext sc = cm.getServiceContext();
    try {
        assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, getContext().getServiceReferences(Factory.class.getName(), null).length);
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e.getMessage());
    }
    ci.dispose();
}
Also used : ComponentTypeDescription(org.apache.felix.ipojo.architecture.ComponentTypeDescription) ServiceContext(org.apache.felix.ipojo.ServiceContext) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CompositeManager(org.apache.felix.ipojo.composite.CompositeManager) Factory(org.apache.felix.ipojo.Factory) CompositeInstanceDescription(org.apache.felix.ipojo.composite.CompositeInstanceDescription) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Properties(java.util.Properties) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Test(org.junit.Test)

Example 2 with ComponentTypeDescription

use of org.apache.felix.ipojo.architecture.ComponentTypeDescription in project felix by apache.

the class TestComponentDesc method testFooProvider1.

/**
 * Check simple providing.
 */
@Test
public void testFooProvider1() {
    // Test SR properties
    // String impl = (String) sr_fooProvider1.getProperty("component.class");
    // assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
    String[] specs = (String[]) sr_fooProvider1.getProperty("component.providedServiceSpecifications");
    assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
    assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
    PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider1.getProperty("component.properties");
    assertEquals("Check component.properties length", pd.length, 0);
    // Test factory
    assertEquals("Check factory name", fooProvider1.getName(), "Factories-FooProviderType-1");
    Element cd = fooProvider1.getDescription();
    // assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
    Element[] specs2 = cd.getElements("provides");
    assertEquals("Check specs length", specs2.length, 1);
    assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
    Element[] pd2 = cd.getElements("property");
    assertNull("Check props null", pd2);
    // Check Description equality
    ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider1.getProperty("component.description");
    assertNotNull("check description equality", desc);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PropertyDescription(org.apache.felix.ipojo.architecture.PropertyDescription) ComponentTypeDescription(org.apache.felix.ipojo.architecture.ComponentTypeDescription) Element(org.apache.felix.ipojo.metadata.Element) Test(org.junit.Test)

Example 3 with ComponentTypeDescription

use of org.apache.felix.ipojo.architecture.ComponentTypeDescription in project felix by apache.

the class TestComponentDesc method testFooBar.

/**
 * Test two services provider.
 */
@Test
public void testFooBar() {
    // Test SR properties
    // String impl = (String) sr_foobarProvider.getProperty("component.class");
    // assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooBarProviderType1");
    String[] specs = (String[]) sr_foobarProvider.getProperty("component.providedServiceSpecifications");
    assertEquals("Check component.providedServiceSpecifications length", specs.length, 2);
    assertContains("Check component.providedServiceSpecifications 1", specs, FooService.class.getName());
    assertContains("Check component.providedServiceSpecifications 2", specs, BarService.class.getName());
    PropertyDescription[] pd = (PropertyDescription[]) sr_foobarProvider.getProperty("component.properties");
    assertEquals("Check component.properties length", pd.length, 0);
    // Test factory
    assertEquals("Check factory name", foobarProvider.getName(), "Factories-FooBarProviderType-1");
    Element cd = foobarProvider.getDescription();
    // assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
    Element[] specs2 = cd.getElements("provides");
    assertEquals("Check specs length", specs2.length, 2);
    assertTrue("Check specs", containsSpecification(FooService.class.getName(), specs2));
    assertTrue("Check specs", containsSpecification(BarService.class.getName(), specs2));
    Element[] pd2 = cd.getElements("property");
    assertNull("Check props null", pd2);
    // Check Description equality
    ComponentTypeDescription desc = (ComponentTypeDescription) sr_foobarProvider.getProperty("component.description");
    assertNotNull("check description equality", desc);
    // Check that we have the complete metadata
    assertNotNull(foobarProvider.getComponentMetadata());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PropertyDescription(org.apache.felix.ipojo.architecture.PropertyDescription) ComponentTypeDescription(org.apache.felix.ipojo.architecture.ComponentTypeDescription) Element(org.apache.felix.ipojo.metadata.Element) BarService(org.apache.felix.ipojo.runtime.core.services.BarService) Test(org.junit.Test)

Example 4 with ComponentTypeDescription

use of org.apache.felix.ipojo.architecture.ComponentTypeDescription in project felix by apache.

the class TestComponentDesc method testFooProviderDyn2.

/**
 * Check component properties (dynamic).
 */
@Test
public void testFooProviderDyn2() {
    // Test SR properties
    // String impl = (String) sr_fooProviderDyn2.getProperty("component.class");
    // assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2");
    String[] specs = (String[]) sr_fooProviderDyn2.getProperty("component.providedServiceSpecifications");
    assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
    assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
    PropertyDescription[] pd = (PropertyDescription[]) sr_fooProviderDyn2.getProperty("component.properties");
    assertEquals("Check component.properties length", pd.length, 5);
    assertEquals("Check component.properties name [" + 0 + "]", "int", pd[0].getName());
    assertEquals("Check component.properties type [" + 0 + "]", "int", pd[0].getType());
    assertEquals("Check component.properties value [" + 0 + "]", "4", pd[0].getValue());
    assertEquals("Check component.properties name [" + 1 + "]", "boolean", pd[1].getName());
    assertEquals("Check component.properties type [" + 1 + "]", "boolean", pd[1].getType());
    assertEquals("Check component.properties name [" + 2 + "]", "string", pd[2].getName());
    assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
    assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd[3].getName());
    assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd[3].getType());
    assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd[4].getName());
    assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd[4].getType());
    // Test factory
    assertEquals("Check factory name", fooProviderDyn2.getName(), "Factories-FooProviderType-Dyn2");
    Element cd = fooProviderDyn2.getDescription();
    // assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
    Element[] specs2 = cd.getElements("provides");
    assertEquals("Check specs length", specs2.length, 1);
    assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
    Element[] pd2 = cd.getElements("property");
    assertEquals("Check props length", pd2.length, 5);
    assertEquals("Check component.properties name [" + 0 + "]", "int", pd2[0].getAttribute("name"));
    assertEquals("Check component.properties type [" + 0 + "]", "int", pd2[0].getAttribute("type"));
    assertEquals("Check component.properties value [" + 0 + "]", "4", pd2[0].getAttribute("value"));
    assertEquals("Check component.properties name [" + 1 + "]", "boolean", pd2[1].getAttribute("name"));
    assertEquals("Check component.properties type [" + 1 + "]", "boolean", pd2[1].getAttribute("type"));
    assertEquals("Check component.properties name [" + 2 + "]", "string", pd2[2].getAttribute("name"));
    assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
    assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd2[3].getAttribute("name"));
    assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd2[3].getAttribute("type"));
    assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd2[4].getAttribute("name"));
    assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd2[4].getAttribute("type"));
    // Check Description equality
    ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProviderDyn2.getProperty("component.description");
    assertNotNull("check description equality", desc);
    // Check that we have the complete metadata
    assertNotNull(fooProvider2.getComponentMetadata());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PropertyDescription(org.apache.felix.ipojo.architecture.PropertyDescription) ComponentTypeDescription(org.apache.felix.ipojo.architecture.ComponentTypeDescription) Element(org.apache.felix.ipojo.metadata.Element) Test(org.junit.Test)

Example 5 with ComponentTypeDescription

use of org.apache.felix.ipojo.architecture.ComponentTypeDescription in project felix by apache.

the class TestComponentDesc method testFooProvider2.

/**
 * Check component properties.
 */
@Test
public void testFooProvider2() {
    // Test SR properties
    // String impl = (String) sr_fooProvider2.getProperty("component.class");
    // assertEquals("Check component.class", impl, "org.apache.felix.ipojo.test.scenarios.component.FooProviderType1");
    String[] specs = (String[]) sr_fooProvider2.getProperty("component.providedServiceSpecifications");
    assertEquals("Check component.providedServiceSpecifications length", specs.length, 1);
    assertEquals("Check component.providedServiceSpecifications", FooService.class.getName(), specs[0]);
    PropertyDescription[] pd = (PropertyDescription[]) sr_fooProvider2.getProperty("component.properties");
    assertEquals("Check component.properties length", pd.length, 5);
    assertEquals("Check component.properties name [" + 0 + "]", "int", pd[0].getName());
    assertEquals("Check component.properties type [" + 0 + "]", "int", pd[0].getType());
    assertEquals("Check component.properties value [" + 0 + "]", "2", pd[0].getValue());
    assertEquals("Check component.properties name [" + 1 + "]", "long", pd[1].getName());
    assertEquals("Check component.properties type [" + 1 + "]", "long", pd[1].getType());
    assertEquals("Check component.properties value [" + 1 + "]", "40", pd[1].getValue());
    assertEquals("Check component.properties name [" + 2 + "]", "string", pd[2].getName());
    assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd[2].getType());
    assertEquals("Check component.properties value [" + 2 + "]", "foo", pd[2].getValue());
    assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd[3].getName());
    assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd[3].getType());
    assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd[4].getName());
    assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd[4].getType());
    // Test factory
    assertEquals("Check factory name", fooProvider2.getName(), "Factories-FooProviderType-2");
    Element cd = fooProvider2.getDescription();
    // assertEquals("Check implementation class ", cd.getAttribute("implementation-class"), impl);
    Element[] specs2 = cd.getElements("provides");
    assertEquals("Check specs length", specs2.length, 1);
    assertEquals("Check specs", FooService.class.getName(), specs2[0].getAttribute("specification"));
    Element[] pd2 = cd.getElements("property");
    assertEquals("Check props length", pd2.length, 5);
    assertEquals("Check component.properties name [" + 0 + "]", "int", pd2[0].getAttribute("name"));
    assertEquals("Check component.properties type [" + 0 + "]", "int", pd2[0].getAttribute("type"));
    assertEquals("Check component.properties value [" + 0 + "]", "2", pd2[0].getAttribute("value"));
    assertEquals("Check component.properties name [" + 1 + "]", "long", pd2[1].getAttribute("name"));
    assertEquals("Check component.properties type [" + 1 + "]", "long", pd2[1].getAttribute("type"));
    assertEquals("Check component.properties value [" + 1 + "]", "40", pd2[1].getAttribute("value"));
    assertEquals("Check component.properties name [" + 2 + "]", "string", pd2[2].getAttribute("name"));
    assertEquals("Check component.properties type [" + 2 + "]", "java.lang.String", pd2[2].getAttribute("type"));
    assertEquals("Check component.properties value [" + 2 + "]", "foo", pd2[2].getAttribute("value"));
    assertEquals("Check component.properties name [" + 3 + "]", "strAProp", pd2[3].getAttribute("name"));
    assertEquals("Check component.properties type [" + 3 + "]", "java.lang.String[]", pd2[3].getAttribute("type"));
    assertEquals("Check component.properties name [" + 4 + "]", "intAProp", pd2[4].getAttribute("name"));
    assertEquals("Check component.properties type [" + 4 + "]", "int[]", pd2[4].getAttribute("type"));
    // Check Description equality
    ComponentTypeDescription desc = (ComponentTypeDescription) sr_fooProvider2.getProperty("component.description");
    assertNotNull("check description equality", desc);
    // Check that we have the complete metadata
    assertNotNull(fooProvider2.getComponentMetadata());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PropertyDescription(org.apache.felix.ipojo.architecture.PropertyDescription) ComponentTypeDescription(org.apache.felix.ipojo.architecture.ComponentTypeDescription) Element(org.apache.felix.ipojo.metadata.Element) Test(org.junit.Test)

Aggregations

ComponentTypeDescription (org.apache.felix.ipojo.architecture.ComponentTypeDescription)7 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)6 Test (org.junit.Test)6 Element (org.apache.felix.ipojo.metadata.Element)5 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)5 Properties (java.util.Properties)2 Factory (org.apache.felix.ipojo.Factory)2 Enumeration (java.util.Enumeration)1 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)1 ServiceContext (org.apache.felix.ipojo.ServiceContext)1 CompositeInstanceDescription (org.apache.felix.ipojo.composite.CompositeInstanceDescription)1 CompositeManager (org.apache.felix.ipojo.composite.CompositeManager)1 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1