[jboss-osgi-commits] JBoss-OSGI SVN: r102778 - in projects/jboss-osgi/projects: runtime/framework/trunk/bundle/felix-cache and 7 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue Mar 23 08:53:29 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-23 08:53:25 -0400 (Tue, 23 Mar 2010)
New Revision: 102778

Added:
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/felix-cache/
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/felix-cache/bundle0/
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/felix-cache/bundle0/bundle.id
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleFrameworkTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleRuntimeTestCase.java
Removed:
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java
Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/BundleClassPathTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverSmokeTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesTestCase.java
   projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleLogServiceTestCase.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java
Log:
Add more test coverage for getServiceReferences

Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/felix-cache/bundle0/bundle.id
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/felix-cache/bundle0/bundle.id	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/felix-cache/bundle0/bundle.id	2010-03-23 12:53:25 UTC (rev 102778)
@@ -0,0 +1 @@
+43
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml	2010-03-23 12:53:25 UTC (rev 102778)
@@ -305,7 +305,7 @@
       <id>framework-equinox</id>
       <activation>
         <property>
-          <name>fmwk</name>
+          <name>frwk</name>
           <value>equinox</value>
         </property>
       </activation>
@@ -358,7 +358,7 @@
       <id>framework-felix</id>
       <activation>
         <property>
-          <name>fmwk</name>
+          <name>frwk</name>
           <value>felix</value>
         </property>
       </activation>
@@ -411,7 +411,7 @@
       <id>framework-jbossmc-default</id>
       <activation>
         <property>
-          <name>!fmwk</name>
+          <name>!frwk</name>
         </property>
       </activation>
       <dependencies>

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextTestCase.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -211,7 +211,7 @@
    public void testInstallBundle() throws Exception
    {
       URL url = getTestArchiveURL("bundles/jboss-osgi-common.jar");
-      Bundle bundle = context.installBundle(url.toExternalForm());
+      Bundle bundle = systemContext.installBundle(url.toExternalForm());
       try
       {
          assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -225,7 +225,7 @@
 
       // Test file location
       String location = getTestArchivePath("bundles/jboss-osgi-common.jar");
-      bundle = context.installBundle(location);
+      bundle = systemContext.installBundle(location);
       try
       {
          assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -238,7 +238,7 @@
       }
 
       // Test symbolic location
-      bundle = context.installBundle("/symbolic/location", url.openStream());
+      bundle = systemContext.installBundle("/symbolic/location", url.openStream());
       try
       {
          assertBundleState(Bundle.INSTALLED, bundle.getState());

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -83,7 +83,7 @@
          assertBundleState(Bundle.INSTALLED, bundleA.getState());
 
          // BundleA not started - service not available  
-         ServiceReference sref = context.getServiceReference(LifecycleService.class.getName());
+         ServiceReference sref = systemContext.getServiceReference(LifecycleService.class.getName());
          assertNull("Service not available", sref);
 
          VirtualFile assemblyB = assembleArchive("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
@@ -207,8 +207,8 @@
          assertBundleState(Bundle.INSTALLED, bundleB.getState());
 
          // Get the PackageAdmin service
-         ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
-         PackageAdmin packageAdmin = (PackageAdmin)context.getService(sref);
+         ServiceReference sref = systemContext.getServiceReference(PackageAdmin.class.getName());
+         PackageAdmin packageAdmin = (PackageAdmin)systemContext.getService(sref);
 
          // Attempt to explicitly resolve a bundle with missing dependency 
          boolean allResolved = packageAdmin.resolveBundles(new Bundle[] { bundleB });

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleTestCase.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -172,7 +172,7 @@
       Bundle bundle = installBundle(assemble1);
       try
       {
-         int beforeCount = context.getBundles().length;
+         int beforeCount = systemContext.getBundles().length;
 
          bundle.start();
          assertBundleState(Bundle.ACTIVE, bundle.getState());
@@ -182,7 +182,7 @@
          assertBundleState(Bundle.ACTIVE, bundle.getState());
          assertEquals("Bundle-Version", "1.0.1", bundle.getHeaders().get(Constants.BUNDLE_VERSION));
 
-         int afterCount = context.getBundles().length;
+         int afterCount = systemContext.getBundles().length;
          assertEquals("Bundle count", beforeCount, afterCount);
       }
       finally

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/BundleClassPathTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/BundleClassPathTestCase.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/BundleClassPathTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -44,7 +44,7 @@
    public void testBundleClassPath() throws Exception
    {
       URL bundleURL = getTestArchiveURL("bundle-classpath.war");
-      Bundle bundle = context.installBundle(bundleURL.toExternalForm());
+      Bundle bundle = systemContext.installBundle(bundleURL.toExternalForm());
 
       bundle.start();
       assertEquals("Bundle state", Bundle.ACTIVE, bundle.getState());

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverSmokeTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverSmokeTestCase.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverSmokeTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -70,7 +70,7 @@
       List<Bundle> unresolved = new ArrayList<Bundle>();
       for (String path : bundlePaths)
       {
-         Bundle bundle = context.installBundle(getTestArchivePath(path));
+         Bundle bundle = systemContext.installBundle(getTestArchivePath(path));
          unresolved.add(bundle);
       }
 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesTestCase.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -23,13 +23,15 @@
 
 // $Id: $
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 import java.util.Dictionary;
 import java.util.Hashtable;
 
+import org.jboss.osgi.testing.OSGiFrameworkTest;
 import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.AbstractFrameworkTest;
 import org.jboss.test.osgi.service.support.a.A;
 import org.jboss.test.osgi.service.support.b.B;
 import org.junit.Test;
@@ -48,9 +50,8 @@
  * @author Thomas.Diesler at jboss.com
  * @version $Revision: 1.1 $
  */
-public class GetServiceReferencesTestCase extends AbstractFrameworkTest
+public class GetServiceReferencesTestCase extends OSGiFrameworkTest
 {
-
    @Test
    public void testGetServiceReferences() throws Exception
    {
@@ -161,6 +162,79 @@
    }
 
    @Test
+   public void testGetServiceReferencesMultiple() throws Exception
+   {
+      VirtualFile assemblyA = assembleArchive("simple1", "/bundles/simple/simple-bundle1", A.class);
+      Bundle bundleA = installBundle(assemblyA);
+      try
+      {
+         bundleA.start();
+         BundleContext contextA = bundleA.getBundleContext();
+         assertNotNull(contextA);
+
+         Class<?> clazz = bundleA.loadClass(A.class.getName());
+         Object service1 = clazz.newInstance();
+         ServiceRegistration sreg1 = contextA.registerService(A.class.getName(), service1, null);
+         assertNotNull(sreg1);
+         ServiceReference sref1 = sreg1.getReference();
+         assertNotNull(sref1);
+
+         VirtualFile assemblyB = assembleArchive("simple2", "/bundles/simple/simple-bundle2", A.class);
+         Bundle bundleB = installBundle(assemblyB);
+         try
+         {
+            bundleB.start();
+            BundleContext contextB = bundleB.getBundleContext();
+            assertNotNull(contextB);
+
+            clazz = bundleB.loadClass(A.class.getName());
+            Object service2 = clazz.newInstance();
+            ServiceRegistration sreg2 = contextB.registerService(A.class.getName(), service2, null);
+            assertNotNull(sreg2);
+            ServiceReference sref2 = sreg2.getReference();
+            assertNotNull(sref2);
+            
+            ServiceReference[] srefs = systemContext.getServiceReferences(A.class.getName(), null);
+            assertEquals(2, srefs.length);
+            assertEquals(sref2, srefs[0]);
+            assertEquals(sref1, srefs[1]);
+            
+            srefs = systemContext.getAllServiceReferences(A.class.getName(), null);
+            assertEquals(2, srefs.length);
+            assertEquals(sref2, srefs[0]);
+            assertEquals(sref1, srefs[1]);
+            
+            srefs = contextA.getServiceReferences(A.class.getName(), null);
+            assertEquals(1, srefs.length);
+            assertEquals(sref1, srefs[0]);
+            
+            System.out.println("FIXME: verify getAllServiceReferences()");
+            //srefs = contextA.getAllServiceReferences(A.class.getName(), null);
+            //assertEquals(2, srefs.length);
+            //assertEquals(sref2, srefs[0]);
+            //assertEquals(sref1, srefs[1]);
+            
+            srefs = contextB.getServiceReferences(A.class.getName(), null);
+            assertEquals(1, srefs.length);
+            assertEquals(sref2, srefs[0]);
+            
+            //srefs = contextB.getAllServiceReferences(A.class.getName(), null);
+            //assertEquals(2, srefs.length);
+            //assertEquals(sref2, srefs[0]);
+            //assertEquals(sref1, srefs[1]);
+         }
+         finally
+         {
+            bundleB.uninstall();
+         }
+      }
+      finally
+      {
+         bundleA.uninstall();
+      }
+   }
+   
+   @Test
    public void testGetServiceReferencesNoClassNotAssignable() throws Exception
    {
       assertGetServiceReferencesNotAssignable(null);
@@ -179,15 +253,15 @@
       try
       {
          bundleA.start();
-         BundleContext context1 = bundleA.getBundleContext();
-         assertNotNull(context1);
+         BundleContext contextA = bundleA.getBundleContext();
+         assertNotNull(contextA);
 
          if (className != null)
-            assertNoGetReference(context1, className);
+            assertNoGetReference(contextA, className);
 
          Class<?> clazz = bundleA.loadClass(A.class.getName());
          Object service1 = clazz.newInstance();
-         ServiceRegistration sreg1 = context1.registerService(A.class.getName(), service1, null);
+         ServiceRegistration sreg1 = contextA.registerService(A.class.getName(), service1, null);
          assertNotNull(sreg1);
          ServiceReference sref1 = sreg1.getReference();
          assertNotNull(sref1);
@@ -197,59 +271,59 @@
          try
          {
             bundleB.start();
-            BundleContext context2 = bundleB.getBundleContext();
-            assertNotNull(context2);
+            BundleContext contextB = bundleB.getBundleContext();
+            assertNotNull(contextB);
 
             if (className != null)
-               assertNoGetReference(context2, className);
+               assertNoGetReference(contextB, className);
 
             clazz = bundleB.loadClass(A.class.getName());
             Object service2 = clazz.newInstance();
-            ServiceRegistration sreg2 = context2.registerService(A.class.getName(), service2, null);
+            ServiceRegistration sreg2 = contextB.registerService(A.class.getName(), service2, null);
             assertNotNull(sreg2);
             ServiceReference sref2 = sreg2.getReference();
             assertNotNull(sref2);
 
             if (className != null)
-               assertGetReference(context1, className, sref1);
+               assertGetReference(contextA, className, sref1);
 
             if (className != null)
-               assertGetReference(context2, className, sref2);
+               assertGetReference(contextB, className, sref2);
 
             sreg1.unregister();
 
             if (className != null)
-               assertNoGetReference(context1, className);
+               assertNoGetReference(contextA, className);
 
             if (className != null)
-               assertGetReference(context2, className, sref2);
+               assertGetReference(contextB, className, sref2);
 
-            sreg1 = context1.registerService(A.class.getName(), service1, null);
+            sreg1 = contextA.registerService(A.class.getName(), service1, null);
             assertNotNull(sreg1);
             sref1 = sreg1.getReference();
             assertNotNull(sref1);
 
             if (className != null)
-               assertGetReference(context1, className, sref1);
+               assertGetReference(contextA, className, sref1);
 
             if (className != null)
-               assertGetReference(context2, className, sref2);
+               assertGetReference(contextB, className, sref2);
 
             sreg2.unregister();
 
             if (className != null)
-               assertGetReference(context1, className, sref1);
+               assertGetReference(contextA, className, sref1);
 
             if (className != null)
-               assertNoGetReference(context2, className);
+               assertNoGetReference(contextB, className);
 
             sreg1.unregister();
 
             if (className != null)
-               assertNoGetReference(context1, className);
+               assertNoGetReference(contextA, className);
 
             if (className != null)
-               assertNoGetReference(context2, className);
+               assertNoGetReference(contextB, className);
          }
          finally
          {

Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -1,101 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.simple;
-
-//$Id$
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.jboss.osgi.spi.util.ServiceLoader;
-import org.jboss.osgi.testing.OSGiBundle;
-import org.jboss.osgi.testing.OSGiRuntime;
-import org.jboss.osgi.testing.OSGiRuntimeHelper;
-import org.jboss.test.osgi.simple.bundleA.SimpleService;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.launch.Framework;
-import org.osgi.framework.launch.FrameworkFactory;
-
-/**
- * A test that deployes a bundle and verifies its state
- * 
- * @author thomas.diesler at jboss.com
- * @since 18-Aug-2009
- */
-public class SimpleBundleTestCase
-{
-   @Test
-   public void testBundleInstallLauchAPI() throws Exception
-   {
-      // Uses the OSGi Framework launch API
-      FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
-      Framework framework = factory.newFramework(null);
-      framework.start();
-
-      OSGiRuntimeHelper helper = new OSGiRuntimeHelper();
-
-      BundleContext sysContext = framework.getBundleContext();
-      Bundle bundle = sysContext.installBundle(helper.getTestArchivePath("simple-bundle.jar"));
-
-      assertEquals("simple-bundle", bundle.getSymbolicName());
-
-      bundle.start();
-      assertEquals("Bundle state", Bundle.ACTIVE, bundle.getState());
-
-      BundleContext bndContext = bundle.getBundleContext();
-      assertNotNull("BundleContext not null", bndContext);
-
-      // getServiceReference from bundle context
-      ServiceReference sref = bndContext.getServiceReference(SimpleService.class.getName());
-      assertNotNull("ServiceReference not null", sref);
-
-      // getServiceReference from system context
-      sref = sysContext.getServiceReference(SimpleService.class.getName());
-      assertNotNull("ServiceReference not null", sref);
-
-      bundle.uninstall();
-      assertEquals("Bundle state", Bundle.UNINSTALLED, bundle.getState());
-
-      framework.stop();
-   }
-
-   @Test
-   public void testBundleInstallRuntimeAPI() throws Exception
-   {
-      // Uses the JBossOSGi SPI provided runtime abstraction
-      OSGiRuntime runtime = new OSGiRuntimeHelper().getEmbeddedRuntime();
-      OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
-
-      assertEquals("simple-bundle", bundle.getSymbolicName());
-
-      bundle.start();
-      assertEquals("Bundle state", Bundle.ACTIVE, bundle.getState());
-
-      bundle.uninstall();
-      assertEquals("Bundle state", Bundle.UNINSTALLED, bundle.getState());
-
-      runtime.shutdown();
-   }
-}
\ No newline at end of file

Copied: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleFrameworkTestCase.java (from rev 102773, projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleBundleTestCase.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleFrameworkTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleFrameworkTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.simple;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URL;
+
+import org.jboss.osgi.testing.OSGiFrameworkTest;
+import org.jboss.test.osgi.simple.bundleA.SimpleService;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A test that deployes a bundle and verifies its state
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public class SimpleFrameworkTestCase extends OSGiFrameworkTest 
+{
+   @Test
+   public void testBundleInstall() throws Exception
+   {
+      URL bundleURL = getTestArchiveURL("simple-bundle.jar");
+      Bundle bundle = systemContext.installBundle(bundleURL.toExternalForm());
+
+      assertEquals("simple-bundle", bundle.getSymbolicName());
+
+      bundle.start();
+      assertEquals("Bundle state", Bundle.ACTIVE, bundle.getState());
+
+      BundleContext bndContext = bundle.getBundleContext();
+      assertNotNull("BundleContext not null", bndContext);
+
+      // getServiceReference from bundle context
+      ServiceReference sref = bndContext.getServiceReference(SimpleService.class.getName());
+      assertNotNull("ServiceReference not null", sref);
+
+      // getServiceReference from system context
+      sref = systemContext.getServiceReference(SimpleService.class.getName());
+      assertNotNull("ServiceReference not null", sref);
+
+      bundle.uninstall();
+      assertEquals("Bundle state", Bundle.UNINSTALLED, bundle.getState());
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleLogServiceTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleLogServiceTestCase.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleLogServiceTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -51,7 +51,7 @@
    @Test
    public void testNoLogService() throws Exception
    {
-      Bundle bundle = context.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+      Bundle bundle = systemContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
       try
       {
          bundle.start();
@@ -70,12 +70,12 @@
    @Test
    public void testLogServiceFromThirdParty() throws Exception
    {
-      Bundle logBundle = context.installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar"));
+      Bundle logBundle = systemContext.installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar"));
       try
       {
          logBundle.start();
 
-         Bundle bundle = context.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+         Bundle bundle = systemContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
          try
          {
             try
@@ -102,10 +102,10 @@
    @Test
    public void testLogServiceFromCompendium() throws Exception
    {
-      Bundle cmpnBundle = context.installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
+      Bundle cmpnBundle = systemContext.installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
       try
       {
-         Bundle bundle = context.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+         Bundle bundle = systemContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
          try
          {
             bundle.start();
@@ -132,15 +132,15 @@
    @Test
    public void testLogServiceFromTwoExporters() throws Exception
    {
-      Bundle cmpnBundle = context.installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
+      Bundle cmpnBundle = systemContext.installBundle(getTestArchivePath("bundles/org.osgi.compendium.jar"));
       try
       {
-         Bundle logBundle = context.installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar"));
+         Bundle logBundle = systemContext.installBundle(getTestArchivePath("bundles/org.apache.felix.log.jar"));
          try
          {
             logBundle.start();
 
-            Bundle bundle = context.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
+            Bundle bundle = systemContext.installBundle(getTestArchivePath("simple-logservice-bundle.jar"));
             try
             {
                bundle.start();

Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleRuntimeTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleRuntimeTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/simple/SimpleRuntimeTestCase.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.simple;
+
+//$Id: SimpleBundleTestCase.java 102773 2010-03-23 11:38:05Z thomas.diesler at jboss.com $
+
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiRuntimeTest;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * A test that deployes a bundle and verifies its state
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public class SimpleRuntimeTestCase extends OSGiRuntimeTest
+{
+   @Test
+   public void testBundleInstall() throws Exception
+   {
+      // Uses the JBossOSGi SPI provided runtime abstraction
+      OSGiRuntime runtime = getDefaultRuntime();
+      OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
+
+      assertEquals("simple-bundle", bundle.getSymbolicName());
+
+      bundle.start();
+      assertEquals("Bundle state", Bundle.ACTIVE, bundle.getState());
+
+      bundle.uninstall();
+      assertEquals("Bundle state", Bundle.UNINSTALLED, bundle.getState());
+
+      runtime.shutdown();
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java	2010-03-23 12:43:47 UTC (rev 102777)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java	2010-03-23 12:53:25 UTC (rev 102778)
@@ -66,7 +66,7 @@
    private static final Logger log = Logger.getLogger(OSGiFrameworkTest.class);
 
    protected static Framework framework;
-   protected static BundleContext context;
+   protected static BundleContext systemContext;
 
    private final List<FrameworkEvent> frameworkEvents = new CopyOnWriteArrayList<FrameworkEvent>();
    private final List<BundleEvent> bundleEvents = new CopyOnWriteArrayList<BundleEvent>();
@@ -80,7 +80,7 @@
       framework.start();
 
       // Get the system context
-      context = framework.getBundleContext();
+      systemContext = framework.getBundleContext();
    }
 
    @AfterClass
@@ -96,21 +96,21 @@
 
    protected PackageAdmin getPackageAdmin()
    {
-      ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
-      return (PackageAdmin)context.getService(sref);
+      ServiceReference sref = systemContext.getServiceReference(PackageAdmin.class.getName());
+      return (PackageAdmin)systemContext.getService(sref);
    }
    
    protected Bundle installBundle(VirtualFile archive) throws Exception
    {
-      String location = archive.toURL().toExternalForm();
-      return context.installBundle(location, archive.openStream());
+      String location = archive.getPathName();
+      return systemContext.installBundle(location, archive.openStream());
    }
    
    protected void assertLoadClass(Bundle bundle, String className, Bundle exporter)
    {
       Class<?> clazz = assertLoadClass(bundle, className);
       Bundle actual = getPackageAdmin().getBundle(clazz);
-      assertEquals(exporter, actual);
+      assertEquals("Loaded from ClassLoader", exporter, actual);
    }
 
    @Override



More information about the jboss-osgi-commits mailing list