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;
}
}
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());
}
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());
}
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);
}
Aggregations