@Test public void testIsFrameworkBundle() { final Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(bundle.getBundleId()).thenReturn(1L); assertFalse(OsgiHelper.isFrameworkBundle(bundle)); Mockito.when(bundle.getBundleId()).thenReturn(0L); assertTrue(OsgiHelper.isFrameworkBundle(bundle)); }
@Test public void testGetBundleName() { final Hashtable<String, Object> headers = new Hashtable<String, Object>(); final Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(bundle.getSymbolicName()).thenReturn("SymbolicName"); Mockito.when(bundle.getHeaders()).thenReturn(headers); assertEquals("SymbolicName", OsgiHelper.getBundleName(bundle)); headers.put("Bundle-Name", "BundleName"); assertEquals("BundleName", OsgiHelper.getBundleName(bundle)); }
@Test public void testRequiredService() { final String service = "Service"; final ServiceReference ref = Mockito.mock(ServiceReference.class); final BundleContext context = Mockito.mock(BundleContext.class); Mockito.when(context.getServiceReference("java.lang.String")).thenReturn(ref); Mockito.when(context.getService(ref)).thenReturn(service); assertSame(service, OsgiHelper.requireService(context, String.class)); }
@Before public void setUp() throws Exception { OsgiHelper.setUtilsService(new DefaultOsgiUtilsService(bundleContext)); setupRulemanager(); auditingMock = mock(AuditingDomain.class); registerServiceAtLocation(auditingMock, "auditing-root", AuditingDomain.class); service = new WorkflowServiceImpl(); service.setAuditingConnectors(makeServiceList(AuditingDomain.class)); setupTaskbox(); service.setRulemanager(manager); service.setTaskbox(taskbox); ContextHolder.get().setCurrentContextId("42"); service.setBundleContext(bundleContext); registerServiceViaId(service, "workflowService", WorkflowService.class); setupDomainsAndOtherServices(); }
@Test(expected = PluginException.class) public void testRequiredServiceNotFound() { final BundleContext context = Mockito.mock(BundleContext.class); OsgiHelper.requireService(context, String.class); }