[jboss-cvs] JBossAS SVN: r96323 - in projects/jboss-osgi/trunk/testsuite/functional: src/test/java/org/jboss/test/osgi/jbosgi99 and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 12 21:42:02 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-11-12 21:42:01 -0500 (Thu, 12 Nov 2009)
New Revision: 96323

Added:
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle/
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle/Activator99.java
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-dontfail.bnd
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-failonresolve.bnd
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-failonstart.bnd
Removed:
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle/ActivatorBundleA.java
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/
   projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd
Modified:
   projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java
Log:
[JBOSGI-99] No explicit control over bundle.start()
Add comprehensive test coverage

Modified: projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml	2009-11-13 01:16:46 UTC (rev 96322)
+++ projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml	2009-11-13 02:42:01 UTC (rev 96323)
@@ -100,7 +100,9 @@
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi92-bundleA.jar" files="${tests.resources.dir}/jbosgi92/jbosgi92-bundleA.bnd" />
   	
     <!-- jbosgi99 -->
-    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi99-bundleA.jar" files="${tests.resources.dir}/jbosgi99/jbosgi99-bundleA.bnd" />
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi99-dontfail.jar" files="${tests.resources.dir}/jbosgi99/jbosgi99-dontfail.bnd" />
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi99-failonresolve.jar" files="${tests.resources.dir}/jbosgi99/jbosgi99-failonresolve.bnd" />
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi99-failonstart.jar" files="${tests.resources.dir}/jbosgi99/jbosgi99-failonstart.bnd" />
   	
     <!-- jbosgi108 -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi108-bundleA.jar" files="${tests.resources.dir}/jbosgi108/jbosgi108-bundleA.bnd" />

Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java	2009-11-13 01:16:46 UTC (rev 96322)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java	2009-11-13 02:42:01 UTC (rev 96323)
@@ -24,13 +24,17 @@
 //$Id: OSGI39TestCase.java 87103 2009-04-09 22:18:31Z thomas.diesler at jboss.com $
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
-import org.jboss.osgi.spi.capability.LogServiceCapability;
+import org.jboss.osgi.spi.util.ConstantsHelper;
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
 import org.jboss.osgi.testing.OSGiTestHelper;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
 
 /**
  * [JBOSGI-99] No explicit control over bundle.start()
@@ -42,25 +46,87 @@
  */
 public class OSGI99TestCase
 {
+   private static OSGiRuntime runtime;
+
+   @BeforeClass
+   public static void beforeClass()
+   {
+      runtime = new OSGiTestHelper().getDefaultRuntime();
+   }
+
+   @AfterClass
+   public static void afterClass()
+   {
+      if (runtime != null)
+      {
+         runtime.shutdown();
+         runtime = null;
+      }
+   }
+
    @Test
-   public void testInstallOnly() throws Exception
+   public void testDontFail() throws Exception
    {
-      OSGiRuntime runtime = new OSGiTestHelper().getDefaultRuntime();
+      OSGiBundle bundle = runtime.installBundle("jbosgi99-dontfail.jar");
+      assertBundleState(bundle, Bundle.INSTALLED);
+
+      bundle.start();
+      assertBundleState(bundle, Bundle.ACTIVE);
+
+      bundle.uninstall();
+
+      if (runtime.isRemoteRuntime() == false)
+         assertBundleState(bundle, Bundle.UNINSTALLED);
+   }
+
+   @Test
+   public void testFailOnResolve() throws Exception
+   {
+      OSGiBundle bundle = runtime.installBundle("jbosgi99-failonresolve.jar");
+      assertBundleState(bundle, Bundle.INSTALLED);
+
       try
       {
-         runtime.addCapability(new LogServiceCapability());
+         bundle.start();
+         fail("BundleException expected");
+      }
+      catch (BundleException e)
+      {
+         assertBundleState(bundle, Bundle.INSTALLED);
+      }
+      
+      bundle.uninstall();
 
-         OSGiBundle bundleA = runtime.installBundle("jbosgi99-bundleA.jar");
-         assertEquals("Bundle installed", Bundle.INSTALLED, bundleA.getState());
+      if (runtime.isRemoteRuntime() == false)
+         assertBundleState(bundle, Bundle.UNINSTALLED);
+   }
 
-         bundleA.start();
-         assertEquals("Bundle active", Bundle.ACTIVE, bundleA.getState());
+   @Test
+   public void testFailOnStart() throws Exception
+   {
+      OSGiBundle bundle = runtime.installBundle("jbosgi99-failonstart.jar");
+      assertBundleState(bundle, Bundle.INSTALLED);
 
-         bundleA.uninstall();
+      try
+      {
+         bundle.start();
+         fail("BundleException expected");
       }
-      finally
+      catch (BundleException e)
       {
-         runtime.shutdown();
+         assertBundleState(bundle, Bundle.RESOLVED);
       }
+      
+      bundle.uninstall();
+
+      if (runtime.isRemoteRuntime() == false)
+         assertBundleState(bundle, Bundle.UNINSTALLED);
    }
+
+   private void assertBundleState(OSGiBundle bundle, int expState)
+   {
+      String exp = ConstantsHelper.bundleState(expState);
+      String was = ConstantsHelper.bundleState(bundle.getState());
+      assertEquals("Bundle " + exp, exp, was);
+   }
 }
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle (from rev 96307, projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA)

Copied: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle/Activator99.java (from rev 96307, projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/ActivatorBundleA.java)
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle/Activator99.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle/Activator99.java	2009-11-13 02:42:01 UTC (rev 96323)
@@ -0,0 +1,39 @@
+/*
+ * 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.jbosgi99.bundle;
+
+//$Id: ServiceActivator.java 87064 2009-04-09 11:08:56Z thomas.diesler at jboss.com $
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator99 implements BundleActivator
+{
+   public void start(BundleContext context)
+   {
+      throw new IllegalStateException("Fail on start");
+   }
+
+   public void stop(BundleContext context)
+   {
+   }
+}
\ No newline at end of file

Deleted: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle/ActivatorBundleA.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/ActivatorBundleA.java	2009-11-12 14:01:14 UTC (rev 96307)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundle/ActivatorBundleA.java	2009-11-13 02:42:01 UTC (rev 96323)
@@ -1,50 +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.jbosgi99.bundleA;
-
-//$Id: ServiceActivator.java 87064 2009-04-09 11:08:56Z thomas.diesler at jboss.com $
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-
-public class ActivatorBundleA implements BundleActivator
-{
-   private LogService log;
-   
-   public void start(BundleContext context)
-   {
-      ServiceReference sref = context.getServiceReference(LogService.class.getName());
-      if (sref != null)
-      {
-         log = (LogService)context.getService(sref);
-         log.log(LogService.LOG_INFO, "ActivatorBundleA.start()");
-      }
-   }
-
-   public void stop(BundleContext context)
-   {
-      if (log != null)
-         log.log(LogService.LOG_INFO, "ActivatorBundleA.stop()");
-   }
-}
\ No newline at end of file

Deleted: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd	2009-11-13 01:16:46 UTC (rev 96322)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd	2009-11-13 02:42:01 UTC (rev 96323)
@@ -1,6 +0,0 @@
-# bnd build -classpath target/test-classes -output target/test-libs/jbosgi99-bundleA.jar src/test/resources/jbosgi99/jbosgi99-bundleA.bnd
-
-Bundle-SymbolicName: jbosgi99-bundleA
-Bundle-Activator: org.jboss.test.osgi.jbosgi99.bundleA.ActivatorBundleA
-Export-Package: org.jboss.test.osgi.jbosgi99.bundleA
-

Copied: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-dontfail.bnd (from rev 96307, projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd)
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-dontfail.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-dontfail.bnd	2009-11-13 02:42:01 UTC (rev 96323)
@@ -0,0 +1,5 @@
+# bnd build -classpath target/test-classes -output target/test-libs/jbosgi99-bundleA.jar src/test/resources/jbosgi99/jbosgi99-bundleA.bnd
+
+Bundle-SymbolicName: jbosgi99-dontfail
+Export-Package: org.jboss.test.osgi.jbosgi99.bundle
+

Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-failonresolve.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-failonresolve.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-failonresolve.bnd	2009-11-13 02:42:01 UTC (rev 96323)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/jbosgi99-bundleA.jar src/test/resources/jbosgi99/jbosgi99-bundleA.bnd
+
+Bundle-SymbolicName: jbosgi99-failonresolve
+Export-Package: org.jboss.test.osgi.jbosgi99.bundle
+Import-Package: org.osgi.framework, org.jboss.test.osgi.jbosgi99.package.does.not.exist
+

Added: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-failonstart.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-failonstart.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-failonstart.bnd	2009-11-13 02:42:01 UTC (rev 96323)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/jbosgi99-bundleA.jar src/test/resources/jbosgi99/jbosgi99-bundleA.bnd
+
+Bundle-SymbolicName: jbosgi99-failonstart
+Bundle-Activator: org.jboss.test.osgi.jbosgi99.bundle.Activator99
+Private-Package: org.jboss.test.osgi.jbosgi99.bundle
+




More information about the jboss-cvs-commits mailing list