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"));
}
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());
}
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"));
}
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"));
}
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"));
}
Aggregations