@Test
public void testServletAccess() 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 = "/service?test=param¶m=Kermit";
try {
// Verify that the alias is not yet available
assertNotAvailable(reqspec);
// Register the test servlet and make a call
httpService.registerServlet("/service", new HttpServiceServlet(module), null, null);
Assert.assertEquals("Hello: Kermit", performCall(reqspec));
// Unregister the servlet alias
httpService.unregister("/service");
assertNotAvailable(reqspec);
// Verify that the alias is not available any more
assertNotAvailable(reqspec);
} finally {
context.ungetService(sref);
}
}