}
}
@Test
public void testComponentRegistration() throws Exception {
JaxRsHandler handler = HandlerCreator.getHandler("", null);
BundlePrefixManager manager = new BundlePrefixManager() {
@Override
public String getPrefix(Bundle bundle) {
return "/test";
}
};
MyComponentContext context = new MyComponentContext();
ServiceReference serviceRef1 = createServiceReferenceMock();
context.addServiceReferenceAndComponent(serviceRef1, new MyResource1());
handler.bindComponent(serviceRef1);
Assert.assertFalse(isReachable(handler, "/test/a"));
handler.bindBundlePrefixManager(manager);
handler.activate(context);
Assert.assertTrue(isReachable(handler, "/test/a"));
handler.unbindBundlePrefixManager(manager);
ServiceReference serviceRef2 = createServiceReferenceMock();
context.addServiceReferenceAndComponent(serviceRef2, new MyResource2());
handler.bindComponent(serviceRef2);
Assert.assertFalse(isReachable(handler, "/test/b"));
handler.bindBundlePrefixManager(manager);
Assert.assertTrue(isReachable(handler, "/test/b"));
ServiceReference serviceRef3 = createServiceReferenceMock();
context.addServiceReferenceAndComponent(serviceRef3, new MyResource3());
handler.bindComponent(serviceRef3);
Assert.assertTrue(isReachable(handler, "/test/c"));
handler.unbindComponent(serviceRef1);
handler.unbindComponent(serviceRef2);
handler.unbindComponent(serviceRef3);
}