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()));
}
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));
}
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));
}
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));
}
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()));
}
Aggregations