Search in sources :

Example 36 with BundleContext

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"));
}
Also used : JobConsumer(org.apache.sling.event.jobs.consumer.JobConsumer) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 37 with BundleContext

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"));
}
Also used : JobExecutor(org.apache.sling.event.jobs.consumer.JobExecutor) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 38 with BundleContext

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"));
}
Also used : JobExecutor(org.apache.sling.event.jobs.consumer.JobExecutor) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 39 with BundleContext

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);
        }
    };
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HealthCheckTestsProvider(org.apache.sling.hc.junitbridge.HealthCheckTestsProvider) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 40 with BundleContext

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());
}
Also used : Bundle(org.osgi.framework.Bundle) FormattingResultLog(org.apache.sling.hc.util.FormattingResultLog) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

BundleContext (org.osgi.framework.BundleContext)1052 Test (org.junit.Test)361 Bundle (org.osgi.framework.Bundle)298 ServiceReference (org.osgi.framework.ServiceReference)229 File (java.io.File)119 Hashtable (java.util.Hashtable)114 HashMap (java.util.HashMap)98 ArrayList (java.util.ArrayList)97 IOException (java.io.IOException)75 ServiceRegistration (org.osgi.framework.ServiceRegistration)68 BundleException (org.osgi.framework.BundleException)60 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)59 Equinox (org.eclipse.osgi.launch.Equinox)51 ComponentContext (org.osgi.service.component.ComponentContext)50 Dictionary (java.util.Dictionary)48 Before (org.junit.Before)48 Properties (java.util.Properties)47 LinkedHashMap (java.util.LinkedHashMap)46 URL (java.net.URL)43 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)40