use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class GetScopeServiceTest method test3.
/**
* A new scope is created as a child of the root scope and the tb3 bundle
* is added to it. The tb3 bundle should receive and be in the new scope.
* @throws Exception
*/
@Test
public void test3() throws Exception {
Scope scope = getScope();
ScopeUpdate scopeUpdate = scope.newScopeUpdate();
ScopeUpdate child = scopeUpdate.newChild("tb3");
scopeUpdate.getChildren().add(child);
String location = getBundleLocation("tb-3.jar");
URL url = new URL(location);
InstallInfo installInfo = new InstallInfo(location, url.openStream());
child.getBundlesToInstall().add(installInfo);
addPackageImportPolicy("org.osgi.framework", child);
addPackageImportPolicy("org.apache.aries.subsystem.scope", child);
addPackageImportPolicy("org.apache.aries.subsystem.scope.itests", child);
addServiceImportPolicy(Scope.class, child);
addServiceExportPolicy(ScopeProvider.class, child);
scopeUpdate.commit();
Bundle bundle = bundleContext.getBundle(location);
bundle.start();
ServiceReference<ScopeProvider> scopeProviderRef = bundleContext.getServiceReference(ScopeProvider.class);
ScopeProvider scopeProvider = bundleContext.getService(scopeProviderRef);
scope = scopeProvider.getScope();
assertEquals("tb3", scope.getName());
assertTrue(scope.getBundles().contains(bundle));
bundleContext.ungetService(scopeProviderRef);
bundle.uninstall();
}
use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class BasicTest method testInstallBundleIntoRootScope.
@Test
public void testInstallBundleIntoRootScope() throws Exception {
Scope scope = getScope();
int previousSize = scope.getBundles().size();
String location = getBundleLocation("tb-2.jar");
URL url = new URL(location);
InstallInfo tb2Info = new InstallInfo(location, url.openStream());
ScopeUpdate scopeUpdate = scope.newScopeUpdate();
scopeUpdate.getBundlesToInstall().add(tb2Info);
assertTrue(scopeUpdate.commit());
Bundle b = bundleContext.getBundle(location);
assertNotNull(b);
Collection<Bundle> bundles = scope.getBundles();
assertEquals(previousSize + 1, bundles.size());
assertTrue(bundles.contains(b));
}
use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class PersistenceTest method test4.
/**
* Create two scopes off of the root scope with the following structure.
*
* R
* / \
* S1 S2
*
* S1 contains bundle tb1, one import policy, and one export policy.
* S2 contains bundle tb2 and two import policies.
*
* This configuration should persist between restarts of the Scope Admin
* bundle.
*
* @throws Exception
*/
@Test
public void test4() throws Exception {
Scope root = getScope();
ScopeUpdate rootUpdate = root.newScopeUpdate();
ScopeUpdate s1Update = rootUpdate.newChild("S1");
rootUpdate.getChildren().add(s1Update);
ScopeUpdate s2Update = rootUpdate.newChild("S2");
rootUpdate.getChildren().add(s2Update);
s1Update.getBundlesToInstall().add(new InstallInfo(null, new URL(getBundleLocation("tb-1.jar"))));
s2Update.getBundlesToInstall().add(new InstallInfo(null, new URL(getBundleLocation("tb-2.jar"))));
addPackageImportPolicy("org.osgi.framework", s1Update);
addPackageExportPolicy("org.apache.aries.subsystem.scope.itests.tb1", s1Update);
addPackageImportPolicy("org.osgi.framework", s2Update);
addPackageImportPolicy("org.apache.aries.subsystem.scope.itests.tb1", s2Update);
assertTrue(rootUpdate.commit());
root = getScope();
assertEquals(2, root.getChildren().size());
Scope s1 = findChildScope("S1", root);
Bundle tb1 = findBundle("org.apache.aries.subsystem.scope.itests.tb1", s1);
assertNotNull(tb1);
assertTrue(s1.getBundles().contains(tb1));
assertEquals(1, s1.getSharePolicies(SharePolicy.TYPE_IMPORT).get("osgi.wiring.package").size());
assertEquals(1, s1.getSharePolicies(SharePolicy.TYPE_EXPORT).get("osgi.wiring.package").size());
Scope s2 = findChildScope("S2", root);
Bundle tb2 = findBundle("org.apache.aries.subsystem.scope.itests.tb2", s2);
assertNotNull(tb2);
assertTrue(s2.getBundles().contains(tb2));
assertEquals(2, s2.getSharePolicies(SharePolicy.TYPE_IMPORT).get("osgi.wiring.package").size());
Bundle scopeAdmin = findBundle("org.apache.aries.subsystem.scope.impl");
assertNotNull(scopeAdmin);
scopeAdmin.stop();
scopeAdmin.start();
root = getScope();
assertEquals(2, root.getChildren().size());
s1 = findChildScope("S1", root);
assertTrue(s1.getBundles().contains(tb1));
assertEquals(1, s1.getSharePolicies(SharePolicy.TYPE_IMPORT).get("osgi.wiring.package").size());
assertEquals(1, s1.getSharePolicies(SharePolicy.TYPE_EXPORT).get("osgi.wiring.package").size());
s2 = findChildScope("S2", root);
assertTrue(s2.getBundles().contains(tb2));
assertEquals(2, s2.getSharePolicies(SharePolicy.TYPE_IMPORT).get("osgi.wiring.package").size());
}
use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class ScopeUpdateImpl method installBundles.
private void installBundles() throws BundleException {
for (InstallInfo installInfo : getBundlesToInstall()) {
ScopeManager.installingBundleToScope.put(installInfo.getLocation(), scope);
Activator.getBundleContext().installBundle(installInfo.getLocation(), installInfo.getContent());
}
}
use of org.apache.aries.subsystem.scope.InstallInfo in project aries by apache.
the class BundleVisibilityTest method test1.
/**
* Install a bundle into the same scope as this one. Both bundles should be
* able to see each other.
* @throws Exception
*/
@Test
public void test1() throws Exception {
Scope scope = getScope();
assertTrue(scope.getBundles().contains(bundleContext.getBundle()));
ScopeUpdate scopeUpdate = scope.newScopeUpdate();
String location = getBundleLocation("tb-4.jar");
assertNull(bundleContext.getBundle(location));
URL url = new URL(location);
InstallInfo installInfo = new InstallInfo(location, url.openStream());
scopeUpdate.getBundlesToInstall().add(installInfo);
scopeUpdate.commit();
Bundle bundle = bundleContext.getBundle(location);
assertTrue(scope.getBundles().contains(bundle));
bundle.start();
ServiceReference<BundleProvider> bundleProviderRef = bundleContext.getServiceReference(BundleProvider.class);
BundleProvider bundleProvider = bundleContext.getService(bundleProviderRef);
assertTrue(bundleProvider.getBundles().contains(bundleContext.getBundle()));
assertTrue(Arrays.asList(bundleContext.getBundles()).contains(bundle));
assertNotNull(bundleContext.getBundle(bundle.getBundleId()));
assertNotNull(bundleProvider.getBundle(bundle.getBundleId()));
bundleContext.ungetService(bundleProviderRef);
bundle.uninstall();
}
Aggregations