use of org.apache.aries.blueprint.sample.Foo 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());
}
use of org.apache.aries.blueprint.sample.Foo in project aries by apache.
the class TestRegistrationListener method testWithAutoExportEnabled.
@Test
public void testWithAutoExportEnabled() throws Exception {
BlueprintContainer blueprintContainer = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.sample");
assertNotNull(blueprintContainer);
Foo foo = context().getService(Foo.class, "(" + BlueprintConstants.COMPONENT_NAME_PROPERTY + "=foo)");
assertEquals(5, foo.getA());
FooRegistrationListener listener = (FooRegistrationListener) blueprintContainer.getComponentInstance("fooRegistrationListener");
// If registration listener works fine, the registration method should
// have already been called and properties that were passed to this
// method should have been not null
Map<?, ?> props = listener.getProperties();
assertNotNull(props);
assertTrue(props.containsKey(BlueprintConstants.COMPONENT_NAME_PROPERTY));
assertEquals("foo", props.get(BlueprintConstants.COMPONENT_NAME_PROPERTY));
assertTrue(props.containsKey("key"));
assertEquals("value", props.get("key"));
}
use of org.apache.aries.blueprint.sample.Foo in project aries by apache.
the class TestConfigAdmin method testManagedServiceFactory.
@SuppressWarnings("rawtypes")
@Test
public void testManagedServiceFactory() throws Exception {
Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory", null);
cf.update(getConfig1());
startTestBundle();
// Make sure only one service is registered
// Ask the service registry, not the container, since the container might have got it wrong :)
Foo foo = context().getService(Foo.class, "(service.pid=blueprint-sample-managed-service-factory.*)");
ServiceReference[] refs = context().getAllServiceReferences(Foo.class.getName(), "(service.pid=blueprint-sample-managed-service-factory.*)");
assertNotNull("No services were registered for the managed service factory", refs);
assertEquals("Multiple services were registered for the same pid.", 1, refs.length);
}
use of org.apache.aries.blueprint.sample.Foo in project aries by apache.
the class TestConfigAdmin method testStrategyComponent.
@Test
public void testStrategyComponent() throws Exception {
// foo should receive initial configuration
ca.getConfiguration("blueprint-sample-managed.component", null).update(getConfig1());
startTestBundle();
Foo foo = getComponent("component-managed");
assertEquals(5, foo.getA());
assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
// Foo.update() should have been called but the bean properties should not have been updated
ca.getConfiguration("blueprint-sample-managed.component", null).update(getConfig2());
Thread.sleep(100);
assertEquals(5, foo.getA());
assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
assertNotNull(foo.getProps());
assertEquals("10", foo.getProps().get("a"));
assertEquals("USD", foo.getProps().get("currency"));
}
use of org.apache.aries.blueprint.sample.Foo in project aries by apache.
the class TestConfigAdmin method testStrategyNone.
@Test
public void testStrategyNone() throws Exception {
ca.getConfiguration("blueprint-sample-managed.none", null).update(getConfig1());
startTestBundle();
// foo should receive initial configuration
Foo foo = getComponent("none-managed");
assertEquals(5, foo.getA());
assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
// foo should not reflect changes in config
ca.getConfiguration("blueprint-sample-managed.none", null).update(getConfig2());
Thread.sleep(100);
assertEquals(5, foo.getA());
assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
}
Aggregations