Search in sources :

Example 1 with HelloWorld

use of org.apache.aries.isolated.sample.HelloWorld in project aries by apache.

the class IsolationTestUtils method findHelloWorldService.

public static HelloWorld findHelloWorldService(BundleContext ctx) throws Exception {
    if (ctx != null) {
        // Dive into the context and pull out the composite bundle for the app
        Filter osgiFilter = FrameworkUtil.createFilter("(" + Constants.OBJECTCLASS + "=" + HelloWorld.class.getName() + ")");
        ServiceTracker tracker = new ServiceTracker(ctx, osgiFilter, null);
        tracker.open();
        final Object hw = tracker.waitForService(DEFAULT_TIMEOUT);
        tracker.close();
        if (hw != null) {
            // proxy because the class space between the sample app and the test bundle is not consistent
            return new HelloWorld() {

                public String getMessage() {
                    try {
                        Method m = hw.getClass().getMethod("getMessage");
                        return (String) m.invoke(hw);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            };
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Method(java.lang.reflect.Method) BundleException(org.osgi.framework.BundleException) MalformedURLException(java.net.MalformedURLException) HelloWorld(org.apache.aries.isolated.sample.HelloWorld)

Example 2 with HelloWorld

use of org.apache.aries.isolated.sample.HelloWorld in project aries by apache.

the class IsolatedRuntimeTest method assertHelloWorldService.

private void assertHelloWorldService(String appName, String message) throws Exception {
    HelloWorld hw = IsolationTestUtils.findHelloWorldService(bundleContext, appName);
    assertNotNull("The Hello World service could not be found.", hw);
    assertEquals(message, hw.getMessage());
}
Also used : HelloWorld(org.apache.aries.isolated.sample.HelloWorld)

Example 3 with HelloWorld

use of org.apache.aries.isolated.sample.HelloWorld in project aries by apache.

the class UpdateAppTest method assertAppMessage.

private void assertAppMessage(String message) throws Exception {
    HelloWorld hw = IsolationTestUtils.findHelloWorldService(bundleContext, SAMPLE_APP_NAME);
    assertNotNull(hw);
    assertEquals(message, hw.getMessage());
}
Also used : HelloWorld(org.apache.aries.isolated.sample.HelloWorld)

Example 4 with HelloWorld

use of org.apache.aries.isolated.sample.HelloWorld 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)

Aggregations

HelloWorld (org.apache.aries.isolated.sample.HelloWorld)4 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 RichBundleContext (org.apache.aries.itest.RichBundleContext)1 BundleException (org.osgi.framework.BundleException)1 Filter (org.osgi.framework.Filter)1 ServiceReference (org.osgi.framework.ServiceReference)1 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)1 ManagedService (org.osgi.service.cm.ManagedService)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1