[jboss-cvs] JBossAS SVN: r96268 - in projects/jboss-osgi/trunk/reactor/framework/src: test/java/org/jboss/test/osgi and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 11 12:37:14 EST 2009


Author: adrian at jboss.org
Date: 2009-11-11 12:37:13 -0500 (Wed, 11 Nov 2009)
New Revision: 96268

Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
Log:
Add some more smoke tests for deploying bundles and non-bundles through the MainDeployer along with tests for passing OSGiMetaData explicitly, as would be done by the management console

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-11-11 17:19:53 UTC (rev 96267)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-11-11 17:37:13 UTC (rev 96268)
@@ -108,7 +108,7 @@
    public static final String BEAN_BUNDLE_MANAGER = "OSGiBundleManager";
 
    /** The string representation of this bundle's location identifier. */
-   private static final String PROPERTY_BUNDLE_LOCATION = "org.jboss.osgi.bundle.location";
+   public static final String PROPERTY_BUNDLE_LOCATION = "org.jboss.osgi.bundle.location";
 
    /** The framework version */
    private static String OSGi_FRAMEWORK_VERSION = "r4v42"; // [TODO] externalise
@@ -233,6 +233,16 @@
    }
 
    /**
+    * Get the deployerClient.
+    * 
+    * @return the deployerClient.
+    */
+   public DeployerClient getDeployerClient()
+   {
+      return deployerClient;
+   }
+
+   /**
     * Set the framework properties
     * 
     * @param properties the properties

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java	2009-11-11 17:19:53 UTC (rev 96267)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java	2009-11-11 17:37:13 UTC (rev 96268)
@@ -34,6 +34,7 @@
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.osgi.framework.bundle.AbstractBundleState;
 import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.spi.util.ConstantsHelper;
 import org.jboss.test.kernel.junit.MicrocontainerTest;
 import org.jboss.virtual.AssembledDirectory;
@@ -142,6 +143,31 @@
    }
 
    /**
+    * Create a bundle 
+    * 
+    * @param root the location of the location to deploy
+    * @param child the child to deploy
+    * @return Bundle for the deployment
+    * @throws Exception for any error
+    */
+   protected Bundle deployBundle(String root, String child) throws Exception
+   {
+      return getDelegate().deployBundle(root, child);
+   }
+
+   /**
+    * Create a bundle 
+    *
+    * @param file the virtual file
+    * @return Bundle for the deployment
+    * @throws Exception for any error
+    */
+   protected Bundle deployBundle(VirtualFile file) throws Exception
+   {
+      return getDelegate().deployBundle(file);
+   }
+
+   /**
     * Remove a bundle 
     * 
     * @param bundle the bundle to remove
@@ -167,6 +193,36 @@
       return getDelegate().assembleBundle(name, resourcePaths, packages);
    }
 
+   protected Bundle deployBundle(String name, Class<?>... packages) throws Exception
+   {
+      return getDelegate().deployBundle(name, null, (String[]) null, packages);
+   }
+
+   protected Bundle deployBundle(String name, String resourcePath, Class<?>... packages) throws Exception
+   {
+      return getDelegate().deployBundle(name, null, resourcePath, packages);
+   }
+
+   protected Bundle deployBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
+   {
+      return getDelegate().deployBundle(name, null, resourcePaths, packages);
+   }
+
+   protected Bundle deployBundle(String name, OSGiMetaData metaData, Class<?>... packages) throws Exception
+   {
+      return getDelegate().deployBundle(name, metaData, (String[]) null, packages);
+   }
+
+   protected Bundle deployBundle(String name, OSGiMetaData metaData, String resourcePath, Class<?>... packages) throws Exception
+   {
+      return getDelegate().deployBundle(name, metaData, resourcePath, packages);
+   }
+
+   protected Bundle deployBundle(String name, OSGiMetaData metaData, String[] resourcePaths, Class<?>... packages) throws Exception
+   {
+      return getDelegate().deployBundle(name, metaData, resourcePaths, packages);
+   }
+
    protected AssembledDirectory createAssembledDirectory(String name) throws Exception
    {
       return getDelegate().createAssembledDirectory(name, "");

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java	2009-11-11 17:19:53 UTC (rev 96267)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java	2009-11-11 17:37:13 UTC (rev 96268)
@@ -23,6 +23,7 @@
 
 // $Id: $
 
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.Collection;
@@ -32,9 +33,17 @@
 
 import org.jboss.classloader.plugins.ClassLoaderUtils;
 import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.osgi.framework.bundle.AbstractBundleState;
 import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
 import org.jboss.virtual.AssembledDirectory;
 import org.jboss.virtual.VFS;
@@ -143,6 +152,11 @@
       }
       return bundleManager;
    }
+   
+   public DeployerClient getDeployerClient()
+   {
+      return getBundleManager().getDeployerClient();
+   }
 
    /**
     * Create a bundle 
@@ -202,14 +216,104 @@
 
    public Bundle assembleBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
    {
-      AssembledDirectory assembledDirectory = createAssembledDirectory(name, "");
-      for (String path : resourcePaths)
-         addPath(assembledDirectory, path, "");
-      for (Class<?> reference : packages)
-         addPackage(assembledDirectory, reference);
+      AssembledDirectory assembledDirectory = createAssembledDirectory(name, "", resourcePaths, packages);
       return addBundle(assembledDirectory);
    }
 
+   public Bundle deployBundle(String name, OSGiMetaData metaData, String resourcePath, Class<?>... packages) throws Exception
+   {
+      AssembledDirectory assembledDirectory = createAssembledDirectory(name, "", new String[] { resourcePath }, packages);
+      return deployBundle(assembledDirectory, metaData);
+   }
+
+   public Bundle deployBundle(String name, OSGiMetaData metaData, String[] resourcePaths, Class<?>... packages) throws Exception
+   {
+      AssembledDirectory assembledDirectory = createAssembledDirectory(name, "", resourcePaths, packages);
+      return deployBundle(assembledDirectory, metaData);
+   }
+
+   public Bundle deployBundle(VirtualFile virtualFile, OSGiMetaData metaData) throws Exception
+   {
+      Deployment deployment = createDeployment(virtualFile, metaData);
+      return deployBundle(deployment);
+   }
+
+   public Bundle deployBundle(String root, String child) throws Exception
+   {
+      URL resourceRoot = getClass().getResource(root);
+      if (resourceRoot == null)
+         throw new AssertionFailedError("Resource not found: " + root);
+      URL childResource = new URL(resourceRoot, child);
+      return deployBundle(childResource);
+   }
+
+   public Bundle deployBundle(URL url) throws Exception
+   {
+      // Get the root file
+      VirtualFile root;
+      try
+      {
+         root = VFS.getRoot(url);
+      }
+      catch (IOException e)
+      {
+         throw new BundleException("Invalid url=" + url, e);
+      }
+
+      return deployBundle(root);
+   }
+
+   public Bundle deployBundle(VirtualFile file) throws Exception
+   {
+      return deployBundle(file, null);
+   }
+   
+   public Bundle deployBundle(Deployment deployment) throws Exception
+   {
+      DeployerClient deployerClient = getDeployerClient();
+      MainDeployerStructure deployerStructure = (MainDeployerStructure) deployerClient;
+      deployerClient.deploy(deployment);
+      try
+      {
+         DeploymentUnit unit = deployerStructure.getDeploymentUnit(deployment.getName());
+         OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+         if (bundleState == null)
+            throw new IllegalStateException("Unable to determine bundle state for " + deployment.getName());
+
+         return bundleState.getBundleInternal();
+      }
+      catch (Exception e)
+      {
+         deployerClient.undeploy(deployment);
+         throw e;
+      }
+   }
+
+   public Deployment createDeployment(VirtualFile virtualFile, OSGiMetaData metaData) throws Exception
+   {
+      VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(virtualFile);
+      MutableAttachments att = (MutableAttachments)deployment.getPredeterminedManagedObjects();
+      if (metaData != null)
+         att.addAttachment(OSGiMetaData.class, metaData);
+      return deployment;
+   }
+
+   public AssembledDirectory createAssembledDirectory(String name, String rootName, String[] resourcePaths, Class<?>... packages) throws Exception
+   {
+      AssembledDirectory assembledDirectory = createAssembledDirectory(name, rootName);
+      if (resourcePaths != null)
+      {
+         for (String path : resourcePaths)
+            addPath(assembledDirectory, path, "");
+      }
+      if (packages != null)
+      {
+         for (Class<?> reference : packages)
+            addPackage(assembledDirectory, reference);
+      }
+      return assembledDirectory;
+   }
+
    public AssembledDirectory createAssembledDirectory(String name) throws Exception
    {
       return createAssembledDirectory(name, "");     

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java	2009-11-11 17:19:53 UTC (rev 96267)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java	2009-11-11 17:37:13 UTC (rev 96268)
@@ -23,9 +23,13 @@
 
 import java.io.InputStream;
 import java.net.URL;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
 
 import junit.framework.Test;
 
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
 import org.jboss.test.osgi.FrameworkTestCase;
 import org.jboss.test.osgi.smoke.support.a.A;
 import org.jboss.test.osgi.smoke.support.a.b.B;
@@ -82,6 +86,59 @@
       }
    }
 
+   public void testDeployedNoManifest() throws Exception
+   {
+      testDeployedBundle("smoke-no-manifest", Bundle.ACTIVE);
+   }
+
+   public void testDeployedNonOSGiManifest() throws Exception
+   {
+      testDeployedBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
+   }
+
+   public void testDeployedOSGiManifest() throws Exception
+   {
+      testDeployedBundle("smoke-osgi-manifest", Bundle.INSTALLED);
+   }
+
+   public void testAssembledDeployment() throws Exception
+   {
+      Manifest manifest = new Manifest();
+      Attributes attributes = manifest.getMainAttributes();
+      attributes.putValue("Bundle-Name", "SmokeDeployment");
+      attributes.putValue("Bundle-SymbolicName", "org.jboss.test.osgi.smoke.deployment");
+      OSGiMetaData metaData = new AbstractOSGiMetaData(manifest);
+      Bundle bundle = deployBundle("smoke-deployment", metaData, A.class);
+      try
+      {
+         assertEquals(Bundle.INSTALLED, bundle.getState());
+         bundle.start();
+         assertLoadClass(bundle, A.class);
+         assertLoadClassFail(bundle, B.class);
+         assertLoadClassFail(bundle, C.class);
+      }
+      finally
+      {
+         bundle.uninstall();
+      }
+   }
+
+   public void testAssembledNonOSGiDeployment() throws Exception
+   {
+      Bundle bundle = deployBundle("smoke-non-osgi-deployment", A.class);
+      try
+      {
+         assertEquals(Bundle.ACTIVE, bundle.getState());
+         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);
@@ -95,6 +152,19 @@
       }
    }
 
+   protected void testDeployedBundle(String name, int expectedState) throws Exception
+   {
+      Bundle bundle = deployBundle("/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());




More information about the jboss-cvs-commits mailing list