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