Search in sources :

Example 21 with ComponentContext

use of org.osgi.service.component.ComponentContext in project sling by apache.

the class MockComponentContextTest method testProvidedProperties.

@Test
public void testProvidedProperties() {
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("prop1", "value1");
    props.put("prop2", 25);
    ComponentContext componentContextWithProperties = MockOsgi.newComponentContext(props);
    Dictionary contextProps = componentContextWithProperties.getProperties();
    assertEquals(2, contextProps.size());
    assertEquals("value1", contextProps.get("prop1"));
    assertEquals(25, contextProps.get("prop2"));
}
Also used : Dictionary(java.util.Dictionary) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Example 22 with ComponentContext

use of org.osgi.service.component.ComponentContext in project sling by apache.

the class MockComponentContextTest method testGetUsingBundle.

@Test
public void testGetUsingBundle() {
    // test context without using bundle
    assertNull(underTest.getUsingBundle());
    // test context with using bundle
    Bundle usingBundle = mock(Bundle.class);
    ComponentContext contextWithUsingBundle = MockOsgi.componentContext().usingBundle(usingBundle).build();
    assertSame(usingBundle, contextWithUsingBundle.getUsingBundle());
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Bundle(org.osgi.framework.Bundle) Test(org.junit.Test)

Example 23 with ComponentContext

use of org.osgi.service.component.ComponentContext in project jackrabbit-oak by apache.

the class OsgiUtilTest method testComponentLookupWithNotFoundValue.

@Test
public void testComponentLookupWithNotFoundValue() {
    Dictionary properties = mock(Dictionary.class);
    doReturn(null).when(properties).get("name");
    ComponentContext context = mock(ComponentContext.class);
    doReturn(properties).when(context).getProperties();
    assertNull(lookup(context, "name"));
}
Also used : Dictionary(java.util.Dictionary) ComponentContext(org.osgi.service.component.ComponentContext) Test(org.junit.Test)

Example 24 with ComponentContext

use of org.osgi.service.component.ComponentContext in project jackrabbit-oak by apache.

the class OsgiUtilTest method testFallbackLookupWithValueInFramework.

@Test
public void testFallbackLookupWithValueInFramework() {
    Dictionary dictionary = mock(Dictionary.class);
    doReturn(null).when(dictionary).get("cname");
    BundleContext bundleContext = mock(BundleContext.class);
    doReturn("value").when(bundleContext).getProperty("fname");
    ComponentContext componentContext = mock(ComponentContext.class);
    doReturn(dictionary).when(componentContext).getProperties();
    doReturn(bundleContext).when(componentContext).getBundleContext();
    assertEquals("value", lookupConfigurationThenFramework(componentContext, "cname", "fname"));
    assertEquals("value", lookupFrameworkThenConfiguration(componentContext, "cname", "fname"));
}
Also used : Dictionary(java.util.Dictionary) ComponentContext(org.osgi.service.component.ComponentContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 25 with ComponentContext

use of org.osgi.service.component.ComponentContext in project jackrabbit-oak by apache.

the class OsgiUtilTest method testComponentLookupWithEmptyString.

@Test
public void testComponentLookupWithEmptyString() {
    Dictionary properties = mock(Dictionary.class);
    doReturn("").when(properties).get("name");
    ComponentContext context = mock(ComponentContext.class);
    doReturn(properties).when(context).getProperties();
    assertNull(lookup(context, "name"));
}
Also used : Dictionary(java.util.Dictionary) ComponentContext(org.osgi.service.component.ComponentContext) Test(org.junit.Test)

Aggregations

ComponentContext (org.osgi.service.component.ComponentContext)35 Test (org.junit.Test)16 Dictionary (java.util.Dictionary)14 BundleContext (org.osgi.framework.BundleContext)11 Hashtable (java.util.Hashtable)5 Expectations (org.jmock.Expectations)4 HashMap (java.util.HashMap)3 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)3 StringSource (org.apache.stanbol.enhancer.servicesapi.impl.StringSource)3 BeforeClass (org.junit.BeforeClass)3 ServiceReference (org.osgi.framework.ServiceReference)3 IRI (org.apache.clerezza.commons.rdf.IRI)2 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)2 LuceneLabelTokenizer (org.apache.stanbol.enhancer.engines.entitylinking.labeltokenizer.lucene.LuceneLabelTokenizer)2 Mockery (org.jmock.Mockery)2 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1