Search in sources :

Example 1 with HelloService

use of org.apache.felix.ipojo.runtime.core.test.services.HelloService in project felix by apache.

the class TestDeclarationBuilderService method testConfiguredInstanceCreation.

@Test
public void testConfiguredInstanceCreation() {
    handle = builder.newInstance("org.apache.felix.ipojo.runtime.core.test.components.FrenchHelloService").name("bonjour-service").configure().property("message", "Salut").build();
    handle.publish();
    assertTrue(ipojoHelper.isServiceAvailableByName(HelloService.class.getName(), "bonjour-service"));
    HelloService service = osgiHelper.getServiceObject(HelloService.class, format("(instance.name=%s)", "bonjour-service"));
    assertEquals(service.hello("Guillaume"), "Salut Guillaume");
}
Also used : HelloService(org.apache.felix.ipojo.runtime.core.test.services.HelloService) Test(org.junit.Test)

Example 2 with HelloService

use of org.apache.felix.ipojo.runtime.core.test.services.HelloService in project felix by apache.

the class TestDeclarationBuilderService method testAnonymousInstanceCreation.

@Test
public void testAnonymousInstanceCreation() {
    handle = builder.newInstance("org.apache.felix.ipojo.runtime.core.test.components.FrenchHelloService").build();
    // When a  service is registered, all events are fired synchronously, we
    // can safely test the declaration binding
    assertFalse(handle.getStatus().isBound());
    handle.publish();
    // This test has been already ssen as failed.
    HelloService hs = osgiHelper.waitForService(HelloService.class, "(factory.name=org.apache.felix.ipojo.runtime" + ".core.test.components.FrenchHelloService)", 1000);
    assertNotNull(hs);
    System.out.println("Status: " + handle.getStatus().isBound());
    assertTrue(handle.getStatus().isBound());
    handle.retract();
    assertFalse(handle.getStatus().isBound());
}
Also used : HelloService(org.apache.felix.ipojo.runtime.core.test.services.HelloService) Test(org.junit.Test)

Example 3 with HelloService

use of org.apache.felix.ipojo.runtime.core.test.services.HelloService 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 4 with HelloService

use of org.apache.felix.ipojo.runtime.core.test.services.HelloService in project felix by apache.

the class TestDeclarationBuilderService method testVersionedTypeInstanceCreation.

@Test
public void testVersionedTypeInstanceCreation() {
    handle = builder.newInstance("hello-service").version("2.0").name("hello2").build();
    handle.publish();
    String filter = format("(instance.name=%s)", "hello2");
    osgiHelper.waitForService(HelloService.class, filter, 1000);
    HelloService service = osgiHelper.getServiceObject(HelloService.class, filter);
    assertEquals(service.hello("Guillaume"), "Hello2 Guillaume");
}
Also used : HelloService(org.apache.felix.ipojo.runtime.core.test.services.HelloService) Test(org.junit.Test)

Aggregations

HelloService (org.apache.felix.ipojo.runtime.core.test.services.HelloService)4 Test (org.junit.Test)4 DeclarationHandle (org.apache.felix.ipojo.extender.DeclarationHandle)1