Search in sources :

Example 6 with DeclarationHandle

use of org.apache.felix.ipojo.extender.DeclarationHandle in project felix by apache.

the class DefaultInstanceBuilderTestCase method testNameConfiguration.

public void testNameConfiguration() throws Exception {
    InstanceBuilder builder = new DefaultInstanceBuilder(m_bundleContext, "type").name("John");
    DeclarationHandle handle = builder.build();
    InstanceDeclaration did = (InstanceDeclaration) handle;
    assertEquals("type", did.getComponentName());
    assertEquals("John", did.getInstanceName());
    assertNull(did.getComponentVersion());
    Dictionary<String, Object> configuration = did.getConfiguration();
    assertEquals("John", configuration.get(Factory.INSTANCE_NAME_PROPERTY));
}
Also used : DefaultInstanceDeclaration(org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration) InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration) DeclarationHandle(org.apache.felix.ipojo.extender.DeclarationHandle) InstanceBuilder(org.apache.felix.ipojo.extender.InstanceBuilder)

Example 7 with DeclarationHandle

use of org.apache.felix.ipojo.extender.DeclarationHandle in project felix by apache.

the class TestDeclarationBuilderService method testTypeCreation.

@Test
public void testTypeCreation() throws Exception {
    handle = builder.newType(germanComponent());
    handle.publish();
    DeclarationHandle instance = builder.newInstance("german-service").name("german-hello").build();
    instance.publish();
    System.out.println(instance.getStatus().getMessage());
    String filter = format("(instance.name=%s)", "german-hello");
    osgiHelper.waitForService(HelloService.class, filter, 1000);
    HelloService service = osgiHelper.getServiceObject(HelloService.class, filter);
    assertEquals(service.hello("Guillaume"), "Hallo Guillaume");
    instance.retract();
}
Also used : HelloService(org.apache.felix.ipojo.runtime.core.test.services.HelloService) DeclarationHandle(org.apache.felix.ipojo.extender.DeclarationHandle) Test(org.junit.Test)

Example 8 with DeclarationHandle

use of org.apache.felix.ipojo.extender.DeclarationHandle in project felix by apache.

the class DefaultInstanceBuilderTestCase method testNoConfiguration.

public void testNoConfiguration() throws Exception {
    InstanceBuilder builder = new DefaultInstanceBuilder(m_bundleContext, "type");
    DeclarationHandle handle = builder.build();
    InstanceDeclaration did = (InstanceDeclaration) handle;
    assertEquals("type", did.getComponentName());
    assertEquals(InstanceDeclaration.UNNAMED_INSTANCE, did.getInstanceName());
    assertNull(did.getComponentVersion());
    Dictionary<String, Object> configuration = did.getConfiguration();
    assertTrue(configuration.isEmpty());
}
Also used : DefaultInstanceDeclaration(org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration) InstanceDeclaration(org.apache.felix.ipojo.extender.InstanceDeclaration) DeclarationHandle(org.apache.felix.ipojo.extender.DeclarationHandle) InstanceBuilder(org.apache.felix.ipojo.extender.InstanceBuilder)

Aggregations

DeclarationHandle (org.apache.felix.ipojo.extender.DeclarationHandle)8 InstanceBuilder (org.apache.felix.ipojo.extender.InstanceBuilder)5 DefaultInstanceDeclaration (org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration)4 Dictionary (java.util.Dictionary)3 InstanceDeclaration (org.apache.felix.ipojo.extender.InstanceDeclaration)3 Element (org.apache.felix.ipojo.metadata.Element)1 HelloService (org.apache.felix.ipojo.runtime.core.test.services.HelloService)1 Test (org.junit.Test)1