use of org.apache.aries.itest.RichBundleContext in project aries by apache.
the class IsolatedCfgAdminRuntimeTest method assertExpectedServices.
/**
* Assert that the following services are present in the service registry:
* <p/>
* - ConfigurationAdmin
* - ManagedService
* - HelloWorld
*
* @param ctx the bundle context
* @param pid the service pid used to register the underlying ManagedService
* @throws Exception
*/
private void assertExpectedServices(RichBundleContext ctx, String pid) throws Exception {
//assert the CfgAdmin service was registered
Assert.assertNotNull("Missing the ConfigurationAdmin service", ctx.getService(ConfigurationAdmin.class));
//assert we have the ManagedService exposed
Assert.assertNotNull("Missing the Managed service", ctx.getService(ManagedService.class, "(" + Constants.SERVICE_PID + "=" + pid + ")"));
//now just make sure we can see it through the context of our config admin bundle context (should be in the same scope)
ServiceReference ref = ctx.getServiceReference(ConfigurationAdmin.class.getName());
Assert.assertNotNull("Couldn't find the ManagedService using the ConfigAdmin bundle context", new RichBundleContext(ref.getBundle().getBundleContext()).getService(ManagedService.class, "(" + Constants.SERVICE_PID + "=" + pid + ")"));
//make sure we have the helloworld service registered
HelloWorld helloWorldBluePrint = IsolationTestUtils.findHelloWorldService(ctx);
Assert.assertNotNull("Missing the HelloWorld service", helloWorldBluePrint);
}
use of org.apache.aries.itest.RichBundleContext in project aries by apache.
the class ConfigurationPostResolverTest method validatePostResolveTransform.
/**
* This test validates that the transformer is correctly detecting the config admin package. Checks
* are performed to validate that an existing import package is still honored etc.
*
* @throws Exception
*/
@Test
public void validatePostResolveTransform() throws Exception {
RichBundleContext ctx = new RichBundleContext(bundleContext);
PostResolveTransformer transformer = ctx.getService(PostResolveTransformer.class);
Assert.assertNotNull("Unable to locate transformer", transformer);
/**
* Try processing deployed content that doesn't have any import for the
* org.osgi.service.cm package, the resultant imports should be unaffected.
*/
ApplicationMetadata mockApplicationMetadata = Skeleton.newMock(ApplicationMetadata.class);
MockDeployedBundles originalDeployedBundles = new MockDeployedBundles();
originalDeployedBundles.setDeployedContent(getNonConfigModelledResources());
DeployedBundles transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
Assert.assertEquals(originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
/**
* Now try processing a deployed bundles instances that has an import for the org.osgi.service.cm package in multiple
* modelled resources with an empty import package set in the mock deployed bundles instance.
*/
originalDeployedBundles = new MockDeployedBundles();
originalDeployedBundles.setDeployedContent(getConfigModelledResources());
transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
Assert.assertNotSame("Missing config package", originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
Assert.assertEquals("Missing config package", "org.osgi.service.cm;version=\"1.2.0\"", transformedDeployedBundles.getImportPackage());
/**
* Now try processing a deployed bundles instances that has an import for the org.osgi.service.cm package in multiple
* modelled resources with a populated import package set in the mock deployed bundles instance.
*/
originalDeployedBundles = new MockDeployedBundles();
originalDeployedBundles.setDeployedContent(getConfigModelledResources());
originalDeployedBundles.setImportPackage("org.foo.bar;version=\1.0.0\",org.bar.foo;version=\"1.0.0\"");
transformedDeployedBundles = transformer.postResolveProcess(mockApplicationMetadata, originalDeployedBundles);
Assert.assertNotNull("An instance should have been returned", transformedDeployedBundles);
Assert.assertNotSame("Missing config package", originalDeployedBundles.getImportPackage(), transformedDeployedBundles.getImportPackage());
Assert.assertEquals("Missing config package", "org.foo.bar;version=\1.0.0\",org.bar.foo;version=\"1.0.0\",org.osgi.service.cm;version=\"1.2.0\"", transformedDeployedBundles.getImportPackage());
}
use of org.apache.aries.itest.RichBundleContext in project aries by apache.
the class AbstractBlueprintIntegrationTest method applyCommonConfiguration.
protected void applyCommonConfiguration(BundleContext ctx) throws Exception {
ConfigurationAdmin ca = (new RichBundleContext(ctx)).getService(ConfigurationAdmin.class);
Configuration cf = ca.getConfiguration("blueprint-sample-placeholder", null);
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("key.b", "10");
cf.update(props);
}
Aggregations