use of org.osgi.framework.BundleContext in project karaf by apache.
the class GuardingFindHookTest method testNullFilter.
@Test
public void testNullFilter() throws Exception {
BundleContext hookBC = mockBundleContext(5L);
GuardProxyCatalog gpc = new GuardProxyCatalog(hookBC);
GuardingFindHook gfh = new GuardingFindHook(hookBC, gpc, null);
// should just do nothing
gfh.find(null, null, null, true, null);
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class GuardProxyCatalogTest method testAssignRoles3.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testAssignRoles3() throws Exception {
abstract class MyAbstractClass implements TestServiceAPI, TestServiceAPI2 {
}
Dictionary<String, Object> config = new Hashtable<>();
config.put(Constants.SERVICE_PID, "foobar");
config.put("service.guard", "(objectClass=" + TestServiceAPI2.class.getName() + ")");
config.put("doit", "X");
BundleContext bc = mockConfigAdminBundleContext(config);
Map<ServiceReference, Object> serviceMap = new HashMap<>();
testCreateProxy(bc, new Class[] { TestServiceAPI.class, TestServiceAPI2.class }, new MyAbstractClass() {
@Override
public String doit() {
return null;
}
@Override
public String doit(String s) {
return null;
}
}, serviceMap);
assertEquals(1, serviceMap.size());
assertEquals(Collections.singleton("X"), serviceMap.keySet().iterator().next().getProperty(GuardProxyCatalog.SERVICE_GUARD_ROLES_PROPERTY));
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class GuardProxyCatalogTest method testAssignRoles4.
@SuppressWarnings("unchecked")
@Test
public void testAssignRoles4() throws Exception {
Dictionary<String, Object> config = new Hashtable<>();
config.put(Constants.SERVICE_PID, "foobar");
config.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")");
config.put("somemethod", "b");
config.put("someOtherMethod", "b");
config.put("somethingelse", "*");
BundleContext bc = mockConfigAdminBundleContext(config);
Dictionary<String, Object> proxyProps = testCreateProxy(bc, TestServiceAPI.class, new TestService());
Collection<String> result = (Collection<String>) proxyProps.get(GuardProxyCatalog.SERVICE_GUARD_ROLES_PROPERTY);
assertEquals(1, result.size());
assertEquals("b", result.iterator().next());
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class GuardProxyCatalogTest method testGuardProxyCatalog.
@Test
public void testGuardProxyCatalog() throws Exception {
Bundle b = EasyMock.createMock(Bundle.class);
EasyMock.expect(b.getBundleId()).andReturn(9823L).anyTimes();
EasyMock.replay(b);
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
bc.addServiceListener(EasyMock.isA(ServiceListener.class));
EasyMock.expectLastCall().once();
String caFilter = "(&(objectClass=org.osgi.service.cm.ConfigurationAdmin)" + "(!(" + GuardProxyCatalog.PROXY_SERVICE_KEY + "=*)))";
EasyMock.expect(bc.createFilter(caFilter)).andReturn(FrameworkUtil.createFilter(caFilter)).anyTimes();
String pmFilter = "(&(objectClass=org.apache.aries.proxy.ProxyManager)" + "(!(" + GuardProxyCatalog.PROXY_SERVICE_KEY + "=*)))";
EasyMock.expect(bc.createFilter(pmFilter)).andReturn(FrameworkUtil.createFilter(pmFilter)).anyTimes();
EasyMock.replay(bc);
GuardProxyCatalog gpc = new GuardProxyCatalog(bc);
assertTrue("Service Tracker for ConfigAdmin should be opened", gpc.configAdminTracker.getTrackingCount() != -1);
assertTrue("Service Tracker for ProxyManager should be opened", gpc.proxyManagerTracker.getTrackingCount() != -1);
EasyMock.verify(bc);
// Add some more behaviour checks to the bundle context
EasyMock.reset(bc);
bc.removeServiceListener(EasyMock.isA(ServiceListener.class));
EasyMock.expectLastCall().once();
EasyMock.replay(bc);
gpc.close();
assertEquals("Service Tracker for ConfigAdmin should be closed", -1, gpc.configAdminTracker.getTrackingCount());
assertEquals("Service Tracker for ProxyManager should be closed", -1, gpc.proxyManagerTracker.getTrackingCount());
EasyMock.verify(bc);
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class ActivatorTest method testStartActivatorNoServicesSecured.
@Test
public void testStartActivatorNoServicesSecured() throws Exception {
// keep the old properties. Note that the Properties 'copy constructor' new Properties(props)
// doesn't actually copy, hence the awkward setup here...
Properties oldProps = new Properties();
oldProps.putAll(System.getProperties());
try {
Properties newProps = removeProperties(System.getProperties(), GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP);
System.setProperties(newProps);
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.replay(bc);
Activator a = new Activator();
a.start(bc);
assertNull(a.guardProxyCatalog);
} finally {
System.setProperties(oldProps);
}
}
Aggregations