Search in sources :

Example 91 with BundleContext

use of org.osgi.framework.BundleContext in project sling by apache.

the class JobConsumerManagerTest method testSubCategoryMappingConsumer.

@Test
public void testSubCategoryMappingConsumer() {
    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"));
    assertNotNull(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 92 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 93 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 94 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 95 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)

Aggregations

BundleContext (org.osgi.framework.BundleContext)524 Test (org.junit.Test)186 Bundle (org.osgi.framework.Bundle)175 ServiceReference (org.osgi.framework.ServiceReference)126 File (java.io.File)82 Hashtable (java.util.Hashtable)75 HashMap (java.util.HashMap)70 Equinox (org.eclipse.osgi.launch.Equinox)51 BundleException (org.osgi.framework.BundleException)51 ArrayList (java.util.ArrayList)50 LinkedHashMap (java.util.LinkedHashMap)45 ServiceRegistration (org.osgi.framework.ServiceRegistration)41 IOException (java.io.IOException)40 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)38 URL (java.net.URL)33 Dictionary (java.util.Dictionary)32 Matchers.anyString (org.mockito.Matchers.anyString)28 Before (org.junit.Before)26 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)26 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)18