Search in sources :

Example 6 with BundleContext

use of org.osgi.framework.BundleContext 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 7 with BundleContext

use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.

the class OsgiUtilTest method testFrameworkLookupWithNonTrimmedString.

@Test
public void testFrameworkLookupWithNonTrimmedString() {
    BundleContext context = mock(BundleContext.class);
    doReturn("   ").when(context).getProperty("name");
    assertNull(lookup(context, "name"));
}
Also used : BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 8 with BundleContext

use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.

the class OsgiUtilTest method testFrameworkLookupWithEmptyString.

@Test
public void testFrameworkLookupWithEmptyString() {
    BundleContext context = mock(BundleContext.class);
    doReturn("").when(context).getProperty("name");
    assertNull(lookup(context, "name"));
}
Also used : BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 9 with BundleContext

use of org.osgi.framework.BundleContext 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)

Example 10 with BundleContext

use of org.osgi.framework.BundleContext in project jackrabbit-oak by apache.

the class SecurityProviderRegistration method maybeRegister.

private void maybeRegister() {
    BundleContext context;
    log.info("Trying to register a SecurityProvider...");
    synchronized (this) {
        if (this.context == null) {
            log.info("Aborting: no BundleContext is available");
            return;
        }
        if (!preconditions.areSatisfied()) {
            log.info("Aborting: preconditions are not satisfied: {}", preconditions);
            return;
        }
        if (registration != null) {
            log.info("Aborting: a SecurityProvider is already registered");
            return;
        }
        if (registering) {
            log.info("Aborting: a SecurityProvider is already being registered");
            return;
        }
        // Mark the start of a registration process.
        registering = true;
        // Save the BundleContext for local usage.
        context = this.context;
    }
    // Register the SecurityProvider.
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put("type", "default");
    ServiceRegistration registration = context.registerService(SecurityProvider.class.getName(), createSecurityProvider(context), properties);
    synchronized (this) {
        this.registration = registration;
        this.registering = false;
    }
    log.info("SecurityProvider instance registered");
}
Also used : Hashtable(java.util.Hashtable) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

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