Search in sources :

Example 6 with HandlerDescription

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

the class IgnoreCaseHandlerSelectionTest method testCreationOfIgnoreCase1.

/**
 * Check that the instance is correctly created with "empty".
 */
@Test
public void testCreationOfIgnoreCase1() {
    ServiceReference refv1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "IgnoreCase-1");
    Assert.assertNotNull(refv1);
    Architecture arch = (Architecture) osgiHelper.getRawServiceObject(refv1);
    Assert.assertEquals(ComponentInstance.VALID, arch.getInstanceDescription().getState());
    HandlerDescription desc = arch.getInstanceDescription().getHandlerDescription(// Check with the declared name.
    "orG.apAche.feliX.iPOJO.tests.CORE.hAnDlEr:EmPtY");
    Assert.assertNotNull(desc);
    Assert.assertTrue(desc.isValid());
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) HandlerDescription(org.apache.felix.ipojo.architecture.HandlerDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 7 with HandlerDescription

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

the class ExternalHandlerTest method createAHost.

@Test
public void createAHost() throws Exception {
    PrimitiveComponentType type = createAWhiteboardHost();
    ComponentInstance ci = type.createInstance();
    assertThat(ci.getState(), is(ComponentInstance.VALID));
    HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE + ":" + Whiteboard.NAME);
    assertThat(hd, is(notNullValue()));
}
Also used : HandlerDescription(org.apache.felix.ipojo.architecture.HandlerDescription) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) Test(org.junit.Test)

Example 8 with HandlerDescription

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

the class ExternalHandlerTest method createDoubleHost.

@Test
public void createDoubleHost() throws Exception {
    PrimitiveComponentType type = createASecondWhiteboardHost();
    ComponentInstance ci = type.createInstance();
    assertThat(ci.getState(), is(ComponentInstance.VALID));
    HandlerDescription hd = ci.getInstanceDescription().getHandlerDescription(Whiteboard.NAMESPACE + ":" + Whiteboard.NAME);
    assertThat(hd, is(notNullValue()));
}
Also used : HandlerDescription(org.apache.felix.ipojo.architecture.HandlerDescription) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) Test(org.junit.Test)

Example 9 with HandlerDescription

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

the class TestProvidedServiceArchitecture method testExposition.

@Test
public void testExposition() {
    String factName = "PS-FooProviderType-1";
    String compName = "FooProvider-1";
    // Get the factory to create a component instance
    Factory fact = ipojoHelper.getFactory(factName);
    assertNotNull("Cannot find the factory FooProvider-1", fact);
    ipojoHelper.createComponentInstance(factName, compName);
    ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), compName);
    assertNotNull("Architecture not available", arch_ref);
    Architecture arch = (Architecture) osgiHelper.getRawServiceObject(arch_ref);
    InstanceDescription id = arch.getInstanceDescription();
    assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
    assertEquals("Check component type implementation class", id.getComponentDescription().getClassName(), "org.apache.felix.ipojo.runtime.core.components.FooProviderType1");
    HandlerDescription[] handlers = id.getHandlers();
    assertEquals("Number of handlers", handlers.length, 2);
    // Look for the ProvidedService Handler
    ProvidedServiceHandlerDescription pshd = null;
    pshd = (ProvidedServiceHandlerDescription) id.getHandlerDescription("org.apache.felix.ipojo:provides");
    // for(int i = 0; i < handlers.length; i++) {
    // if(handlers[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
    // pshd = (ProvidedServiceHandlerDescription) handlers[i];
    // }
    // }
    // 
    assertNotNull("Check ProvidedServiceHandlerDescription", pshd);
    ProvidedServiceDescription[] ps = pshd.getProvidedServices();
    assertEquals("Check ProvidedService number", ps.length, 1);
    assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecifications().length, 1);
    assertEquals("Check Provided Service Specs - 2", ps[0].getServiceSpecifications()[0], FooService.class.getName());
    assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
    Properties prop = ps[0].getProperties();
    assertNotNull("Check Props", prop);
    assertEquals("Check service properties number", prop.size(), 2);
    assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
    assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ProvidedServiceDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription) Architecture(org.apache.felix.ipojo.architecture.Architecture) HandlerDescription(org.apache.felix.ipojo.architecture.HandlerDescription) ProvidedServiceHandlerDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription) Factory(org.apache.felix.ipojo.Factory) InstanceDescription(org.apache.felix.ipojo.architecture.InstanceDescription) Properties(java.util.Properties) ProvidedServiceHandlerDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 10 with HandlerDescription

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

the class TestProvidedServiceArchitecture method testPropsNoValue.

@Test
public void testPropsNoValue() {
    String factName = "PS-FooProviderType-3";
    String compName = "FooProvider";
    // Get the factory to create a component instance
    Factory fact = ipojoHelper.getFactory(factName);
    assertNotNull("Cannot find the factory FooProvider", fact);
    ipojoHelper.createComponentInstance(factName, compName);
    ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), compName);
    assertNotNull("Architecture not available", arch_ref);
    Architecture arch = (Architecture) osgiHelper.getRawServiceObject(arch_ref);
    InstanceDescription id = arch.getInstanceDescription();
    assertEquals("Check component instance name (" + id.getName() + ")", id.getName(), compName);
    assertEquals("Check component type implementation class", id.getComponentDescription().getClassName(), "org.apache.felix.ipojo.runtime.core.components.FooProviderType1");
    HandlerDescription[] handlers = id.getHandlers();
    assertEquals("Number of handlers", handlers.length, 3);
    // Look for the ProvidedService Handler
    ProvidedServiceHandlerDescription pshd = null;
    pshd = (ProvidedServiceHandlerDescription) id.getHandlerDescription("org.apache.felix.ipojo:provides");
    // for(int i = 0; i < handlers.length; i++) {
    // if(handlers[i].getHandlerName().equals("org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandler")) {
    // pshd = (ProvidedServiceHandlerDescription) handlers[i];
    // }
    // }
    assertNotNull("Check ProvidedServiceHandlerDescription", pshd);
    ProvidedServiceDescription[] ps = pshd.getProvidedServices();
    assertEquals("Check ProvidedService number", ps.length, 1);
    assertEquals("Check Provided Service Specs - 1", ps[0].getServiceSpecifications().length, 1);
    assertEquals("Check Provided Service Specs - 2", ps[0].getServiceSpecifications()[0], FooService.class.getName());
    assertEquals("Check Provided Service availability", ps[0].getState(), ProvidedServiceDescription.REGISTERED);
    Properties prop = ps[0].getProperties();
    assertNotNull("Check Props", prop);
    assertEquals("Check service properties number (#" + prop + "?=5)", prop.size(), 2);
    assertEquals("Check instance.name property", prop.getProperty("instance.name"), compName);
    assertEquals("Check factory.name property", prop.getProperty("factory.name"), factName);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ProvidedServiceDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription) Architecture(org.apache.felix.ipojo.architecture.Architecture) HandlerDescription(org.apache.felix.ipojo.architecture.HandlerDescription) ProvidedServiceHandlerDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription) Factory(org.apache.felix.ipojo.Factory) InstanceDescription(org.apache.felix.ipojo.architecture.InstanceDescription) Properties(java.util.Properties) ProvidedServiceHandlerDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

HandlerDescription (org.apache.felix.ipojo.architecture.HandlerDescription)11 Test (org.junit.Test)11 Architecture (org.apache.felix.ipojo.architecture.Architecture)8 ServiceReference (org.osgi.framework.ServiceReference)6 Properties (java.util.Properties)4 Factory (org.apache.felix.ipojo.Factory)4 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)4 ProvidedServiceDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription)4 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)4 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)4 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)2 PrimitiveComponentType (org.apache.felix.ipojo.api.PrimitiveComponentType)2 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)2 DependencyHandlerDescription (org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription)2 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)1 CheckServiceHandlerDescription (org.apache.felix.ipojo.runtime.externalhandlers.services.CheckServiceHandlerDescription)1 Ignore (org.junit.Ignore)1