[jboss-cvs] JBossAS SVN: r96320 - in projects/jboss-osgi: projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 12 19:49:24 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-11-12 19:49:24 -0500 (Thu, 12 Nov 2009)
New Revision: 96320

Added:
   projects/jboss-osgi/trunk/reactor/deployment/scripts/
   projects/jboss-osgi/trunk/reactor/deployment/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/simple/
   projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/simple/DeploymentSerializationTestCase.java
   projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/
   projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/log4j.xml
   projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/simple/
   projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/simple/simple.bnd
Modified:
   projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
   projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
   projects/jboss-osgi/trunk/reactor/deployment/.classpath
   projects/jboss-osgi/trunk/reactor/deployment/pom.xml
   projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java
Log:
Husky remote test client uses serializable Deployment to explicitly control autoStart behaviour.
So far this relied on the default autoStart value when constructed on the server side.

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java	2009-11-12 23:46:59 UTC (rev 96319)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java	2009-11-13 00:49:24 UTC (rev 96320)
@@ -36,10 +36,14 @@
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
+import javax.management.MBeanException;
 import javax.management.ObjectName;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
+import org.jboss.osgi.deployment.deployer.AbstractDeployerService;
+import org.jboss.osgi.deployment.deployer.DeployerService;
+import org.jboss.osgi.deployment.deployer.Deployment;
 import org.jboss.osgi.spi.capability.Capability;
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
@@ -84,12 +88,12 @@
          addCapability(dependency);
 
       OSGiServiceReference[] srefs = null;
-      
+
       // Check if the service provided by the capability exists already
       String serviceName = capability.getServiceName();
       if (serviceName != null)
          srefs = getServiceReferences(serviceName, capability.getFilter());
-      
+
       if (srefs == null || srefs.length == 0)
       {
          log.debug("Add capability: " + capability);
@@ -143,7 +147,7 @@
       // Uninstall the registered bundles
       ArrayList<String> locations = new ArrayList<String>(bundles.keySet());
       Collections.reverse(locations);
-      
+
       while (locations.size() > 0)
       {
          String location = locations.remove(0);
@@ -164,21 +168,17 @@
    protected void deploy(String location) throws Exception
    {
       URL archiveURL = getTestHelper().getTestArchiveURL(location);
-      invokeDeployerService("deploy", archiveURL);
+      DeployerServiceClient deployer = new DeployerServiceClient(DeployerService.MBEAN_DEPLOYER_SERVICE);
+      deployer.deploy(archiveURL);
    }
 
    protected void undeploy(String location) throws Exception
    {
       URL archiveURL = getTestHelper().getTestArchiveURL(location);
-      invokeDeployerService("undeploy", archiveURL);
+      DeployerServiceClient deployer = new DeployerServiceClient(DeployerService.MBEAN_DEPLOYER_SERVICE);
+      deployer.undeploy(archiveURL);
    }
 
-   protected void invokeDeployerService(String method, URL archiveURL) throws Exception
-   {
-      ObjectName oname = new ObjectName("jboss.osgi:service=DeployerService");
-      getMBeanServer().invoke(oname, method, new Object[] { archiveURL }, new String[] { URL.class.getName() });
-   }
-
    public InitialContext getInitialContext() throws NamingException
    {
       return helper.getInitialContext();
@@ -198,9 +198,9 @@
    public OSGiServiceReference getServiceReference(String clazz, long timeout)
    {
       int fraktion = 200;
-      timeout = timeout/fraktion;
+      timeout = timeout / fraktion;
       OSGiServiceReference sref = getServiceReference(clazz);
-      while (sref == null &&  0 < timeout--)
+      while (sref == null && 0 < timeout--)
       {
          try
          {
@@ -214,7 +214,7 @@
       }
       return sref;
    }
-   
+
    protected OSGiBundle getBundle(String symbolicName, Version version, boolean mustExist)
    {
       OSGiBundle bundle = null;
@@ -230,13 +230,13 @@
             }
          }
       }
-      
+
       if (bundle == null && mustExist == true)
          throw new IllegalStateException("Cannot obtain bundle: " + symbolicName + "-" + version + ". We have " + bundles);
-      
+
       return bundle;
    }
-   
+
    protected String getManifestEntry(String location, String key)
    {
       Manifest manifest = getManifest(location);
@@ -267,7 +267,7 @@
    {
       if (bundle == null)
          throw new IllegalArgumentException("Cannot register null bundle for: " + location);
-      
+
       bundles.put(location, bundle);
       return bundle;
    }
@@ -276,7 +276,7 @@
    {
       if (bundle == null)
          throw new IllegalArgumentException("Cannot unregister null bundle");
-      
+
       if (bundles.containsValue(bundle))
       {
          Set<Entry<String, OSGiBundle>> entrySet = bundles.entrySet();
@@ -307,4 +307,58 @@
          }
       }
    }
+
+   class DeployerServiceClient extends AbstractDeployerService
+   {
+      private ObjectName oname;
+
+      DeployerServiceClient(ObjectName oname)
+      {
+         this.oname = oname;
+      }
+
+      public void deploy(Deployment[] bundleDeps) throws BundleException
+      {
+         invokeDeployerMBean(oname, "deploy", bundleDeps, Deployment[].class.getName());
+      }
+
+      public void deploy(URL url) throws BundleException
+      {
+         invokeDeployerMBean(oname, "deploy", url, URL.class.getName());
+      }
+
+      public void undeploy(Deployment[] bundleDeps) throws BundleException
+      {
+         invokeDeployerMBean(oname, "undeploy", bundleDeps, Deployment[].class.getName());
+      }
+
+      public void undeploy(URL url) throws BundleException
+      {
+         invokeDeployerMBean(oname, "undeploy", url, URL.class.getName());
+      }
+
+      private void invokeDeployerMBean(ObjectName oname, String method, Object arg, String type) throws BundleException
+      {
+         try
+         {
+            getMBeanServer().invoke(oname, method, new Object[] { arg }, new String[] { type });
+         }
+         catch (RuntimeException rte)
+         {
+            throw rte;
+         }
+         catch (MBeanException ex)
+         {
+            Exception target = ex.getTargetException();
+            if (target instanceof BundleException)
+               throw (BundleException)target;
+
+            throw new BundleException("Cannot " + method + ": " + arg, target);
+         }
+         catch (Exception ex)
+         {
+            throw new BundleException("Cannot " + method + ": " + arg, ex);
+         }
+      }
+   }
 }

Modified: projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java	2009-11-12 23:46:59 UTC (rev 96319)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java	2009-11-13 00:49:24 UTC (rev 96320)
@@ -27,12 +27,14 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import javax.management.MBeanException;
 import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
+import org.jboss.osgi.deployment.deployer.DeployerService;
+import org.jboss.osgi.deployment.deployer.Deployment;
 import org.jboss.osgi.spi.management.MBeanProxy;
 import org.jboss.osgi.spi.management.MBeanProxyException;
 import org.jboss.osgi.spi.management.ManagedBundleMBean;
@@ -66,13 +68,21 @@
    {
       try
       {
+         // Get the bundle info from the location
          URL bundleURL = getTestHelper().getTestArchiveURL(location);
-         BundleInfo bundleInfo = BundleInfo.createBundleInfo(bundleURL);
-         String symbolicName = bundleInfo.getSymbolicName();
-         String version = bundleInfo.getVersion().toString();
+         BundleInfo info = BundleInfo.createBundleInfo(bundleURL);
 
-         deployInternal(location, true);
+         // Create the deployment from the info
+         DeployerServiceClient deployer = new DeployerServiceClient(DeployerService.MBEAN_DEPLOYER_SERVICE);
+         Deployment dep = deployer.createDeployment(info);
+         dep.setAutoStart(false);
+         
+         // Deploy the deployemnt through the DeployerService
+         deployer.deploy(new Deployment[] { dep });
 
+         String symbolicName = info.getSymbolicName();
+         String version = info.getVersion().toString();
+         
          // The remote framework uses a BundleTracker that works of an asynchronous 
          // event to register the installed bundle. It is not available immediately.
          int timeout = 50;
@@ -92,13 +102,9 @@
       {
          throw rte;
       }
-      catch (MBeanException ex)
+      catch (BundleException ex)
       {
-         Exception target = ex.getTargetException();
-         if (target instanceof BundleException)
-            throw (BundleException)target;
-
-         throw new BundleException("Cannot install: " + location, target);
+         throw ex;
       }
       catch (Exception ex)
       {
@@ -108,41 +114,20 @@
 
    public void deploy(String location) throws Exception
    {
-      deployInternal(location, false);
-   }
-
-   private void deployInternal(String location, boolean isBundle) throws Exception
-   {
       URL archiveURL = getTestHelper().getTestArchiveURL(location);
-      if (isBundle)
-         invokeDeployerService("deploy", archiveURL);
-      else
-         invokeMainDeployer("deploy", archiveURL);
+      ObjectName oname = getDeployerServiceName(archiveURL);
+      DeployerServiceClient deployer = new DeployerServiceClient(oname);
+      deployer.deploy(archiveURL);
    }
 
    public void undeploy(String location) throws Exception
    {
       URL archiveURL = getTestHelper().getTestArchiveURL(location);
-      if (isBundleArchive(location))
-         invokeDeployerService("undeploy", archiveURL);
-      else
-         invokeMainDeployer("undeploy", archiveURL);
+      ObjectName oname = getDeployerServiceName(archiveURL);
+      DeployerServiceClient deployer = new DeployerServiceClient(oname);
+      deployer.undeploy(archiveURL);
    }
 
-   private boolean isBundleArchive(String location)
-   {
-      try
-      {
-         URL archiveURL = getTestHelper().getTestArchiveURL(location);
-         BundleInfo.createBundleInfo(archiveURL);
-         return true;
-      }
-      catch (RuntimeException ex)
-      {
-         return false;
-      }
-   }
-
    public OSGiBundle[] getBundles()
    {
       try
@@ -298,9 +283,22 @@
       };
    }
 
-   private void invokeMainDeployer(String method, URL archiveURL) throws Exception
+   /**
+    * Return ObjectName of the DeployerService MBean if hte archive is a bundle
+    * otherwise if returns the ObjectName of the MainDeployer
+    */
+   private ObjectName getDeployerServiceName(URL archiveURL) throws MalformedObjectNameException
    {
-      ObjectName oname = new ObjectName("jboss.system:service=MainDeployer");
-      getMBeanServer().invoke(oname, method, new Object[] { archiveURL }, new String[] { URL.class.getName() });
+      ObjectName oname;
+      try
+      {
+         BundleInfo.createBundleInfo(archiveURL);
+         oname = DeployerService.MBEAN_DEPLOYER_SERVICE;
+      }
+      catch (Exception e)
+      {
+         oname = new ObjectName("jboss.system:service=MainDeployer");
+      }
+      return oname;
    }
 }

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-11-12 23:46:59 UTC (rev 96319)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java	2009-11-13 00:49:24 UTC (rev 96320)
@@ -25,6 +25,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.Serializable;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.jar.Attributes;
@@ -42,13 +43,16 @@
  * @author thomas.diesler at jboss.com
  * @since 16-Oct-2009
  */
-public class BundleInfo
+public class BundleInfo implements Serializable
 {
+   private static final long serialVersionUID = 2196462922955338109L;
+   
    private VirtualFile root;
    private String location;
-   private Manifest manifest;
    private String symbolicName;
-   private Version version;
+   private String version;
+   
+   private transient Manifest manifest;
 
    public static BundleInfo createBundleInfo(String location)
    {
@@ -146,30 +150,20 @@
       }
       this.location = location;      
 
-      // Get the Manifest
-      try
-      {
-         manifest = VFSUtils.getManifest(root);
-      }
-      catch (Exception ex)
-      {
-         throw new IllegalArgumentException("Cannot get manifest from: " + root, ex);
-      }
-      
       symbolicName = getManifestHeader(Constants.BUNDLE_SYMBOLICNAME);
       if (symbolicName == null)
          throw new IllegalArgumentException("Cannot obtain Bundle-SymbolicName for: " + root);
 
-      String versionStr = getManifestHeader(Constants.BUNDLE_VERSION);
-      version = Version.parseVersion(versionStr);
+      version = getManifestHeader(Constants.BUNDLE_VERSION);
+      version = Version.parseVersion(version).toString();
    }
-   
+
    /**
     * Get the manifest header for the given key.
     */
    public String getManifestHeader(String key)
    {
-      Attributes attribs = manifest.getMainAttributes();
+      Attributes attribs = getManifest().getMainAttributes();
       String value = attribs.getValue(key);
       return value;
    }
@@ -203,9 +197,30 @@
     */
    public Version getVersion()
    {
-      return version;
+      return Version.parseVersion(version);
    }
 
+   private Manifest getManifest()
+   {
+      if (manifest == null)
+      {
+         try
+         {
+            manifest = VFSUtils.getManifest(root);
+         }
+         catch (Exception ex)
+         {
+            throw new IllegalArgumentException("Cannot get manifest from: " + root, ex);
+         }
+      }
+      return manifest;
+   }
+   
+   private String toEqualString()
+   {
+      return "[" + symbolicName + "-" + version + ",url=" + location + "]";
+   }
+   
    @Override
    public boolean equals(Object obj)
    {
@@ -213,18 +228,18 @@
          return false;
       
       BundleInfo other = (BundleInfo)obj;
-      return root.equals(other.root);
+      return toEqualString().equals(other.toEqualString());
    }
 
    @Override
    public int hashCode()
    {
-      return toString().hashCode();
+      return toEqualString().hashCode();
    }
 
    @Override
    public String toString()
    {
-      return "[" + symbolicName + "-" + version + ",url=" + root + "]";
+      return toEqualString();
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/deployment/.classpath
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/.classpath	2009-11-12 23:46:59 UTC (rev 96319)
+++ projects/jboss-osgi/trunk/reactor/deployment/.classpath	2009-11-13 00:49:24 UTC (rev 96320)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>

Modified: projects/jboss-osgi/trunk/reactor/deployment/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/pom.xml	2009-11-12 23:46:59 UTC (rev 96319)
+++ projects/jboss-osgi/trunk/reactor/deployment/pom.xml	2009-11-13 00:49:24 UTC (rev 96320)
@@ -36,6 +36,10 @@
   <!-- Dependencies -->
   <dependencies>
     <dependency>
+      <groupId>biz.aQute</groupId>
+      <artifactId>bnd</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.jboss.osgi</groupId>
       <artifactId>jboss-osgi-spi</artifactId>
     </dependency>
@@ -96,6 +100,25 @@
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>build-test-jars</id>
+            <phase>test-compile</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <tasks>
+                <property name="maven.runtime.classpath" refid="maven.runtime.classpath" />
+                <property name="tests.output.dir" value="${project.build.directory}" />
+                <ant antfile="scripts/antrun-test-jars.xml" />
+              </tasks>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 

Added: projects/jboss-osgi/trunk/reactor/deployment/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/scripts/antrun-test-jars.xml	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/scripts/antrun-test-jars.xml	2009-11-13 00:49:24 UTC (rev 96320)
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- ============================================================ -->
+<!--  JBoss, the OpenSource J2EE webOS                            -->
+<!--  Distributable under LGPL license.                           -->
+<!--  See terms of license at http://www.gnu.org.                 -->
+<!-- ============================================================ -->
+
+<!-- $Id$ -->
+
+<project default="build-test-jars">
+
+  <description>OSGi test archive builder</description>
+
+  <!-- ================================================================== -->
+  <!-- Init                                                               -->
+  <!-- ================================================================== -->
+
+  <target name="init">
+
+    <!-- Property override when not called from maven -->
+    <property name="maven.runtime.classpath" value="/usr/java/bnd.jar" />
+    <property name="tests.output.dir" value="${basedir}/../target" />
+
+    <mkdir dir="${tests.output.dir}/test-libs" />
+    <property name="tests.classes.dir" value="${tests.output.dir}/test-classes" />
+    <property name="tests.resources.dir" value="${tests.output.dir}/test-classes" />
+
+    <taskdef resource="aQute/bnd/ant/taskdef.properties">
+      <classpath>
+        <pathelement path="${maven.runtime.classpath}" />
+      </classpath>
+    </taskdef>
+
+  </target>
+
+  <!-- ================================================================== -->
+  <!-- Building                                                           -->
+  <!-- ================================================================== -->
+
+  <target name="build-test-jars" depends="init" description="Build the test deployments">
+
+    <!-- Please add alphabetically -->
+
+    <!-- simple -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/simple-bundle.jar" files="${tests.resources.dir}/simple/simple.bnd" />
+  	
+    <!-- Please add alphabetically -->
+
+  </target>
+
+</project>


Property changes on: projects/jboss-osgi/trunk/reactor/deployment/scripts/antrun-test-jars.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java	2009-11-12 23:46:59 UTC (rev 96319)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java	2009-11-13 00:49:24 UTC (rev 96320)
@@ -40,7 +40,7 @@
  */
 public class DeploymentImpl extends AttachmentSupport implements Deployment, Serializable
 {
-   private static final long serialVersionUID = 1L;
+   private static final long serialVersionUID = 6216977125749367927L;
    
    private BundleInfo info;
    private URL location;

Added: projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/simple/DeploymentSerializationTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/simple/DeploymentSerializationTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/simple/DeploymentSerializationTestCase.java	2009-11-13 00:49:24 UTC (rev 96320)
@@ -0,0 +1,94 @@
+/*
+ * 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.deployment.simple;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.MalformedURLException;
+
+import org.jboss.osgi.deployment.deployer.Deployment;
+import org.jboss.osgi.deployment.internal.DeploymentImpl;
+import org.jboss.osgi.spi.util.BundleInfo;
+import org.junit.Test;
+
+/**
+ * Test Deployment serialization
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 12-Nov-2009
+ */
+public class DeploymentSerializationTestCase
+{
+   @Test
+   public void testSerializeBundleInfo() throws Exception
+   {
+      BundleInfo info = getBundleInfo();
+      
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      ObjectOutputStream oos = new ObjectOutputStream(baos);
+      oos.writeObject(info);
+      baos.close();
+      
+      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+      ObjectInputStream ois = new ObjectInputStream(bais);
+      Object res = ois.readObject();
+      assertTrue("Instance of BundleInfo: " + res, res instanceof BundleInfo);
+      
+      assertEquals(info, res);
+   }
+
+   @Test
+   public void testSerializeDeployment() throws Exception
+   {
+      BundleInfo info = getBundleInfo();
+      Deployment dep = new DeploymentImpl(info);
+      
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      ObjectOutputStream oos = new ObjectOutputStream(baos);
+      oos.writeObject(dep);
+      baos.close();
+      
+      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+      ObjectInputStream ois = new ObjectInputStream(bais);
+      Object res = ois.readObject();
+      assertTrue("Instance of Deployment: " + res, res instanceof Deployment);
+      
+      assertEquals(dep, res);
+   }
+
+   private BundleInfo getBundleInfo() throws MalformedURLException
+   {
+      File file = new File("target/test-libs/simple-bundle.jar");
+      assertTrue("File exists: " + file, file.exists());
+      
+      BundleInfo info = BundleInfo.createBundleInfo(file.toURL());
+      return info;
+   }
+}


Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/simple/DeploymentSerializationTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/log4j.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/log4j.xml	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/log4j.xml	2009-11-13 00:49:24 UTC (rev 96320)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+  <!-- ================================= -->
+  <!-- Preserve messages in a local file -->
+  <!-- ================================= -->
+
+  <appender name="FILE" class="org.apache.log4j.FileAppender">
+    <param name="File" value="${log4j.output.dir}/test.log"/>
+    <param name="Append" value="false"/>
+    <layout class="org.apache.log4j.PatternLayout">
+      <!-- The default pattern: Date Priority [Category] Message\n -->
+      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
+    </layout>
+  </appender>
+  
+  <!-- ============================== -->
+  <!-- Append messages to the console -->
+  <!-- ============================== -->
+
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out" />
+    <param name="Threshold" value="INFO" />
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n" />
+    </layout>
+  </appender>
+
+  <!-- ================ -->
+  <!-- Limit categories -->
+  <!-- ================ -->
+
+  <!-- Show jboss deployer traces  
+  <category name="org.jboss.deployer">
+    <priority value="TRACE" />
+  </category>
+  -->
+
+  <!-- ======================= -->
+  <!-- Setup the Root category -->
+  <!-- ======================= -->
+
+  <root>
+    <!--appender-ref ref="CONSOLE"/-->
+    <appender-ref ref="FILE"/>
+  </root>
+
+</log4j:configuration>


Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/simple/simple.bnd
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/simple/simple.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/test/resources/simple/simple.bnd	2009-11-13 00:49:24 UTC (rev 96320)
@@ -0,0 +1,4 @@
+# bnd build -classpath target/test-classes -output target/test-libs/simple-bundle.jar src/test/resources/simple/simple.bnd
+
+Bundle-SymbolicName: simple-bundle
+Export-Package: org.jboss.test.osgi.deployment.simple




More information about the jboss-cvs-commits mailing list