use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class MoveBundleTest method test1.
/**
* Create two scopes off of the root scope with the following structure.
* R
* / \
* S1 S2
* Install a bundle using the test bundle's bundle context. This should add
* the bundle to R since the test bundle is in R. Next, move the bundle
* into S1. Finally, move the bundle into S2.
* @throws Exception
*/
@Test
@Ignore
public void test1() throws Exception {
Bundle tb2 = installBundle("tb-2.jar");
Scope root = getScope();
ScopeUpdate rootUpdate = root.newScopeUpdate();
ScopeUpdate s1Update = rootUpdate.newChild("S1");
ScopeUpdate s2Update = rootUpdate.newChild("S2");
rootUpdate.getChildren().add(s1Update);
rootUpdate.getChildren().add(s2Update);
rootUpdate.commit();
Scope s1 = s1Update.getScope();
Scope s2 = s2Update.getScope();
assertTrue(root.getBundles().contains(tb2));
assertFalse(s1.getBundles().contains(tb2));
assertFalse(s2.getBundles().contains(tb2));
rootUpdate = root.newScopeUpdate();
rootUpdate.getBundles().remove(tb2);
s1Update = findChildUpdate("S1", rootUpdate);
s1Update.getBundles().add(tb2);
rootUpdate.commit();
assertFalse(root.getBundles().contains(tb2));
assertTrue(s1.getBundles().contains(tb2));
assertFalse(s2.getBundles().contains(tb2));
rootUpdate = root.newScopeUpdate();
s1Update = findChildUpdate("S1", rootUpdate);
s1Update.getBundles().remove(tb2);
s2Update = findChildUpdate("S2", rootUpdate);
s2Update.getBundles().add(tb2);
rootUpdate.commit();
assertFalse(root.getBundles().contains(tb2));
assertFalse(s1.getBundles().contains(tb2));
assertTrue(s2.getBundles().contains(tb2));
tb2.uninstall();
}
use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class PersistenceTest method test2.
/**
* Stopping and starting the Scope Admin bundle should cause it to pull
* from the persistent storage. If nothing changed after the original
* bundle start, the persisted root bundle should look exactly the same
* as before.
*
* @throws Exception
*/
@Test
public void test2() throws Exception {
Scope scope = getScope();
Bundle bundle = findBundle("org.apache.aries.subsystem.scope.impl");
assertNotNull(bundle);
bundle.stop();
bundle.start();
assertEquals(0, scope.getId());
assertEquals("root", scope.getName());
assertEquals(null, scope.getLocation());
assertEquals(null, scope.getParent());
assertEquals(0, scope.getChildren().size());
assertCollectionEquals(Arrays.asList(bundleContext.getBundles()), scope.getBundles());
assertEquals(0, scope.getSharePolicies(SharePolicy.TYPE_EXPORT).size());
assertEquals(0, scope.getSharePolicies(SharePolicy.TYPE_IMPORT).size());
}
use of org.apache.aries.subsystem.scope.Scope 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.Scope in project aries by apache.
the class Scopes method addScope.
public synchronized void addScope(ScopeImpl scope) {
idToScope.put(scope.getId(), scope);
for (Bundle bundle : scope.getBundles()) {
bundleToScope.put(bundle, scope);
}
ScopeImpl parent = (ScopeImpl) scope.getParent();
if (parent != null) {
parent.addChild(scope);
}
insert(scope);
for (Scope child : scope.getChildren()) {
addScope((ScopeImpl) child);
}
}
use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class Scopes method removeScope.
public synchronized void removeScope(ScopeImpl scope) {
for (Scope child : scope.getChildren()) {
removeScope((ScopeImpl) child);
}
idToScope.remove(scope.getId());
for (Bundle bundle : scope.getBundles()) {
bundleToScope.remove(bundle);
}
ScopeImpl parent = (ScopeImpl) scope.getParent();
if (parent != null) {
parent.removeChild(scope);
}
delete(scope);
}
Aggregations