use of org.osgi.framework.BundleContext in project karaf by apache.
the class JdbcLoginModuleTest method setUp.
@Before
public void setUp() throws Exception {
System.setProperty("derby.stream.error.file", "target/derby.log");
// Create datasource
dataSource = new EmbeddedDataSource40();
dataSource.setDatabaseName("memory:db");
dataSource.setCreateDatabase("create");
// Delete tables
try (Connection connection = dataSource.getConnection()) {
connection.setAutoCommit(true);
try {
try (Statement statement = connection.createStatement()) {
statement.execute("drop table USERS");
}
} catch (SQLException e) {
// Ignore
}
try {
try (Statement statement = connection.createStatement()) {
statement.execute("drop table ROLES");
}
} catch (SQLException e) {
// Ignore
}
connection.commit();
}
// Create tables
try (Connection connection = dataSource.getConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute("create table USERS (USERNAME VARCHAR(32) PRIMARY KEY, PASSWORD VARCHAR(32))");
}
try (Statement statement = connection.createStatement()) {
statement.execute("create table ROLES (USERNAME VARCHAR(32), ROLE VARCHAR(1024))");
}
connection.commit();
}
// Mocks
BundleContext context = EasyMock.createMock(BundleContext.class);
ServiceReference reference = EasyMock.createMock(ServiceReference.class);
// Create options
options = new HashMap<>();
options.put(JDBCUtils.DATASOURCE, "osgi:" + DataSource.class.getName());
options.put(BundleContext.class.getName(), context);
expect(context.getServiceReferences(DataSource.class.getName(), null)).andReturn(new ServiceReference[] { reference });
expect((DataSource) context.getService(reference)).andReturn(dataSource);
expect(context.ungetService(reference)).andReturn(true);
EasyMock.replay(context);
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class BlueprintCommand method createNewAction.
public Action createNewAction() {
Action action = (Action) blueprintContainer.getComponentInstance(actionId);
if (action instanceof BlueprintContainerAware) {
((BlueprintContainerAware) action).setBlueprintContainer(blueprintContainer);
}
if (action instanceof BundleContextAware) {
BundleContext context = (BundleContext) blueprintContainer.getComponentInstance("blueprintBundleContext");
((BundleContextAware) action).setBundleContext(context);
}
return action;
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class TestBundleFactory method createBundleContext.
public BundleContext createBundleContext() {
BundleContext bundleContext = createMock(BundleContext.class);
Bundle[] bundles = createBundles();
expect(bundleContext.getProperty("karaf.systemBundlesStartLevel")).andReturn(Integer.toString(50)).anyTimes();
expect(bundleContext.getBundles()).andReturn(bundles).anyTimes();
expect(bundleContext.getBundle(0)).andReturn(null).anyTimes();
expect(bundleContext.getBundle(1)).andReturn(bundles[0]).anyTimes();
expect(bundleContext.getBundle(2)).andReturn(bundles[1]).anyTimes();
replay(bundleContext);
return bundleContext;
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class InfoAction method getOsgiFramework.
String getOsgiFramework() {
try {
Callable<String> call = new Callable<String>() {
@Override
public String call() throws Exception {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
Bundle sysBundle = context.getBundle(0);
return sysBundle.getSymbolicName() + "-" + sysBundle.getVersion();
}
};
return call.call();
} catch (Throwable t) {
// We're not in OSGi, just safely return null
return null;
}
}
use of org.osgi.framework.BundleContext in project karaf by apache.
the class GuardProxyCatalogTest method testIsProxy.
@Test
public void testIsProxy() throws Exception {
BundleContext bc = mockBundleContext();
GuardProxyCatalog gpc = new GuardProxyCatalog(bc);
Dictionary<String, Object> props = new Hashtable<>();
props.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE);
assertTrue(gpc.isProxy(mockServiceReference(props)));
assertFalse(gpc.isProxy(mockServiceReference(new Hashtable<>())));
}
Aggregations