[jboss-cvs] JBossAS SVN: r85240 - in projects/jboss-osgi/trunk: runtime/spi/src/main/java/org/jboss/osgi/spi/junit and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 4 11:45:20 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-03-04 11:45:20 -0500 (Wed, 04 Mar 2009)
New Revision: 85240

Added:
   projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi39/OSGI39DeployerTestCase.java
Modified:
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleManagementDeployer.java
   projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java
   projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
Log:
[JBOSGI-39] Add more test coverage

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleManagementDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleManagementDeployer.java	2009-03-04 16:23:53 UTC (rev 85239)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleManagementDeployer.java	2009-03-04 16:45:20 UTC (rev 85240)
@@ -54,31 +54,37 @@
 
    public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
    {
-      ManagedBundle mb = new ManagedBundle(bundle);
-      ObjectName oname = mb.getObjectName();
-      try
+      if (mbeanServer != null)
       {
-         mbeanServer.registerMBean(mb, oname);
-         unit.addAttachment(ManagedBundle.class, mb);
+         ManagedBundle mb = new ManagedBundle(bundle);
+         ObjectName oname = mb.getObjectName();
+         try
+         {
+            mbeanServer.registerMBean(mb, oname);
+            unit.addAttachment(ManagedBundle.class, mb);
+         }
+         catch (Exception ex)
+         {
+            DeploymentException.rethrowAsDeploymentException(ex.getMessage(), ex);
+         }
       }
-      catch (Exception ex)
-      {
-         DeploymentException.rethrowAsDeploymentException(ex.getMessage(), ex);
-      }
    }
 
    @Override
    public void undeploy(DeploymentUnit unit, Bundle bundle)
    {
-      try
+      if (mbeanServer != null)
       {
-         ManagedBundle mb = unit.getAttachment(ManagedBundle.class);
-         if (mb != null && mbeanServer.isRegistered(mb.getObjectName()))
-            mbeanServer.unregisterMBean(mb.getObjectName());
+         try
+         {
+            ManagedBundle mb = unit.getAttachment(ManagedBundle.class);
+            if (mb != null && mbeanServer.isRegistered(mb.getObjectName()))
+               mbeanServer.unregisterMBean(mb.getObjectName());
+         }
+         catch (Exception ex)
+         {
+            log.warn("Cannot unregister: " + bundle, ex);
+         }
       }
-      catch (Exception ex)
-      {
-         log.warn("Cannot unregister: " + bundle, ex);
-      }
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java	2009-03-04 16:23:53 UTC (rev 85239)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java	2009-03-04 16:45:20 UTC (rev 85240)
@@ -51,7 +51,7 @@
 
    // The list of unresolved bundles
    private List<Bundle> unresolvedBundles = new ArrayList<Bundle>();
-   private boolean simpleStartStop;
+   private boolean simpleStart;
 
    public BundleStartStopDeployer()
    {
@@ -63,20 +63,20 @@
       this.systemContext = systemContext;
    }
 
-   public void setSimpleStartStop(boolean simpleStartStop)
+   public void setSimpleStart(boolean simpleStartStop)
    {
-      this.simpleStartStop = simpleStartStop;
+      this.simpleStart = simpleStartStop;
    }
 
    public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
    {
-      if (simpleStartStop)
+      if (simpleStart)
       {
-         simpleStartDeploy(unit, bundle);
+         simpleStart(unit, bundle);
       }
       else
       {
-         deferredStartDeploy(unit, bundle);
+         deferredStart(unit, bundle);
       }
    }
 
@@ -86,6 +86,8 @@
       try
       {
          bundle.stop();
+         
+         unresolvedBundles.remove(bundle);
 
          String state = StateFormat.formatBundleState(bundle.getState());
          log.info(bundle.getSymbolicName() + ",state=" + state);
@@ -96,7 +98,7 @@
       }
    }
 
-   private void simpleStartDeploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
+   private void simpleStart(DeploymentUnit unit, Bundle bundle) throws DeploymentException
    {
       try
       {
@@ -110,7 +112,7 @@
       }
    }
 
-   private void deferredStartDeploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
+   private void deferredStart(DeploymentUnit unit, Bundle bundle) throws DeploymentException
    {
       // Get the required dependency on the PackageAdmin service
       if (packageAdmin == null)

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java	2009-03-04 16:23:53 UTC (rev 85239)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java	2009-03-04 16:45:20 UTC (rev 85240)
@@ -27,9 +27,7 @@
 
 import javax.management.MBeanServerConnection;
 
-import org.jboss.osgi.spi.management.MBeanProxy;
 import org.jboss.osgi.spi.management.ManagedBundleMBean;
-import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
 
 /**
  * An integration test case

Modified: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2009-03-04 16:23:53 UTC (rev 85239)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java	2009-03-04 16:45:20 UTC (rev 85240)
@@ -25,7 +25,9 @@
 
 import javax.management.ObjectName;
 
+import org.jboss.logging.Logger;
 import org.jboss.osgi.spi.Constants;
+import org.jboss.osgi.spi.framework.StateFormat;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 
@@ -37,6 +39,9 @@
  */
 public class ManagedBundle implements ManagedBundleMBean
 {
+   // Provide logging
+   final Logger log = Logger.getLogger(ManagedBundle.class);
+   
    private Bundle bundle;
    private ObjectName oname;
 
@@ -64,11 +69,16 @@
    public void start() throws BundleException
    {
       bundle.start();
+      
+      String state = StateFormat.formatBundleState(bundle.getState());
+      log.info(bundle.getSymbolicName() + ",state=" + state);
    }
 
    public void stop() throws BundleException
    {
       bundle.stop();
+      
+      String state = StateFormat.formatBundleState(bundle.getState());
+      log.info(bundle.getSymbolicName() + ",state=" + state);
    }
-
 }
\ No newline at end of file

Added: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi39/OSGI39DeployerTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi39/OSGI39DeployerTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi39/OSGI39DeployerTestCase.java	2009-03-04 16:45:20 UTC (rev 85240)
@@ -0,0 +1,109 @@
+/*
+ * 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.jbosgi39;
+
+//$Id$
+
+import org.jboss.osgi.spi.junit.IntegrationTest;
+import org.jboss.osgi.spi.management.ManagedBundleMBean;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * [JBOSGI-39] Bundle undeploy does not clean up properly
+ * 
+ * https://jira.jboss.org/jira/browse/JBOSGI-39
+ * 
+ * Bundle B depends on bundle X.
+ * 
+ * B ---> X 
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public class OSGI39DeployerTestCase extends IntegrationTest
+{
+   public void testInstallBWithoutX() throws Exception
+   {
+      ManagedBundleMBean bundleB = deployBundle("jbosgi38-bundleB");
+      
+      assertEquals("Bundle installed", Bundle.INSTALLED, bundleB.getState());
+
+      try
+      {
+         bundleB.start();
+         fail("BundleException expected");
+      }
+      catch (BundleException ex)
+      {
+         // expected
+      }
+      
+      undeploy("jbosgi38-bundleB.jar");
+   }
+
+   public void testInstallX() throws Exception
+   {
+      ManagedBundleMBean bundleX = deployBundle("jbosgi38-bundleX");
+      
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleX.getState());
+      
+      undeploy("jbosgi38-bundleX.jar");
+   }
+
+   public void testInstallBAfterX() throws Exception
+   {
+      ManagedBundleMBean bundleX = deployBundle("jbosgi38-bundleX");
+      ManagedBundleMBean bundleB = deployBundle("jbosgi38-bundleB");
+      
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleX.getState());
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleB.getState());
+      
+      undeploy("jbosgi38-bundleB.jar");
+      undeploy("jbosgi38-bundleX.jar");
+   }
+
+   public void testInstallBAfterUninstallX() throws Exception
+   {
+      ManagedBundleMBean bundleX = deployBundle("jbosgi38-bundleX");
+      
+      assertEquals("Bundle active", Bundle.ACTIVE, bundleX.getState());
+      
+      undeploy("jbosgi38-bundleX.jar");
+      
+      ManagedBundleMBean bundleB = deployBundle("jbosgi38-bundleB");
+      
+      assertEquals("Bundle installed", Bundle.INSTALLED, bundleB.getState());
+
+      try
+      {
+         bundleB.start();
+         fail("BundleException expected");
+      }
+      catch (BundleException ex)
+      {
+         // expected
+      }
+      
+      undeploy("jbosgi38-bundleB.jar");
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi39/OSGI39DeployerTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-cvs-commits mailing list