Search in sources :

Example 6 with Scope

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();
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Test(org.junit.Test)

Example 7 with Scope

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;
}
Also used : Scope(org.apache.aries.subsystem.scope.Scope)

Example 8 with Scope

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));
}
Also used : Scope(org.apache.aries.subsystem.scope.Scope) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) Test(org.junit.Test)

Example 9 with Scope

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));
}
Also used : InstallInfo(org.apache.aries.subsystem.scope.InstallInfo) Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) URL(java.net.URL) Test(org.junit.Test)

Example 10 with Scope

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();
}
Also used : Scope(org.apache.aries.subsystem.scope.Scope) Bundle(org.osgi.framework.Bundle) ScopeUpdate(org.apache.aries.subsystem.scope.ScopeUpdate) Test(org.junit.Test)

Aggregations

Scope (org.apache.aries.subsystem.scope.Scope)29 Bundle (org.osgi.framework.Bundle)22 Test (org.junit.Test)20 ScopeUpdate (org.apache.aries.subsystem.scope.ScopeUpdate)16 URL (java.net.URL)12 InstallInfo (org.apache.aries.subsystem.scope.InstallInfo)12 IOException (java.io.IOException)5 MalformedURLException (java.net.MalformedURLException)5 Ignore (org.junit.Ignore)5 BundleException (org.osgi.framework.BundleException)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SharePolicy (org.apache.aries.subsystem.scope.SharePolicy)4 Filter (org.osgi.framework.Filter)4 ServiceReference (org.osgi.framework.ServiceReference)3 HelloIsolation (org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)2 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)2 BundleContext (org.osgi.framework.BundleContext)2 Permission (java.security.Permission)1