use of org.osgi.framework.BundleContext in project sling by apache.
the class JobConsumerManagerTest method testCategoryMappingConsumer.
@Test
public void testCategoryMappingConsumer() {
final BundleContext bc = Mockito.mock(BundleContext.class);
final JobConsumerManager jcs = new JobConsumerManager();
jcs.activate(bc, getDefaultConfig());
final JobConsumer jc1 = Mockito.mock(JobConsumer.class);
final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
Mockito.when(ref1.getProperty(JobConsumer.PROPERTY_TOPICS)).thenReturn("a/*");
Mockito.when(ref1.getProperty(Constants.SERVICE_RANKING)).thenReturn(1);
Mockito.when(ref1.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
Mockito.when(bc.getService(ref1)).thenReturn(jc1);
jcs.bindJobConsumer(ref1);
assertNotNull(jcs.getExecutor("a/b"));
assertNull(jcs.getExecutor("a"));
assertNotNull(jcs.getExecutor("a/c"));
assertNull(jcs.getExecutor("a/b/a"));
}
use of org.osgi.framework.BundleContext in project sling by apache.
the class JobConsumerManagerTest method testCategoryMappingExecutor.
@Test
public void testCategoryMappingExecutor() {
final BundleContext bc = Mockito.mock(BundleContext.class);
final JobConsumerManager jcs = new JobConsumerManager();
jcs.activate(bc, getDefaultConfig());
final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
Mockito.when(ref1.getProperty(JobExecutor.PROPERTY_TOPICS)).thenReturn("a/*");
Mockito.when(ref1.getProperty(Constants.SERVICE_RANKING)).thenReturn(1);
Mockito.when(ref1.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
Mockito.when(bc.getService(ref1)).thenReturn(jc1);
jcs.bindJobExecutor(ref1);
assertNotNull(jcs.getExecutor("a/b"));
assertNull(jcs.getExecutor("a"));
assertNotNull(jcs.getExecutor("a/c"));
assertNull(jcs.getExecutor("a/b/a"));
}
use of org.osgi.framework.BundleContext in project sling by apache.
the class JobConsumerManagerTest method testSubCategoryMappingExecutor.
@Test
public void testSubCategoryMappingExecutor() {
final BundleContext bc = Mockito.mock(BundleContext.class);
final JobConsumerManager jcs = new JobConsumerManager();
jcs.activate(bc, getDefaultConfig());
final JobExecutor jc1 = Mockito.mock(JobExecutor.class);
final ServiceReference ref1 = Mockito.mock(ServiceReference.class);
Mockito.when(ref1.getProperty(JobExecutor.PROPERTY_TOPICS)).thenReturn("a/**");
Mockito.when(ref1.getProperty(Constants.SERVICE_RANKING)).thenReturn(1);
Mockito.when(ref1.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
Mockito.when(bc.getService(ref1)).thenReturn(jc1);
jcs.bindJobExecutor(ref1);
assertNotNull(jcs.getExecutor("a/b"));
assertNull(jcs.getExecutor("a"));
assertNotNull(jcs.getExecutor("a/c"));
assertNotNull(jcs.getExecutor("a/b/a"));
}
use of org.osgi.framework.BundleContext in project sling by apache.
the class HealthCheckTestsProviderTest method setup.
@Before
public void setup() throws InvalidSyntaxException {
setupTimestamp = System.currentTimeMillis();
final ComponentContext ctx = Mockito.mock(ComponentContext.class);
// context properties
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(HealthCheckTestsProvider.PROP_TAG_GROUPS, TAG_GROUPS);
props.put(Constants.SERVICE_PID, getClass().getName());
Mockito.when(ctx.getProperties()).thenReturn(props);
// bundle context
final BundleContext bc = Mockito.mock(BundleContext.class);
Mockito.when(ctx.getBundleContext()).thenReturn(bc);
// HealthCheck ServiceReferences mocks
Mockito.when(bc.getServiceReferences(Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer<ServiceReference[]>() {
@Override
public ServiceReference[] answer(InvocationOnMock invocation) throws Throwable {
return getMockReferences(bc, (String) invocation.getArguments()[1]);
}
});
provider = new HealthCheckTestsProvider() {
{
activate(ctx);
}
};
}
use of org.osgi.framework.BundleContext in project sling by apache.
the class OsgiScriptBindingsProviderTest method testInactiveBundles.
@Test
public void testInactiveBundles() throws Exception {
final BundleContext ctx = Mockito.mock(BundleContext.class);
final Bundle[] bundles = { mockBundle(false, true), mockBundle(false, false), mockBundle(false, true), mockBundle(true, false) };
Mockito.when(ctx.getBundles()).thenReturn(bundles);
final FormattingResultLog resultLog = new FormattingResultLog();
final OsgiScriptBindingsProvider.OsgiBinding b = new OsgiScriptBindingsProvider.OsgiBinding(ctx, resultLog);
assertEquals(1, b.inactiveBundlesCount());
}
Aggregations