public void testServletThroughModuleContext() throws Exception {
Runtime runtime = RuntimeLocator.getRequiredRuntime();
Module module = runtime.getModule(getClass().getClassLoader());
ModuleContext context = module.getModuleContext();
ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
HttpService httpService = context.getService(sref);
String reqspec = "/gravia/servlet?test=module";
try {
// Verify that the alias is not yet available
assertNotAvailable(reqspec);
// Register the test servlet and make a call
String servletAlias = getRuntimeAwareAlias("/servlet");
httpService.registerServlet(servletAlias, new HttpServiceServlet(module), null, null);
Assert.assertEquals("http-service:1.0.0", performCall(reqspec));
// Unregister the servlet alias
httpService.unregister(servletAlias);
assertNotAvailable(reqspec);
// Verify that the alias is not available any more
assertNotAvailable(reqspec);
} finally {
context.ungetService(sref);
}
}