[jboss-osgi-commits] JBoss-OSGI SVN: r96174 - in projects/jboss-osgi/trunk/reactor/framework/src/test: java/org/jboss/test/osgi and 9 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Mon Nov 9 09:12:07 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-11-09 09:12:05 -0500 (Mon, 09 Nov 2009)
New Revision: 96174

Added:
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ClassLoaderDomainUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/
Removed:
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata/
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/test/
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/filter/
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/test/
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/bundle/
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/deployers/
Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/AbstractManifestTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/VersionRangeTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/metadata/SimpleManifest.mf
Log:
Allign location of metadata tests with others

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/BundleContextUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,508 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.bundle;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Set;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * BundleContextUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class BundleContextUnitTestCase extends OSGiTestCase
+{
+   public BundleContextUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testGetBundle() throws Exception
+   {
+      Bundle bundle1 = addBundle("/bundles/simple/", "simple-bundle1");
+      BundleContext context1 = null;
+      try
+      {
+         bundle1.start();
+         context1 = bundle1.getBundleContext();
+         assertEquals(bundle1, context1.getBundle());
+         assertEquals(bundle1, context1.getBundle(bundle1.getBundleId()));
+         
+         Bundle[] bundles = context1.getBundles();
+         Set<Bundle> actual = new HashSet<Bundle>(Arrays.asList(bundles));
+         Set<Bundle> expected = new HashSet<Bundle>(Arrays.asList(bundle1));
+         addBaseBundles(expected);
+         assertEquals(expected, actual);
+         
+         Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+         BundleContext context2 = null;
+         try
+         {
+            bundle2.start();
+            context2 = bundle2.getBundleContext();
+            assertEquals(bundle2, context2.getBundle());
+            
+            bundles = context1.getBundles();
+            actual = new HashSet<Bundle>(Arrays.asList(bundles));
+            expected = new HashSet<Bundle>(Arrays.asList(bundle1, bundle2));
+            addBaseBundles(expected);
+            assertEquals(expected, actual);
+            
+            assertEquals(bundle1, context2.getBundle(bundle1.getBundleId()));
+            assertEquals(bundle2, context1.getBundle(bundle2.getBundleId()));
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+
+         assertEquals(bundle1, context1.getBundle(bundle1.getBundleId()));
+         assertNull(context1.getBundle(bundle2.getBundleId()));
+         
+         bundles = context1.getBundles();
+         actual = new HashSet<Bundle>(Arrays.asList(bundles));
+         expected = new HashSet<Bundle>(Arrays.asList(bundle1));
+         addBaseBundles(expected);
+         assertEquals(expected, actual);
+         
+         try
+         {
+            context2.getBundle();
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+         
+         try
+         {
+            context2.getBundle(bundle1.getBundleId());
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+         
+         try
+         {
+            context2.getBundles();
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+      
+      try
+      {
+         context1.getBundle();
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalStateException.class, t);
+      }
+      
+      try
+      {
+         context1.getBundle(bundle1.getBundleId());
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalStateException.class, t);
+      }
+      
+      try
+      {
+         context1.getBundles();
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalStateException.class, t);
+      }
+   }
+         
+   public void testProperties() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+         assertEquals("r4v42", bundleContext.getProperty(Constants.FRAMEWORK_VERSION)); 
+         assertEquals("jboss.org", bundleContext.getProperty(Constants.FRAMEWORK_VENDOR));
+         assertEquals(Locale.getDefault().getISO3Language(), bundleContext.getProperty(Constants.FRAMEWORK_LANGUAGE));
+         assertSystemProperty(bundleContext, "os.name", Constants.FRAMEWORK_OS_NAME);
+         assertSystemProperty(bundleContext, "os.version", Constants.FRAMEWORK_OS_VERSION);
+         assertSystemProperty(bundleContext, "os.arch", Constants.FRAMEWORK_PROCESSOR);
+         
+         assertNull(bundleContext.getProperty(getClass().getName()));
+         System.setProperty(getClass().getName(), "test");
+         assertEquals("test", bundleContext.getProperty(getClass().getName()));
+
+         bundle.stop();
+         try
+         {
+            bundleContext.getProperty(getClass().getName());
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testInstallBundle() throws Exception
+   {
+      // TODO testInstallBundle
+   }
+   
+   public void testServiceListener() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+         
+         try
+         {
+            bundleContext.addServiceListener(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.addServiceListener(null, "(a=b)");
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.removeServiceListener(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         bundleContext.addServiceListener(this);
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+         bundleContext.removeServiceListener(this);
+         
+         bundleContext.addServiceListener(this);
+         bundleContext.removeServiceListener(this);
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, false);
+         
+         bundleContext.addServiceListener(this);
+         bundleContext.addServiceListener(this);
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+         bundleContext.removeServiceListener(this);
+         
+         bundleContext.addServiceListener(this, null);
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+         bundleContext.removeServiceListener(this);
+         
+         bundleContext.addServiceListener(this, null);
+         bundleContext.removeServiceListener(this);
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, false);
+         
+         bundleContext.addServiceListener(this, null);
+         bundleContext.addServiceListener(this, null);
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+         bundleContext.removeServiceListener(this);
+         
+         Dictionary<String, Object> properties = new Hashtable<String, Object>();
+         properties.put("a", "b");
+         
+         bundleContext.addServiceListener(this, ("(a=b)"));
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, true);
+         bundleContext.removeServiceListener(this);
+         
+         bundleContext.addServiceListener(this, ("(c=d)"));
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, false);
+         bundleContext.removeServiceListener(this);
+         
+         bundleContext.addServiceListener(this, "(a=b)");
+         bundleContext.removeServiceListener(this);
+         bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, false);
+         
+         bundleContext.addServiceListener(this, "(c=d)");
+         bundleContext.addServiceListener(this, "(a=b)");
+         assertServiceLifecycle(bundle, bundleContext, properties, true);
+         bundleContext.removeServiceListener(this);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   protected BundleContext assertServiceLifecycle(Bundle bundle, BundleContext bundleContext, boolean events) throws Exception
+   {
+      return assertServiceLifecycle(bundle, bundleContext, null, events);
+   }
+   
+   protected BundleContext assertServiceLifecycle(Bundle bundle, BundleContext bundleContext, Dictionary<String, Object> properties, boolean events) throws Exception
+   {
+      assertNoServiceEvent();
+      
+      ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+      ServiceReference reference = registration.getReference();
+      
+      if (events)
+         assertServiceEvent(ServiceEvent.REGISTERED, reference);
+      else
+         assertNoServiceEvent();
+
+      registration.setProperties(properties);
+      if (events)
+         assertServiceEvent(ServiceEvent.MODIFIED, reference);
+      else
+         assertNoServiceEvent();
+
+      registration.unregister();
+      if (events)
+         assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+      else
+         assertNoServiceEvent();
+      
+      registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+      reference = registration.getReference();
+      if (events)
+         assertServiceEvent(ServiceEvent.REGISTERED, reference);
+      else
+         assertNoServiceEvent();
+
+      bundle.stop();
+      if (events)
+         assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+      else
+         assertNoServiceEvent();
+      
+      try
+      {
+         bundleContext.addServiceListener(this);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalStateException.class, t);
+      }
+      
+      bundle.start();
+      bundleContext = bundle.getBundleContext();
+      assertNotNull(bundleContext);
+      return bundleContext;
+   }
+   
+   public void testBundleListener() throws Exception
+   {
+      // todo how to test INSTALLED/RESOLVED?
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+         
+         try
+         {
+            bundleContext.addBundleListener(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.removeBundleListener(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         bundleContext.addBundleListener(this);
+         bundleContext = assertBundleLifecycle(bundle, bundleContext, true);
+         bundleContext.removeBundleListener(this);
+         
+         bundleContext.addBundleListener(this);
+         bundleContext.removeBundleListener(this);
+         bundleContext = assertBundleLifecycle(bundle, bundleContext, false);
+         
+         bundleContext.addBundleListener(this);
+         bundleContext.addBundleListener(this);
+         bundleContext = assertBundleLifecycle(bundle, bundleContext, true);
+         bundleContext.removeBundleListener(this);
+
+         bundleContext.addBundleListener(this);
+         
+         // todo test asynch BundleListener
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+      assertBundleEvent(BundleEvent.STOPPING, bundle);
+      assertBundleEvent(BundleEvent.STOPPED, bundle);
+      // todo assertBundleEvent(BundleEvent.UNRESOLVED, bundle);
+      assertBundleEvent(BundleEvent.UNINSTALLED, bundle);
+   }
+   
+   protected BundleContext assertBundleLifecycle(Bundle bundle, BundleContext bundleContext, boolean events) throws Exception
+   {
+      assertNoBundleEvent();
+      
+      bundle.stop();
+      if (events)
+      {
+         assertBundleEvent(BundleEvent.STOPPING, bundle);
+         assertBundleEvent(BundleEvent.STOPPED, bundle);
+      }
+      else
+      {
+         assertNoBundleEvent();
+      }
+      
+      bundle.start();
+      if (events)
+      {
+         assertBundleEvent(BundleEvent.STARTING, bundle);
+         assertBundleEvent(BundleEvent.STARTED, bundle);
+      }
+      else
+      {
+         assertNoBundleEvent();
+      }
+      
+      return bundleContext;
+   }
+   
+   public void testFrameworkListener() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+         
+         try
+         {
+            bundleContext.addFrameworkListener(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.removeFrameworkListener(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         // todo test events
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testGetDataFile() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+         
+         File dataFile = bundleContext.getDataFile("blah");
+         assertNotNull(dataFile);
+         assertTrue(dataFile.toString().endsWith(File.separator + "blah"));
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   protected void assertSystemProperty(BundleContext bundleContext, String property, String osgiProperty)
+   {
+      String expected = System.getProperty(property);
+      assertNotNull(expected);
+      assertEquals(expected, bundleContext.getProperty(osgiProperty));
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/BundleEntriesUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,462 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.bundle;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+
+/**
+ * BundleEntriesUnitTestCase.
+ * 
+ * TODO test security
+ * TODO test fragments
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleEntriesUnitTestCase extends OSGiTestCase
+{
+   public BundleEntriesUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testEntriesNotInstalled() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+      uninstall(bundle);
+      try
+      {
+         bundle.getEntry("root.xml");
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalStateException.class, t);
+      }
+      try
+      {
+         bundle.findEntries("", "root.xml", false);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalStateException.class, t);
+      }
+   }
+   
+   public void testFindEntriesNoPath() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+      try
+      {
+         bundle.findEntries(null, "root.xml", false);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testEntries() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+      try
+      {
+         assertEntry(bundle, "");
+         assertNoEntries(bundle, "", "", false);
+         assertNoEntries(bundle, "", "", true);
+         assertEntryPaths("", bundle, 
+               "/",
+               "root.xml",
+               "root-no-suffix",
+               "entry1.xml",
+               "META-INF/",
+               "META-INF/MANIFEST.MF",
+               "org/",
+               "org/jboss/",
+               "org/jboss/test/",
+               "org/jboss/test/osgi/",
+               "org/jboss/test/osgi/bundle/",
+               "org/jboss/test/osgi/bundle/entries/",
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertNoEntry(bundle, "DoesNotExist");
+         assertNoEntries(bundle, "", "DoesNotExist", false);
+         assertNoEntries(bundle, "", "DoesNotExist", true);
+         assertNoEntryPaths(bundle, "DoesNotExist");
+
+         assertEntry(bundle, "root-no-suffix");
+         assertEntries(bundle, "", "root-no-suffix", false, "root-no-suffix");
+         assertEntries(bundle, "", "root-no-suffix", true, "root-no-suffix");
+         assertEntryPaths(bundle, "root-no-suffix");
+
+         assertEntry(bundle, "root.xml");
+         assertEntries(bundle, "", "root.xml", false, "root.xml");
+         assertEntries(bundle, "", "root.xml", true, "root.xml");
+         assertEntryPaths(bundle, "root.xml");
+
+         assertEntry(bundle, "entry1.xml");
+         assertEntries(bundle, "", "entry1.xml", false, "entry1.xml");
+         assertEntries(bundle, "", "entry1.xml", true, 
+               "entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml"
+         );
+         assertEntryPaths(bundle, "entry1.xml");
+
+         assertEntry(bundle, "META-INF");
+         assertNoEntries(bundle, "", "META-INF", false);
+         assertNoEntries(bundle, "", "META-INF", true);
+         assertEntryPaths("META-INF", bundle, 
+               "META-INF/",
+               "META-INF/MANIFEST.MF"
+         );
+         
+         assertNoEntry(bundle, "META-INF/DoesNotExist");
+         assertNoEntries(bundle, "META-INF", "DoesNotExist", false);
+         assertNoEntries(bundle, "META-INF", "DoesNotExist", true);
+         assertNoEntryPaths(bundle, "META-INF/DoesNotExist");
+
+         assertEntry(bundle, "META-INF/MANIFEST.MF");
+         assertEntries(bundle, "META-INF", "MANIFEST.MF", false, "META-INF/MANIFEST.MF");
+         assertEntries(bundle, "META-INF", "MANIFEST.MF", true, "META-INF/MANIFEST.MF");
+         assertEntryPaths(bundle, "META-INF/MANIFEST.MF");
+
+         assertEntry(bundle, "org");
+         assertNoEntries(bundle, "", "org", false);
+         assertNoEntries(bundle, "", "org", true);
+         assertEntryPaths("org", bundle, 
+               "org/",
+               "org/jboss/",
+               "org/jboss/test/",
+               "org/jboss/test/osgi/",
+               "org/jboss/test/osgi/bundle/",
+               "org/jboss/test/osgi/bundle/entries/",
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertNoEntry(bundle, "org/DoesNotExist");
+         assertNoEntries(bundle, "org", "DoesNotExist", false);
+         assertNoEntries(bundle, "org", "DoesNotExist", true);
+         assertNoEntryPaths(bundle, "org/DoesNotExist");
+
+         assertEntry(bundle, "org/jboss/test/osgi/bundle/entries");
+         assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries", false);
+         assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries", true);
+         assertEntryPaths("org/jboss/test/osgi/bundle/entries", bundle, 
+               "org/jboss/test/osgi/bundle/entries/",
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertNoEntry(bundle, "org/jboss/test/osgi/bundle/DoesNotExist");
+         assertNoEntries(bundle, "org/jboss/test/osgi/bundle", "DoesNotExist", false);
+         assertNoEntries(bundle, "org/jboss/test/osgi/bundle", "DoesNotExist", true);
+         assertNoEntryPaths(bundle, "org/jboss/test/osgi/bundle/DoesNotExist");
+
+         assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "notxml.suffix", false, 
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "notxml.suffix", true, 
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix"
+         );
+         assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/notxml.suffix");
+
+         assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/entry1.xml");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry1.xml", false, 
+               "org/jboss/test/osgi/bundle/entries/entry1.xml");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry1.xml", true, 
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml"
+         );
+         assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/entry1.xml");
+
+         assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/entry2.xml");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry2.xml", false, 
+               "org/jboss/test/osgi/bundle/entries/entry2.xml");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry2.xml", true, 
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/entry2.xml");
+
+         assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub");
+         assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries/sub", false);
+         assertEntries(bundle, "", "org/jboss/test/osgi/bundle/entries/sub", true);
+         assertEntryPaths("org/jboss/test/osgi/bundle/entries/sub", bundle, 
+               "org/jboss/test/osgi/bundle/entries/sub/",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertNoEntry(bundle, "org/jboss/test/osgi/bundle/DoesNotExist/sub");
+         assertNoEntries(bundle, "org/jboss/test/osgi/bundle/sub", "DoesNotExist", false);
+         assertNoEntries(bundle, "org/jboss/test/osgi/bundle/sub", "DoesNotExist", true);
+         assertNoEntryPaths(bundle, "org/jboss/test/osgi/bundle/DoesNotExist/sub");
+
+         assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry1.xml", false, 
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry1.xml", true, 
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+         assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry1.xml");
+
+         assertEntry(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry2.xml", false, 
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries/sub", "entry2.xml", true, 
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+         assertEntryPaths(bundle, "org/jboss/test/osgi/bundle/entries/sub/entry2.xml");
+
+         assertEntries(bundle, "", "*", false,
+               "root.xml",
+               "root-no-suffix",
+               "entry1.xml"
+         );
+         assertEntries(bundle, "", "*", true,
+               "root.xml",
+               "root-no-suffix",
+               "entry1.xml",
+               "META-INF/MANIFEST.MF",
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+
+         assertEntries(bundle, "", null, false,
+               "root.xml",
+               "root-no-suffix",
+               "entry1.xml"
+         );
+         assertEntries(bundle, "", null, true,
+               "root.xml",
+               "root-no-suffix",
+               "entry1.xml",
+               "META-INF/MANIFEST.MF",
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertEntries(bundle, "", "root*", false,
+               "root-no-suffix",
+               "root.xml"
+         );
+         assertEntries(bundle, "", "root*", true,
+               "root-no-suffix",
+               "root.xml"
+         );
+         
+         assertEntries(bundle, "", "entry*", false,
+               "entry1.xml"
+         );
+         assertEntries(bundle, "", "entry*", true,
+               "entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry*", false,
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml"
+         );
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "entry*", true,
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertEntries(bundle, "", "*.xml", false,
+               "root.xml",
+               "entry1.xml"
+         );
+         assertEntries(bundle, "", "*.xml", true,
+               "root.xml",
+               "entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertEntries(bundle, "", "*xml*", false,
+               "root.xml",
+               "entry1.xml"
+         );
+         assertEntries(bundle, "", "*xml*", true,
+               "root.xml",
+               "entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+         
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "*xml*", false,
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml"
+         );
+         assertEntries(bundle, "org/jboss/test/osgi/bundle/entries", "*xml*", true,
+               "org/jboss/test/osgi/bundle/entries/notxml.suffix",
+               "org/jboss/test/osgi/bundle/entries/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry1.xml",
+               "org/jboss/test/osgi/bundle/entries/entry2.xml",
+               "org/jboss/test/osgi/bundle/entries/sub/entry2.xml"
+         );
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+
+   protected void assertEntry(Bundle bundle, String path) throws Exception
+   {
+      URL expected = getBundleResource(bundle, path);
+      if (expected == null)
+         fail("Expected resource not found: " + path);
+
+      assertEntry(bundle, path, expected);
+      assertEntry(bundle, "/" + path, expected);
+   }
+
+   protected void assertEntry(Bundle bundle, String path, URL expected) throws Exception
+   {
+      URL actual = bundle.getEntry(path);
+      assertEquals(expected, actual);
+   }
+
+   protected void assertNoEntry(Bundle bundle, String path) throws Exception
+   {
+      URL actual = bundle.getEntry(path);
+      assertNull("Did not expect entry: " + actual + " for path: " + path, actual);
+   }
+   
+   protected void assertEntries(Bundle bundle, String path, String filePattern, boolean recurse, String... entries) throws Exception
+   {
+      Set<URL> expected = new HashSet<URL>();
+      for (String entry : entries)
+      {
+         Enumeration<URL> urls = getBundleResources(bundle, entry);
+         if (urls == null || urls.hasMoreElements() == false)
+            fail("Expected resource not found: " + entry);
+         while (urls.hasMoreElements())
+            expected.add(urls.nextElement());
+      }
+
+      assertEntries(bundle, path, filePattern, recurse, expected);
+      assertEntries(bundle, "/" + path, filePattern, recurse, expected);
+   }
+   
+   @SuppressWarnings("unchecked")
+   protected void assertEntries(Bundle bundle, String path, String filePattern, boolean recurse, Set<URL> expected) throws Exception
+   {
+      Set<URL> actual = new HashSet<URL>();
+      Enumeration<URL> enumeration = bundle.findEntries(path, filePattern, recurse);
+      while (enumeration != null && enumeration.hasMoreElements())
+         actual.add(enumeration.nextElement());
+      
+      assertEquals(expected, actual);
+   }
+
+   protected void assertNoEntries(Bundle bundle, String path, String filePattern, boolean recurse) throws Exception
+   {
+      assertEntries(bundle, path, filePattern, recurse);
+   }
+   
+   protected void assertEntryPaths(Bundle bundle, String path) throws Exception
+   {
+      Set<String> expected = Collections.singleton(path);
+
+      assertEntryPaths(bundle, path, expected);
+      assertEntryPaths(bundle, "/" + path, expected);
+   }
+   
+   protected void assertEntryPaths(String path, Bundle bundle, String... entries) throws Exception
+   {
+      Set<String> expected = new HashSet<String>();
+      expected.addAll(Arrays.asList(entries));
+
+      assertEntryPaths(bundle, path, expected);
+      assertEntryPaths(bundle, "/" + path, expected);
+   }
+   
+   @SuppressWarnings("unchecked")
+   protected void assertEntryPaths(Bundle bundle, String path, Set<String> expected) throws Exception
+   {
+      Set<String> actual = new HashSet<String>();
+      Enumeration<String> enumeration = bundle.getEntryPaths(path);
+      while (enumeration != null && enumeration.hasMoreElements())
+         actual.add(enumeration.nextElement());
+      
+      assertEquals(expected, actual);
+   }
+   
+   @SuppressWarnings("unchecked")
+   protected void assertNoEntryPaths(Bundle bundle, String path) throws Exception
+   {
+      Enumeration<String> enumeration = bundle.getEntryPaths(path);
+      if (enumeration != null)
+      {
+         Set<String> actual = new HashSet<String>();
+         while (enumeration.hasMoreElements())
+            actual.add(enumeration.nextElement());
+         fail("For path " + path + " did not expect entry paths: " + actual);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/BundleUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,245 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.bundle;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.jar.Attributes;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * BundleUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleUnitTestCase extends OSGiTestCase
+{
+   public BundleUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testBundleId() throws Exception
+   {
+      long id1 = -1;
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         id1 = bundle.getBundleId();
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+      assertEquals(id1, bundle.getBundleId());
+
+      long id2 = -1;
+      bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         id2 = bundle.getBundleId();
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+      assertEquals(id2, bundle.getBundleId());
+      assertTrue("Ids should be different" + id1 + "," + id2, id1 != id2);
+   }
+   
+   public void testSymbolicName() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName());
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+      assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName());
+   }
+   
+   public void testState() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         assertEquals(Bundle.INSTALLED, bundle.getState());
+
+         bundle.start();
+         assertEquals(Bundle.ACTIVE, bundle.getState());
+
+         bundle.stop();
+         assertEquals(Bundle.RESOLVED, bundle.getState());
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+      assertEquals(Bundle.UNINSTALLED, bundle.getState());
+   }
+   
+   public void testGetBundleContext() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNull(bundleContext);
+         
+         bundle.start();
+         bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+         
+         bundle.stop();
+         bundleContext = bundle.getBundleContext();
+         assertNull(bundleContext);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testLastModified() throws Exception
+   {
+      // TODO testLastModified
+   }
+   
+   public void testStartStop() throws Exception
+   {
+      // TODO testStartStop
+   }
+   
+   public void testUpdate() throws Exception
+   {
+      // TODO testUpdate
+   }
+   
+   public void testUninstall() throws Exception
+   {
+      // TODO testUninstall
+   }
+   
+   public void testSingleton() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundle1", "/bundles/singleton/singleton1");
+      try
+      {
+         Bundle bundle2 = assembleBundle("bundle2", "/bundles/singleton/singleton2");
+         uninstall(bundle2);
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(BundleException.class, t);
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testNotSingleton() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundle1", "/bundles/singleton/singleton1");
+      try
+      {
+         Bundle bundle2 = assembleBundle("not-singleton", "/bundles/singleton/not-singleton");
+         try
+         {
+            assertEquals(bundle1.getSymbolicName(), bundle2.getSymbolicName());
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   @SuppressWarnings("unchecked")
+   public void testGetHeaders() throws Exception
+   {
+      // TODO case insensistive
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         Dictionary expected = new Hashtable();
+         expected.put(Constants.BUNDLE_NAME, "Simple1");
+         expected.put(Constants.BUNDLE_SYMBOLICNAME, "org.jboss.test.osgi.simple1");
+         expected.put(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
+         expected.put(Attributes.Name.IMPLEMENTATION_TITLE.toString(), "JBoss OSGi tests");
+         expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
+         expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "test");
+         
+         Dictionary dictionary = bundle.getHeaders();
+         assertEquals(expected, dictionary);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testLocation() throws Exception
+   {
+      // TODO testGetLocation
+   }
+   
+   public void testGetRegisteredServices() throws Exception
+   {
+      // TODO testGetRegisteredServices
+   }
+   
+   public void testServicesInUse() throws Exception
+   {
+      // TODO testServicesInUse
+   }
+   
+   public void testHasPermission() throws Exception
+   {
+      // TODO testHasPermission
+   }
+   
+   public void testGetResources() throws Exception
+   {
+      // TODO testGetResource(s)
+   }
+   
+   public void testLoadClass() throws Exception
+   {
+      // TODO testLoadClass
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/test/SystemBundleUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,147 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.bundle;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.OSGiTestDelegate;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * SystemBundleUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SystemBundleUnitTestCase extends OSGiTestCase
+{
+   /** The system bundle */
+   private static Bundle systemBundle = null;
+   
+   public SystemBundleUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static void deployBundles(OSGiTestDelegate delegate) throws Exception
+   {
+      Bundle bundle = delegate.addBundle("/bundles/simple/", "simple-bundle1");
+      bundle.start();
+      BundleContext context = bundle.getBundleContext();
+      assertNotNull(context);
+      systemBundle = context.getBundle(0);
+      assertNotNull(systemBundle);
+   }
+   
+   public void testBundleId() throws Exception
+   {
+      assertEquals(0, systemBundle.getBundleId());
+   }
+   
+   public void testSymbolicName() throws Exception
+   {
+      assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, systemBundle.getSymbolicName());
+   }
+   
+   public void testState() throws Exception
+   {
+      assertEquals(Bundle.ACTIVE, systemBundle.getState());
+   }
+   
+   public void testStartStop() throws Exception
+   {
+      // TODO testStartStop
+   }
+   
+   public void testUpdate() throws Exception
+   {
+      // TODO testUpdate
+   }
+   
+   public void testUninstall() throws Exception
+   {
+      try
+      {
+         systemBundle.uninstall();
+         fail("Should not be here!");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(BundleException.class, t);
+      }
+   }
+   
+   @SuppressWarnings("unchecked")
+   public void testGetHeaders() throws Exception
+   {
+      Dictionary expected = new Hashtable();
+      expected.put(Constants.BUNDLE_NAME, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
+      expected.put(Constants.BUNDLE_SYMBOLICNAME, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
+      // todo expected.put(Attributes.Name.IMPLEMENTATION_TITLE.toString(), "JBoss OSGi");
+      // todo expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
+      // todo expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "r4v41");
+      
+      Dictionary dictionary = systemBundle.getHeaders();
+      assertEquals(expected, dictionary);
+   }
+   
+   public void testLocation() throws Exception
+   {
+      assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, systemBundle.getLocation());
+   }
+   
+   public void testGetEntry()
+   {
+      // TODO [JBOSGI-138] Proper system BundleContext implementation
+   }
+   
+   public void testGetEntryPath()
+   {
+      // TODO [JBOSGI-138] Proper system BundleContext implementation
+   }
+   
+   public void testFindEntries()
+   {
+      // TODO [JBOSGI-138] Proper system BundleContext implementation
+   }
+   
+   public void testLoadClass()
+   {
+      // TODO [JBOSGI-138] Proper system BundleContext implementation
+   }
+   
+   public void testGetResource()
+   {
+      // TODO [JBOSGI-138] Proper system BundleContext implementation
+   }
+   
+   public void testGetResources()
+   {
+      // TODO [JBOSGI-138] Proper system BundleContext implementation
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata)

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/AbstractManifestTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata/AbstractManifestTestCase.java	2009-11-05 18:58:42 UTC (rev 96066)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/AbstractManifestTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -19,7 +19,7 @@
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
-package org.jboss.test.bundle.metadata;
+package org.jboss.test.osgi.bundle.metadata;
 
 import java.io.IOException;
 import java.io.InputStream;

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata/HeaderValuesTestCase.java	2009-11-05 18:58:42 UTC (rev 96066)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/HeaderValuesTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -19,7 +19,7 @@
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
-package org.jboss.test.bundle.metadata;
+package org.jboss.test.osgi.bundle.metadata;
 
 import java.io.Serializable;
 import java.net.URL;
@@ -79,7 +79,7 @@
       Manifest manifest = getManifest(createName("Simple"));
       OSGiMetaData metaData = new AbstractOSGiMetaData(manifest);
 
-      assertEquals(metaData.getBundleActivator(), "org.jboss.test.bundle.metadata.BundleActivator");
+      assertEquals(metaData.getBundleActivator(), "org.jboss.test.osgi.bundle.metadata.BundleActivator");
       List<String> classpath = Arrays.asList("test.jar", "mc.jar", "seam.jar");
       assertEquals(metaData.getBundleClassPath(), classpath);
       assertEquals(metaData.getBundleDescription(), "TestHeadersManifest");

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/VersionRangeTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/bundle/metadata/VersionRangeTestCase.java	2009-11-05 18:58:42 UTC (rev 96066)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/metadata/VersionRangeTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -1,4 +1,4 @@
-package org.jboss.test.bundle.metadata;
+package org.jboss.test.osgi.bundle.metadata;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ClassLoaderDomainUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/test/ClassLoaderDomainUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ClassLoaderDomainUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ClassLoaderDomainUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,112 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.classloader;
+
+// $Id$
+
+import static org.junit.Assert.fail;
+
+import java.net.URL;
+
+import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.spi.filter.PackageClassFilter;
+import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.testing.OSGiTestHelper;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * ClassLoaderDomainUnitTestCase.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 03-Sep-2009
+ */
+public class ClassLoaderDomainUnitTestCase
+{
+   private static final String OSGI_CLASSLOADER_DOMAIN = "OSGiDomain";
+   private ClassLoaderSystem classLoaderSystem;
+
+   @Before
+   public void setUp()
+   {
+      classLoaderSystem = new DefaultClassLoaderSystem();
+      AbstractJDKChecker.getExcluded().add(getClass());
+   }
+
+   @Test
+   public void testSystemPolicy() throws Exception
+   {
+      ClassLoaderDomain domain = new ClassLoaderDomain(OSGI_CLASSLOADER_DOMAIN);
+      classLoaderSystem.registerDomain(domain);
+      
+      // Setup the class filter
+      String filteredPackages = Logger.class.getPackage().getName();
+      PackageClassFilter classFilter = PackageClassFilter.createPackageClassFilterFromString(filteredPackages);
+      classFilter.setIncludeJava(true);
+
+      domain.setParentPolicy(new ParentPolicy(classFilter, ClassFilter.NOTHING));
+
+      URL coreURL = new OSGiTestHelper().getTestArchiveURL("bundles/org.osgi.core.jar");
+      VirtualFile coreVF = VFS.createNewRoot(coreURL);
+
+      ClassLoaderPolicy systemPolicy = new VFSClassLoaderPolicy("OSGiSystemPolicy", new VirtualFile[] { coreVF });
+      ClassLoader classLoader = classLoaderSystem.registerClassLoaderPolicy(OSGI_CLASSLOADER_DOMAIN, systemPolicy);
+
+      // Load JDK class
+      assertLoadClass(classLoader, String.class.getName(), true);
+      
+      // Load from org.osgi.core
+      assertLoadClass(classLoader, Bundle.class.getName(), true);
+      
+      // Load from system classpath 
+      assertLoadClass(classLoader, Logger.class.getName(), true);
+      
+      // No access to implementation
+      assertLoadClass(classLoader, OSGiBundleManager.class.getName(), false);
+   }
+   
+   private void assertLoadClass(ClassLoader classLoader, String name, boolean success)
+   {
+      try
+      {
+         classLoader.loadClass(name);
+         if (success == false)
+            fail("Expected ClassNotFoundException for '" + name + "' from " + classLoader);
+      }
+      catch (ClassNotFoundException ex)
+      {
+         if (success)
+            fail("Cannot load '" + name + "' from " + classLoader);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/test/ExportImportPackageUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,519 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.classloader;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.classloader.support.a.A;
+import org.jboss.test.osgi.classloader.support.b.B;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * ExportImportUnitTestCase.
+ * 
+ * TODO test security 
+ * TODO test mandatory attributes 
+ * TODO test include/exclude 
+ * TODO test uses
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
+ * @version $Revision: 1.1 $
+ */
+public class ExportImportPackageUnitTestCase extends OSGiTestCase
+{
+   public ExportImportPackageUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testSimpleImportPackage() throws Exception
+   {
+      //Bundle-Name: BundleA
+      //Bundle-Version: 1.0.0
+      //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
+      //Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         
+         //Bundle-Name: BundleB
+         //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+         //Export-Package: org.jboss.test.osgi.classloader.support.b
+         //Import-Package: org.jboss.test.osgi.classloader.support.a
+         Bundle bundle2 = assembleBundle("simpleimportpackageA", "/bundles/classloader/simpleimportpackageA", B.class);
+         
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+
+            assertLoadClassFail(bundle1, B.class);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+
+   public void testSimpleImportPackageFails() throws Exception
+   {
+      //Bundle-Name: BundleA
+      //Bundle-Version: 1.0.0
+      //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
+      //Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         
+         //Bundle-Name: BundleB
+         //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+         //Import-Package: doesnotexist
+         Bundle bundle2 = assembleBundle("simpleimportpackagefails", "/bundles/classloader/simpleimportpackagefails", B.class);
+         
+         try
+         {
+            bundle2.start();
+            fail("Should not be here!");
+         }
+         catch (BundleException ex)
+         {
+            // expected
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+
+   public void testSelfImportPackage() throws Exception
+   {
+      //Bundle-Name: BundleB
+      //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+      //Export-Package: org.jboss.test.osgi.classloader.support.b
+      //Import-Package: org.jboss.test.osgi.classloader.support.a
+      Bundle bundleB = assembleBundle("BundleB", "/bundles/classloader/simpleimportpackageA", B.class);
+      
+      try
+      {
+         assertEquals("Bundle INSTALLED", Bundle.INSTALLED, bundleB.getState());
+         
+         try
+         {
+            bundleB.start();
+            fail("Expected to fail due to unresolved import");
+         }
+         catch (BundleException ex)
+         {
+            // expected
+         }
+         
+         //Bundle-Name: BundleA
+         //Bundle-Version: 1.0.0
+         //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA
+         //Export-Package: org.jboss.test.osgi.classloader.support.a, org.jboss.test.osgi.classloader.support.b 
+         //Import-Package: org.jboss.test.osgi.classloader.support.a, org.jboss.test.osgi.classloader.support.b 
+         Bundle bundleA = assembleBundle("BundleA", "/bundles/classloader/selfimportpackageAB", A.class, B.class);
+         
+         try
+         {
+            bundleB.start();
+            assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundleB.getState());
+            
+            // BundleA is expected to resolve when BundleB gets started
+            assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundleA.getState());
+            assertLoadClass(bundleA, A.class, bundleA);
+            assertLoadClass(bundleA, B.class, bundleA);
+
+            // BundleB imports A from BundleA
+            assertLoadClass(bundleB, A.class, bundleA);
+            
+            // BundleB does not import B
+            assertLoadClass(bundleB, B.class, bundleB);
+         }
+         finally
+         {
+            uninstall(bundleA);
+         }
+      }
+      finally
+      {
+         uninstall(bundleB);
+      }
+   }
+
+   public void testVersionImportPackage() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("versionimportpackageA", "/bundles/classloader/versionimportpackageA", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+
+   public void testVersionImportPackageFails() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("versionimportpackagefails", "/bundles/classloader/versionimportpackagefails", B.class);
+         try
+         {
+            bundle2.start();
+            fail("Should not be here!");
+         }
+         catch (BundleException ex)
+         {
+            // expected
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+
+   public void testOptionalImportPackage() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("optionalimportpackageA", "/bundles/classloader/optionalimportpackageA", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+
+   public void testOptionalImportPackageFails() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("optionalimportpackagefails", "/bundles/classloader/optionalimportpackagefails", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClassFail(bundle2, A.class);
+            assertLoadClass(bundle2, B.class);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+
+   public void testBundleNameImportPackage() throws Exception
+   {
+      //Bundle-Name: NotBundleA
+      //Bundle-Version: 1.0.0
+      //Bundle-SymbolicName: org.jboss.test.osgi.classloader.notbundleA
+      //Export-Package: org.jboss.test.osgi.classloader.support.a
+      Bundle bundle0 = assembleBundle("notbundleA", "/bundles/classloader/notbundleA", A.class);
+      
+      try
+      {
+         bundle0.start();
+         assertLoadClass(bundle0, A.class);
+         assertLoadClass(bundle0, A.class, bundle0);
+         
+         //Bundle-Name: BundleA
+         //Bundle-Version: 1.0.0
+         //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
+         //Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
+         Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+         
+         try
+         {
+            bundle1.start();
+            assertLoadClass(bundle1, A.class);
+            assertLoadClass(bundle1, A.class, bundle1);
+            
+            //Bundle-Name: BundleB
+            //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+            //Import-Package: org.jboss.test.osgi.classloader.support.a;bundle-symbolic-name=org.jboss.test.osgi.classloader.bundleA
+            Bundle bundle2 = assembleBundle("bundlenameimportpackageA", "/bundles/classloader/bundlenameimportpackageA", B.class);
+            
+            try
+            {
+               bundle2.start();
+               assertLoadClass(bundle2, A.class, bundle1);
+               assertLoadClass(bundle2, B.class, bundle2);
+            }
+            finally
+            {
+               uninstall(bundle2);
+            }
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         uninstall(bundle0);
+      }
+   }
+
+   public void testBundleNameImportPackageFails() throws Exception
+   {
+      Bundle bundle0 = assembleBundle("notbundleA", "/bundles/classloader/notbundleA", A.class);
+      try
+      {
+         bundle0.start();
+         assertLoadClass(bundle0, A.class);
+         Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+         try
+         {
+            bundle1.start();
+            assertLoadClass(bundle1, A.class);
+            Bundle bundle2 = assembleBundle("bundlenameimportpackagefails", "/bundles/classloader/bundlenameimportpackagefails", B.class);
+            try
+            {
+               bundle2.start();
+               fail("Should not be here!");
+            }
+            catch (BundleException ex)
+            {
+               // expected
+            }
+            finally
+            {
+               uninstall(bundle2);
+            }
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         uninstall(bundle0);
+      }
+   }
+
+   public void testBundleVersionImportPackage() throws Exception
+   {
+      Bundle bundle0 = assembleBundle("bundleA2", "/bundles/classloader/bundleA2", A.class);
+      try
+      {
+         bundle0.start();
+         assertLoadClass(bundle0, A.class);
+         Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+         try
+         {
+            bundle1.start();
+            assertLoadClass(bundle1, A.class);
+            Bundle bundle2 = assembleBundle("bundleversionimportpackageA", "/bundles/classloader/bundleversionimportpackageA", B.class);
+            try
+            {
+               bundle2.start();
+               assertLoadClass(bundle2, A.class, bundle1);
+               assertLoadClass(bundle2, B.class, bundle2);
+            }
+            finally
+            {
+               uninstall(bundle2);
+            }
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         uninstall(bundle0);
+      }
+   }
+
+   public void testBundleVersionImportPackageFails() throws Exception
+   {
+      Bundle bundle0 = assembleBundle("bundleA2", "/bundles/classloader/bundleA2", A.class);
+      try
+      {
+         bundle0.start();
+         assertLoadClass(bundle0, A.class);
+         Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+         try
+         {
+            bundle1.start();
+            assertLoadClass(bundle1, A.class);
+            Bundle bundle2 = assembleBundle("bundleversionimportpackagefails", "/bundles/classloader/bundleversionimportpackagefails", B.class);
+            try
+            {
+               bundle2.start();
+               fail("Should not be here!");
+            }
+            catch (BundleException ex)
+            {
+               // expected
+            }
+            finally
+            {
+               uninstall(bundle2);
+            }
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         uninstall(bundle0);
+      }
+   }
+
+   public void testAttributeImportPackage() throws Exception
+   {
+      Bundle bundle0 = assembleBundle("bundleA2", "/bundles/classloader/bundleA2", A.class);
+      try
+      {
+         bundle0.start();
+         assertLoadClass(bundle0, A.class);
+         Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+         try
+         {
+            bundle1.start();
+            assertLoadClass(bundle1, A.class);
+            Bundle bundle2 = assembleBundle("attributeimportpackageA", "/bundles/classloader/attributeimportpackageA", B.class);
+            try
+            {
+               bundle2.start();
+               assertLoadClass(bundle2, A.class, bundle1);
+               assertLoadClass(bundle2, B.class, bundle2);
+            }
+            finally
+            {
+               uninstall(bundle2);
+            }
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         uninstall(bundle0);
+      }
+   }
+
+   public void testAttributeImportPackageFails() throws Exception
+   {
+      Bundle bundle0 = assembleBundle("bundleA2", "/bundles/classloader/bundleA2", A.class);
+      try
+      {
+         bundle0.start();
+         assertLoadClass(bundle0, A.class);
+         Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+         try
+         {
+            bundle1.start();
+            assertLoadClass(bundle1, A.class);
+            Bundle bundle2 = assembleBundle("attributeimportpackagefails", "/bundles/classloader/attributeimportpackagefails", B.class);
+            try
+            {
+               bundle2.start();
+               fail("Should not be here!");
+            }
+            catch (BundleException ex)
+            {
+               // expected
+            }
+            finally
+            {
+               uninstall(bundle2);
+            }
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         uninstall(bundle0);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/test/RequireBundleUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,338 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.classloader;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.classloader.support.a.A;
+import org.jboss.test.osgi.classloader.support.b.B;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * RequireBundleUnitTestCase.
+ *
+ * TODO test security
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RequireBundleUnitTestCase extends OSGiTestCase
+{
+   public RequireBundleUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testSimpleRequireBundle() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("simplerequirebundleA", "/bundles/classloader/simplerequirebundleA", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testSimpleRequireBundleFails() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("simplerequirebundlefails", "/bundles/classloader/simplerequirebundlefails", B.class);
+         try
+         {
+            bundle2.start();
+            fail("Should not be here!");
+         }
+         catch (BundleException ex)
+         {
+            // expected
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testVersionRequireBundle() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("versionrequirebundleA", "/bundles/classloader/versionrequirebundleA", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testVersionRequireBundleFails() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("versionrequirebundlefails", "/bundles/classloader/versionrequirebundlefails", B.class);
+         try
+         {
+            bundle2.start();
+            fail("Should not be here!");
+         }
+         catch (RuntimeException rte)
+         {
+            // expected
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testOptionalRequireBundle() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("optionalrequirebundleA", "/bundles/classloader/optionalrequirebundleA", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testOptionalRequireBundleFails() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("optionalrequirebundlefails", "/bundles/classloader/optionalrequirebundlefails", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClassFail(bundle2, A.class);
+            assertLoadClass(bundle2, B.class);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testReExportRequireBundle() throws Exception
+   {
+      //Bundle-Name: BundleA
+      //Bundle-Version: 1.0.0
+      //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
+      //Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         
+         //Bundle-Name: BundleB
+         //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
+         //Require-Bundle: org.jboss.test.osgi.classloader.bundleA;visibility:=reexport
+         //Export-Package: org.jboss.test.osgi.classloader.support.b
+         Bundle bundle2 = assembleBundle("reexportrequirebundleA", "/bundles/classloader/reexportrequirebundleA", B.class);
+         
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+            
+            //Bundle-Name: BundleC
+            //Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleC
+            //Require-Bundle: org.jboss.test.osgi.classloader.bundleB
+            Bundle bundle3 = assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
+            
+            try
+            {
+               assertLoadClass(bundle3, A.class, bundle1);
+               assertLoadClass(bundle3, B.class, bundle2);
+            }
+            finally
+            {
+               uninstall(bundle3);
+            }
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testNoReExportRequireBundle() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("noreexportrequirebundleA", "/bundles/classloader/noreexportrequirebundleA", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+            Bundle bundle3 = assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
+            try
+            {
+               assertLoadClassFail(bundle3, A.class);
+               assertLoadClass(bundle3, B.class, bundle2);
+            }
+            finally
+            {
+               uninstall(bundle3);
+            }
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testAttributeRequireBundle() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("attributerequirebundleA", "/bundles/classloader/attributerequirebundleA", B.class);
+         try
+         {
+            bundle2.start();
+            assertLoadClass(bundle2, A.class, bundle1);
+            assertLoadClass(bundle2, B.class, bundle2);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testAttributeRequireBundleFails() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+      try
+      {
+         bundle1.start();
+         assertLoadClass(bundle1, A.class);
+         Bundle bundle2 = assembleBundle("attributerequirebundlefails", "/bundles/classloader/attributerequirebundlefails", B.class);
+         try
+         {
+            bundle2.start();
+            fail("Should not be here!");
+         }
+         catch (RuntimeException rte)
+         {
+            // expected
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/GetServiceReferencesUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,569 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.service;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.a.A;
+import org.jboss.test.osgi.service.support.b.B;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetServiceReferencesUnitTestCase.
+ *
+ * todo test service permissions
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class GetServiceReferencesUnitTestCase extends OSGiTestCase
+{
+   public GetServiceReferencesUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testGetServiceReferences() throws Exception
+   {
+      Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+      try
+      {
+         bundle1.start();
+         BundleContext bundleContext1 = bundle1.getBundleContext();
+         assertNotNull(bundleContext1);
+         
+         assertNoGetReference(bundleContext1, A.class.getName());
+         assertNoReferences(bundleContext1, A.class.getName());
+         assertNoAllReferences(bundleContext1, A.class.getName());
+         assertNoGetReference(bundleContext1, B.class.getName());
+         assertNoReferences(bundleContext1, B.class.getName());
+         assertNoAllReferences(bundleContext1, B.class.getName());
+
+         Class<?> clazz = bundle1.loadClass(A.class.getName());
+         Object service1 = clazz.newInstance();
+         ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+         assertNotNull(registration1);
+         ServiceReference reference1 = registration1.getReference();
+         assertNotNull(reference1);
+
+         assertGetReference(bundleContext1, A.class.getName(), reference1);
+         assertReferences(bundleContext1, A.class.getName(), reference1);
+         assertAllReferences(bundleContext1, A.class.getName(), reference1);
+         assertNoGetReference(bundleContext1, B.class.getName());
+         assertNoReferences(bundleContext1, B.class.getName());
+         assertNoAllReferences(bundleContext1, B.class.getName());
+         
+         registration1.unregister();
+         
+         assertNoGetReference(bundleContext1, A.class.getName());
+         assertNoReferences(bundleContext1, A.class.getName());
+         assertNoAllReferences(bundleContext1, A.class.getName());
+         assertNoGetReference(bundleContext1, B.class.getName());
+         assertNoReferences(bundleContext1, B.class.getName());
+         assertNoAllReferences(bundleContext1, B.class.getName());
+         
+         try
+         {
+            bundleContext1.getServiceReference(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext1.getServiceReferences(null, "invalid");
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(InvalidSyntaxException.class, t);
+         }
+         
+         try
+         {
+            bundleContext1.getAllServiceReferences(null, "invalid");
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(InvalidSyntaxException.class, t);
+         }
+         
+         bundle1.stop();
+         
+         try
+         {
+            bundleContext1.getServiceReference(A.class.getName());
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+         
+         try
+         {
+            bundleContext1.getServiceReferences(null, null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+         
+         try
+         {
+            bundleContext1.getAllServiceReferences(null, null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testGetServiceReferencesNoClassNotAssignable() throws Exception
+   {
+      assertGetServiceReferencesNotAssignable(null);
+   }
+   
+   public void testGetServiceReferencesNotAssignable() throws Exception
+   {
+      assertGetServiceReferencesNotAssignable(A.class.getName());
+   }
+   
+   public void assertGetServiceReferencesNotAssignable(String className) throws Exception
+   {
+      Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+      try
+      {
+         bundle1.start();
+         BundleContext bundleContext1 = bundle1.getBundleContext();
+         assertNotNull(bundleContext1);
+         
+         if (className != null)
+            assertNoGetReference(bundleContext1, className);
+
+         Class<?> clazz = bundle1.loadClass(A.class.getName());
+         Object service1 = clazz.newInstance();
+         ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+         assertNotNull(registration1);
+         ServiceReference reference1 = registration1.getReference();
+         assertNotNull(reference1);
+
+         Bundle bundle2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+         try
+         {
+            bundle2.start();
+            BundleContext bundleContext2 = bundle2.getBundleContext();
+            assertNotNull(bundleContext2);
+
+            if (className != null)
+               assertNoGetReference(bundleContext2, className);
+
+            clazz = bundle2.loadClass(A.class.getName());
+            Object service2 = clazz.newInstance();
+            ServiceRegistration registration2 = bundleContext2.registerService(A.class.getName(), service2, null);
+            assertNotNull(registration2);
+            ServiceReference reference2 = registration2.getReference();
+            assertNotNull(reference2);
+            
+            if (className != null)
+               assertGetReference(bundleContext1, className, reference1);
+
+            if (className != null)
+               assertGetReference(bundleContext2, className, reference2);
+            
+            registration1.unregister();
+            
+            if (className != null)
+               assertNoGetReference(bundleContext1, className);
+
+            if (className != null)
+               assertGetReference(bundleContext2, className, reference2);
+
+            registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+            assertNotNull(registration1);
+            reference1 = registration1.getReference();
+            assertNotNull(reference1);
+            
+            if (className != null)
+               assertGetReference(bundleContext1, className, reference1);
+
+            if (className != null)
+               assertGetReference(bundleContext2, className, reference2);
+            
+            registration2.unregister();
+            
+            if (className != null)
+               assertGetReference(bundleContext1, className, reference1);
+
+            if (className != null)
+               assertNoGetReference(bundleContext2, className);
+            
+            registration1.unregister();
+            
+            if (className != null)
+               assertNoGetReference(bundleContext1, className);
+
+            if (className != null)
+               assertNoGetReference(bundleContext2, className);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+
+   public void testGetServiceReferencesNoClassAssignable() throws Exception
+   {
+      assertGetServiceReferencesAssignable(null);
+   }
+
+   public void testGetServiceReferencesClassAssignable() throws Exception
+   {
+      assertGetServiceReferencesAssignable(A.class.getName());
+   }
+
+   public void assertGetServiceReferencesAssignable(String className) throws Exception
+   {
+      Bundle bundle1 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+      try
+      {
+         bundle1.start();
+         BundleContext bundleContext1 = bundle1.getBundleContext();
+         assertNotNull(bundleContext1);
+
+         if (className != null)
+            assertNoGetReference(bundleContext1, className);
+
+         Class<?> clazz = bundle1.loadClass(A.class.getName());
+         Object service1 = clazz.newInstance();
+         ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+         assertNotNull(registration1);
+         ServiceReference reference1 = registration1.getReference();
+         assertNotNull(reference1);
+
+         Bundle bundle2 = assembleBundle("service1", "/bundles/service/service-bundle1");
+         try
+         {
+            bundle2.start();
+            BundleContext bundleContext2 = bundle2.getBundleContext();
+            assertNotNull(bundleContext2);
+
+            if (className != null)
+               assertGetReference(bundleContext2, className, reference1);
+
+            clazz = bundle2.loadClass(A.class.getName());
+            Object service2 = clazz.newInstance();
+            ServiceRegistration registration2 = bundleContext2.registerService(A.class.getName(), service2, null);
+            assertNotNull(registration2);
+            ServiceReference reference2 = registration2.getReference();
+            assertNotNull(reference2);
+            
+            if (className != null)
+               assertGetReference(bundleContext1, className, reference1);
+
+            if (className != null)
+               assertGetReference(bundleContext2, className, reference1);
+            
+            registration1.unregister();
+            
+            if (className != null)
+               assertGetReference(bundleContext1, className, reference2);
+
+            if (className != null)
+               assertGetReference(bundleContext2, className, reference2);
+
+            registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
+            assertNotNull(registration1);
+            reference1 = registration1.getReference();
+            assertNotNull(reference1);
+            
+            if (className != null)
+               assertGetReference(bundleContext1, className, reference2);
+
+            if (className != null)
+               assertGetReference(bundleContext2, className, reference2);
+            
+            registration2.unregister();
+            
+            if (className != null)
+               assertGetReference(bundleContext1, className, reference1);
+
+            if (className != null)
+               assertGetReference(bundleContext2, className, reference1);
+            
+            registration1.unregister();
+            
+            if (className != null)
+               assertNoGetReference(bundleContext1, className);
+
+            if (className != null)
+               assertNoGetReference(bundleContext2, className);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+
+   public void testGetServiceReferencesRankings() throws Exception
+   {
+      String className = A.class.getName();
+      
+      Bundle bundle1 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+      try
+      {
+         bundle1.start();
+         BundleContext bundleContext1 = bundle1.getBundleContext();
+         assertNotNull(bundleContext1);
+         
+         assertNoGetReference(bundleContext1, className);
+         assertNoReferences(bundleContext1, className);
+         assertNoAllReferences(bundleContext1, className);
+
+         Dictionary<String, Object> properties1 = new Hashtable<String, Object>();
+         properties1.put(Constants.SERVICE_RANKING, 1);
+         Class<?> clazz = bundle1.loadClass(className);
+         Object service1 = clazz.newInstance();
+         ServiceRegistration registration1 = bundleContext1.registerService(className, service1, properties1);
+         assertNotNull(registration1);
+         ServiceReference reference1 = registration1.getReference();
+         assertNotNull(reference1);
+
+         Bundle bundle2 = assembleBundle("service1", "/bundles/service/service-bundle1");
+         try
+         {
+            bundle2.start();
+            BundleContext bundleContext2 = bundle2.getBundleContext();
+            assertNotNull(bundleContext2);
+
+            assertGetReference(bundleContext2, className, reference1);
+            assertReferences(bundleContext2, className,  reference1);
+            assertAllReferences(bundleContext2, className,  reference1);
+
+            Dictionary<String, Object> properties2 = new Hashtable<String, Object>();
+            properties2.put(Constants.SERVICE_RANKING, 2);
+            clazz = bundle2.loadClass(className);
+            Object service2 = clazz.newInstance();
+            ServiceRegistration registration2 = bundleContext2.registerService(className, service2, properties2);
+            assertNotNull(registration2);
+            ServiceReference reference2 = registration2.getReference();
+            assertNotNull(reference2);
+            
+            assertGetReference(bundleContext1, className, reference2);
+            assertReferences(bundleContext1, className,  reference2, reference1);
+            assertAllReferences(bundleContext1, className,  reference2, reference1);
+
+            assertGetReference(bundleContext2, className, reference2);
+            assertReferences(bundleContext2, className,  reference2, reference1);
+            assertAllReferences(bundleContext2, className,  reference2, reference1);
+            
+            registration1.unregister();
+            
+            assertGetReference(bundleContext1, className, reference2);
+            assertReferences(bundleContext1, className,  reference2);
+            assertAllReferences(bundleContext1, className,  reference2);
+
+            assertGetReference(bundleContext2, className, reference2);
+            assertReferences(bundleContext2, className,  reference2);
+            assertAllReferences(bundleContext2, className,  reference2);
+
+            registration1 = bundleContext1.registerService(className, service1, properties1);
+            assertNotNull(registration1);
+            reference1 = registration1.getReference();
+            assertNotNull(reference1);
+            
+            assertGetReference(bundleContext1, className, reference2);
+            assertReferences(bundleContext1, className,  reference2, reference1);
+            assertAllReferences(bundleContext1, className,  reference2, reference1);
+
+            assertGetReference(bundleContext2, className, reference2);
+            assertReferences(bundleContext2, className,  reference2, reference1);
+            assertAllReferences(bundleContext2, className,  reference2, reference1);
+            
+            registration2.unregister();
+            
+            assertGetReference(bundleContext1, className, reference1);
+            assertReferences(bundleContext1, className,  reference1);
+            assertAllReferences(bundleContext1, className,  reference1);
+
+            assertGetReference(bundleContext2, className, reference1);
+            assertReferences(bundleContext2, className,  reference1);
+            assertAllReferences(bundleContext2, className,  reference1);
+            
+            registration1.unregister();
+            
+            assertNoGetReference(bundleContext1, className);
+            assertNoReferences(bundleContext1, className);
+            assertNoAllReferences(bundleContext1, className);
+
+            if (className != null)
+               assertNoGetReference(bundleContext2, className);
+            assertNoReferences(bundleContext2, className);
+            assertNoAllReferences(bundleContext2, className);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+   
+   public void testGetServiceReferencesFilterted() throws Exception
+   {
+      String className = A.class.getName();
+      String wrongClassName = B.class.getName();
+      
+      Bundle bundle1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+      try
+      {
+         bundle1.start();
+         BundleContext bundleContext1 = bundle1.getBundleContext();
+         assertNotNull(bundleContext1);
+         
+         assertNoGetReference(bundleContext1, A.class.getName());
+         assertNoReferences(bundleContext1, null, "(a=b)");
+         assertNoAllReferences(bundleContext1, null, "(a=b)");
+         assertNoReferences(bundleContext1, className, "(a=b)");
+         assertNoAllReferences(bundleContext1, className, "(a=b)");
+         assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+         assertNoReferences(bundleContext1, null, "(c=d)");
+         assertNoAllReferences(bundleContext1, null, "(c=d)");
+         assertNoReferences(bundleContext1, className, "(c=d)");
+         assertNoAllReferences(bundleContext1, className, "(c=d)");
+         assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+         assertNoReferences(bundleContext1, null, "(c=x)");
+         assertNoAllReferences(bundleContext1, null, "(c=x)");
+         assertNoReferences(bundleContext1, className, "(c=x)");
+         assertNoAllReferences(bundleContext1, className, "(c=x)");
+         assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+         assertNoReferences(bundleContext1, null, "(x=d)");
+         assertNoAllReferences(bundleContext1, null, "(x=d)");
+         assertNoReferences(bundleContext1, className, "(x=d)");
+         assertNoAllReferences(bundleContext1, className, "(x=d)");
+         assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+
+         Dictionary<String, Object> properties = new Hashtable<String, Object>();
+         properties.put("a", "b");
+         properties.put("c", "d");
+         
+         Class<?> clazz = bundle1.loadClass(A.class.getName());
+         Object service1 = clazz.newInstance();
+         ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, properties);
+         assertNotNull(registration1);
+         ServiceReference reference1 = registration1.getReference();
+         assertNotNull(reference1);
+
+         assertGetReference(bundleContext1, A.class.getName(), reference1);
+         assertReferences(bundleContext1, null, "(a=b)", reference1);
+         assertAllReferences(bundleContext1, null, "(a=b)", reference1);
+         assertReferences(bundleContext1, className, "(a=b)", reference1);
+         assertAllReferences(bundleContext1, className, "(a=b)", reference1);
+         assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+         assertReferences(bundleContext1, null, "(c=d)", reference1);
+         assertAllReferences(bundleContext1, null, "(c=d)", reference1);
+         assertReferences(bundleContext1, className, "(c=d)", reference1);
+         assertAllReferences(bundleContext1, className, "(c=d)", reference1);
+         assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+         assertNoReferences(bundleContext1, null, "(c=x)");
+         assertNoAllReferences(bundleContext1, null, "(c=x)");
+         assertNoReferences(bundleContext1, className, "(c=x)");
+         assertNoAllReferences(bundleContext1, className, "(c=x)");
+         assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+         assertNoReferences(bundleContext1, null, "(x=d)");
+         assertNoAllReferences(bundleContext1, null, "(x=d)");
+         assertNoReferences(bundleContext1, className, "(x=d)");
+         assertNoAllReferences(bundleContext1, className, "(x=d)");
+         assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+         
+         registration1.unregister();
+         
+         assertNoGetReference(bundleContext1, A.class.getName());
+         assertNoReferences(bundleContext1, null, "(a=b)");
+         assertNoAllReferences(bundleContext1, null, "(a=b)");
+         assertNoReferences(bundleContext1, className, "(a=b)");
+         assertNoAllReferences(bundleContext1, className, "(a=b)");
+         assertNoReferences(bundleContext1, wrongClassName, "(a=b)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(a=b)");
+         assertNoReferences(bundleContext1, null, "(c=d)");
+         assertNoAllReferences(bundleContext1, null, "(c=d)");
+         assertNoReferences(bundleContext1, className, "(c=d)");
+         assertNoAllReferences(bundleContext1, className, "(c=d)");
+         assertNoReferences(bundleContext1, wrongClassName, "(c=d)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(c=d)");
+         assertNoReferences(bundleContext1, null, "(c=x)");
+         assertNoAllReferences(bundleContext1, null, "(c=x)");
+         assertNoReferences(bundleContext1, className, "(c=x)");
+         assertNoAllReferences(bundleContext1, className, "(c=x)");
+         assertNoReferences(bundleContext1, wrongClassName, "(c=x)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(c=x)");
+         assertNoReferences(bundleContext1, null, "(x=d)");
+         assertNoAllReferences(bundleContext1, null, "(x=d)");
+         assertNoReferences(bundleContext1, className, "(x=d)");
+         assertNoAllReferences(bundleContext1, className, "(x=d)");
+         assertNoReferences(bundleContext1, wrongClassName, "(x=d)");
+         assertNoAllReferences(bundleContext1, wrongClassName, "(x=d)");
+      }
+      finally
+      {
+         uninstall(bundle1);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,197 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.service;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.BrokenServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetUnGetServiceUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class GetUnGetServiceUnitTestCase extends OSGiTestCase
+{
+   static String OBJCLASS = BundleContext.class.getName();
+
+   public GetUnGetServiceUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testGetUnServiceErrors() throws Exception
+   {
+      String OBJCLASS = BundleContext.class.getName();
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         bundleContext.registerService(OBJCLASS, bundleContext, null);
+         
+         try
+         {
+            bundleContext.getService(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.ungetService(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testGetService() throws Exception
+   {
+      String OBJCLASS = BundleContext.class.getName();
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+         ServiceReference reference = registration.getReference();
+
+         Object actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+         
+         registration.unregister();
+         actual = bundleContext.getService(reference);
+         assertNull("" + actual, actual);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testGetServiceAfterStop() throws Exception
+   {
+      String OBJCLASS = BundleContext.class.getName();
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+         ServiceReference reference = registration.getReference();
+
+         Object actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+         
+         bundle.stop();
+         try
+         {
+            bundleContext.getService(reference);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testErrorInGetService() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         bundleContext.addFrameworkListener(this);
+         
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), new BrokenServiceFactory(bundleContext, true), null);
+         ServiceReference reference = registration.getReference();
+         Object actual = bundleContext.getService(reference);
+         assertNull("" + actual, actual);
+         
+         assertFrameworkEvent(FrameworkEvent.ERROR, bundle, RuntimeException.class);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testErrorInUnGetService() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         bundleContext.addFrameworkListener(this);
+         
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), new BrokenServiceFactory(bundleContext, false), null);
+         ServiceReference reference = registration.getReference();
+         Object actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+         assertNoFrameworkEvent();
+
+         registration.unregister();
+         
+         assertFrameworkEvent(FrameworkEvent.WARNING, bundle, RuntimeException.class);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,240 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.service;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * RegisterServiceUnitTestCase.
+ *
+ * todo test secutiry
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RegisterServiceUnitTestCase extends OSGiTestCase
+{
+   static String OBJCLASS = BundleContext.class.getName();
+   static String[] OBJCLASSES = new String[] { OBJCLASS };
+
+   public RegisterServiceUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testRegisterServiceErrors() throws Exception
+   {
+      String OBJCLASS = BundleContext.class.getName();
+      String[] OBJCLASSES = new String[] { OBJCLASS };
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+         
+         try
+         {
+            bundleContext.registerService((String) null, new Object(), null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.registerService((String[]) null, new Object(), null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.registerService(new String[0], new Object(), null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.registerService(OBJCLASS, null, null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.registerService(OBJCLASSES, null, null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.registerService(OBJCLASS, new Object(), null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.registerService(OBJCLASSES, new Object(), null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+
+         Dictionary<String, Object> properties = new Hashtable<String, Object>();
+         properties.put("case", "a");
+         properties.put("CASE", "a");
+         try
+         {
+            bundleContext.registerService(OBJCLASS, bundleContext, properties);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.registerService(OBJCLASSES, bundleContext, properties);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         bundle.stop();
+
+         try
+         {
+            bundleContext.registerService(OBJCLASS, bundleContext, null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+         
+         try
+         {
+            bundleContext.registerService(OBJCLASSES, bundleContext, null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testRegisterServiceOBJCLASS() throws Exception
+   {
+      Dictionary<String, Object> properties = new Hashtable<String, Object>();
+      properties.put(Constants.OBJECTCLASS, new String[] { "rubbish" });
+
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+         ServiceReference reference = registration.getReference();
+         assertObjectClass(OBJCLASS, reference);
+         registration.setProperties(properties);
+         assertObjectClass(OBJCLASS, reference);
+         registration.unregister();
+
+         registration = bundleContext.registerService(OBJCLASSES, bundleContext, null);
+         reference = registration.getReference();
+         assertObjectClass(OBJCLASSES, reference);
+         registration.setProperties(properties);
+         assertObjectClass(OBJCLASSES, reference);
+         registration.unregister();
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testRegisterService() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
+         ServiceReference reference = registration.getReference();
+         Object actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+
+         registration = bundleContext.registerService(OBJCLASSES, bundleContext, null);
+         reference = registration.getReference();
+         actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,198 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.service;
+
+import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetUnGetServiceUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
+ * @version $Revision$
+ */
+public class ServiceFactoryUnitTestCase extends OSGiTestCase
+{
+   static String OBJCLASS = BundleContext.class.getName();
+   static String[] OBJCLASSES = new String[] { OBJCLASS };
+
+   public ServiceFactoryUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testRegisterServiceFactory() throws Exception
+   {
+      Bundle bundleA = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundleA.start();
+         BundleContext contextA = bundleA.getBundleContext();
+         assertNotNull(contextA);
+
+         SimpleServiceFactory serviceFactory = new SimpleServiceFactory(contextA);
+         ServiceRegistration sregA = contextA.registerService(OBJCLASS, serviceFactory, null);
+         
+         ServiceReference srefA = sregA.getReference();
+         Object actual = contextA.getService(srefA);
+         assertEquals(contextA, actual);
+         assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+         assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+         assertEquals(1, serviceFactory.getCount);
+         
+         srefA = contextA.getServiceReference(OBJCLASS);
+         actual = contextA.getService(srefA);
+         assertEquals(contextA, actual);
+         assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+         assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+         assertEquals(1, serviceFactory.getCount);
+
+         Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
+         try
+         {
+            bundleB.start();
+            BundleContext contextB = bundleB.getBundleContext();
+            assertNotNull(contextB);
+
+            ServiceReference srefB = contextB.getServiceReference(OBJCLASS);
+            actual = contextB.getService(srefB);
+            assertEquals(contextA, actual);
+            assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+            
+            assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+            assertEquals(2, serviceFactory.getCount);
+         }
+         finally
+         {
+            uninstall(bundleB);
+         }
+      }
+      finally
+      {
+         uninstall(bundleA);
+      }
+   }
+   
+   public void testGetServiceFactory() throws Exception
+   {
+      String OBJCLASS = BundleContext.class.getName();
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+         ServiceReference reference = registration.getReference();
+
+         Object actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+
+         actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+         
+         registration.unregister();
+         actual = bundleContext.getService(reference);
+         assertNull("" + actual, actual);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testGetServiceFactoryAfterStop() throws Exception
+   {
+      String OBJCLASS = BundleContext.class.getName();
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+         ServiceReference reference = registration.getReference();
+
+         Object actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+         
+         bundle.stop();
+         try
+         {
+            bundleContext.getService(reference);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testGetWrongInterfacesForServiceFactory() throws Exception
+   {
+      String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         bundleContext.addFrameworkListener(this);
+         
+         ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), null);
+         ServiceReference reference = registration.getReference();
+         Object actual = bundleContext.getService(reference);
+         assertNull("" + actual, actual);
+         
+         assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+         
+         registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
+         reference = registration.getReference();
+         actual = bundleContext.getService(reference);
+         assertNull("" + actual, actual);
+         
+         assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/ServiceReferenceUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,605 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.service;
+
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.a.A;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * ServiceReferenceUnitTestCase.
+ *
+ * todo more isAssignableTests
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceReferenceUnitTestCase extends OSGiTestCase
+{
+   public ServiceReferenceUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testGetProperty() throws Exception
+   {
+      ServiceReference reference = null;
+      String[] clazzes = new String[] { BundleContext.class.getName() };
+      Object serviceID = null;
+
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         Dictionary<String, Object> properties = new Hashtable<String, Object>();
+         properties.put("testA", "a");
+         properties.put("testB", "b");
+         properties.put("MiXeD", "Case");
+         ServiceRegistration registration = bundleContext.registerService(clazzes, bundleContext, properties);
+         assertNotNull(registration);
+         
+         reference = registration.getReference();
+         assertNotNull(reference);
+         
+         serviceID = reference.getProperty(Constants.SERVICE_ID);
+         assertNotNull(serviceID);
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toLowerCase()));
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toUpperCase()));
+         assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS));
+         assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));
+         assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toUpperCase()));
+         assertEquals("a", reference.getProperty("testA"));
+         assertEquals("b", reference.getProperty("testB"));
+         assertEquals("Case", reference.getProperty("MiXeD"));
+         assertEquals("Case", reference.getProperty("mixed"));
+         assertEquals("Case", reference.getProperty("MIXED"));
+         assertNull(reference.getProperty(null));
+         assertNull(reference.getProperty("doesNotExist"));
+         
+         properties.put("testA", "notA");
+         assertEquals("a", reference.getProperty("testA"));
+         properties.put(Constants.SERVICE_ID, "rubbish");
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+         properties.put(Constants.OBJECTCLASS, "rubbish");
+         assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+         
+         registration.setProperties(properties);
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+         assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+         assertEquals("notA", reference.getProperty("testA"));
+         assertEquals("b", reference.getProperty("testB"));
+         assertEquals("Case", reference.getProperty("MiXeD"));
+         assertEquals("Case", reference.getProperty("mixed"));
+         assertEquals("Case", reference.getProperty("MIXED"));
+         
+         registration.setProperties(null);
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+         assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+         assertNull(reference.getProperty("testA"));
+         assertNull(reference.getProperty("testB"));
+         assertNull(reference.getProperty("MiXeD"));
+         assertNull(reference.getProperty("mixed"));
+         assertNull(reference.getProperty("MIXED"));
+         assertNull(reference.getProperty(null));
+         
+         registration.setProperties(properties);
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+         assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+         assertEquals("notA", reference.getProperty("testA"));
+         assertEquals("b", reference.getProperty("testB"));
+         assertEquals("Case", reference.getProperty("MiXeD"));
+         assertEquals("Case", reference.getProperty("mixed"));
+         assertEquals("Case", reference.getProperty("MIXED"));
+         assertNull(reference.getProperty(null));
+         
+         registration.unregister();
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+         assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+         assertEquals("notA", reference.getProperty("testA"));
+         assertEquals("b", reference.getProperty("testB"));
+         assertEquals("Case", reference.getProperty("MiXeD"));
+         assertEquals("Case", reference.getProperty("mixed"));
+         assertEquals("Case", reference.getProperty("MIXED"));
+         assertNull(reference.getProperty(null));
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+      
+      assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+      assertEquals(clazzes, reference.getProperty(Constants.OBJECTCLASS));
+      assertEquals("notA", reference.getProperty("testA"));
+      assertEquals("b", reference.getProperty("testB"));
+      assertEquals("Case", reference.getProperty("MiXeD"));
+      assertEquals("Case", reference.getProperty("mixed"));
+      assertEquals("Case", reference.getProperty("MIXED"));
+      assertNull(reference.getProperty(null));
+   }
+   
+   public void testGetPropertyKeys() throws Exception
+   {
+      ServiceReference reference = null;
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         Dictionary<String, Object> properties = new Hashtable<String, Object>();
+         properties.put("testA", "a");
+         properties.put("testB", "b");
+         properties.put("MiXeD", "Case");
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+         assertNotNull(registration);
+         
+         reference = registration.getReference();
+         assertNotNull(reference);
+
+         assertPropertyKeys(reference, "testA", "testB", "MiXeD");
+
+         properties.put("testC", "c");
+         assertPropertyKeys(reference, "testA", "testB", "MiXeD");
+
+         registration.setProperties(properties);
+         assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+
+         registration.setProperties(null);
+         assertPropertyKeys(reference);
+
+         registration.setProperties(properties);
+         assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+         
+         registration.unregister();
+         assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+      assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
+   }
+
+   protected void assertPropertyKeys(ServiceReference reference, String... expectedKeys)
+   {
+      Set<String> expected = new HashSet<String>();
+      expected.add(Constants.SERVICE_ID);
+      expected.add(Constants.OBJECTCLASS);
+      for (String key : expectedKeys)
+         expected.add(key);
+      
+      Set<String> actual = new HashSet<String>();
+      for (String key : reference.getPropertyKeys())
+         actual.add(key);
+      
+      assertEquals(expected, actual);
+   }
+   
+   public void testGetBundle() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+         
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+         
+         Bundle other = reference.getBundle();
+         assertEquals(bundle, other);
+         
+         registration.unregister();
+         
+         other = reference.getBundle();
+         assertNull("" + other, other);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testGetBundleAfterStop() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+         
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+         
+         Bundle other = reference.getBundle();
+         assertEquals(bundle, other);
+
+         bundle.stop();
+         
+         other = reference.getBundle();
+         assertNull("" + other, other);
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testUsingBundles() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+         
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+         
+         assertUsingBundles(reference);
+         
+         Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+         try
+         {
+            bundle2.start();
+            BundleContext bundleContext2 = bundle2.getBundleContext();
+            assertNotNull(bundleContext2);
+            
+            bundleContext2.getService(reference);
+            assertUsingBundles(reference, bundle2);
+            
+            bundleContext2.ungetService(reference);
+            assertUsingBundles(reference);
+            
+            bundleContext2.getService(reference);
+            bundleContext2.getService(reference);
+            assertUsingBundles(reference, bundle2);
+            bundleContext2.ungetService(reference);
+            assertUsingBundles(reference, bundle2);
+            bundleContext2.ungetService(reference);
+            assertUsingBundles(reference);
+
+            bundleContext.getService(reference);
+            bundleContext2.getService(reference);
+            assertUsingBundles(reference, bundle, bundle2);
+            
+            registration.unregister();
+            assertUsingBundles(reference);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testUsingBundlesAfterStop() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+         
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+         
+         assertUsingBundles(reference);
+         
+         Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+         try
+         {
+            bundle2.start();
+            BundleContext bundleContext2 = bundle2.getBundleContext();
+            assertNotNull(bundleContext2);
+
+            bundleContext.getService(reference);
+            bundleContext2.getService(reference);
+            assertUsingBundles(reference, bundle, bundle2);
+            
+            bundle.stop();
+            assertUsingBundles(reference);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testIsAssignableToErrors() throws Exception
+   {
+      Bundle bundle = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+         
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+         
+         try
+         {
+            reference.isAssignableTo(null, A.class.getName());
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            reference.isAssignableTo(bundle, null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }   
+
+   public void testNotAssignableTo() throws Exception
+   {
+      Bundle bundle = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+         
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+
+         Bundle bundle2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+         try
+         {
+            assertFalse(reference.isAssignableTo(bundle2, A.class.getName()));
+            assertTrue(reference.isAssignableTo(bundle2, String.class.getName()));
+            
+            registration.unregister();
+            assertFalse(reference.isAssignableTo(bundle2, A.class.getName()));
+            assertFalse(reference.isAssignableTo(bundle2, String.class.getName())); // review ???
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testIsAssignableTo() throws Exception
+   {
+      //Bundle-Name: Service2
+      //Bundle-SymbolicName: org.jboss.test.osgi.service2
+      //Export-Package: org.jboss.test.osgi.service.support.a
+      Bundle bundle2 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+      
+      try
+      {
+         bundle2.start();
+         BundleContext bundleContext2 = bundle2.getBundleContext();
+         assertNotNull(bundleContext2);
+
+         //Bundle-Name: Service1
+         //Bundle-SymbolicName: org.jboss.test.osgi.service1
+         //Import-Package: org.jboss.test.osgi.service.support.a
+         Bundle bundle1 = assembleBundle("service1", "/bundles/service/service-bundle1");
+         
+         try
+         {
+
+            ServiceRegistration registration = bundleContext2.registerService(BundleContext.class.getName(), bundleContext2, null);
+            assertNotNull(registration);
+            
+            ServiceReference reference = registration.getReference();
+            assertNotNull(reference);
+
+            assertTrue(reference.isAssignableTo(bundle2, A.class.getName()));
+            assertTrue(reference.isAssignableTo(bundle2, String.class.getName()));
+            assertTrue(reference.isAssignableTo(bundle1, A.class.getName()));
+            assertTrue(reference.isAssignableTo(bundle1, String.class.getName()));
+            
+            registration.unregister();
+            assertTrue(reference.isAssignableTo(bundle2, A.class.getName()));
+            assertTrue(reference.isAssignableTo(bundle2, String.class.getName()));
+            assertFalse(reference.isAssignableTo(bundle1, A.class.getName()));
+            assertFalse(reference.isAssignableTo(bundle1, String.class.getName())); // review ???
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         uninstall(bundle2);
+      }
+   }
+   
+   public void testCompareTo() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration1 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration1);
+         
+         ServiceReference reference1 = registration1.getReference();
+         assertNotNull(reference1);
+
+         ServiceRegistration registration2 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration2);
+         
+         ServiceReference reference2 = registration2.getReference();
+         assertNotNull(reference2);
+
+         Dictionary<String, Object> properties = new Hashtable<String, Object>();
+         properties.put(Constants.SERVICE_RANKING, 10);
+         ServiceRegistration registration3 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+         assertNotNull(registration3);
+         
+         ServiceReference reference3 = registration3.getReference();
+         assertNotNull(reference3);
+
+         properties = new Hashtable<String, Object>();
+         properties.put(Constants.SERVICE_RANKING, -10);
+         ServiceRegistration registration4 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+         assertNotNull(registration4);
+         
+         ServiceReference reference4 = registration4.getReference();
+         assertNotNull(reference4);
+         
+         assertGreaterRanking(reference1, reference2);
+         assertGreaterRanking(reference3, reference1);
+         assertGreaterRanking(reference3, reference2);
+         assertGreaterRanking(reference1, reference4);
+         assertGreaterRanking(reference2, reference4);
+         assertGreaterRanking(reference3, reference4);
+         
+         try
+         {
+            reference1.compareTo(null);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         
+         try
+         {
+            reference1.compareTo(new Object());
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+
+         properties = new Hashtable<String, Object>();
+         properties.put(Constants.SERVICE_RANKING, "NotANumber");
+         ServiceRegistration registration5 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+         assertNotNull(registration5);
+         
+         ServiceReference reference5 = registration5.getReference();
+         assertNotNull(reference5);
+
+         assertGreaterRanking(reference1, reference5); // review ???
+         
+         Set<ServiceReference> ordering = new TreeSet<ServiceReference>();
+         ordering.add(reference1);
+         ordering.add(reference2);
+         ordering.add(reference3);
+         ordering.add(reference4);
+         ordering.add(reference5);
+         Iterator<ServiceReference> iterator = ordering.iterator();
+         assertEquals(reference4, iterator.next());
+         assertEquals(reference5, iterator.next());
+         assertEquals(reference2, iterator.next());
+         assertEquals(reference1, iterator.next());
+         assertEquals(reference3, iterator.next());
+         
+         ordering = new TreeSet<ServiceReference>();
+         ordering.add(reference5);
+         ordering.add(reference4);
+         ordering.add(reference3);
+         ordering.add(reference2);
+         ordering.add(reference1);
+         iterator = ordering.iterator();
+         assertEquals(reference4, iterator.next());
+         assertEquals(reference5, iterator.next());
+         assertEquals(reference2, iterator.next());
+         assertEquals(reference1, iterator.next());
+         assertEquals(reference3, iterator.next());
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   protected void assertGreaterRanking(ServiceReference reference1, ServiceReference reference2) throws Exception
+   {
+      assertTrue(reference1 + " > " + reference2, reference1.compareTo(reference2) > 0);
+      assertTrue(reference2 + " < " + reference1, reference2.compareTo(reference1) < 0);
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,355 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.service;
+
+import java.util.Hashtable;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * ServiceRegistrationUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ServiceRegistrationUnitTestCase extends OSGiTestCase
+{
+   public ServiceRegistrationUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testGetReference() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+         
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+
+         ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+         assertEquals(reference, reference2);
+         
+         Object object = bundleContext.getService(reference);
+         assertEquals(bundleContext, object);
+
+         reference2 = registration.getReference();
+         assertEquals(reference, reference2);
+         
+         registration.unregister();
+         try
+         {
+            registration.getReference();
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+
+         ServiceRegistration registration2 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+         assertNotSame(registration, registration2);
+         
+         reference2 = registration2.getReference();
+         assertNotNull(reference2);
+         assertNotSame(reference, reference2);
+         
+         bundle.stop();
+         try
+         {
+            registration2.getReference();
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testSetProperties() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         String propertyA = "org.jboss.osgi.test.PropertyA";
+         String propertyALower = "org.jboss.osgi.test.propertya";
+         
+         Hashtable<String, Object> properties = new Hashtable<String, Object>();
+         properties.put(propertyA, "testA");
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+         assertNotNull(registration);
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+         assertEquals("testA", reference.getProperty(propertyA));
+         assertEquals("testA", reference.getProperty(propertyALower));
+         
+         Object serviceID = reference.getProperty(Constants.SERVICE_ID);
+         Object objectClass = reference.getProperty(Constants.OBJECTCLASS);
+
+         assertAllReferences(bundleContext, null, "(" + propertyA + "=testA)", reference);
+         assertAllReferences(bundleContext, null, "(" + propertyALower + "=testA)", reference);
+         assertAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=" + serviceID + ")", reference);
+
+         bundleContext.addServiceListener(this);
+         
+         properties = new Hashtable<String, Object>();
+         properties.put(propertyA, "testAChanged");
+         registration.setProperties(properties);
+         assertServiceEvent(ServiceEvent.MODIFIED, reference);
+         assertEquals("testAChanged", reference.getProperty(propertyA));
+         assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testA)");
+         assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testA)");
+         assertAllReferences(bundleContext, null, "(" + propertyA + "=testAChanged)", reference);
+         assertAllReferences(bundleContext, null, "(" + propertyALower + "=testAChanged)", reference);
+         
+         registration.setProperties(null);
+         assertServiceEvent(ServiceEvent.MODIFIED, reference);
+         assertNull(reference.getProperty(propertyA));
+         assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testA)");
+         assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testA)");
+         assertNoAllReferences(bundleContext, null, "(" + propertyA + "=testAChanged)");
+         assertNoAllReferences(bundleContext, null, "(" + propertyALower + "=testAChanged)");
+         
+         properties = new Hashtable<String, Object>();
+         properties.put(propertyA, "testA2");
+         properties.put(Constants.SERVICE_ID, "rubbish1");
+         properties.put(Constants.OBJECTCLASS, "rubbish2");
+         registration.setProperties(properties);
+         assertServiceEvent(ServiceEvent.MODIFIED, reference);
+         assertEquals("testA2", reference.getProperty(propertyA));
+         assertEquals("testA2", reference.getProperty(propertyALower));
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
+         assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toLowerCase()));
+         assertEquals(objectClass, reference.getProperty(Constants.OBJECTCLASS));
+         assertEquals(objectClass, reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));
+         
+         try
+         {
+            assertNoAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=rubbish1)");
+            fail("NumberFormatException expected");
+         }
+         catch (NumberFormatException ex)
+         {
+            // expected
+         }
+         
+         assertAllReferences(bundleContext, null, "(" + Constants.SERVICE_ID + "=" + serviceID + ")", reference);
+
+         properties = new Hashtable<String, Object>();
+         properties.put("a", "1");
+         properties.put("A", "2");
+         try
+         {
+            registration.setProperties(properties);
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalArgumentException.class, t);
+         }
+         assertNoServiceEvent();
+         
+         registration.unregister();
+         assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+         
+         try
+         {
+            registration.setProperties(new Hashtable<String, Object>());
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+         assertNoServiceEvent();
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testSetPropertiesAfterStop() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+
+         bundle.stop();
+         
+         try
+         {
+            registration.setProperties(new Hashtable<String, Object>());
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+         assertNoServiceEvent();
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testUnregister() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         SimpleServiceFactory factory = new SimpleServiceFactory(bundleContext);
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), factory, null);
+         assertNotNull(registration);
+         
+         ServiceReference reference = registration.getReference();
+         assertNotNull(reference);
+
+         ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+         assertEquals(reference, reference2);
+
+         ServiceReference[] inUse = bundle.getServicesInUse();
+         assertNull(inUse);
+         
+         bundleContext.getService(reference);
+         inUse = bundle.getServicesInUse();
+         assertEquals(new ServiceReference[] { reference }, inUse);
+
+         Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+         try
+         {
+            bundle2.start();
+            BundleContext bundleContext2 = bundle2.getBundleContext();
+            assertNotNull(bundleContext2);
+            bundleContext2.getService(reference);
+            inUse = bundle2.getServicesInUse();
+            assertEquals(new ServiceReference[] { reference }, inUse);
+
+            assertNull(factory.ungetBundle);
+            assertNull(factory.ungetRegisation);
+            assertNull(factory.ungetService);
+            
+            bundleContext.addServiceListener(this);
+            registration.unregister();
+
+            reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+            assertNull("" + reference2, reference2);
+            
+            Object actual = bundleContext.getService(reference);
+            assertNull("" + actual, actual);
+            
+            assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+
+            inUse = bundle.getServicesInUse();
+            assertNull(inUse);
+            inUse = bundle2.getServicesInUse();
+            assertNull(inUse);
+
+            assertEquals(registration, factory.ungetRegisation);
+            assertEquals(bundleContext, factory.ungetService);
+         }
+         finally
+         {
+            uninstall(bundle2);
+         }
+         
+         try
+         {
+            registration.unregister();
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+   
+   public void testUnregisterAfterStop() throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+      try
+      {
+         bundle.start();
+         BundleContext bundleContext = bundle.getBundleContext();
+         assertNotNull(bundleContext);
+
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
+         assertNotNull(registration);
+
+         bundle.stop();
+         
+         try
+         {
+            registration.unregister();
+            fail("Should not be here!");
+         }
+         catch (Throwable t)
+         {
+            checkThrowable(IllegalStateException.class, t);
+         }
+      }
+      finally
+      {
+         uninstall(bundle);
+      }
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java (from rev 96066, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/test/OSGiSmokeTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java	2009-11-09 14:12:05 UTC (rev 96174)
@@ -0,0 +1,112 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.smoke;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.smoke.support.a.A;
+import org.jboss.test.osgi.smoke.support.a.b.B;
+import org.jboss.test.osgi.smoke.support.c.C;
+import org.osgi.framework.Bundle;
+
+/**
+ * OSGiSmokeTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiSmokeTestCase extends OSGiTestCase
+{
+   public OSGiSmokeTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testNoManifest() throws Exception
+   {
+      // [TODO] discuss no manifest
+      //testBundle("smoke-no-manifest", Bundle.ACTIVE);
+   }
+
+   public void testNonOSGiManifest() throws Exception
+   {
+      // [TODO] discuss no osgi manifest
+      //testBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
+   }
+
+   public void testOSGiManifest() throws Exception
+   {
+      testBundle("smoke-osgi-manifest", Bundle.INSTALLED);
+   }
+
+   public void testAssembled() throws Exception
+   {
+      Bundle bundle = assembleBundle("smoke-assembled", "/bundles/smoke/smoke-assembled", A.class);
+      try
+      {
+         testBundle(bundle, "smoke-assembled", Bundle.INSTALLED);
+         bundle.start();
+         assertLoadClass(bundle, A.class);
+         assertLoadClassFail(bundle, B.class);
+         assertLoadClassFail(bundle, C.class);
+      }
+      finally
+      {
+         bundle.uninstall();
+      }
+   }
+
+   protected void testBundle(String name, int expectedState) throws Exception
+   {
+      Bundle bundle = addBundle("/bundles/smoke/", name);
+      try
+      {
+         testBundle(bundle, name, expectedState);
+      }
+      finally
+      {
+         bundle.uninstall();
+      }
+   }
+
+   protected void testBundle(Bundle bundle, String name, int expectedState) throws Exception
+   {
+      assertEquals(expectedState, bundle.getState());
+      checkId(bundle, name);
+      bundle.start();
+      bundle.stop();
+   }
+
+   protected void checkId(Bundle bundle, String name) throws Exception
+   {
+      URL url = bundle.getEntry("id");
+      if (url == null)
+         fail("id entry not found for " + bundle);
+      InputStream is = url.openStream();
+      byte[] bytes = new byte[100];
+      is.read(bytes);
+      String value = new String(bytes);
+      assertTrue("Expected=" + name + " was " + value, value.startsWith(name));
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle (from rev 96123, projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/bundle)

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/metadata/SimpleManifest.mf
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/bundle/metadata/SimpleManifest.mf	2009-11-07 19:16:20 UTC (rev 96123)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/org/jboss/test/osgi/bundle/metadata/SimpleManifest.mf	2009-11-09 14:12:05 UTC (rev 96174)
@@ -4,7 +4,7 @@
 Implementation-Title: JBoss OSGi tests
 Implementation-Version: 2.0.0.beta2
 Implementation-Vendor: jboss.org
-Bundle-Activator: org.jboss.test.bundle.metadata.BundleActivator
+Bundle-Activator: org.jboss.test.osgi.bundle.metadata.BundleActivator
 Bundle-ClassPath: test.jar,mc.jar,seam.jar
 Bundle-Description: TestHeadersManifest
 Bundle-Localization: OSGI-INF/l10n/bundle



More information about the jboss-osgi-commits mailing list