[jboss-cvs] JBossAS SVN: r106439 - in projects/weld-int/branches/Deployment_WELDINT-1: deployer and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 5 23:49:45 EDT 2010


Author: flavia.rainone at jboss.com
Date: 2010-07-05 23:49:45 -0400 (Mon, 05 Jul 2010)
New Revision: 106439

Added:
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/support/MockArchiveManifest.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AssembledDirectoryFactory.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/BasicEarJBossDeploymentTestCase.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/resources/org/jboss/test/deployers/test/BasicEarJBossDeploymentTestCase.xml
Modified:
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/pom.xml
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldDiscoveryEnvironment.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ClasspathFactory.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ClasspathImpl.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/DeploymentImpl.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AbstractWeldTest.java
   projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/ArchiveDiscoveryDeploymentTestCase.java
   projects/weld-int/branches/Deployment_WELDINT-1/pom.xml
Log:
[WELDINT-1] ArchiveDiscoveryDeploymentTestCase implemented with ShrinkWrap.
Rename JBossDeploymentTestCase to BasicEarJBossDeploymentTestCase.
Comment out BasicEarJBossDeploymentTestCase test because of an error involving a duplicate ClassLoader being created for top-level.ear.
Mark all points that need to be reviewed with TODO and FIXME.
Fix a few typos and minor bugs in the Archive implementation.

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/pom.xml
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/pom.xml	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/pom.xml	2010-07-06 03:49:45 UTC (rev 106439)
@@ -283,6 +283,22 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+       <groupId>org.jboss.shrinkwrap</groupId>
+       <artifactId>shrinkwrap-impl-base</artifactId>
+       <scope>test</scope>
+    </dependency>
+    <dependency>
+       <groupId>org.jboss.shrinkwrap</groupId>
+       <artifactId>shrinkwrap-extension-vfs3</artifactId>
+       <scope>test</scope>
+        <exclusions>
+          <exclusion>
+            <groupId>org.jboss</groupId>
+            <artifactId>jboss-vfs</artifactId>
+          </exclusion>
+        </exclusions>
+    </dependency>
+    <dependency>
     	<groupId>org.jboss.ejb3</groupId>
         <artifactId>jboss-ejb3-core</artifactId>
     </dependency>

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldDiscoveryEnvironment.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldDiscoveryEnvironment.java	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WeldDiscoveryEnvironment.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -64,9 +64,11 @@
     */
    public Collection<Class<?>> getWeldClasses()
    {
-      return Collections.unmodifiableCollection(classes);
+      // FIXME WELDINT-1 old classes that use this method should get an Unmodifiable
+      // collection; if those classes are not deleted this method needs to be reviewed
+      return classes;
    }
-
+   
    /**
     * Get weld xmls.
     *

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -108,6 +108,16 @@
    {
       return beanClass.getClassLoader() == this.classLoader;
    }
+   
+   /**
+    * Adds a class to this archive.
+    * 
+    * @param beanClass a class whose ClassLoader is associated with this archive
+    */
+   public void addClass(Class<?> beanClass)
+   {
+      classes.add(beanClass);
+   }
 
    /**
     * Returns the URLs of all bean.xml files contained in this archive.

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -40,7 +40,7 @@
    // creates the classpaths for the archive
    private static final ClasspathFactory classpathFactory = ClasspathFactory.getInstance();
 
-   // keeps track of the instances that are currently under use by depoyers
+   // keeps track of the instances that are currently under use by deployers
    private static final Map<ClassLoader, ArchiveInfo> instances = new WeakHashMap<ClassLoader, ArchiveInfo>();
    
    /**

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ClasspathFactory.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ClasspathFactory.java	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ClasspathFactory.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -85,6 +85,7 @@
       return getClasspath(classLoader, domain);
    }
    
+   // FIXME: remove classLoader parameter!
    private Classpath getClasspath(ClassLoader cl, Loader domain)
    {
       if (domain == null)
@@ -98,8 +99,8 @@
          {
             if (domain instanceof ClassLoaderToLoaderAdapter)
             {
-               ClassLoaderToLoaderAdapter cp2la = (ClassLoaderToLoaderAdapter) domain;
-               ClassLoader unitLoader = SecurityActions.getClassLoader(cp2la);
+               ClassLoaderToLoaderAdapter cl2la = (ClassLoaderToLoaderAdapter) domain;
+               ClassLoader unitLoader = SecurityActions.getClassLoader(cl2la);
                ArchiveInfo archiveInfo = unitLoader == null? null: ArchiveInfo.getInstance(unitLoader);
                if (archiveInfo == null)
                {
@@ -129,6 +130,7 @@
       }
    }
 
+   // FIXME: getCachedClassPath
    private Classpath getClasspath(Loader domain)
    {
       WeakReference<Classpath> ref = domainToClasspath.get(domain);
@@ -139,6 +141,7 @@
       return ref.get();
    }
    
+   // FIXME addClasspathToCache
    private void addClasspath(Loader domain, Classpath domainClasspath)
    {
       domainToClasspath.put(domain, new WeakReference<Classpath>(domainClasspath));

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ClasspathImpl.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ClasspathImpl.java	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ClasspathImpl.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -115,7 +115,7 @@
          BeanDeploymentArchive bda = archive.getBeanDeploymentArchive();
          if (bda != null)
          {
-            bdas.add(archive.getBeanDeploymentArchive());
+            bdas.add(bda);
          }
       }
       return bdas;

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/DeploymentImpl.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/DeploymentImpl.java	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/DeploymentImpl.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -88,11 +88,17 @@
       // collection to mark the classpaths we have already searched
       Collection<Classpath> searchedClasspaths = new HashSet<Classpath>();
       // TODO -- why the search? beanClass' ClassLoader should be mapped to Archive?
+      // need to throw an IllegalArgumentException if the Archive is not reachable from
+      // the archives contained in the archives of this deployment
       Archive archive = findArchive(beanClass, archives, searchedArchives, searchedClasspaths);
       if (archive == null)
       {
          throw new IllegalArgumentException("Bean class " + beanClass + " is not reachable from deployment " + this);
       }
+      if (!archive.containsClass(beanClass))
+      {
+         archive.addClass(beanClass);
+      }
       return archive.createBeanDeploymentArchive();
    }
    

Added: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/support/MockArchiveManifest.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/support/MockArchiveManifest.java	                        (rev 0)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/support/MockArchiveManifest.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.deployers.support;
+
+import java.util.Map;
+
+import org.jboss.shrinkwrap.api.ArchivePath;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Filter;
+import org.jboss.shrinkwrap.api.Node;
+import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+
+/**
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ * @version $Revision$
+ */
+public class MockArchiveManifest
+{
+   private static Filter<ArchivePath> EAR_MODULE_FILTER = new Filter<ArchivePath>(){
+
+      public boolean include(ArchivePath pathObject)
+      {
+         String path = pathObject.get();
+         // ear modules are not "/" and don't belong to /lib
+         return path.length() > 1 && !path.startsWith("/lib");
+      }
+   };
+   
+   public static void addCDIManifest(JavaArchive archive)
+   {
+      archive.addManifestResource(new ByteArrayAsset("<web-beans></web-beans>".getBytes()), 
+               ArchivePaths.create("beans.xml"));
+   }
+   
+   public static void addCDIManifest(WebArchive archive)
+   {
+      archive.add(new ByteArrayAsset("<beans/>".getBytes()), 
+               ArchivePaths.create("WEB-INF/beans.xml"));
+   }
+   
+   public static void addManifest(JavaArchive archive)
+   {
+      archive.addManifestResource(new ByteArrayAsset("<ejb-jar/>".getBytes()), 
+               ArchivePaths.create("ejb-jar.xml"));
+   }
+   
+   public static void addManifest(JavaArchive archive, boolean isCDI)
+   {
+      addManifest(archive);
+      if (isCDI)
+      {
+         addCDIManifest(archive);
+      }
+   }
+   
+   public static void addManifest(WebArchive archive)
+   {
+      archive.add(new ByteArrayAsset("<web/>".getBytes()), ArchivePaths.create("WEB-INF/web.xml"));
+   }
+
+   public static void addManifest(WebArchive archive, boolean isCDI)
+   {
+      addManifest(archive);
+      if (isCDI)
+      {
+         addCDIManifest(archive);
+      }
+   }
+   
+   public static void addManifest(EnterpriseArchive archive)
+   {
+      Map<ArchivePath, Node> modules = archive.getContent(EAR_MODULE_FILTER);
+      StringBuffer appProperties = new StringBuffer();
+      for(ArchivePath archivePath: modules.keySet())
+      {
+         // remove leading '/' char
+         String path = archivePath.get().substring(1);
+         appProperties.append(path.replace('.', '_')).append("-module=").append(path);
+         appProperties.append('\n');
+      }
+      archive.addManifestResource(new ByteArrayAsset(appProperties.toString().getBytes()),
+               "application.properties");
+   }
+}


Property changes on: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/support/MockArchiveManifest.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AbstractWeldTest.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AbstractWeldTest.java	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AbstractWeldTest.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -21,11 +21,20 @@
  */
 package org.jboss.test.deployers.test;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.Executors;
 
 import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
 import org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataFactoryVisitor;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.vfs3.ArchiveFileSystem;
 import org.jboss.test.deployers.BootstrapDeployersTest;
 import org.jboss.test.deployers.support.crm.CrmWebBean;
 import org.jboss.test.deployers.support.ejb.MySLSBean;
@@ -35,6 +44,8 @@
 import org.jboss.test.deployers.support.ui.UIWebBean;
 import org.jboss.test.deployers.support.util.SomeUtil;
 import org.jboss.test.deployers.support.web.ServletWebBean;
+import org.jboss.vfs.TempDir;
+import org.jboss.vfs.TempFileProvider;
 import org.jboss.vfs.VFS;
 import org.jboss.vfs.VirtualFile;
 
@@ -56,7 +67,7 @@
       // excluding class that knows hot to load from system classloader
       Set<Class<?>> excluded = AbstractJDKChecker.getExcluded();
       excluded.add(BeanMetaDataFactoryVisitor.class);
-
+      tempFileProvider = TempFileProvider.create("shrinkwrap-", Executors.newSingleThreadScheduledExecutor());
       super.setUp();
    }
 
@@ -174,4 +185,41 @@
          .addPath("/weld/simple/ejb");
       return jarFile;
    }
+   
+   private static TempFileProvider tempFileProvider;
+   private final List<Closeable> vfsHandles = new ArrayList<Closeable>();
+   
+   protected VFSDeploymentUnit assertDeploy(Archive<?> archive) throws Exception
+   {
+      VirtualFile virtualFile = mount(archive);
+      return super.assertDeploy(virtualFile);
+   }
+   
+   private VirtualFile mount(Archive<?> archive) throws IOException
+   {
+      final TempDir tempDir = tempFileProvider.createTempDir(archive.getName());
+      VirtualFile virtualFile = VFS.getChild(UUID.randomUUID().toString()).getChild(archive.getName());
+      vfsHandles.add(VFS.mount(virtualFile, new ArchiveFileSystem(archive, tempDir)));
+      mountZipFiles(virtualFile);
+      return virtualFile;
+   }
+   
+   private void mountZipFiles(VirtualFile file) throws IOException
+   {
+      if (!file.isDirectory() && file.getName().matches("^.*\\.([EeWwJj][Aa][Rr]|[Zz][Ii][Pp])$"))
+         vfsHandles.add(VFS.mountZip(file, file, tempFileProvider));
+
+      if (file.isDirectory())
+         for (VirtualFile child : file.getChildren())
+            mountZipFiles(child);
+   }
+   
+   protected void tearDown() throws Exception
+   {
+      for (Closeable vfsHandle: vfsHandles)
+      {
+            vfsHandle.close();
+      }
+      super.tearDown();
+   }
 }
\ No newline at end of file

Modified: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/ArchiveDiscoveryDeploymentTestCase.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/ArchiveDiscoveryDeploymentTestCase.java	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/ArchiveDiscoveryDeploymentTestCase.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -22,6 +22,7 @@
 package org.jboss.test.deployers.test;
 
 import java.net.URL;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
@@ -29,17 +30,25 @@
 import junit.framework.Test;
 
 import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.container.LibraryContainer;
+import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.test.deployers.support.MockArchiveManifest;
 import org.jboss.test.deployers.support.crm.CrmWebBean;
 import org.jboss.test.deployers.support.ejb.BusinessInterface;
 import org.jboss.test.deployers.support.ejb.MySLSBean;
 import org.jboss.test.deployers.support.ext.ExternalWebBean;
 import org.jboss.test.deployers.support.jar.PlainJavaBean;
+import org.jboss.test.deployers.support.jsf.NotWBJsfBean;
 import org.jboss.test.deployers.support.ui.UIWebBean;
+import org.jboss.test.deployers.support.util.SomeUtil;
 import org.jboss.test.deployers.support.web.ServletWebBean;
 import org.jboss.vfs.VirtualFile;
 import org.jboss.weld.integration.deployer.env.WeldDiscoveryEnvironment;
 import org.jboss.weld.integration.deployer.env.bda.ArchiveInfo;
+import org.jboss.wsf.spi.metadata.j2ee.SLSBMetaData;
 
 /**
  * ArchiveInfo environment discovery test case.
@@ -59,134 +68,573 @@
       return suite(ArchiveDiscoveryDeploymentTestCase.class);
    }
 
-   public void testSimpleUsage() throws Exception
+   private DeploymentUnit unit;
+   
+   public void tearDown() throws Exception
    {
-      VirtualFile ear = createBasicEar();
-      VFSDeploymentUnit topUnit = assertDeploy(ear);
-      try
+      undeploy(unit);
+      super.tearDown();
+   }
+   
+   public void testEjbJar() throws Exception
+   {
+      JavaArchive ejbJar = createEjbJar(true);
+      unit = assertDeploy(ejbJar);
+
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, PlainJavaBean.class);
+      assertExpectedResources(discovery, unit.getSimpleName());
+   }
+
+   public void testEjbJarWithoutXml() throws Exception
+   {
+      JavaArchive ejbJar = createEjbJar(false);
+      unit = assertDeploy(ejbJar);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+   }
+
+   public void testEjbJarInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("simple.ear", EnterpriseArchive.class);
+      JavaArchive ejbJar = createEjbJar(true);
+      ear.addModule(ejbJar);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, PlainJavaBean.class);
+      assertExpectedResources(discovery, unit.getSimpleName() + "/ejb.jar");
+      
+      assertSingleChildAsUnit("ejb.jar");
+      assertNoArchiveInfo(unit);
+   }
+
+   public void testEjbJarWithoutXmlInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("simple.ear", EnterpriseArchive.class);
+      JavaArchive ejbJar = createEjbJar(false);
+      ear.addModule(ejbJar);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      assertSingleChildAsUnit("ejb.jar");
+      assertNoArchiveInfo(unit);
+   }
+   
+   public void testEjbJarsInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("simple.ear", EnterpriseArchive.class);
+      JavaArchive ejbJar1 = createEjbJar("ejbJar1.jar", true, PlainJavaBean.class);
+      ear.addModule(ejbJar1);
+      JavaArchive ejbJar2 = createEjbJar("ejbJar2.jar", true, MySLSBean.class, SLSBMetaData.class);
+      ear.addModule(ejbJar2);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, PlainJavaBean.class, MySLSBean.class,
+               SLSBMetaData.class);
+      assertExpectedResources(discovery, "simple.ear/ejbJar1.jar", "simple.ear/ejbJar2.jar");
+      
+      assertEquals(2, unit.getChildren().size());
+      for (DeploymentUnit childUnit: unit.getChildren())
       {
-         ArchiveInfo archiveInfo = topUnit.getAttachment(ArchiveInfo.class);
-         WeldDiscoveryEnvironment wbDiscovery = archiveInfo.getEnvironment();
-         assertNotNull("Null WBDiscoveryEnv.", wbDiscovery);
+         assertNoArchiveInfo(childUnit);
+      }
+   }
 
-         Set<String> expected = new HashSet<String>();
-         addExpectedResource(expected, "ejbs.jar");
-         addExpectedResource(expected, "ext.jar");
-         addExpectedResource(expected, "simple.jar");
+   public void testMixedEjbJarsInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("simple.ear", EnterpriseArchive.class);
+      JavaArchive ejbJar1 = createEjbJar("ejbJar1.jar", false, PlainJavaBean.class);
+      ear.addModule(ejbJar1);
+      JavaArchive ejbJar2 = createEjbJar("ejbJar2.jar", true, MySLSBean.class, SLSBMetaData.class);
+      ear.addModule(ejbJar2);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, MySLSBean.class, SLSBMetaData.class);
+      assertExpectedResources(discovery, "simple.ear/ejbJar2.jar");
+      
+      assertEquals(2, unit.getChildren().size());
+      for (DeploymentUnit childUnit: unit.getChildren())
+      {
+         assertNoArchiveInfo(childUnit);
+      }
+   }
 
-         for (URL url : wbDiscovery.getWeldXml())
-         {
-            boolean found = false;
-            Iterator<String> iter = expected.iterator();
-            while (iter.hasNext())
-            {
-               String expectedURL = iter.next();
-               if (url.toExternalForm().contains(expectedURL))
-               {
-                  iter.remove();
-                  found = true;
-                  break;
-               }
-            }
-            assertTrue("Unexpected wb url: " + url, found);
-         }
+   public void testEjbJarsWithoutXmlInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("simple.ear", EnterpriseArchive.class);
+      JavaArchive ejbJar1 = createEjbJar("ejbJar1.jar", false, PlainJavaBean.class);
+      ear.addModule(ejbJar1);
+      JavaArchive ejbJar2 = createEjbJar("ejbJar2.jar", false, MySLSBean.class, SLSBMetaData.class);
+      ear.addModule(ejbJar2);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      assertEquals(2, unit.getChildren().size());
+      for (DeploymentUnit childUnit: unit.getChildren())
+      {
+         assertNoArchiveInfo(childUnit);
+      }
+   }
+   
+   public void testWar() throws Exception
+   {
+      WebArchive war = createWar(true);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), true);
+   }
+   
+   public void testWarWithLib() throws Exception
+   {
+      WebArchive war = createWarWithLib(true, true);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class, UIWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), true, "lib.jar");
+   }
 
-         assertEmpty("Should be emtpy, missing " + expected, expected);
+   public void testWarWithLibs() throws Exception
+   {
+      WebArchive war = createWarWithLibs(true, true, true);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class, UIWebBean.class, CrmWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), true, "lib1.jar", "lib2.jar");
+   }
 
-         addExpectedClass(expected, BusinessInterface.class);
-         addExpectedClass(expected, MySLSBean.class);
-         addExpectedClass(expected, ExternalWebBean.class);
-         addExpectedClass(expected, PlainJavaBean.class);
+   public void testWarWithLibWithoutXml() throws Exception
+   {
+      WebArchive war = createWarWithLib(true, false);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), true);
+   }
 
-         for (Class<?> clazz : wbDiscovery.getWeldClasses())
-            assertTrue(expected.remove(clazz.getName()));
+   public void testWarWithLibsWithoutXml() throws Exception
+   {
+      WebArchive war = createWarWithLibs(true, false, false);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), true);
+   }
 
-         assertEmpty("Should be emtpy, missing " + expected, expected);
-         
-         for (DeploymentUnit unit: topUnit.getChildren())
-         {
-            archiveInfo = unit.getAttachment(ArchiveInfo.class);
-            if (unit.getName().contains("simple.war"))
-            {
-               assertNotNull(archiveInfo);
-               wbDiscovery = archiveInfo.getEnvironment();
-               expected = new HashSet<String>();
-               addExpectedResource(expected, "ui.jar");
-               addExpectedResource(expected, "simple.war", "/WEB-INF/beans.xml");
+   public void testWarWithMixedLibs() throws Exception
+   {
+      WebArchive war = createWarWithLibs(true, true, false);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class, UIWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), true, "lib1.jar");
+   }
 
-               for (URL url : wbDiscovery.getWeldXml())
-               {
-                  boolean found = false;
-                  Iterator<String> iter = expected.iterator();
-                  while (iter.hasNext())
-                  {
-                     String expectedURL = iter.next();
-                     if (url.toExternalForm().contains(expectedURL))
-                     {
-                        iter.remove();
-                        found = true;
-                        break;
-                     }
-                  }
-                  assertTrue("Unexpected wb url: " + url, found);
-               }
+   public void testWarWithoutXmlWithLib() throws Exception
+   {
+      WebArchive war = createWarWithLib(false, true);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, UIWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), false, "lib.jar");
+   }
 
-               assertEmpty("Should be emtpy, missing " + expected, expected);
+   public void testWarWithoutXmlWithLibs() throws Exception
+   {
+      WebArchive war = createWarWithLibs(false, true, true);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, UIWebBean.class, CrmWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), false, "lib1.jar", "lib2.jar");
+   }
 
-               addExpectedClass(expected, UIWebBean.class);
-               addExpectedClass(expected, ServletWebBean.class);
-               //addExpectedClass(expected, CrmWebBean.class);
+   public void testWarWithoutXmlWithLibWithoutXml() throws Exception
+   {
+      WebArchive war = createWarWithLib(false, false);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+   }
 
-               for (Class<?> clazz : wbDiscovery.getWeldClasses())
-                  assertTrue(expected.remove(clazz.getName()));
+   public void testWarWithoutXmlWithMixedLibs() throws Exception
+   {
+      WebArchive war = createWarWithLibs(false, true, false);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, UIWebBean.class);
+      assertExpectedWarResources(discovery, unit.getSimpleName(), false, "lib1.jar");
+   }
 
-               assertEmpty("Should be emtpy, missing " + expected, expected);
-            }
-            else if (unit.getName().contains("crm.war"))
-            {
-               assertNotNull(archiveInfo);
-               wbDiscovery = archiveInfo.getEnvironment();
-               expected = new HashSet<String>();
-               addExpectedResource(expected, "crm.jar");
+   public void testWarWithoutXmlWithLibsWithoutXml() throws Exception
+   {
+      WebArchive war = createWarWithLibs(false, false, false);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+   }
 
-               for (URL url : wbDiscovery.getWeldXml())
-               {
-                  boolean found = false;
-                  Iterator<String> iter = expected.iterator();
-                  while (iter.hasNext())
-                  {
-                     String expectedURL = iter.next();
-                     if (url.toExternalForm().contains(expectedURL))
-                     {
-                        iter.remove();
-                        found = true;
-                        break;
-                     }
-                  }
-                  assertTrue("Unexpected wb url: " + url, found);
-               }
+   public void testWarWithoutXml() throws Exception
+   {
+      WebArchive war = createWar(false);
+      unit = assertDeploy(war);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+   }
+   
+   public void testWarInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("warinear.ear", EnterpriseArchive.class);
+      WebArchive war = createWar(true);
+      ear.addModule(war);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      assertSingleChildAsUnit("simple.war");
+      discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class);
+      assertExpectedWarResources(discovery, "simple.war", true);
+   }
 
-               assertEmpty("Should be emtpy, missing " + expected, expected);
+   public void testWarsInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("warinear.ear", EnterpriseArchive.class);
+      WebArchive war = createWar("simple1.war", true, ServletWebBean.class);
+      ear.addModule(war);
+      war = createWar("simple2.war", true, NotWBJsfBean.class);
+      ear.addModule(war);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      for (DeploymentUnit childUnit: unit.getChildren())
+      {
+         unit = childUnit;
+         if (unit.getSimpleName().equals("simple1.war"))
+         {
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery, ServletWebBean.class);
+            assertExpectedWarResources(discovery, "simple1.war", true);
+         }
+         else if (unit.getSimpleName().equals("simple2.war"))
+         {
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery, NotWBJsfBean.class);
+            assertExpectedWarResources(discovery, "simple2.war", true);
+         }
+         else
+         {
+            fail("Unexpected childUnit: " + unit.getSimpleName());
+         }
+      }
+   }
 
-               addExpectedClass(expected, CrmWebBean.class);
+   public void testMixedWarsInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("warinear.ear", EnterpriseArchive.class);
+      WebArchive war = createWar("simple1.war", true, ServletWebBean.class);
+      ear.addModule(war);
+      war = createWar("simple2.war", false, NotWBJsfBean.class);
+      ear.addModule(war);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      for (DeploymentUnit childUnit: unit.getChildren())
+      {
+         unit = childUnit;
+         if (unit.getSimpleName().equals("simple1.war"))
+         {
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery, ServletWebBean.class);
+            assertExpectedWarResources(discovery, "simple1.war", true);
+         }
+         else if (unit.getSimpleName().equals("simple2.war"))
+         {
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery);
+            assertExpectedResources(discovery);
+         }
+         else
+         {
+            fail("Unexpected childUnit: " + unit.getSimpleName());
+         }
+      }
+   }
+   
+   public void testWarsWithoutXmlInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("warinear.ear", EnterpriseArchive.class);
+      WebArchive war = createWar("simple1.war", false, ServletWebBean.class);
+      ear.addModule(war);
+      war = createWar("simple2.war", false, NotWBJsfBean.class);
+      ear.addModule(war);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      for (DeploymentUnit childUnit: unit.getChildren())
+      {
+         unit = childUnit;
+         assertTrue("Unexpected childUnit: " + unit.getSimpleName(), 
+                  unit.getSimpleName().equals("simple1.war") ||
+                  unit.getSimpleName().equals("simple2.war"));
+         discovery = assertDiscoveryEnvironment();
+         assertExpectedClasses(discovery);
+         assertExpectedResources(discovery);
+      }
+   }
 
-               for (Class<?> clazz : wbDiscovery.getWeldClasses())
-                  assertTrue(expected.remove(clazz.getName()));
+   public void testWarWithLibInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("warinear.ear", EnterpriseArchive.class);
+      WebArchive war = createWarWithLib(true, true);
+      ear.addModule(war);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      assertSingleChildAsUnit("simple.war");
+      discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class, UIWebBean.class);
+      assertExpectedWarResources(discovery, "simple.war", true, "lib.jar");
+   }
 
-               assertEmpty("Should be emtpy, missing " + expected, expected);
-            }
-            else
-            {
-               assertNull("Unit " + unit.getName() +  " contains a not null ArchiveInfo", archiveInfo);
-            }
+   public void testWarWithLibWithoutXmlInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("warinear.ear", EnterpriseArchive.class);
+      WebArchive war = createWarWithLib(true, false);
+      ear.addModule(war);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      assertSingleChildAsUnit("simple.war");
+      discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, ServletWebBean.class);
+      assertExpectedWarResources(discovery, "simple.war", true);
+   }
+
+   public void testWarWithoutXmlWithLibWithoutXmlInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("warinear.ear", EnterpriseArchive.class);
+      WebArchive war = createWarWithLib(false, false);
+      ear.addModule(war);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      assertSingleChildAsUnit("simple.war");
+      discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+   }
+
+   public void testWarWithoutXmlWithLibInEar() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("warinear.ear", EnterpriseArchive.class);
+      WebArchive war = createWarWithLib(false, true);
+      ear.addModule(war);
+      MockArchiveManifest.addManifest(ear);
+      unit = assertDeploy(ear);
+      
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
+      
+      assertSingleChildAsUnit("simple.war");
+      discovery = assertDiscoveryEnvironment();
+      assertExpectedClasses(discovery, UIWebBean.class);
+      assertExpectedWarResources(discovery, "simple.war", false, "lib.jar");
+   }
+
+   public void testBasicEar() throws Exception
+   {
+      VirtualFile ear = createBasicEar();
+      unit = assertDeploy(ear);
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      
+      assertExpectedClasses(discovery, BusinessInterface.class, MySLSBean.class,
+               ExternalWebBean.class, PlainJavaBean.class);
+      assertExpectedResources(discovery, "ejbs.jar", "ext.jar", "simple.jar");
+
+      for (DeploymentUnit childUnit: unit.getChildren())
+      {
+         unit = childUnit;
+         if (childUnit.getName().endsWith("simple.war/"))
+         {
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery, UIWebBean.class, ServletWebBean.class);
+            assertExpectedWarResources(discovery, "simple.war", true, "ui.jar");
          }
+         else if (childUnit.getName().endsWith("crm.war/"))
+         {
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery, CrmWebBean.class);
+            assertExpectedResources(discovery, "crm.jar");
+         }
+         else
+         {
+            ArchiveInfo archiveInfo = childUnit.getAttachment(ArchiveInfo.class);
+            assertNull("Unit " + unit.getName() +  " contains a not null ArchiveInfo", archiveInfo);
+         }
       }
-      finally
+   }
+   
+   public void testBasicEarFullCDI() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("simple.ear", EnterpriseArchive.class);
+      createLib(ear, "util.jar", true, SomeUtil.class);
+      createLib(ear, "ext.jar", true, ExternalWebBean.class);
+      JavaArchive ejbJar = createEjbJar("simple.jar", true, PlainJavaBean.class);
+      ear.addModule(ejbJar);
+      ejbJar = createEjbJar("ejbs.jar", true, MySLSBean.class, BusinessInterface.class);
+      ear.addModule(ejbJar);
+      WebArchive war = createWar("simple.war", true, ServletWebBean.class);
+      createLib(war, "ui.jar", true, UIWebBean.class);
+      ear.addModule(war);
+      war = createWar("crm.war", true, NotWBJsfBean.class);
+      createLib(war, "crm.jar", true, CrmWebBean.class);
+      ear.addModule(war);
+      unit = assertDeploy(ear);
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      
+      assertExpectedClasses(discovery, BusinessInterface.class, MySLSBean.class,
+               ExternalWebBean.class, PlainJavaBean.class, SomeUtil.class);
+      assertExpectedResources(discovery, "util.jar", "ext.jar", "simple.jar", "ejbs.jar");
+
+      for (DeploymentUnit childUnit: unit.getChildren())
       {
-         undeploy(topUnit);
+         unit = childUnit;
+         if (childUnit.getName().endsWith("simple.war/"))
+         {
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery, UIWebBean.class, ServletWebBean.class);
+            assertExpectedWarResources(discovery, "simple.war", true, "ui.jar");
+         }
+         else if (childUnit.getName().endsWith("crm.war/"))
+         {
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery, CrmWebBean.class, NotWBJsfBean.class);
+            assertExpectedWarResources(discovery, "simple.ear/crm.war", true, "crm.jar");
+         }
+         else
+         {
+            ArchiveInfo archiveInfo = childUnit.getAttachment(ArchiveInfo.class);
+            assertNull("Unit " + unit.getName() +  " contains a not null ArchiveInfo", archiveInfo);
+         }
       }
    }
+   
+   public void testBasicEarWithoutXml() throws Exception
+   {
+      EnterpriseArchive ear = ShrinkWrap.create("simple.ear", EnterpriseArchive.class);
+      createLib(ear, "util.jar", false, SomeUtil.class);
+      createLib(ear, "ext.jar", false, ExternalWebBean.class);
+      JavaArchive ejbJar = createEjbJar("simple.jar", false, PlainJavaBean.class);
+      ear.addModule(ejbJar);
+      ejbJar = createEjbJar("ejbs.jar", false, MySLSBean.class, BusinessInterface.class);
+      ear.addModule(ejbJar);
+      WebArchive war = createWar("simple.war", false, ServletWebBean.class);
+      createLib(war, "ui.jar", false, UIWebBean.class);
+      ear.addModule(war);
+      war = createWar("crm.war", false, NotWBJsfBean.class);
+      createLib(war, "crm.jar", false, CrmWebBean.class);
+      ear.addModule(war);
+      unit = assertDeploy(ear);
+      WeldDiscoveryEnvironment discovery = assertDiscoveryEnvironment();
+      
+      assertExpectedClasses(discovery);
+      assertExpectedResources(discovery);
 
+      for (DeploymentUnit childUnit: unit.getChildren())
+      {
+         if (childUnit.getName().endsWith("simple.war/") ||
+                  childUnit.getName().endsWith("crm.war/"))
+         {
+            unit = childUnit;
+            discovery = assertDiscoveryEnvironment();
+            assertExpectedClasses(discovery);
+            assertExpectedResources(discovery);
+         }
+         else
+         {
+            ArchiveInfo archiveInfo = childUnit.getAttachment(ArchiveInfo.class);
+            assertNull("Unit " + unit.getName() +  " contains a not null ArchiveInfo", archiveInfo);
+         }
+      }
+   }
+   
+   
+   // TODO
+   // Several of these methods will be reused by other test classes and will be
+   // extracted to a common superclass once done
+   private void assertNoArchiveInfo(DeploymentUnit unit)
+   {
+      assertNull(unit.getAttachment(ArchiveInfo.class));
+   }
+
+   private WeldDiscoveryEnvironment assertDiscoveryEnvironment()
+   {
+      ArchiveInfo archiveInfo = unit.getAttachment(ArchiveInfo.class);
+      assertNotNull(archiveInfo);
+      WeldDiscoveryEnvironment discovery = archiveInfo.getEnvironment();
+      assertNotNull(discovery);
+      return discovery;
+   }
+
    private static void addExpectedResource(Set<String> expected, String unit)
    {
       addExpectedResource(expected, unit, "/META-INF/beans.xml");
@@ -201,4 +649,141 @@
    {
       expected.add(clazz.getName());
    }
+   
+   private void assertExpectedClasses(WeldDiscoveryEnvironment discoveryEnvironment, Set<String> expected)
+   {
+      Collection<Class<?>> weldClasses = discoveryEnvironment.getWeldClasses();
+      assertNotNull(weldClasses);
+      assertTrue("Unexpected empty weld classes collection", expected.isEmpty() || !weldClasses.isEmpty());
+      for (Class<?> clazz : weldClasses)
+      {
+         assertTrue("Found unexpected class: " + clazz.getName(), expected.remove(clazz.getName()));
+      }
+      assertEmpty("Should be emtpy, missing " + expected, expected);
+   }
+   
+   private void assertExpectedClasses(WeldDiscoveryEnvironment discoveryEnvironment, Class<?>... classes)
+   {
+      Set<String> expected = new HashSet<String>();
+      for(Class<?> clazz: classes)
+      {
+         addExpectedClass(expected, clazz);
+      }
+      assertExpectedClasses(discoveryEnvironment, expected);
+   }
+   
+   private void assertExpectedResources(WeldDiscoveryEnvironment discoveryEnvironment, Set<String> expected)
+   {
+      Collection<URL> weldXml = discoveryEnvironment.getWeldXml();
+      assertNotNull(weldXml);
+      assertTrue("Unexpected empty weld XML collection", expected.isEmpty() || !weldXml.isEmpty());
+      for (URL url : weldXml)
+      {
+         boolean found = false;
+         Iterator<String> iter = expected.iterator();
+         while (iter.hasNext())
+         {
+            String expectedURL = iter.next();
+            if (url.toExternalForm().endsWith(expectedURL))
+            {
+               iter.remove();
+               found = true;
+               break;
+            }
+         }
+         assertTrue("Unexpected wb url: " + url, found);
+      }
+      assertEmpty("Should be emtpy, missing " + expected, expected);
+   }
+   
+   public void assertExpectedResources(WeldDiscoveryEnvironment discoveryEnvironment, String... units)
+   {
+      Set<String> expected = new HashSet<String>();
+      for (String unit: units)
+      {
+         addExpectedResource(expected, unit);
+      }
+      assertExpectedResources(discoveryEnvironment, expected);
+   }
+   
+   public void assertExpectedWarResources(WeldDiscoveryEnvironment discoveryEnvironment, String warUnit, boolean warResourceExpected, String... units)
+   {
+      Set<String> expected = new HashSet<String>();
+      if (warResourceExpected)
+         addExpectedResource(expected, warUnit, "/WEB-INF/beans.xml");
+      for (String unit: units)
+      {
+         addExpectedResource(expected, warUnit, "/WEB-INF/lib/" + unit + "/META-INF/beans.xml");
+      }
+      assertExpectedResources(discoveryEnvironment, expected);
+   }
+   
+   private JavaArchive createEjbJar(boolean jarCDI)
+   {
+      return createEjbJar("ejb.jar", jarCDI, PlainJavaBean.class);
+   }
+   
+   private JavaArchive createEjbJar(String jarName, boolean jarCDI, Class<?>... classes)
+   {
+      JavaArchive ejbJar = ShrinkWrap.create(jarName, JavaArchive.class);
+      for (Class<?> clazz: classes)
+      {
+         ejbJar.addClass(clazz);
+      }
+      MockArchiveManifest.addManifest(ejbJar, jarCDI);
+      return ejbJar;
+   }
+
+   private WebArchive createWar(boolean warCDI)
+   {
+      return createWar("simple.war", warCDI, ServletWebBean.class);
+   }
+   
+   private WebArchive createWar(String warName, boolean warCDI, Class<?>... classes)
+   {
+      WebArchive war = ShrinkWrap.create(warName, WebArchive.class);
+      for (Class<?> clazz: classes)
+      {
+         war.addClass(clazz);
+      }
+      MockArchiveManifest.addManifest(war, warCDI);
+      return war;
+   }
+   
+   private WebArchive createWarWithLib(boolean warCDI, boolean libCDI)
+   {
+      WebArchive war = createWar(warCDI);
+      createLib(war, "lib.jar", libCDI, UIWebBean.class);
+      return war;
+   }
+   
+   private WebArchive createWarWithLibs(boolean warCDI, boolean lib1CDI, boolean lib2CDI)
+   {
+      WebArchive war = createWar(warCDI);
+      createLib(war, "lib1.jar", lib1CDI, UIWebBean.class);
+      createLib(war, "lib2.jar", lib2CDI, CrmWebBean.class);
+      return war;
+   }
+
+   
+   private void createLib(LibraryContainer<?> archive, String libName, boolean cdi, Class<?>... classes)
+   {
+      JavaArchive lib = ShrinkWrap.create(libName, JavaArchive.class);
+      if (cdi)
+      {
+         MockArchiveManifest.addCDIManifest(lib);
+      }
+      for (Class<?> libClass: classes)
+      {
+         lib.addClass(libClass);
+      }
+      archive.addLibrary(lib);
+   }
+   
+   private void assertSingleChildAsUnit(String name)
+   {
+      assertEquals(1, unit.getChildren().size());
+      unit = unit.getChildren().iterator().next();//FIXME
+      assertEquals(unit.getSimpleName(), name);
+   }
 }

Added: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AssembledDirectoryFactory.java
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AssembledDirectoryFactory.java	                        (rev 0)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AssembledDirectoryFactory.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.deployers.test;
+
+import org.jboss.test.deployers.support.AssembledDirectory;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ *
+ * @version $Revision$
+ */
+public interface AssembledDirectoryFactory
+{
+   public AssembledDirectory createAssembledDirectory(VirtualFile virtualFile) throws Exception;
+}
\ No newline at end of file


Property changes on: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/AssembledDirectoryFactory.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/BasicEarJBossDeploymentTestCase.java (from rev 105413, projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/JBossDeploymentTestCase.java)
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/BasicEarJBossDeploymentTestCase.java	                        (rev 0)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/java/org/jboss/test/deployers/test/BasicEarJBossDeploymentTestCase.java	2010-07-06 03:49:45 UTC (rev 106439)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.deployers.test;
+
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+
+/**
+ * JBoss Deployment test case.
+ *
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ */
+public class BasicEarJBossDeploymentTestCase extends AbstractDeploymentTest
+{
+   public BasicEarJBossDeploymentTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(BasicEarJBossDeploymentTestCase.class);
+   }
+
+   protected int getExpectedArchives()
+   {
+      return 3;
+   }
+
+   protected void assertNewBeanDeploymentArchive(List<BeanDeploymentArchive> archives, BeanDeploymentArchive newBDA)
+   {
+      assertSame(newBDA, archives.iterator().next());
+   }
+   
+   /* FIXME a duplicate ClassLoader is being created for top-level.ear, as can be seen
+    * in the messages below (the message below is generated by uncommitted code and
+    * its purpose is to evidence only the error
+    * (PS: error cannot be reproduced in my Eclipse)
+    * 6980 ERROR [AbstractKernelController] Error installing to Instantiated: name=vfs:///top-level.ear/_JBossDeployment state=Described
+java.lang.RuntimeException: ArchiveInfo found at ADAPTERS collection: ArchiveInfo[BaseClassLoader at 7371b246{vfs:///top-level.ear/}]
+ArchiveInfo found has classpath adapter: true
+ArchiveInfo found is the same as current archiveInfo: false
+Current ArchiveInfo: ArchiveInfo[BaseClassLoader at 927e4be{vfs:///top-level.ear/}]
+    * 
+    */
+   @Override
+   public void testSimpleUsage(){}
+}
\ No newline at end of file

Added: projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/resources/org/jboss/test/deployers/test/BasicEarJBossDeploymentTestCase.xml
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/resources/org/jboss/test/deployers/test/BasicEarJBossDeploymentTestCase.xml	                        (rev 0)
+++ projects/weld-int/branches/Deployment_WELDINT-1/deployer/src/test/resources/org/jboss/test/deployers/test/BasicEarJBossDeploymentTestCase.xml	2010-07-06 03:49:45 UTC (rev 106439)
@@ -0,0 +1,33 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+  <bean name="EarStructure" class="org.jboss.test.deployers.vfs.structure.ear.support.MockEarStructureDeployer"/>
+  <bean name="WarStructure" class="org.jboss.test.deployers.vfs.structure.war.support.MockWarStructureDeployer"/>
+  <bean name="WarClassLoader" class="org.jboss.test.deployers.vfs.reflect.support.MockWarClassLoaderDeployer"/>
+
+  <bean name="JWBMDDeployer" class="org.jboss.weld.integration.deployer.ext.JBossWeldMetaDataDeployer"/>
+  <bean name="WBFilesDeployer" class="org.jboss.weld.integration.deployer.metadata.WeldFilesDeployer"/>
+  <bean name="ArchiveInfoDeployer" class="org.jboss.weld.integration.deployer.env.ArchiveInfoDeployer"/>
+  <bean name="ArchiveDiscoveryDeployer" class="org.jboss.weld.integration.deployer.env.ArchiveDiscoveryDeployer"/>
+
+  <beanfactory name="JBossEjbServices" class="org.jboss.test.deployers.support.MockEmptyEjbServices"/>
+
+  <bean name="EjbServicesDeployer" class="org.jboss.weld.integration.deployer.env.EjbServicesDeployer">
+    <property name="ejbServicesClassName">org.jboss.test.deployers.support.MockEmptyEjbServices</property>
+  </bean>
+
+  <!-- Target of the Test -->
+  <bean name="DeploymentDeployer" class="org.jboss.weld.integration.deployer.env.JBossDeploymentDeployer"/>
+
+  <bean name="BootDeployer" class="org.jboss.test.deployers.support.deployer.MockBootDeployer"/>
+
+  <bean name="DynamicDependencyCreator" class="org.jboss.weld.integration.deployer.env.DynamicDependencyCreator">
+    <constructor>
+      <parameter><inject bean="jboss.kernel:service=KernelController"/></parameter>
+    </constructor>
+  </bean>
+
+  <bean name="JBossTransactionServices" class="org.jboss.test.deployers.support.MockTransactionServices"/>
+
+  <bean name="RealTransactionManager" class="java.lang.Object"/>
+
+</deployment>

Modified: projects/weld-int/branches/Deployment_WELDINT-1/pom.xml
===================================================================
--- projects/weld-int/branches/Deployment_WELDINT-1/pom.xml	2010-07-06 03:08:31 UTC (rev 106438)
+++ projects/weld-int/branches/Deployment_WELDINT-1/pom.xml	2010-07-06 03:49:45 UTC (rev 106439)
@@ -27,7 +27,7 @@
    <properties>
       <version.weld>1.0.1-Final</version.weld>
       <version.jboss.interceptor>1.0.0-CR11</version.jboss.interceptor>
-      <version.jboss.vfs>3.0.0.CR1</version.jboss.vfs>
+      <version.jboss.vfs>3.0.0.CR5</version.jboss.vfs>
       <version.jboss.man>2.1.1.SP1</version.jboss.man>
       <version.jboss.mdr>2.2.0.Alpha2</version.jboss.mdr>
       <version.jboss.microcontainer>2.2.0.Alpha9</version.jboss.microcontainer>
@@ -50,6 +50,7 @@
       <version.jsp.api>2.1</version.jsp.api>
       <version.org.jboss.test>1.1.1.GA</version.org.jboss.test>
       <version.junit>4.4</version.junit>
+      <version.shrinkwrap>1.0.0-alpha-9</version.shrinkwrap>
       <version.validation>1.0.CR3</version.validation>
       <version.jbossts>4.6.1.GA</version.jbossts>
       <version.faces>2.0.0-RC</version.faces>
@@ -548,6 +549,18 @@
             <scope>test</scope>
          </dependency>
          <dependency>
+            <groupId>org.jboss.shrinkwrap</groupId>
+            <artifactId>shrinkwrap-impl-base</artifactId>
+            <version>${version.shrinkwrap}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
+            <groupId>org.jboss.shrinkwrap</groupId>
+            <artifactId>shrinkwrap-extension-vfs3</artifactId>
+            <version>${version.shrinkwrap}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
             <groupId>org.jboss.weld</groupId>
             <artifactId>weld-core-bom</artifactId>
             <version>${version.weld}</version>



More information about the jboss-cvs-commits mailing list