@Test public void testServlets() throws Exception { final Injector injector = GuiceInjectorBuilder.getInjector(new CronGuiModulesMock()); final CronGuiActivator activator = new CronGuiActivator() { @Override public Injector getInjector() { return injector; } }; final BundleActivatorTestUtil bundleActivatorTestUtil = new BundleActivatorTestUtil(); final ExtHttpServiceMock extHttpServiceMock = bundleActivatorTestUtil.startBundle(activator); final List<String> paths = new ArrayList<String>(); paths.add("/" + CronGuiConstants.NAME + CronGuiConstants.URL_HOME); paths.add("/" + CronGuiConstants.NAME + CronGuiConstants.URL_LIST); paths.add("/" + CronGuiConstants.NAME + CronGuiConstants.URL_CRON_TRIGGER); paths.add("/" + CronGuiConstants.NAME + CronGuiConstants.URL_LATEST); paths.add("/" + CronGuiConstants.NAME + CronGuiConstants.URL_MANAGE); assertEquals(paths.size(), extHttpServiceMock.getRegisterServletCallCounter()); for (final String path : paths) { assertTrue( "no servlet for path " + path + " registered", extHttpServiceMock.hasServletPath(path)); } }
@Test public void testFilters() throws Exception { final Injector injector = GuiceInjectorBuilder.getInjector(new CronGuiModulesMock()); final CronGuiActivator activator = new CronGuiActivator() { @Override public Injector getInjector() { return injector; } }; final BundleActivatorTestUtil bundleActivatorTestUtil = new BundleActivatorTestUtil(); final ExtHttpServiceMock extHttpServiceMock = bundleActivatorTestUtil.startBundle(activator); final List<String> paths = Arrays.asList("/cron.*"); assertEquals(paths.size(), extHttpServiceMock.getRegisterFilterCallCounter()); for (final String path : paths) { assertTrue( "no filter for path " + path + " registered", extHttpServiceMock.hasFilterPath(path)); } final BaseGuiceFilter guiceFilter = injector.getInstance(BaseGuiceFilter.class); for (final Filter filter : Arrays.asList(guiceFilter)) { assertTrue("no filter " + filter + " registered", extHttpServiceMock.hasFilter(filter)); } }
@Test public void testResources() throws Exception { final Injector injector = GuiceInjectorBuilder.getInjector(new CronGuiModulesMock()); final CronGuiActivator activator = new CronGuiActivator() { @Override public Injector getInjector() { return injector; } }; final BundleActivatorTestUtil bundleActivatorTestUtil = new BundleActivatorTestUtil(); final ExtHttpServiceMock extHttpServiceMock = bundleActivatorTestUtil.startBundle(activator); final List<String> paths = new ArrayList<String>(); assertEquals(paths.size(), extHttpServiceMock.getRegisterResourceCallCounter()); for (final String path : paths) { assertTrue( "no resource for path " + path + " registered", extHttpServiceMock.hasResource(path)); } }
public void testGetExtHttpService() { final BundleContext bundleContext = getContext(); assertNotNull(bundleContext); final ExtHttpServiceMock extHttpService = new ExtHttpServiceMock(new UrlUtilImpl()); assertNotNull(extHttpService); // zum start: keine Dienste registriert assertEquals(0, extHttpService.getRegisterFilterCallCounter()); assertEquals(0, extHttpService.getRegisterServletCallCounter()); assertEquals(0, extHttpService.getUnregisterFilterCallCounter()); assertEquals(0, extHttpService.getUnregisterServletCallCounter()); final ServiceRegistration serviceRegistration = bundleContext.registerService(ExtHttpService.class.getName(), extHttpService, null); assertNotNull(serviceRegistration); // nach start: Dienste vorhanden? assertTrue("no filters registered", extHttpService.getRegisterFilterCallCounter() > 0); assertTrue("no servlets registered.", extHttpService.getRegisterServletCallCounter() > 0); assertEquals(0, extHttpService.getUnregisterFilterCallCounter()); assertEquals(0, extHttpService.getUnregisterServletCallCounter()); // do unregister serviceRegistration.unregister(); assertTrue("no servlets unregistered", extHttpService.getUnregisterServletCallCounter() > 0); assertEquals( extHttpService.getRegisterServletCallCounter(), extHttpService.getRegisterServletCallCounter()); assertEquals( extHttpService.getRegisterFilterCallCounter(), extHttpService.getUnregisterFilterCallCounter()); }