@Test public void testAddsApplicationConfigurationsOnStart() { BundleContext context = mock(BundleContext.class); ServiceContainer container = new ServiceContainer(context); ServiceReference reference = mock(ServiceReference.class); ApplicationConfiguration appConfig = mock(ApplicationConfiguration.class); Map<String, Object> map = new HashMap<>(); map.put("foo", "bar"); when(appConfig.getProperties()).thenReturn(map); Set<Object> set = new HashSet<Object>(); set.add("test"); when(appConfig.getSingletons()).thenReturn(set); when(context.getService(reference)).thenReturn(appConfig); container.add(reference); Configuration configuration = createConfiguration("/test", false, 23L); ServletConfiguration servletConfigurationService = mock(ServletConfiguration.class); JerseyContext jerseyContext = new JerseyContext(httpService, configuration, servletConfigurationService, container); Map<String, Object> properties = jerseyContext.getRootApplication().getProperties(); assertEquals(properties.get("foo"), "bar"); Set<Object> singletons = jerseyContext.getRootApplication().getSingletons(); assertEquals(singletons.contains("test"), true); }
@Test public void testUpdateAppConfiguration() { BundleContext context = mock(BundleContext.class); ServiceContainer container = new ServiceContainer(context); ServiceReference reference = mock(ServiceReference.class); ApplicationConfiguration appConfig = mock(ApplicationConfiguration.class); Map<String, Object> map = new HashMap<>(); map.put("foo", "bar"); when(appConfig.getProperties()).thenReturn(map); when(context.getService(reference)).thenReturn(appConfig); container.add(reference); jerseyContext.updateAppConfiguration(container); verify(rootApplication).addProperties(map); }