Search in sources :

Example 6 with RichBundleContext

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);
}
Also used : ManagedService(org.osgi.service.cm.ManagedService) RichBundleContext(org.apache.aries.itest.RichBundleContext) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceReference(org.osgi.framework.ServiceReference) HelloWorld(org.apache.aries.isolated.sample.HelloWorld)

Example 7 with RichBundleContext

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());
}
Also used : RichBundleContext(org.apache.aries.itest.RichBundleContext) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) PostResolveTransformer(org.apache.aries.application.management.spi.resolve.PostResolveTransformer) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 8 with RichBundleContext

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);
}
Also used : RichBundleContext(org.apache.aries.itest.RichBundleContext) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Aggregations

RichBundleContext (org.apache.aries.itest.RichBundleContext)8 Hello (org.apache.aries.subsystem.itests.hello.api.Hello)3 Test (org.junit.Test)3 BundleContext (org.osgi.framework.BundleContext)3 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)2 Subsystem (org.osgi.service.subsystem.Subsystem)2 URL (java.net.URL)1 Hashtable (java.util.Hashtable)1 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)1 PostResolveTransformer (org.apache.aries.application.management.spi.resolve.PostResolveTransformer)1 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)1 HelloWorld (org.apache.aries.isolated.sample.HelloWorld)1 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)1 ZipFixture (org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture)1 Before (org.junit.Before)1 MavenArtifactProvisionOption (org.ops4j.pax.exam.options.MavenArtifactProvisionOption)1 ServiceReference (org.osgi.framework.ServiceReference)1 Configuration (org.osgi.service.cm.Configuration)1 ManagedService (org.osgi.service.cm.ManagedService)1 URLStreamHandlerService (org.osgi.service.url.URLStreamHandlerService)1