You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gc...@apache.org on 2011/03/04 18:14:07 UTC

svn commit: r1078060 [3/3] - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-itests/ subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ subsystem-itests/src/test/java/org/ops4j/...

Modified: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeAdminTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeAdminTest.java?rev=1078060&r1=1075924&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeAdminTest.java (original)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeAdminTest.java Fri Mar  4 17:14:05 2011
@@ -16,18 +16,18 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.subsystem.itests;
+package org.apache.aries.subsystem.scope.itests;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.equinox;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
-import java.io.FileOutputStream;
+import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -38,14 +38,9 @@ import java.util.Map;
 import org.apache.aries.subsystem.example.helloIsolation.HelloIsolation;
 import org.apache.aries.subsystem.scope.InstallInfo;
 import org.apache.aries.subsystem.scope.Scope;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
 import org.apache.aries.subsystem.scope.ScopeUpdate;
 import org.apache.aries.subsystem.scope.SharePolicy;
-import org.apache.aries.subsystem.scope.impl.ScopeAdminServiceFactory;
-import org.apache.aries.unittest.fixture.ArchiveFixture;
-import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
@@ -58,7 +53,7 @@ import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.wiring.Capability;
+import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.util.tracker.BundleTracker;
 import org.osgi.util.tracker.BundleTrackerCustomizer;
 
@@ -85,7 +80,7 @@ public class ScopeAdminTest extends Abst
     @Test
     public void testBundleServiceIsolation() throws Exception {
         // make sure we are using a framework that provides composite admin service
-        ScopeAdmin scopeAdmin = getOsgiService(ScopeAdmin.class);
+        Scope scopeAdmin = getOsgiService(Scope.class);
         assertNotNull("scope admin should not be null", scopeAdmin);
         System.out.println("able to get scope admin service");
 
@@ -129,10 +124,13 @@ public class ScopeAdminTest extends Abst
         ScopeUpdate su = scopeAdmin.newScopeUpdate();
         
         ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
+        su.getChildren().add(childScopeUpdate);
+        addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
+        addPackageImportPolicy("org.osgi.util.tracker", childScopeUpdate);
         
         // build up installInfo object for the scope
-        InstallInfo info1 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.3-SNAPSHOT"), "helloIsolation");
-        InstallInfo info2 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.3-SNAPSHOT"), "helloIsolationRef");
+        InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.4-SNAPSHOT"));
+        InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.4-SNAPSHOT"));
 
         List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
         bundlesToInstall.add(info1);
@@ -145,7 +143,7 @@ public class ScopeAdminTest extends Abst
         assertEquals("modify event count should be 0", 0, modifyEventCount);
         assertEquals("remove event count should be 0", 0, removeEventCount);
         // start all bundles in the scope scope_test1
-        Collection<Bundle> bundlesToStart = childScopeUpdate.getBundles();
+        Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
         for (Bundle b : bundlesToStart) {
             b.start();
             
@@ -176,7 +174,7 @@ public class ScopeAdminTest extends Abst
         // test bundle service find hook
         //ServiceReference sr = bundleContext.getServiceReference(HelloIsolation.class.getName());
         //assertNull("sr should be null", sr);
-        Collection<Scope> children = scopeAdmin.getScope().getChildren();
+        Collection<Scope> children = scopeAdmin.getChildren();
         assertEquals(1, children.size());
         
         for (Scope child : children) {
@@ -201,39 +199,49 @@ public class ScopeAdminTest extends Abst
         
         // remove child scope
         su = scopeAdmin.newScopeUpdate();
-        Collection<Scope> scopes = su.getToBeRemovedChildren();
+//        Collection<Scope> scopes = su.getToBeRemovedChildren();
+        Collection<ScopeUpdate> scopes = su.getChildren();
+        childScopeUpdate = scopes.iterator().next();
         
         // obtain child scope admin from service registry
-        String filter = "ScopeName=scope_test1";
-        ScopeAdmin childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        assertEquals(scopeAdmin.getScope(), childScopeAdmin.getParentScope());
-        scopes.add(childScopeAdmin.getScope());
+//        String filter = "ScopeName=scope_test1";
+//        Scope childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
+        Scope childScopeAdmin = childScopeUpdate.getScope();
+        assertEquals(scopeAdmin, childScopeAdmin.getParent());
+//        scopes.add(childScopeAdmin);
+        scopes.remove(childScopeUpdate);
         su.commit();
         
-        childScopeAdmin = null;
-        try {
-            childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        } catch (Exception ex) {
-            // ignore
-        }
-        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
+        assertFalse(scopeAdmin.getChildren().contains(childScopeAdmin));
+        su = scopeAdmin.newScopeUpdate();
+        assertFalse(su.getChildren().contains(childScopeUpdate));
+        
+//        childScopeAdmin = null;
+//        try {
+//            childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
+//        } catch (Exception ex) {
+//            // ignore
+//        }
+//        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
         
     }
     
     @Test
     public void testPackageIsolation() throws Exception {
         // make sure we are using a framework that provides composite admin service
-        ScopeAdmin scopeAdmin = getOsgiService(ScopeAdmin.class);
+        Scope scopeAdmin = getOsgiService(Scope.class);
         assertNotNull("scope admin should not be null", scopeAdmin);
         System.out.println("able to get scope admin service");
 
         ScopeUpdate su = scopeAdmin.newScopeUpdate();
         
         ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
-        
+        su.getChildren().add(childScopeUpdate);
+        addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
+        addPackageImportPolicy("org.osgi.util.tracker", childScopeUpdate);
         // build up installInfo object for the scope
-        InstallInfo info1 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.3-SNAPSHOT"), "helloIsolation");
-        InstallInfo info2 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.3-SNAPSHOT"), "helloIsolationRef");
+        InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.4-SNAPSHOT"));
+        InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.4-SNAPSHOT"));
 
         List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
         bundlesToInstall.add(info1);
@@ -243,7 +251,7 @@ public class ScopeAdminTest extends Abst
         su.commit();
         
         // start all bundles in the scope scope_test1
-        Collection<Bundle> bundlesToStart = childScopeUpdate.getBundles();
+        Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
         for (Bundle b : bundlesToStart) {
             b.start();
             
@@ -274,22 +282,29 @@ public class ScopeAdminTest extends Abst
         
         // remove child scope
         su = scopeAdmin.newScopeUpdate();
-        Collection<Scope> scopes = su.getToBeRemovedChildren();
-        
+//        Collection<Scope> scopes = su.getToBeRemovedChildren();
+        Collection<ScopeUpdate> scopes = su.getChildren();
+        childScopeUpdate = scopes.iterator().next();
         // obtain child scope admin from service registry
-        String filter = "ScopeName=scope_test1";
-        ScopeAdmin childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        assertEquals(scopeAdmin.getScope(), childScopeAdmin.getParentScope());
-        scopes.add(childScopeAdmin.getScope());
+//        String filter = "ScopeName=scope_test1";
+//        Scope childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
+        Scope childScopeAdmin = childScopeUpdate.getScope();
+        assertEquals(scopeAdmin, childScopeAdmin.getParent());
+//        scopes.add(childScopeAdmin);
+        scopes.remove(childScopeUpdate);
         su.commit();
         
-        childScopeAdmin = null;
-        try {
-            childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        } catch (Exception ex) {
-            // ignore
-        }
-        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
+        assertFalse(scopeAdmin.getChildren().contains(childScopeAdmin));
+        su = scopeAdmin.newScopeUpdate();
+        assertFalse(su.getChildren().contains(childScopeUpdate));
+        
+//        childScopeAdmin = null;
+//        try {
+//            childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
+//        } catch (Exception ex) {
+//            // ignore
+//        }
+//        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
         
     }
     
@@ -297,40 +312,42 @@ public class ScopeAdminTest extends Abst
     @Test
     public void testPackageSharingFromTestScope() throws Exception {
         // make sure we are using a framework that provides composite admin service
-        ScopeAdmin scopeAdmin = getOsgiService(ScopeAdmin.class);
+        Scope scopeAdmin = getOsgiService(Scope.class);
         assertNotNull("scope admin should not be null", scopeAdmin);
         System.out.println("able to get scope admin service");
 
         ScopeUpdate su = scopeAdmin.newScopeUpdate();
         
         ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
-        
+        su.getChildren().add(childScopeUpdate);
+        addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
+        addPackageImportPolicy("org.osgi.util.tracker", childScopeUpdate);
         Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
         final Filter filter1 = FrameworkUtil.createFilter(
                 "(&" + 
-                  "(osgi.package=org.apache.aries.subsystem.example.helloIsolation)" +
+                  "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" +
                 ")");
         final Filter filter2 = FrameworkUtil.createFilter(
                 "(&" + 
-                  "(osgi.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
+                  "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
                 ")");
-        List<SharePolicy> packagePolicies = sharePolicies.get(Capability.PACKAGE_CAPABILITY);
+        List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
         if (packagePolicies == null) {
             packagePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(Capability.PACKAGE_CAPABILITY, packagePolicies);
+            sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
         }
-        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, Capability.PACKAGE_CAPABILITY, filter1));
-        List<SharePolicy> servicePolicies = sharePolicies.get(ScopeAdminServiceFactory.SERVICE_CAPABILITY);
+        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
+        List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
         if (servicePolicies == null) {
             servicePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(ScopeAdminServiceFactory.SERVICE_CAPABILITY, servicePolicies);
+            sharePolicies.put("scope.share.service", servicePolicies);
         }
-        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, ScopeAdminServiceFactory.SERVICE_CAPABILITY, filter2));
+        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter2));
 
 
         // build up installInfo object for the scope
-        InstallInfo info1 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.3-SNAPSHOT"), "helloIsolation");
-        InstallInfo info2 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.3-SNAPSHOT"), "helloIsolationRef");
+        InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.4-SNAPSHOT"));
+        InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.4-SNAPSHOT"));
 
         List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
         bundlesToInstall.add(info1);
@@ -340,7 +357,7 @@ public class ScopeAdminTest extends Abst
         su.commit();
         
         // start all bundles in the scope scope_test1
-        Collection<Bundle> bundlesToStart = childScopeUpdate.getBundles();
+        Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
         for (Bundle b : bundlesToStart) {
             b.start();
             
@@ -360,22 +377,26 @@ public class ScopeAdminTest extends Abst
         helloIsolationRef.uninstall();
         // remove child scope
         su = scopeAdmin.newScopeUpdate();
-        Collection<Scope> scopes = su.getToBeRemovedChildren();
-        
+        Collection<ScopeUpdate> scopes = su.getChildren();
+        childScopeUpdate = scopes.iterator().next();
         // obtain child scope admin from service registry
-        String filter = "ScopeName=scope_test1";
-        ScopeAdmin childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        assertEquals(scopeAdmin.getScope(), childScopeAdmin.getParentScope());
-        scopes.add(childScopeAdmin.getScope());
+//        String filter = "ScopeName=scope_test1";
+        Scope childScopeAdmin = childScopeUpdate.getScope();
+        assertEquals(scopeAdmin, childScopeAdmin.getParent());
+        scopes.remove(childScopeUpdate);
         su.commit();
         
-        childScopeAdmin = null;
-        try {
-            childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        } catch (Exception ex) {
-            // ignore
-        }
-        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
+        assertFalse(scopeAdmin.getChildren().contains(childScopeAdmin));
+        su = scopeAdmin.newScopeUpdate();
+        assertFalse(su.getChildren().contains(childScopeUpdate));
+        
+//        childScopeAdmin = null;
+//        try {
+//            childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
+//        } catch (Exception ex) {
+//            // ignore
+//        }
+//        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
         
     }
 
@@ -393,39 +414,40 @@ public class ScopeAdminTest extends Abst
         }
         
         // make sure we are using a framework that provides composite admin service
-        ScopeAdmin scopeAdmin = getOsgiService(ScopeAdmin.class);
+        Scope scopeAdmin = getOsgiService(Scope.class);
         assertNotNull("scope admin should not be null", scopeAdmin);
         System.out.println("able to get scope admin service");
 
         ScopeUpdate su = scopeAdmin.newScopeUpdate();
         
         ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
-        
+        su.getChildren().add(childScopeUpdate);
+        addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
         Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
         final Filter filter1 = FrameworkUtil.createFilter(
                 "(&" + 
-                  "(osgi.package=org.apache.aries.subsystem.example.helloIsolation)" +
+                  "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" +
                 ")");
         final Filter filter2 = FrameworkUtil.createFilter(
                 "(&" + 
-                  "(osgi.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
+                  "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
                 ")");
-        List<SharePolicy> packagePolicies = sharePolicies.get(Capability.PACKAGE_CAPABILITY);
+        List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
         if (packagePolicies == null) {
             packagePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(Capability.PACKAGE_CAPABILITY,packagePolicies);
+            sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE,packagePolicies);
         }
-        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, Capability.PACKAGE_CAPABILITY, filter1));
-        List<SharePolicy> servicePolicies = sharePolicies.get(ScopeAdminServiceFactory.SERVICE_CAPABILITY);
+        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
+        List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
         if (servicePolicies == null) {
             servicePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(ScopeAdminServiceFactory.SERVICE_CAPABILITY, servicePolicies);
+            sharePolicies.put("scope.share.service", servicePolicies);
         }
-        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, ScopeAdminServiceFactory.SERVICE_CAPABILITY, filter2));
+        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, "scope.share.service", filter2));
 
 
         // build up installInfo object for the scope
-        InstallInfo info2 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.3-SNAPSHOT"), "helloIsolationRef");
+        InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.4-SNAPSHOT"));
 
         List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
         bundlesToInstall.add(info2);
@@ -434,11 +456,12 @@ public class ScopeAdminTest extends Abst
         su.commit();
         
         // start all bundles in the scope scope_test1
-        Collection<Bundle> bundlesToStart = childScopeUpdate.getBundles();
+        Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
         for (Bundle b : bundlesToStart) {
             try {
                 b.start();
             } catch (Exception ex) {
+            	ex.printStackTrace();
                 fail("should be able to start helloIsolationRef in scope_test1");
             }
             
@@ -449,22 +472,26 @@ public class ScopeAdminTest extends Abst
         
         // remove child scope
         su = scopeAdmin.newScopeUpdate();
-        Collection<Scope> scopes = su.getToBeRemovedChildren();
-        
+        Collection<ScopeUpdate> scopes = su.getChildren();
+        childScopeUpdate = scopes.iterator().next();
         // obtain child scope admin from service registry
-        String filter = "ScopeName=scope_test1";
-        ScopeAdmin childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        assertEquals(scopeAdmin.getScope(), childScopeAdmin.getParentScope());
-        scopes.add(childScopeAdmin.getScope());
+//        String filter = "ScopeName=scope_test1";
+        Scope childScopeAdmin = childScopeUpdate.getScope();
+        assertEquals(scopeAdmin, childScopeAdmin.getParent());
+        scopes.remove(childScopeUpdate);
         su.commit();
         
-        childScopeAdmin = null;
-        try {
-            childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        } catch (Exception ex) {
-            // ignore
-        }
-        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
+        assertFalse(scopeAdmin.getChildren().contains(childScopeAdmin));
+        su = scopeAdmin.newScopeUpdate();
+        assertFalse(su.getChildren().contains(childScopeUpdate));
+        
+//        childScopeAdmin = null;
+//        try {
+//            childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
+//        } catch (Exception ex) {
+//            // ignore
+//        }
+//        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
     }
     
     // test ability to select the helloIsolation package from which scope it wants to use
@@ -472,13 +499,13 @@ public class ScopeAdminTest extends Abst
     @Test
     public void testScopeAffinity() throws Exception {
         // make sure we are using a framework that provides composite admin service
-        ScopeAdmin scopeAdmin = getOsgiService(ScopeAdmin.class);
+        Scope scopeAdmin = getOsgiService(Scope.class);
         assertNotNull("scope admin should not be null", scopeAdmin);
         System.out.println("able to get scope admin service");
 
         // install helloIsolation 0.3 in scope_test1
         Scope scope1 = createScope(scopeAdmin, "scope_test1", 
-                "mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.3-SNAPSHOT",
+                "mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.4-SNAPSHOT",
                 "0.3");
         
         // install helloIsolation 2.0 in scope_test2
@@ -490,6 +517,8 @@ public class ScopeAdminTest extends Abst
         ScopeUpdate su = scopeAdmin.newScopeUpdate();
         
         ScopeUpdate childScopeUpdate = su.newChild("scope_test3");
+        su.getChildren().add(childScopeUpdate);
+        addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
         Scope scope3 = childScopeUpdate.getScope();
         
         Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
@@ -501,29 +530,29 @@ public class ScopeAdminTest extends Abst
                 ")");*/
         final Filter filter1 = FrameworkUtil.createFilter(
                 "(&" + 
-                  "(osgi.package=org.apache.aries.subsystem.example.helloIsolation)" +
+                  "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" +
                   //"(scopeName=scope_test1)" +  
                 ")");
         final Filter filter2 = FrameworkUtil.createFilter(
                 "(&" + 
-                  "(osgi.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
+                  "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
                 ")");
-        List<SharePolicy> packagePolicies = sharePolicies.get(Capability.PACKAGE_CAPABILITY);
+        List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
         if (packagePolicies == null) {
             packagePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(Capability.PACKAGE_CAPABILITY,packagePolicies);
+            sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE,packagePolicies);
         }
-        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, Capability.PACKAGE_CAPABILITY, filter1));
-        List<SharePolicy> servicePolicies = sharePolicies.get(ScopeAdminServiceFactory.SERVICE_CAPABILITY);
+        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
+        List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
         if (servicePolicies == null) {
             servicePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(ScopeAdminServiceFactory.SERVICE_CAPABILITY, servicePolicies);
+            sharePolicies.put("scope.share.service", servicePolicies);
         }
-        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, ScopeAdminServiceFactory.SERVICE_CAPABILITY, filter2));
+        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_IMPORT, "scope.share.service", filter2));
 
 
         // build up installInfo object for the scope
-        InstallInfo info2 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.3-SNAPSHOT"), "helloIsolationRef");
+        InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.4-SNAPSHOT"));
 
         List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
         bundlesToInstall.add(info2);
@@ -532,11 +561,12 @@ public class ScopeAdminTest extends Abst
         su.commit();
         
         // start all bundles in the scope scope_test3
-        Collection<Bundle> bundlesToStart = childScopeUpdate.getBundles();
+        Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
         for (Bundle b : bundlesToStart) {
             try {
                 b.start();
             } catch (Exception ex) {
+            	ex.printStackTrace();
                 fail("should be able to start helloIsolationRef in scope_test1");
             }
             
@@ -554,12 +584,14 @@ public class ScopeAdminTest extends Abst
         
         // remove child scope - cleanup
         su = scopeAdmin.newScopeUpdate();
-        Collection<Scope> scopes = su.getToBeRemovedChildren();
-        scopes.add(scope1);
-        scopes.add(scope2);
-        scopes.add(scope3);
+        Collection<ScopeUpdate> scopes = su.getChildren();
+        scopes.clear();
+//        scopes.add(scope1);
+//        scopes.add(scope2);
+//        scopes.add(scope3);
         su.commit();
-        
+        assertTrue(scopeAdmin.getChildren().isEmpty());
+        assertTrue(scopeAdmin.newScopeUpdate().getChildren().isEmpty());
     }
     
     @org.ops4j.pax.exam.junit.Configuration
@@ -587,47 +619,49 @@ public class ScopeAdminTest extends Abst
             mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.api"),
             mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.impl"),
 
-            //org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+            // org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
 
             PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
 
-            equinox().version("3.7.0.v20101022")
+            equinox().version("3.7.0.v20110221")
         );
         options = updateOptions(options);
         return options;
     }
 
-    private Scope createScope(ScopeAdmin scopeAdmin, String scopeName, String loc, String version) throws MalformedURLException, InvalidSyntaxException, BundleException {
+    private Scope createScope(Scope scopeAdmin, String scopeName, String loc, String version) throws MalformedURLException, InvalidSyntaxException, BundleException, IOException {
         ScopeUpdate su = scopeAdmin.newScopeUpdate();
         
         ScopeUpdate childScopeUpdate = su.newChild(scopeName);
-        
+        su.getChildren().add(childScopeUpdate);
+        addPackageImportPolicy("org.osgi.framework", childScopeUpdate);
+        addPackageImportPolicy("org.osgi.util.tracker", childScopeUpdate);
         Map<String, List<SharePolicy>> sharePolicies = childScopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
         final Filter filter1 = FrameworkUtil.createFilter(
                 "(&" + 
-                  "(osgi.package=org.apache.aries.subsystem.example.helloIsolation)" +
+                  "(osgi.wiring.package=org.apache.aries.subsystem.example.helloIsolation)" +
                   "(version=" + version + ")" +
                 ")");
         final Filter filter2 = FrameworkUtil.createFilter(
                 "(&" + 
-                  "(osgi.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
+                  "(scope.share.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
                 ")");
-        List<SharePolicy> packagePolicies = sharePolicies.get(Capability.PACKAGE_CAPABILITY);
+        List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
         if (packagePolicies == null) {
             packagePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(Capability.PACKAGE_CAPABILITY, packagePolicies);
+            sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
         }
-        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, Capability.PACKAGE_CAPABILITY, filter1));
-        List<SharePolicy> servicePolicies = sharePolicies.get(ScopeAdminServiceFactory.SERVICE_CAPABILITY);
+        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
+        List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
         if (servicePolicies == null) {
             servicePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(ScopeAdminServiceFactory.SERVICE_CAPABILITY, servicePolicies);
+            sharePolicies.put("scope.share.service", servicePolicies);
         }
-        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, ScopeAdminServiceFactory.SERVICE_CAPABILITY, filter2));
+        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter2));
 
 
         // build up installInfo object for the scope
-        InstallInfo info1 = new InstallInfo(new URL(loc), "helloIsolation_" + scopeName);
+        InstallInfo info1 = new InstallInfo("helloIsolation_" + scopeName, new URL(loc));
 
         List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
         bundlesToInstall.add(info1);
@@ -636,7 +670,7 @@ public class ScopeAdminTest extends Abst
         su.commit();
         
         // start all bundles in the scope scope_test1
-        Collection<Bundle> bundlesToStart = childScopeUpdate.getBundles();
+        Collection<Bundle> bundlesToStart = childScopeUpdate.getScope().getBundles();
         for (Bundle b : bundlesToStart) {
             b.start();
         }

Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeProvider.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeProvider.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeProvider.java Fri Mar  4 17:14:05 2011
@@ -0,0 +1,7 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import org.apache.aries.subsystem.scope.Scope;
+
+public interface ScopeProvider {
+	Scope getScope();
+}

Modified: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeSecurityTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeSecurityTest.java?rev=1078060&r1=1075924&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeSecurityTest.java (original)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeSecurityTest.java Fri Mar  4 17:14:05 2011
@@ -16,19 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.subsystem.itests;
+package org.apache.aries.subsystem.scope.itests;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.equinox;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
-import java.io.FileOutputStream;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.Permission;
 import java.util.ArrayList;
@@ -39,14 +37,9 @@ import java.util.Map;
 import org.apache.aries.subsystem.example.helloIsolation.HelloIsolation;
 import org.apache.aries.subsystem.scope.InstallInfo;
 import org.apache.aries.subsystem.scope.Scope;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
 import org.apache.aries.subsystem.scope.ScopeUpdate;
 import org.apache.aries.subsystem.scope.SharePolicy;
-import org.apache.aries.subsystem.scope.impl.ScopeAdminServiceFactory;
-import org.apache.aries.unittest.fixture.ArchiveFixture;
-import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
 import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
@@ -54,21 +47,17 @@ import org.ops4j.pax.exam.container.def.
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleException;
 import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.PackagePermission;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.wiring.Capability;
+import org.osgi.framework.wiring.BundleRevision;
 import org.osgi.service.condpermadmin.ConditionInfo;
 import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
 import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
 import org.osgi.service.condpermadmin.ConditionalPermissionUpdate;
 import org.osgi.service.permissionadmin.PermissionInfo;
 import org.osgi.util.tracker.BundleTracker;
-import org.osgi.util.tracker.BundleTrackerCustomizer;
 
 
 @RunWith(JUnit4TestRunner.class)
@@ -103,7 +92,7 @@ public class ScopeSecurityTest extends A
     //@Test
     public void testScopeSecurityWithServiceIsolation() throws Exception {
         // make sure we are using a framework that provides composite admin service
-        ScopeAdmin scopeAdmin = getOsgiService(ScopeAdmin.class);
+        Scope scopeAdmin = getOsgiService(Scope.class);
         assertNotNull("scope admin should not be null", scopeAdmin);
         System.out.println("able to get scope admin service");
        
@@ -112,8 +101,8 @@ public class ScopeSecurityTest extends A
         ScopeUpdate childScopeUpdate = su.newChild("scope_test1");
         
         // build up installInfo object for the scope
-        InstallInfo info1 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.3-SNAPSHOT"), "helloIsolation");
-        InstallInfo info2 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.3-SNAPSHOT"), "helloIsolationRef");
+        InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.4-SNAPSHOT"));
+        InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.4-SNAPSHOT"));
 
         List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
         bundlesToInstall.add(info1);
@@ -150,7 +139,7 @@ public class ScopeSecurityTest extends A
         // test bundle service find hook
         //ServiceReference sr = bundleContext.getServiceReference(HelloIsolation.class.getName());
         //assertNull("sr should be null", sr);
-        Collection<Scope> children = scopeAdmin.getScope().getChildren();
+        Collection<Scope> children = scopeAdmin.getChildren();
         assertEquals(1, children.size());
         
         for (Scope child : children) {
@@ -183,26 +172,30 @@ public class ScopeSecurityTest extends A
         
         // remove child scope
         su = scopeAdmin.newScopeUpdate();
-        Collection<Scope> scopes = su.getToBeRemovedChildren();
+        Collection<ScopeUpdate> scopes = su.getChildren();
         
         // obtain child scope admin from service registry
-        String filter = "ScopeName=scope_test1";
-        ScopeAdmin childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        assertEquals(scopeAdmin.getScope(), childScopeAdmin.getParentScope());
-        scopes.add(childScopeAdmin.getScope());
+//        String filter = "ScopeName=scope_test1";
+        Scope childScopeAdmin = childScopeUpdate.getScope();
+        assertEquals(scopeAdmin, childScopeAdmin.getParent());
+        scopes.remove(childScopeUpdate);
         su.commit();
         
-        childScopeAdmin = null;
-        try {
-            childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        } catch (Exception ex) {
-            // ignore
-        }
-        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
+        assertFalse(scopeAdmin.getChildren().contains(childScopeAdmin));
+        su = scopeAdmin.newScopeUpdate();
+        assertFalse(su.getChildren().contains(childScopeUpdate));
+        
+//        childScopeAdmin = null;
+//        try {
+//            childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
+//        } catch (Exception ex) {
+//            // ignore
+//        }
+//        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
         
     }
     
-    @Test
+    //@Test
     public void testScopeSecurityWithServiceShared() throws Exception {
         
         SecurityManager security = System.getSecurityManager();
@@ -231,7 +224,7 @@ public class ScopeSecurityTest extends A
         }
         
         // make sure we are using a framework that provides composite admin service
-        ScopeAdmin scopeAdmin = getOsgiService(ScopeAdmin.class);
+        Scope scopeAdmin = getOsgiService(Scope.class);
         assertNotNull("scope admin should not be null", scopeAdmin);
         System.out.println("able to get scope admin service");
         
@@ -248,22 +241,22 @@ public class ScopeSecurityTest extends A
                 "(&" + 
                   "(osgi.service=org.apache.aries.subsystem.example.helloIsolation.HelloIsolation)" +
                 ")");
-        List<SharePolicy> packagePolicies = sharePolicies.get(Capability.PACKAGE_CAPABILITY);
+        List<SharePolicy> packagePolicies = sharePolicies.get(BundleRevision.PACKAGE_NAMESPACE);
         if (packagePolicies == null) {
             packagePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(Capability.PACKAGE_CAPABILITY, packagePolicies);
+            sharePolicies.put(BundleRevision.PACKAGE_NAMESPACE, packagePolicies);
         }
-        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, Capability.PACKAGE_CAPABILITY, filter1));
-        List<SharePolicy> servicePolicies = sharePolicies.get(ScopeAdminServiceFactory.SERVICE_CAPABILITY);
+        packagePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, BundleRevision.PACKAGE_NAMESPACE, filter1));
+        List<SharePolicy> servicePolicies = sharePolicies.get("scope.share.service");
         if (servicePolicies == null) {
             servicePolicies = new ArrayList<SharePolicy>();
-            sharePolicies.put(ScopeAdminServiceFactory.SERVICE_CAPABILITY, servicePolicies);
+            sharePolicies.put("scope.share.service", servicePolicies);
         }
-        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, ScopeAdminServiceFactory.SERVICE_CAPABILITY, filter2));
+        servicePolicies.add(new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter2));
 
         // build up installInfo object for the scope
-        InstallInfo info1 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.3-SNAPSHOT"), "helloIsolation");
-        InstallInfo info2 = new InstallInfo(new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.3-SNAPSHOT"), "helloIsolationRef");
+        InstallInfo info1 = new InstallInfo("helloIsolation", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolation/0.4-SNAPSHOT"));
+        InstallInfo info2 = new InstallInfo("helloIsolationRef", new URL("mvn:org.apache.aries.subsystem.example/org.apache.aries.subsystem.example.helloIsolationRef/0.4-SNAPSHOT"));
 
         List<InstallInfo> bundlesToInstall = childScopeUpdate.getBundlesToInstall();
         bundlesToInstall.add(info1);
@@ -300,7 +293,7 @@ public class ScopeSecurityTest extends A
         // test bundle service find hook
         //ServiceReference sr = bundleContext.getServiceReference(HelloIsolation.class.getName());
         //assertNull("sr should be null", sr);
-        Collection<Scope> children = scopeAdmin.getScope().getChildren();
+        Collection<Scope> children = scopeAdmin.getChildren();
         assertEquals(1, children.size());
         
         for (Scope child : children) {
@@ -335,22 +328,26 @@ public class ScopeSecurityTest extends A
         
         // remove child scope
         su = scopeAdmin.newScopeUpdate();
-        Collection<Scope> scopes = su.getToBeRemovedChildren();
+        Collection<ScopeUpdate> scopes = su.getChildren();
         
         // obtain child scope admin from service registry
-        String filter = "ScopeName=scope_test1";
-        ScopeAdmin childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        assertEquals(scopeAdmin.getScope(), childScopeAdmin.getParentScope());
-        scopes.add(childScopeAdmin.getScope());
+//        String filter = "ScopeName=scope_test1";
+        Scope childScopeAdmin = childScopeUpdate.getScope();
+        assertEquals(scopeAdmin, childScopeAdmin.getParent());
+        scopes.remove(childScopeUpdate);
         su.commit();
         
-        childScopeAdmin = null;
-        try {
-            childScopeAdmin = getOsgiService(ScopeAdmin.class, filter, DEFAULT_TIMEOUT);
-        } catch (Exception ex) {
-            // ignore
-        }
-        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
+        assertFalse(scopeAdmin.getChildren().contains(childScopeAdmin));
+        su = scopeAdmin.newScopeUpdate();
+        assertFalse(su.getChildren().contains(childScopeUpdate));
+        
+//        childScopeAdmin = null;
+//        try {
+//            childScopeAdmin = getOsgiService(Scope.class, filter, DEFAULT_TIMEOUT);
+//        } catch (Exception ex) {
+//            // ignore
+//        }
+//        assertNull("scope admin service for the scope should be unregistered", childScopeAdmin);
         
     }
     
@@ -387,7 +384,7 @@ public class ScopeSecurityTest extends A
 
             PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
 
-            equinox().version("3.7.0.v20101022")
+            equinox().version("3.7.0.v20110221")
         );
         options = updateOptions(options);
         return options;

Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Service.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Service.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Service.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Service.java Fri Mar  4 17:14:05 2011
@@ -0,0 +1,4 @@
+package org.apache.aries.subsystem.scope.itests;
+
+public interface Service {
+}

Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ServiceVisibilityTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ServiceVisibilityTest.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ServiceVisibilityTest.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ServiceVisibilityTest.java Fri Mar  4 17:14:05 2011
@@ -0,0 +1,78 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import org.apache.aries.subsystem.scope.InstallInfo;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Bundles may only see other services registered by other bundles within the 
+ * same scope. The one exception is the system bundle, whose services may be 
+ * seen by all bundles regardless of scope.
+ */
+@RunWith(JUnit4TestRunner.class)
+public class ServiceVisibilityTest extends AbstractTest {
+	/**
+	 * Install a bundle registering a service into the same scope as this one. 
+	 * This bundle should be able to see the service.
+	 * @throws Exception
+	 */
+	@Test
+	public void test1() throws Exception {
+		assertTrue(scope.getBundles().contains(bundleContext.getBundle()));
+		ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+		String location = getBundleLocation("tb-7.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);
+		assertNotNull(bundle);
+		assertTrue(scope.getBundles().contains(bundle));
+		bundle.start();
+		ServiceReference<Service> serviceRef = bundleContext.getServiceReference(Service.class);
+		assertNotNull(serviceRef);
+		Service service = bundleContext.getService(serviceRef);
+		assertNotNull(service);
+		bundleContext.ungetService(serviceRef);
+		bundle.uninstall();
+	}
+	
+	/**
+	 * Install a bundle registering a service into a different scope than this 
+	 * one. This bundle should not be able to see the service.
+	 * @throws Exception
+	 */
+	@Test
+	public void test2() throws Exception {
+		assertTrue(scope.getBundles().contains(bundleContext.getBundle()));
+		String location = getBundleLocation("tb-7.jar");
+		assertNull(bundleContext.getBundle(location));
+		URL url = new URL(location);
+		InstallInfo installInfo = new InstallInfo(location, url.openStream());
+		ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+		ScopeUpdate child = scopeUpdate.newChild("tb7");
+		scopeUpdate.getChildren().add(child);
+		child.getBundlesToInstall().add(installInfo);
+		addPackageImportPolicy("org.osgi.framework", child);
+		addPackageImportPolicy("org.apache.aries.subsystem.scope.itests", child);
+		scopeUpdate.commit();
+		Bundle bundle = bundleContext.getBundle(location);
+		assertNotNull(bundle);
+		assertTrue(child.getScope().getBundles().contains(bundle));
+		bundle.start();
+		ServiceReference<Service> serviceRef = bundleContext.getServiceReference(Service.class);
+		assertNull(serviceRef);
+		bundle.uninstall();
+	}
+}

Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/SharePolicyTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/SharePolicyTest.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/SharePolicyTest.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/SharePolicyTest.java Fri Mar  4 17:14:05 2011
@@ -0,0 +1,197 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+import java.util.Arrays;
+
+import org.apache.aries.subsystem.scope.InstallInfo;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.wiring.FrameworkWiring;
+
+@RunWith(JUnit4TestRunner.class)
+public class SharePolicyTest extends AbstractTest {
+	/**
+	 * Bundle tb5
+	 * Bundle tb6
+	 * tb5 imports package exported by tb6
+	 * tb5 and tb6 in same scope
+	 * tb5 should resolve
+	 * 
+	 * Share policies have no effect within the same scope.
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void test1() throws Exception {
+		Bundle tb5 = null;
+		Bundle tb6 = null;
+		try {
+			String tb5Location = getBundleLocation("tb-5.jar");
+			String tb6Location = getBundleLocation("tb-6.jar");
+			InstallInfo tb5Info = new InstallInfo(tb5Location, new URL(tb5Location));
+			InstallInfo tb6Info = new InstallInfo(tb6Location, new URL(tb6Location));
+			ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+			scopeUpdate.getBundlesToInstall().add(tb5Info);
+			scopeUpdate.commit();
+			tb5 = findBundleInRootScope("org.apache.aries.subsystem.scope.itests.tb5");
+			assertNotNull(tb5);
+			FrameworkWiring frameworkWiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
+			assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[]{tb5})));
+			scopeUpdate = scope.newScopeUpdate();
+			scopeUpdate.getBundlesToInstall().add(tb6Info);
+			scopeUpdate.commit();
+			tb6 = findBundleInRootScope("org.apache.aries.subsystem.scope.itests.tb6");
+			assertNotNull(tb6);
+			assertTrue(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[]{tb5,tb6})));
+		}
+		finally {
+			uninstallQuietly(tb6);
+			uninstallQuietly(tb5);
+		}
+	}
+	
+	/**
+	 * Bundle tb5
+	 * Bundle tb6
+	 * tb5 imports package exported by tb6
+	 * tb5 in root scope
+	 * tb6 in child scope of root
+	 * tb6 scope does not export tb6 package
+	 * tb5 should not resolve
+	 * @throws Exception
+	 */
+	@Test
+	public void test2() throws Exception {
+		Bundle tb5 = null;
+		Bundle tb6 = null;
+		try {
+			String tb5Location = getBundleLocation("tb-5.jar");
+			String tb6Location = getBundleLocation("tb-6.jar");
+			InstallInfo tb5Info = new InstallInfo(tb5Location, new URL(tb5Location));
+			InstallInfo tb6Info = new InstallInfo(tb6Location, new URL(tb6Location));
+			ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+			scopeUpdate.getBundlesToInstall().add(tb5Info);
+			scopeUpdate.commit();
+			tb5 = findBundleInRootScope("org.apache.aries.subsystem.scope.itests.tb5");
+			assertNotNull(tb5);
+			FrameworkWiring frameworkWiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
+			assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[]{tb5})));
+			scopeUpdate = scope.newScopeUpdate();
+			ScopeUpdate tb6ScopeUpdate = scopeUpdate.newChild("tb6");
+			scopeUpdate.getChildren().add(tb6ScopeUpdate);
+			tb6ScopeUpdate.getBundlesToInstall().add(tb6Info);
+			scopeUpdate.commit();
+			tb6 = findBundle("org.apache.aries.subsystem.scope.itests.tb6", tb6ScopeUpdate.getScope());
+			assertNotNull(tb6);
+			assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[]{tb5,tb6})));
+		}
+		finally {
+			uninstallQuietly(tb6);
+			uninstallQuietly(tb5);
+		}
+	}
+	
+	/**
+	 * Bundle tb5
+	 * Bundle tb6
+	 * tb5 imports package exported by tb6
+	 * tb5 in root scope
+	 * tb6 in child scope of root
+	 * tb6 scope exports tb6 package
+	 * tb5 should resolve
+	 * 
+	 * There is an implicit import between parent and child. In other words,
+	 * anything exported by a child is automatically available without the
+	 * parent explicitly importing it.
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void test3() throws Exception {
+		Bundle tb5 = null;
+		Bundle tb6 = null;
+		try {
+			String tb5Location = getBundleLocation("tb-5.jar");
+			String tb6Location = getBundleLocation("tb-6.jar");
+			InstallInfo tb5Info = new InstallInfo(tb5Location, new URL(tb5Location));
+			InstallInfo tb6Info = new InstallInfo(tb6Location, new URL(tb6Location));
+			ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+			scopeUpdate.getBundlesToInstall().add(tb5Info);
+			scopeUpdate.commit();
+			tb5 = findBundleInRootScope("org.apache.aries.subsystem.scope.itests.tb5");
+			assertNotNull(tb5);
+			FrameworkWiring frameworkWiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
+			assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[]{tb5})));
+			scopeUpdate = scope.newScopeUpdate();
+			ScopeUpdate tb6ScopeUpdate = scopeUpdate.newChild("tb6");
+			scopeUpdate.getChildren().add(tb6ScopeUpdate);
+			tb6ScopeUpdate.getBundlesToInstall().add(tb6Info);
+			addPackageExportPolicy("org.apache.aries.subsystem.scope.itests.tb6", tb6ScopeUpdate);
+			scopeUpdate.commit();
+			tb6 = findBundle("org.apache.aries.subsystem.scope.itests.tb6", tb6ScopeUpdate.getScope());
+			assertNotNull(tb6);
+			tb5.start();
+			assertTrue(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[]{tb5,tb6})));
+		}
+		finally {
+			uninstallQuietly(tb6);
+			uninstallQuietly(tb5);
+		}
+	}
+	
+	/**
+	 * Bundle tb5
+	 * Bundle tb6
+	 * tb5 imports package exported by tb6
+	 * tb5 in child scope of root
+	 * tb6 in different child scope of root
+	 * tb6 scope exports tb6 package
+	 * root scope exports tb6 package
+	 * tb5 scope imports tb6 package
+	 * tb5 should resolve
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void test4() throws Exception {
+		Bundle tb5 = null;
+		Bundle tb6 = null;
+		try {
+			String tb5Location = getBundleLocation("tb-5.jar");
+			String tb6Location = getBundleLocation("tb-6.jar");
+			InstallInfo tb5Info = new InstallInfo(tb5Location, new URL(tb5Location));
+			InstallInfo tb6Info = new InstallInfo(tb6Location, new URL(tb6Location));
+			ScopeUpdate rootUpdate = scope.newScopeUpdate();
+			addPackageExportPolicy("org.apache.aries.subsystem.scope.itests.tb6", rootUpdate);
+			ScopeUpdate tb5Update = rootUpdate.newChild("tb5");
+			rootUpdate.getChildren().add(tb5Update);
+			tb5Update.getBundlesToInstall().add(tb5Info);
+			addPackageImportPolicy("org.apache.aries.subsystem.scope.itests.tb6", tb5Update);
+			rootUpdate.commit();
+			tb5 = findBundle("org.apache.aries.subsystem.scope.itests.tb5", tb5Update.getScope());
+			assertNotNull(tb5);
+			FrameworkWiring frameworkWiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
+			assertFalse(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[]{tb5})));
+			rootUpdate = scope.newScopeUpdate();
+			ScopeUpdate tb6Update = rootUpdate.newChild("tb6");
+			rootUpdate.getChildren().add(tb6Update);
+			tb6Update.getBundlesToInstall().add(tb6Info);
+			addPackageExportPolicy("org.apache.aries.subsystem.scope.itests.tb6", tb6Update);
+			rootUpdate.commit();
+			tb6 = findBundle("org.apache.aries.subsystem.scope.itests.tb6", tb6Update.getScope());
+			assertNotNull(tb6);
+			assertTrue(frameworkWiring.resolveBundles(Arrays.asList(new Bundle[]{tb5,tb6})));
+		}
+		finally {
+			uninstallQuietly(tb6);
+			uninstallQuietly(tb5);
+		}
+	}
+}

Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/UninstallBundleTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/UninstallBundleTest.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/UninstallBundleTest.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/UninstallBundleTest.java Fri Mar  4 17:14:05 2011
@@ -0,0 +1,54 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+
+/**
+ * Tests whether or not a bundle can be successfully uninstalled from a scope.
+ * The root scope is used for this test.
+ */
+@RunWith(JUnit4TestRunner.class)
+public class UninstallBundleTest extends AbstractTest {
+	private Bundle bundle;
+	private String location;
+	
+	@Test
+	public void test() throws Exception {
+		ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+		assertTrue("The bundle should have been removed", scopeUpdate.getBundles().remove(bundle));
+		assertTrue("The commit should have been successful", scopeUpdate.commit());
+		assertFalse("The bundle should have been removed from the scope", scope.getBundles().contains(bundle));
+		assertFalse(Arrays.asList(bundleContext.getBundles()).contains(bundle));
+		assertNull("The bundle should have been uninstalled", bundleContext.getBundle(location));
+	}
+	
+	@Before
+	public void before0() throws Exception {
+		super.before();
+		location = getBundleLocation("tb-2.jar");
+		bundle = bundleContext.getBundle(location);
+		assertNull("The bundle should not exist", bundle);
+		installBundles(scope, new String[]{"tb-2.jar"});
+		bundle = bundleContext.getBundle(location);
+		assertNotNull("The bundle should exist", bundle);
+		assertTrue("The bundle should part of the scope", scope.getBundles().contains(bundle));
+	}
+	
+	@After
+	public void after0() throws Exception {
+		uninstallQuietly(bundle);
+		super.after();
+	}
+}

Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Utils.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Utils.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Utils.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Utils.java Fri Mar  4 17:14:05 2011
@@ -0,0 +1,52 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import org.apache.aries.subsystem.scope.Scope;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public class Utils {
+	public static Bundle findBundle(String symbolicName, Scope scope) {
+		if (scope == null) return null;
+		for (Bundle b : scope.getBundles()) {
+			if (symbolicName == null) {
+				if (b.getSymbolicName() == null)
+					return b;
+			}
+			else if (symbolicName.equals(b.getSymbolicName()))
+				return b;
+		}
+		return null;
+	}
+	
+	public static void ungetQuietly(ServiceReference<?> serviceReference, BundleContext bundleContext) {
+		if (serviceReference == null) return;
+		try {
+			bundleContext.ungetService(serviceReference);
+		}
+		catch (Exception e) {
+			// ignore
+		}
+	}
+	
+	public static void uninstallQuietly(Bundle bundle) {
+		if (bundle == null) return;
+		try {
+			bundle.uninstall();
+		}
+		catch (Exception e) {
+			// ignore
+		}
+	}
+	
+	public static void unregisterQuietly(ServiceRegistration<?> serviceRegistration) {
+		if (serviceRegistration == null) return;
+		try {
+			serviceRegistration.unregister();
+		}
+		catch (Exception e) {
+			// ignore
+		}
+	}
+}

Modified: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java (original)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java Fri Mar  4 17:14:05 2011
@@ -43,6 +43,7 @@ public class SsActivator extends Abstrac
             new EquinoxPlatformBuilder( bundleContext, "3.5.1" ),
             new EquinoxPlatformBuilder( bundleContext, "3.6.0" ),
             new EquinoxPlatformBuilder( bundleContext, "3.7.0.V20101022" ),
+            new EquinoxPlatformBuilder( bundleContext, "3.7.0.V20110221" ),
             new EquinoxPlatformBuilderSnapshot( bundleContext )
         };
     }

Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml Fri Mar  4 17:14:05 2011
@@ -0,0 +1,8 @@
+<platform>
+
+  <name>Equinox 3.7.0</name>
+  <system>mvn:org.eclipse/osgi/3.7.0.v20110221</system>
+
+  <profile name="minimal" default="true"/>
+
+</platform>

Modified: aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/ss-runner.properties
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/ss-runner.properties?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/ss-runner.properties (original)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/ss-runner.properties Fri Mar  4 17:14:05 2011
@@ -65,6 +65,7 @@ platform.equinox.3.6.0=org.ops4j.pax.run
 platform.equinox.SNAPSHOT=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
 platform.equinox.V43PROTOTYPE-3.6.0.201003231329=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
 platform.equinox.3.7.0.V20101022=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
+platform.equinox.3.7.0.V20110221=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
 # Felix
 platform.felix.1.0.0=org.ops4j.pax.runner.platform.felix.internal.Activator
 platform.felix.1.0.1=org.ops4j.pax.runner.platform.felix.internal.Activator