[jboss-svn-commits] JBL Code SVN: r24179 - in labs/jbossesb/workspace/skeagh/container/microcontainer/src: main/java/org/jboss/esb/microcontainer/metadata and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Dec 1 09:09:29 EST 2008


Author: beve
Date: 2008-12-01 09:09:29 -0500 (Mon, 01 Dec 2008)
New Revision: 24179

Added:
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbDeployment.java
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployerTest.java
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployerTest.xml
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/esb-archive-xml-in-root.jar
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/esb-archive.jar
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive-xml-in-root.jar/
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive-xml-in-root.jar/META-INF/
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive-xml-in-root.jar/jboss-esb.xml
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive.jar/
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive.jar/META-INF/
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive.jar/META-INF/jboss-esb.xml
Removed:
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/esb1.jar/
Modified:
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbParserDeployer.java
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployer.java
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/metadata/EsbMetaData.java
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbParserDeployerTest.java
   labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/log4j.xml
Log:
More refactoring.


Added: labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbDeployment.java
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbDeployment.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbDeployment.java	2008-12-01 14:09:29 UTC (rev 24179)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.esb.microcontainer.deployers;
+
+import org.jboss.esb.api.exception.DeploymentException;
+import org.jboss.esb.deploy.DeploymentRuntime;
+import org.jboss.esb.deploy.config.DeploymentUnit;
+import org.jboss.esb.microcontainer.config.DeploymentUnitResourceLocator;
+import org.jboss.esb.util.AssertArgument;
+
+/**
+ * An EsbDeployment is a MicroContainer deployment that wraps
+ * an ESB DeploymentUnit and methods for starting and stoping an {@link EsbRuntimeDeployment}
+ * <p/>
+ * An EsbDeployment is created by the Microcontainer and the Microcontainer
+ * is also responsible for the lifecycle events, like starting and stopping.
+ *
+ * <h1>Lifecycle</h1>
+ * Starting an EsbDeployment will deploy the EsbRuntimeDeployment hence staring
+ * the {@link EsbRuntimeDeployment}
+ * Stopping an EsbDeployment will undeploy the EsbRuntimeDeployment hence
+ * undeploying the {@link EsbRuntimeDeployment}
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class EsbDeployment
+{
+    /**
+     * The name of the achive.
+     */
+    private String archiveName;
+
+    /**
+     * The ESB DeploymentUnit.
+     */
+    private DeploymentUnit deploymentUnit;
+
+    private DeploymentRuntime runtime;
+
+    /**
+     * Construct.
+     *
+     * @param archiveName       The name of the archive that this deployment came from.
+     * @param deploymentUnit    The ESB DeploymentUnit that is to be deployed.
+     */
+    public EsbDeployment(final String archiveName, final DeploymentUnit deploymentUnit)
+    {
+        AssertArgument.isNotNull(archiveName, "archiveName");
+        AssertArgument.isNotNull(deploymentUnit, "deploymentUnit");
+        this.archiveName = archiveName;
+        this.deploymentUnit = deploymentUnit;
+    }
+
+    /**
+     * Deploys the EsbRuntimeDeployment when called by the MicroContainer.
+     *
+     * @throws DeploymentException
+     */
+    public void start() throws DeploymentException
+    {
+        // TODO: Fix classloading..make it play nicely with MC. Daniel
+        runtime = new DeploymentRuntime(new DeploymentUnitResourceLocator(getClass().getClassLoader()));
+        runtime.setDeploymentName(archiveName);
+        runtime.addDeploymentUnit(deploymentUnit);
+        runtime.deploy();
+    }
+
+    /**
+     * Undeploys the EsbRuntimeDeployment when called by the MicroContainer.
+     *
+     * @throws DeploymentException
+     */
+    public void stop() throws DeploymentException
+    {
+        if (runtime != null)
+        {
+            runtime.undeploy();
+        }
+    }
+
+    public DeploymentUnit getDeploymentUnit()
+    {
+        return deploymentUnit;
+    }
+
+    public String getArchiveName()
+    {
+        return archiveName;
+    }
+
+}

Modified: labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbParserDeployer.java
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbParserDeployer.java	2008-12-01 14:03:32 UTC (rev 24178)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbParserDeployer.java	2008-12-01 14:09:29 UTC (rev 24179)
@@ -20,15 +20,32 @@
  */
 package org.jboss.esb.microcontainer.deployers;
 
+import java.io.IOException;
+import java.util.List;
+
 import org.apache.log4j.Logger;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.esb.api.context.ResourceLocator;
+import org.jboss.esb.api.exception.DeploymentException;
+import org.jboss.esb.deploy.config.DeploymentUnit;
+import org.jboss.esb.deploy.config.digest.DefaultConfigurationDigester;
+import org.jboss.esb.microcontainer.config.DeploymentUnitResourceLocator;
 import org.jboss.esb.microcontainer.metadata.EsbMetaData;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
 
 /**
- * EsbParserDeployer picks up jboss-esb.xml files and .esb archives.
+ * EsbParserDeployer picks up jboss-esb.xml files.
+ * Is responsible for parsing a -esb.xml configuration file and producing an
+ * {@link EsbMetaData} instance using the information contained in the conifg file.
+ * <p/>
  *
+ * The reason for creating the EsbMetaData is to allow other types of Deployers
+ * to create the metadata by other means, for example through alternative
+ * configurations, annotations, other languages, etc.
+ *
  * Sample configuration:
  * <pre>{@code
  *  <bean name="EsbParserDeployer" class="org.jboss.esb.microcontainer.deployers.EsbParserDeployer"/>
@@ -63,7 +80,8 @@
     {
         super(EsbMetaData.class);
         setSuffix(ESB_FILE_SUFFIX);
-        setJarExtension(ESB_JAR_SUFFIX);
+        setJarExtension(ESB_JAR_SUFFIX);
+        setStage(DeploymentStages.CLASSLOADER);
     }
 
     /**
@@ -75,11 +93,71 @@
      * @return EsbMetaData      {@link EsbMetaData} created with the virtual file of the deployment and the archive name.
      */
     @Override
-    protected EsbMetaData parse(final VFSDeploymentUnit deploymentUnit, final VirtualFile file, final EsbMetaData metaData)
+    protected EsbMetaData parse(final VFSDeploymentUnit deploymentUnit, final VirtualFile file, final EsbMetaData metaData) throws DeploymentException
     {
-        final EsbMetaData esbMetaData = new EsbMetaData(file, deploymentUnit.getSimpleName());
-        log.info("Created EsbMetaData " + esbMetaData);
-        return esbMetaData;
+        final DeploymentUnit esbDeploymentUnit = createEsbDeploymentUnit(deploymentUnit, file);
+
+        return new EsbMetaData(esbDeploymentUnit, file.getPathName());
     }
 
+    private DeploymentUnit createEsbDeploymentUnit(final VFSDeploymentUnit deploymentUnit, final VirtualFile file) throws DeploymentException
+    {
+        log.info("Parsing ESB configuration'" + file + "'");
+
+        final ResourceLocator resourceLocator = new DeploymentUnitResourceLocator(deploymentUnit.getClassLoader());
+        final VirtualFile esbConfigFile = findEsbConfigFile(file);
+        try
+        {
+            return new DefaultConfigurationDigester(resourceLocator).digest(esbConfigFile.openStream());
+        }
+        catch (final IOException e)
+        {
+            throw new DeploymentException(e.getMessage(), e);
+        }
+    }
+
+    private VirtualFile findEsbConfigFile(final VirtualFile file) throws DeploymentException
+    {
+        if (file.getName().endsWith(ESB_FILE_SUFFIX))
+        {
+            return file;
+        }
+
+        List<VirtualFile> esbConfigFiles;
+        try
+        {
+            esbConfigFiles = file.getChildrenRecursively(new EsbConfigFileFilter());
+        }
+        catch (final IOException e)
+        {
+            throw new DeploymentException(e.getMessage(), e);
+        }
+
+        final int esbConfigFilesFound = esbConfigFiles.size();
+
+        if (esbConfigFilesFound == 0)
+        {
+            throw new DeploymentException("No JBossESB configuration could be located in file '" + file + "'");
+        }
+        else if (esbConfigFilesFound > 1)
+        {
+            throw new DeploymentException("Only one JBossESB configuration can exist in a file. Please check '" + file + "'");
+        }
+        else
+        {
+            return esbConfigFiles.get(0);
+        }
+    }
+
+    private static class EsbConfigFileFilter implements VirtualFileFilter
+    {
+
+        public boolean accepts(VirtualFile file)
+        {
+            return file.getName().endsWith(ESB_FILE_SUFFIX);
+        }
+    }
+
+
+
 }

Modified: labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployer.java
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployer.java	2008-12-01 14:03:32 UTC (rev 24178)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployer.java	2008-12-01 14:09:29 UTC (rev 24179)
@@ -20,22 +20,15 @@
  */
 package org.jboss.esb.microcontainer.deployers;
 
-import java.io.IOException;
-
 import org.apache.log4j.Logger;
-import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.esb.api.context.ResourceLocator;
-import org.jboss.esb.deploy.DeploymentRuntime;
-import org.jboss.esb.deploy.DeploymentUtil;
-import org.jboss.esb.microcontainer.config.DeploymentUnitResourceLocator;
 import org.jboss.esb.microcontainer.metadata.EsbMetaData;
-import org.jboss.virtual.VirtualFile;
 
 /**
- * EsbDeployer takes care of the deployment of an esb archive or a single jboss-esb.xml
- * configuration file.
+ * EsbDeployer takes care of the deployment of an {@link EsbMetaData} instance.
  * <p/>
  *
  * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
@@ -55,68 +48,40 @@
     {
         super(EsbMetaData.class);
         log.info("Created EsbDeployer");
+
+        // Tell the MicroContainer that we are producing BeanMetaData.
+        setOutput(BeanMetaData.class);
     }
 
     /**
-     * Deploys the an ESB Runtime.
-     * If the deployment is already deploy it will first be undeployed.
+     * Creates an {@link BeanMetaData} instance that describes the JBossESB deployment.
+     * The BeanMetaData is created using the information from the EsbMetaData object, such
+     * as the ESB DeploymentUnit and the archive name.
      *
+     * The BeanMeatData is then attached to the Microcontainers deployment unit and will be
+     * picked up by the BeanMetaDataDeployer.
+     *
      * @param deploymentUnit    The deployment unit to deploy.
      * @param esbMetaData       The ESB MetaData that is associated with the deployment unit.
      *
-     * TODO: Remove the actual deployment from here. Instead create BeanMetaData for the DeploymentRuntime or
-     * as wrapper that has a start and stop method. Those lifecycle methods will be called then by MC./Daniel
      */
     @Override
-    public void deploy(final DeploymentUnit deploymentUnit, final EsbMetaData esbMetaData) throws DeploymentException
+    public void deploy(final DeploymentUnit deploymentUnit, final EsbMetaData esbMetaData)
     {
-        final String deploymentName = deploymentUnit.getName();
-        try
-        {
-            final DeploymentRuntime runtime = createRuntime(deploymentUnit, esbMetaData, deploymentName);
-            runtime.deploy();
-            deploymentUnit.addAttachment(DeploymentRuntime.class, runtime);
-        }
-        catch (org.jboss.esb.api.exception.DeploymentException e)
-        {
-           throw new DeploymentException(e.getMessage(), e);
-        }
-        catch (final IOException e)
-        {
-           throw new DeploymentException(e.getMessage(), e);
-        }
+        final BeanMetaData beanMetaData = createBeanMetaData(deploymentUnit, esbMetaData);
+        deploymentUnit.addAttachment(BeanMetaData.class, beanMetaData);
+        log.info("Created beanMetaData : " + beanMetaData);
     }
 
-    /**
-     * Undeploys the deploymentunit.
-     *
-     * @param deploymentUnit    The deployment unit to undeploy.
-     * @param esbMetaData       The ESB MetaData that is associated with the deployment unit.
-     */
-    @Override
-    public void undeploy(final DeploymentUnit deploymentUnit, final EsbMetaData esbMetaData)
+    private BeanMetaData createBeanMetaData(final DeploymentUnit deploymentUnit, final EsbMetaData esbMetaData)
     {
-        // Retrieve the runtime to undeploy from the deployment unit.
-        final DeploymentRuntime runtime = deploymentUnit.getAttachment(DeploymentRuntime.class);
-        if (runtime != null)
-        {
-            try
-            {
-                runtime.undeploy();
-            }
-            catch (final org.jboss.esb.api.exception.DeploymentException e)
-            {
-                log.error("DeploymentException while trying to undeploy '" + deploymentUnit.getName() + "' : ", e);
-            }
-        }
-    }
+        BeanMetaDataBuilder bmdBuilder = BeanMetaDataBuilder.createBuilder("jboss.esb." + deploymentUnit.getName(), EsbDeployment.class.getName());
+        // Setup the first constructor argument.
+        bmdBuilder.addConstructorParameter(String.class.getName(), esbMetaData.getAchiveName());
+        // Setup the second constructor argument.
+        bmdBuilder.addConstructorParameter(org.jboss.esb.deploy.config.DeploymentUnit.class.getName(), esbMetaData.getDeploymentUnit());
 
-    private DeploymentRuntime createRuntime(final DeploymentUnit deploymentUnit, final EsbMetaData esbMetaData, final String deploymentName) throws org.jboss.esb.api.exception.DeploymentException, IOException
-    {
-        final ResourceLocator resourceLocator = new DeploymentUnitResourceLocator(deploymentUnit.getClassLoader());
-        final VirtualFile esbConfig = esbMetaData.getEsbConfig();
-        final DeploymentRuntime runtime = DeploymentUtil.createRuntime(esbConfig.openStream(), resourceLocator);
-        runtime.setDeploymentName(deploymentName);
-        return runtime;
+        return bmdBuilder.getBeanMetaData();
     }
+
 }

Modified: labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/metadata/EsbMetaData.java
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/metadata/EsbMetaData.java	2008-12-01 14:03:32 UTC (rev 24178)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/main/java/org/jboss/esb/microcontainer/metadata/EsbMetaData.java	2008-12-01 14:09:29 UTC (rev 24179)
@@ -22,12 +22,10 @@
 
 import java.io.Serializable;
 
-import org.jboss.virtual.VirtualFile;
+import org.jboss.esb.deploy.config.DeploymentUnit;
 
 /**
  * Metadata for an ESB deployment.
- * The metadata consists of the deployment archive name(.esb or .jar) and a virtual
- * file that provides access to the jboss-esb.xml configuration file.
  * </p>
  *
  * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
@@ -38,9 +36,9 @@
     private static final long serialVersionUID = 0L;
 
     /**
-     * VirtualFile to the jboss-esb.xml.
+     * The ESB DeploymentUnit.
      */
-    private VirtualFile esbConfig;
+    private DeploymentUnit deploymentUnit;
 
     /**
      * The name of the .esb archive.
@@ -54,15 +52,15 @@
      * @param fileURL       The VirtualFile object to jboss-esb.xml.
      * @param archiveName   The name of the .esb archive.
      */
-    public EsbMetaData(final VirtualFile fileURL, final String archiveName)
+    public EsbMetaData(final DeploymentUnit deploymentUnit, final String archiveName)
     {
-        this.esbConfig = fileURL;
+        this.deploymentUnit = deploymentUnit;
         this.archiveName = archiveName;
     }
 
-    public VirtualFile getEsbConfig()
+    public DeploymentUnit getDeploymentUnit()
     {
-        return esbConfig;
+        return deploymentUnit;
     }
 
     public String getAchiveName()
@@ -73,9 +71,10 @@
     @Override
     public String toString()
     {
-        final StringBuilder builder = new StringBuilder();
-        builder.append("EsbMetaData[esbConfig='").append(esbConfig);
-        builder.append("', archiveName='").append(archiveName).append("']");
-        return builder.toString();
+        final StringBuilder sb = new StringBuilder();
+        sb.append("EsbMetaData [deploymentUnit='").append(deploymentUnit);
+        sb.append("', archiveName='").append(archiveName);
+        sb.append("']");
+        return sb.toString();
     }
 }

Modified: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbParserDeployerTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbParserDeployerTest.java	2008-12-01 14:03:32 UTC (rev 24178)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbParserDeployerTest.java	2008-12-01 14:09:29 UTC (rev 24179)
@@ -31,6 +31,7 @@
 import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.esb.api.exception.DeploymentException;
 import org.jboss.esb.microcontainer.metadata.EsbMetaData;
 import org.jboss.test.kernel.junit.MicrocontainerTest;
 import org.jboss.virtual.VFS;
@@ -52,14 +53,34 @@
         super(name);
     }
 
-    public void testEsbDeployer() throws Throwable
+    public void testExplodedEsbArchive() throws Throwable
     {
-        final String archiveName = "esb1.jar";
+        assertDeployed("exploded-esb-archive.jar");
+    }
 
+    public void testExplodedEsbArchiveConfigInRoot() throws Throwable
+    {
+        assertDeployed("exploded-esb-archive-xml-in-root.jar");
+    }
+
+    public void testEsbArchive() throws Throwable
+    {
+        assertDeployed("esb-archive.jar");
+    }
+
+    public void testEsbArchiveConfigInRoot() throws Throwable
+    {
+        assertDeployed("esb-archive-xml-in-root.jar");
+    }
+
+    private void assertDeployed(final String archiveName) throws Exception, DeploymentException
+    {
         VirtualFile virtualFile = getVirtualFile(testArchivesDir, archiveName);
         VFSDeploymentUnit deploymentUnit = getDeploymentUnit(virtualFile);
         EsbMetaData esbMetaData = parserDeployer.parse(deploymentUnit, virtualFile, (EsbMetaData)null);
-        assertEquals(archiveName, esbMetaData.getAchiveName());
+
+        System.out.println(esbMetaData.getAchiveName());
+        assertEquals(virtualFile.getName(), esbMetaData.getAchiveName());
     }
 
     @Override
@@ -72,6 +93,7 @@
     private VFSDeploymentUnit getDeploymentUnit(final VirtualFile esbArchive) throws Exception
     {
         VFSDeploymentContext deploymentContext = getDeploymentContext(esbArchive);
+        deploymentContext.setClassLoader(getClass().getClassLoader());
         return getDeploymentUnit(deploymentContext);
     }
 

Added: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployerTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployerTest.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployerTest.java	2008-12-01 14:09:29 UTC (rev 24179)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.esb.microcontainer.deployers;
+
+import java.net.URL;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.deployers.vfs.plugins.structure.AbstractVFSDeploymentUnit;
+import org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl;
+import org.jboss.deployers.vfs.plugins.structure.VFSStructureBuilder;
+import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.esb.microcontainer.metadata.EsbMetaData;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Test for {@link EsbRuntimeDeployer}.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class EsbRuntimeDeployerTest extends MicrocontainerTest
+{
+    private VFSDeploymentUnit deploymentUnit;
+    private EsbMetaData esbMetaData;
+    private EsbRuntimeDeployer runtimeDeployer;
+    private String testArchivesDir = "/test_esb_archives";
+
+    public EsbRuntimeDeployerTest(final String name)
+    {
+        super(name);
+    }
+
+    public void testDeploy() throws Throwable
+    {
+        runtimeDeployer.deploy(deploymentUnit, esbMetaData);
+        BeanMetaData beanMetaData = deploymentUnit.getAttachment(BeanMetaData.class);
+        assertNotNull(beanMetaData);
+        assertEquals(EsbDeployment.class.getName(), beanMetaData.getBean());
+    }
+
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        final String archiveName = "exploded-esb-archive.jar";
+        VirtualFile virtualFile = getVirtualFile(testArchivesDir, archiveName);
+        deploymentUnit = getDeploymentUnit(virtualFile);
+        EsbParserDeployer parserDeployer = (EsbParserDeployer) getBean("EsbParserDeployer");
+        esbMetaData = parserDeployer.parse(deploymentUnit, virtualFile, (EsbMetaData)null);
+        runtimeDeployer = (EsbRuntimeDeployer) getBean("EsbRuntimeDeployer");
+    }
+
+    private VFSDeploymentUnit getDeploymentUnit(final VirtualFile esbArchive) throws Exception
+    {
+        VFSDeploymentContext deploymentContext = getDeploymentContext(esbArchive);
+        deploymentContext.setClassLoader(getClass().getClassLoader());
+        return getDeploymentUnit(deploymentContext);
+    }
+
+    private VFSDeploymentUnit getDeploymentUnit(final VFSDeploymentContext deploymentContext)
+    {
+        return new AbstractVFSDeploymentUnit(deploymentContext);
+    }
+
+    private VFSDeploymentContext getDeploymentContext(final VirtualFile esbArchive) throws Exception
+    {
+        VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(esbArchive);
+        VFSStructuralDeployersImpl structuralDeployers = new VFSStructuralDeployersImpl();
+        VFSStructureBuilder builder = new VFSStructureBuilder();
+        structuralDeployers.setStructureBuilder(builder);
+        StructureDeployer[] deployers = new StructureDeployer[]{new JARStructure()};
+        for (StructureDeployer deployer : deployers)
+        {
+            structuralDeployers.addDeployer(deployer);
+        }
+        return (VFSDeploymentContext) structuralDeployers.determineStructure(deployment);
+    }
+
+
+    private VirtualFile getVirtualFile(String directory, String fileName) throws Exception
+    {
+        URL url = getResource(directory);
+        return VFS.getVirtualFile(url, fileName);
+    }
+
+}

Added: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployerTest.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployerTest.xml	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/java/org/jboss/esb/microcontainer/deployers/EsbRuntimeDeployerTest.xml	2008-12-01 14:09:29 UTC (rev 24179)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="EsbParserDeployer" class="org.jboss.esb.microcontainer.deployers.EsbParserDeployer"/>
+   <bean name="EsbRuntimeDeployer" class="org.jboss.esb.microcontainer.deployers.EsbRuntimeDeployer"/>
+   
+   <bean name="MainDeployer" class="org.jboss.deployers.plugins.main.MainDeployerImpl">
+      <property name="structuralDeployers"><inject bean="StructuralDeployers"/></property>
+      <property name="deployers"><inject bean="Deployers"/></property>
+   </bean>
+
+   <bean name="StructuralDeployers" class="org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl">
+      <property name="structureBuilder">
+         <bean name="StructureBuilder" class="org.jboss.deployers.vfs.plugins.structure.VFSStructureBuilder"/>
+      </property>
+      <incallback method="addDeployer"/>
+      <uncallback method="removeDeployer"/>
+   </bean>
+
+   <bean name="Deployers" class="org.jboss.deployers.plugins.deployers.DeployersImpl">
+      <constructor><parameter><inject bean="jboss.kernel:service=KernelController"/></parameter></constructor>
+      <incallback method="addDeployer"/>
+      <uncallback method="removeDeployer"/>
+   </bean>
+   
+</deployment>

Modified: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/log4j.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/log4j.xml	2008-12-01 14:03:32 UTC (rev 24178)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/log4j.xml	2008-12-01 14:09:29 UTC (rev 24179)
@@ -35,6 +35,10 @@
    </category>
 
    <category name="org.jboss.esb">
+      <priority value="debug"/>
+   </category>
+   
+   <category name="org.milyn">
       <priority value="info"/>
    </category>
 

Added: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/esb-archive-xml-in-root.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/esb-archive-xml-in-root.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/esb-archive.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/esb-archive.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive-xml-in-root.jar/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive-xml-in-root.jar/jboss-esb.xml	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive-xml-in-root.jar/jboss-esb.xml	2008-12-01 14:09:29 UTC (rev 24179)
@@ -0,0 +1,10 @@
+<jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd">
+
+    <resources>
+        <resource id="schedule1" class="org.jboss.esb.schedule.SimpleSchedule">
+            <property name="frequency">100</property>
+            <property name="execCount">1</property>
+        </resource>
+    </resources>
+    
+</jbossesb>
\ No newline at end of file

Added: labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive.jar/META-INF/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive.jar/META-INF/jboss-esb.xml	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/container/microcontainer/src/test/resources/test_esb_archives/exploded-esb-archive.jar/META-INF/jboss-esb.xml	2008-12-01 14:09:29 UTC (rev 24179)
@@ -0,0 +1,10 @@
+<jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd">
+
+    <resources>
+        <resource id="schedule1" class="org.jboss.esb.schedule.SimpleSchedule">
+            <property name="frequency">100</property>
+            <property name="execCount">1</property>
+        </resource>
+    </resources>
+    
+</jbossesb>
\ No newline at end of file




More information about the jboss-svn-commits mailing list