Search in sources :

Example 6 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType 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 7 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class PrimitiveComponentTest method createAServiceCons.

@Test
public void createAServiceCons() throws Exception {
    assertThat(context, is(notNullValue()));
    ComponentInstance ci = null;
    PrimitiveComponentType type = createAConsumer();
    ci = type.createInstance();
    assertThat("Ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
}
Also used : PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) Test(org.junit.Test)

Example 8 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class CompositeTest method createACompositeWithAnImportedService.

@Test
public void createACompositeWithAnImportedService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    // Define the component types
    PrimitiveComponentType prov = createAProvider();
    prov.createInstance();
    PrimitiveComponentType cons = createAConsumer();
    ServiceReference[] refs = osgiHelper.getServiceReferences(Factory.class.getName(), "(component.providedServiceSpecifications=" + Foo.class.getName() + ")");
    assertThat(refs.length, is(not(0)));
    CompositeComponentType type = new CompositeComponentType().setBundleContext(context).setComponentTypeName("comp2").addSubService(new ImportedService().setSpecification(Foo.class.getName())).addInstance(new Instance(cons.getFactory().getName()));
    ComponentInstance ci = type.createInstance();
    System.out.println(ci.getInstanceDescription().getDescription());
    assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
    // Stop prov
    prov.stop();
    assertThat("ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
    // Restart prov
    prov.start();
    prov.createInstance();
    assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
}
Also used : Foo(org.apache.felix.ipojo.runtime.core.api.services.Foo) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 9 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class CompositeTest method createACompositeWithExportingAService.

@Test
public void createACompositeWithExportingAService() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
    // Define the component types
    PrimitiveComponentType prov = createAProvider();
    prov.start();
    PrimitiveComponentType cons = createAConsumer();
    ComponentInstance c = cons.createInstance();
    CompositeComponentType type = new CompositeComponentType().setBundleContext(context).setComponentTypeName("compExport").addSubService(new InstantiatedService().setSpecification(Foo.class.getName())).addService(new ExportedService().setSpecification(Foo.class.getName()));
    ComponentInstance ci = type.createInstance();
    assertThat("ci is valid", ci.getState(), is(ComponentInstance.VALID));
    assertThat("c is valid", c.getState(), is(ComponentInstance.VALID));
    // Stop prov
    prov.stop();
    assertThat("ci is invalid", ci.getState(), is(ComponentInstance.INVALID));
    assertThat("c is invalid", c.getState(), is(ComponentInstance.INVALID));
    // Restart prov
    prov.start();
    assertThat("ci is valid - 2", ci.getState(), is(ComponentInstance.VALID));
    assertThat("c is valid - 2", c.getState(), is(ComponentInstance.VALID));
}
Also used : Foo(org.apache.felix.ipojo.runtime.core.api.services.Foo) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) Test(org.junit.Test)

Example 10 with PrimitiveComponentType

use of org.apache.felix.ipojo.api.PrimitiveComponentType in project felix by apache.

the class PrimitiveComponentTest method createAServiceProvider.

@Test
public void createAServiceProvider() throws Exception {
    assertThat(context, is(notNullValue()));
    ComponentInstance ci;
    PrimitiveComponentType type = createAProvider();
    ci = type.createInstance();
    assertThat("Ci is valid", ci.getState(), is(ComponentInstance.VALID));
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(Foo.class.getName(), ci.getInstanceName());
    assertThat(ref, is(notNullValue()));
}
Also used : Foo(org.apache.felix.ipojo.runtime.core.api.services.Foo) PrimitiveComponentType(org.apache.felix.ipojo.api.PrimitiveComponentType) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

PrimitiveComponentType (org.apache.felix.ipojo.api.PrimitiveComponentType)12 Test (org.junit.Test)12 Foo (org.apache.felix.ipojo.runtime.core.api.services.Foo)6 ServiceReference (org.osgi.framework.ServiceReference)3 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)2 HandlerDescription (org.apache.felix.ipojo.architecture.HandlerDescription)2 PlainHelloImpl (org.apache.felix.ipojo.runtime.core.api.components.PlainHelloImpl)1