use of org.apache.aries.subsystem.scope.Scope 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.Scope in project aries by apache.
the class AbstractTest method findChildScope.
protected Scope findChildScope(String name, Scope parent) {
assertNotNull(name);
assertNotNull(parent);
Scope result = null;
for (Scope child : parent.getChildren()) {
if (name.equals(child.getName())) {
result = child;
break;
}
}
assertNotNull(result);
return result;
}
use of org.apache.aries.subsystem.scope.Scope in project aries by apache.
the class BasicTest method testCreateChildScope.
@Test
public void testCreateChildScope() throws Exception {
Scope scope = getScope();
String name = "scope1";
ScopeUpdate parent = scope.newScopeUpdate();
ScopeUpdate child = parent.newChild(name);
parent.getChildren().add(child);
assertTrue(parent.commit());
Collection<Scope> children = scope.getChildren();
assertEquals(1, children.size());
Scope feature1 = null;
for (Scope s : children) {
if (name.equals(s.getName())) {
feature1 = s;
break;
}
}
assertNotNull(feature1);
assertEmpty(feature1.getBundles());
assertEmpty(feature1.getChildren());
assertEquals(1, feature1.getId());
assertNull(feature1.getLocation());
assertEquals(name, feature1.getName());
assertEquals(scope, feature1.getParent());
assertEmpty(feature1.getSharePolicies(SharePolicy.TYPE_EXPORT));
assertEmpty(feature1.getSharePolicies(SharePolicy.TYPE_IMPORT));
}
use of org.apache.aries.subsystem.scope.Scope 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.Scope in project aries by apache.
the class MoveBundleTest method test2.
/**
* Create one scope off of the root scope with the following structure.
* R
* |
* S
* 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
* S without removing it from R. This should result in an
* IllegalStateException. Finally, correct the error using the same
* ScopeUpdate objects and commit again. This should succeed, and the bundle
* should now be in S.
* @throws Exception
*/
@Test
public void test2() throws Exception {
Bundle tb2 = installBundle("tb-2.jar");
Scope root = getScope();
ScopeUpdate rootUpdate = root.newScopeUpdate();
ScopeUpdate sUpdate = rootUpdate.newChild("S");
rootUpdate.getChildren().add(sUpdate);
rootUpdate.commit();
Scope s = sUpdate.getScope();
assertTrue(root.getBundles().contains(tb2));
assertFalse(s.getBundles().contains(tb2));
rootUpdate = root.newScopeUpdate();
sUpdate = findChildUpdate("S", rootUpdate);
sUpdate.getBundles().add(tb2);
try {
rootUpdate.commit();
fail();
} catch (IllegalStateException e) {
// Okay.
}
assertTrue(root.getBundles().contains(tb2));
assertFalse(s.getBundles().contains(tb2));
rootUpdate.getBundles().remove(tb2);
rootUpdate.commit();
assertFalse(root.getBundles().contains(tb2));
assertTrue(s.getBundles().contains(tb2));
tb2.uninstall();
}
Aggregations