Search in sources :

Example 1 with AccountFactory

use of org.apache.aries.blueprint.sample.AccountFactory in project aries by apache.

the class Helper method testBlueprintContainer.

public static void testBlueprintContainer(RichBundleContext context, Bundle bundle) throws Exception {
    BlueprintContainer blueprintContainer = getBlueprintContainerForBundle(context, SAMPLE_SYM_NAME);
    assertNotNull(blueprintContainer);
    Bar bar = getInstance(blueprintContainer, "bar", Bar.class);
    checkBar(bar);
    Foo foo = getInstance(blueprintContainer, "foo", Foo.class);
    checkFoo(bar, foo);
    Foo fooService = context.getService(Foo.class);
    assertNotNull(fooService);
    checkFoo(bar, fooService);
    // TODO Does not work
    //assertEquals(obj, foo);
    Account account = getInstance(blueprintContainer, "accountOne", Account.class);
    assertEquals(1, account.getAccountNumber());
    Account account2 = getInstance(blueprintContainer, "accountTwo", Account.class);
    assertEquals(2, account2.getAccountNumber());
    Account account3 = getInstance(blueprintContainer, "accountThree", Account.class);
    assertEquals(3, account3.getAccountNumber());
    AccountFactory accountFactory = getInstance(blueprintContainer, "accountFactory", AccountFactory.class);
    assertEquals("account factory", accountFactory.getFactoryName());
    bundle.stop();
    Thread.sleep(1000);
    try {
        blueprintContainer = getBlueprintContainerForBundle(context, SAMPLE_SYM_NAME, 1);
        fail("BlueprintContainer should have been unregistered");
    } catch (Exception e) {
    // Expected, as the module container should have been unregistered
    }
    assertTrue(foo.isInitialized());
    assertTrue(foo.isDestroyed());
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) Account(org.apache.aries.blueprint.sample.Account) AccountFactory(org.apache.aries.blueprint.sample.AccountFactory) Bar(org.apache.aries.blueprint.sample.Bar) Foo(org.apache.aries.blueprint.sample.Foo) ParseException(java.text.ParseException)

Aggregations

ParseException (java.text.ParseException)1 Account (org.apache.aries.blueprint.sample.Account)1 AccountFactory (org.apache.aries.blueprint.sample.AccountFactory)1 Bar (org.apache.aries.blueprint.sample.Bar)1 Foo (org.apache.aries.blueprint.sample.Foo)1 BlueprintContainer (org.osgi.service.blueprint.container.BlueprintContainer)1