Search in sources :

Example 1 with ComponentContext

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

the class OsgiUtilTest method testFallbackLookupWithNoValue.

@Test
public void testFallbackLookupWithNoValue() {
    Dictionary dictionary = mock(Dictionary.class);
    doReturn(null).when(dictionary).get("cname");
    BundleContext bundleContext = mock(BundleContext.class);
    doReturn(null).when(bundleContext).getProperty("fname");
    ComponentContext componentContext = mock(ComponentContext.class);
    doReturn(dictionary).when(componentContext).getProperties();
    doReturn(bundleContext).when(componentContext).getBundleContext();
    assertNull(lookupConfigurationThenFramework(componentContext, "cname", "fname"));
    assertNull(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 2 with ComponentContext

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

the class OsgiUtilTest method testComponentLookupWithNonStringValue.

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

Example 3 with ComponentContext

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

the class OsgiUtilTest method testComponentLookupWithNonTrimmedString.

@Test
public void testComponentLookupWithNonTrimmedString() {
    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)

Example 4 with ComponentContext

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

the class OsgiUtilTest method testComponentLookupWithStringValue.

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

Example 5 with ComponentContext

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

the class OsgiUtilTest method testFallbackLookupWithValueInComponent.

@Test
public void testFallbackLookupWithValueInComponent() {
    Dictionary dictionary = mock(Dictionary.class);
    doReturn("value").when(dictionary).get("cname");
    BundleContext bundleContext = mock(BundleContext.class);
    doReturn(null).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)

Aggregations

ComponentContext (org.osgi.service.component.ComponentContext)78 BundleContext (org.osgi.framework.BundleContext)49 Test (org.junit.Test)34 Dictionary (java.util.Dictionary)17 Before (org.junit.Before)12 JaxbUser (org.opencastproject.security.api.JaxbUser)11 SecurityService (org.opencastproject.security.api.SecurityService)11 Hashtable (java.util.Hashtable)10 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)10 JaxbRole (org.opencastproject.security.api.JaxbRole)10 File (java.io.File)9 Bundle (org.osgi.framework.Bundle)9 URI (java.net.URI)8 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)7 User (org.opencastproject.security.api.User)7 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)7 ServiceReference (org.osgi.framework.ServiceReference)7 Workspace (org.opencastproject.workspace.api.Workspace)6 Version (org.osgi.framework.Version)6 IOException (java.io.IOException)5