[jboss-cvs] JBossAS SVN: r82128 - in projects/ejb3/trunk/common/src: main/java/org/jboss/ejb3/common/resolvers/spi and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 9 01:26:10 EST 2008


Author: ALRubinger
Date: 2008-12-09 01:26:10 -0500 (Tue, 09 Dec 2008)
New Revision: 82128

Added:
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1CommonBusiness.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2And3CommonBusiness.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child3Bean.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child3LocalBusiness.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/InterDuCommonBusiness.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/FirstMatchEjbReferenceResolverUnitTestCase.java
Removed:
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java
Modified:
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/FirstMatchEjbReferenceResolver.java
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalBusiness.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteBusiness.java
   projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2LocalBusiness.java
Log:
[EJBTHREE-1616] EJB Reference Resolver development and tests

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/FirstMatchEjbReferenceResolver.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/FirstMatchEjbReferenceResolver.java	2008-12-09 05:14:16 UTC (rev 82127)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/plugins/FirstMatchEjbReferenceResolver.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -37,6 +37,13 @@
  * found.  In cases where the reference may be non-deterministic 
  * this implementation will stop when the reference requirements
  * are satisfied
+ * 
+ * NonDeterministicInterfaceException is therefore avoided 
+ * when a common interface is used across DeploymentUnits
+ * in the same DU Hierarchy; very simply the first DU
+ * which is able to resolve the reference (without conflicting 
+ * with possible references to other EJBs 
+ * within that DU) will be used.
  *
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
@@ -55,18 +62,18 @@
    {
       // Initialize
       String jndiName = null;
-      
+
       // Resolve from the root deployment
       DeploymentUnit root = this.getRoot(du);
       jndiName = this.resolveEjbFromRoot(root, reference);
-      
+
       // Check that we could resolve
-      if(jndiName==null)
+      if (jndiName == null)
       {
          throw new UnresolvableReferenceException("Could not resolve reference " + reference + " for "
                + DeploymentUnit.class.getSimpleName() + " " + du);
       }
-      
+
       // Return
       return jndiName;
    }
@@ -76,18 +83,6 @@
    // --------------------------------------------------------------------------------||
 
    /**
-    * Obtains the root deployment unit 
-    * 
-    * @param du
-    * @return
-    */
-   protected DeploymentUnit getRoot(DeploymentUnit du)
-   {
-      // Recurse until we hit the root
-      return du.getParent() == null ? du : this.getRoot(du.getParent());
-   }
-
-   /**
     * Follows a preorder traversal scheme to resolve the specified reference from the
     * specified metadata (or its children).  Returns the resolved target JNDI name. 
     * 
@@ -107,7 +102,7 @@
       if (metadata != null)
       {
          // Look for a match within this metadata
-         jndiName = this.getMatch(reference, metadata);
+         jndiName = this.getMatch(reference, metadata, rootDu.getClassLoader());
       }
 
       // If we haven't found the JNDI name in this DU

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java	2008-12-09 05:14:16 UTC (rev 82127)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -23,8 +23,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.List;
 
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
@@ -82,22 +81,32 @@
     * 
     * @param reference
     * @param metadata
+    * @param cl The ClassLoader for the specified metadata
     * @return
     */
-   protected String getMatch(EjbReference reference, JBossMetaData metadata) throws NonDeterministicInterfaceException
+   protected String getMatch(EjbReference reference, JBossMetaData metadata, ClassLoader cl)
+         throws NonDeterministicInterfaceException
    {
-
       // Initialize
       log.debug("Resolving reference for " + reference + " in " + metadata);
       Collection<JBossSessionBeanMetaData> matches = new ArrayList<JBossSessionBeanMetaData>();
 
+      /*
+       * If mapped-name is defined, bypass all other resolution and use it 
+       */
+      String mappedName = reference.getMappedName();
+      if (mappedName != null && mappedName.trim().length() > 0)
+      {
+         return mappedName;
+      }
+
       // Get all Enterprise Beans contained in the metadata
       JBossEnterpriseBeansMetaData beans = metadata.getEnterpriseBeans();
 
       // Loop through all EJBs
       for (JBossEnterpriseBeanMetaData bean : beans)
       {
-         // We only can inject Session Beans (Entity and MD are not targets)
+         // We only can inject Session Beans (Entity and MDB are not targets)
          if (!bean.isSession())
          {
             continue;
@@ -107,7 +116,7 @@
          JBossSessionBeanMetaData smd = (JBossSessionBeanMetaData) bean;
 
          // See if this is a match
-         if (this.isMatch(reference, smd))
+         if (this.isMatch(reference, smd, cl))
          {
             // Add to the matches found
             matches.add(smd);
@@ -123,7 +132,7 @@
          String beanName = reference.getBeanName();
          assert beanName == null || beanName.trim().length() == 0 : "Error in resolution logic, more than one eligible EJB "
                + "was found to satisfy beanInterface "
-               + this.getBeanInterfaceName(reference)
+               + this.getBeanInterfaceName(reference, cl)
                + ", but EJB Name was explicitly-specified.";
 
          // Report error
@@ -133,7 +142,7 @@
       }
 
       // Return the JNDI name of the matching metadata if present, otherwise null
-      return matches.size() > 0 ? this.getJndiName(reference, matches.iterator().next()) : null;
+      return matches.size() > 0 ? this.getJndiName(reference, matches.iterator().next(), cl) : null;
 
    }
 
@@ -143,34 +152,16 @@
     * 
     * @param reference
     * @param md
+    * @param cl The ClassLoader for the specified metadata
     * @return
     */
-   protected boolean isMatch(EjbReference reference, JBossSessionBeanMetaData md)
+   protected boolean isMatch(EjbReference reference, JBossSessionBeanMetaData md, ClassLoader cl)
    {
       // Initialize
-      Set<String> interfaces = new HashSet<String>();
+      List<String> interfaces = new ArrayList<String>();
 
       // Add all eligible bean interfaces
-      BusinessLocalsMetaData businessLocals = md.getBusinessLocals();
-      BusinessRemotesMetaData businessRemotes = md.getBusinessRemotes();
-      String home = md.getHome();
-      String localHome = md.getLocalHome();
-      if (businessLocals != null)
-      {
-         interfaces.addAll(businessLocals);
-      }
-      if (businessRemotes != null)
-      {
-         interfaces.addAll(businessRemotes);
-      }
-      if (home != null && home.trim().length() > 0)
-      {
-         interfaces.add(home);
-      }
-      if (localHome != null && localHome.trim().length() > 0)
-      {
-         interfaces.add(localHome);
-      }
+      interfaces.addAll(this.getAllParentInterfaces(this.getEligibleBeanInterfaces(md), cl));
 
       // Get the requested bean interface 
       String requestedInterface = reference.getBeanInterface();
@@ -179,6 +170,24 @@
       // Does this EJB have the requested interface?
       if (interfaces.contains(requestedInterface))
       {
+         /*
+          * Check that the interface is unique to this EJB
+          */
+         boolean found = false;
+         for (String interfaze : interfaces)
+         {
+            boolean equal = interfaze.equals(requestedInterface);
+            if (equal && !found)
+            {
+               found = true;
+            }
+            else if (equal && found)
+            {
+               throw new NonDeterministicInterfaceException("beanInterface specified, " + interfaze
+                     + ", is not unique within EJB " + md.getEjbName());
+            }
+         }
+
          // Get the requested EJB name
          String ejbName = reference.getBeanName();
 
@@ -201,17 +210,163 @@
    }
 
    /**
+    * Returns a Collection containing the union of the interface names specified
+    * as well as all all parent interfaces
+    * 
+    * @param interfaceNames
+    * @param cl
+    * @return
+    */
+   private Collection<String> getAllParentInterfaces(Collection<String> interfaceNames, ClassLoader cl)
+   {
+      // Initialize
+      Collection<String> interfaces = new ArrayList<String>();
+
+      // Go through all interface names
+      for (String interfaceName : interfaceNames)
+      {
+         // Add this
+         interfaces.addAll(this.getAllParentInterfaces(interfaceName, cl));
+      }
+
+      // Return
+      return interfaces;
+   }
+
+   private Collection<String> getAllParentInterfaces(String interfaceName, ClassLoader cl)
+   {
+      // Initialize
+      Collection<String> interfaces = new ArrayList<String>();
+      interfaces.add(interfaceName);
+
+      // Load this interface, so we can get the parent interfaces
+      try
+      {
+         Class<?> interfaze = Class.forName(interfaceName, false, cl);
+         Class<?>[] parentInterfaces = interfaze.getInterfaces();
+         for (Class<?> parentInterface : parentInterfaces)
+         {
+            // Get the parent interface name
+            String parentInterfaceName = parentInterface.getName();
+
+            // Get the parents of the parent
+            Collection<String> grandParents = this.getAllParentInterfaces(parentInterfaceName, cl);
+            if (grandParents.size() > 0)
+            {
+               interfaces.addAll(grandParents);
+            }
+
+            // Add the parent interface name
+            if (!interfaces.contains(parentInterfaceName))
+            {
+               interfaces.add(parentInterfaceName);
+            }
+         }
+      }
+      catch (ClassNotFoundException cnfe)
+      {
+         throw new RuntimeException("Could not load class from specified ClassLoader " + cl, cnfe);
+      }
+
+      // Return
+      return interfaces;
+   }
+
+   /**
+    * Obtains all interfaces declared by the metadata
+    * that are eligible for "beanInterface" inclusion
+    * (local business, remote business, local home, home) 
+    * 
+    * @param smd
+    * @return
+    */
+   private Collection<String> getEligibleBeanInterfaces(JBossSessionBeanMetaData smd)
+   {
+      Collection<String> interfaces = new ArrayList<String>();
+
+      // Add all eligible bean interfaces
+      BusinessLocalsMetaData businessLocals = smd.getBusinessLocals();
+      BusinessRemotesMetaData businessRemotes = smd.getBusinessRemotes();
+      String home = smd.getHome();
+      String localHome = smd.getLocalHome();
+      if (businessLocals != null)
+      {
+         interfaces.addAll(businessLocals);
+      }
+      if (businessRemotes != null)
+      {
+         interfaces.addAll(businessRemotes);
+      }
+      if (home != null && home.trim().length() > 0)
+      {
+         interfaces.add(home);
+      }
+      if (localHome != null && localHome.trim().length() > 0)
+      {
+         interfaces.add(localHome);
+      }
+
+      // Return
+      return interfaces;
+   }
+
+   /**
     * Obtains the resolved JNDI target for the specified reference
     * within the specified metadata
     * 
     * @param reference
     * @param metadata
+    * @param cl
     * @return
     */
-   protected String getJndiName(EjbReference reference, JBossSessionBeanMetaData metadata)
+   protected String getJndiName(EjbReference reference, JBossSessionBeanMetaData metadata, ClassLoader cl)
    {
-      String interfaceName = this.getBeanInterfaceName(reference);
-      return JbossSessionBeanJndiNameResolver.resolveJndiName(metadata, interfaceName);
+      // If mapped-name is specified, just use it
+      String mappedName = reference.getMappedName();
+      if (mappedName != null && mappedName.trim().length() > 0)
+      {
+         log.debug("Bypassing resolution, using mappedName of " + reference);
+         return mappedName;
+      }
+
+      // Get the bean interface name
+      String interfaceName = this.getBeanInterfaceName(reference, cl);
+
+      // Get eligible interfaces
+      Collection<String> eligibleInterfaces = this.getEligibleBeanInterfaces(metadata);
+
+      // Ensure the bean interface name is directly declared in metadata
+      if (!eligibleInterfaces.contains(interfaceName))
+      {
+
+         /*
+          *  Not directly in metadata, so we've got to resolve this
+          */
+         log.debug("Found specified beanInterface that is not a direct beanInterface of EJB " + metadata.getEjbName()
+               + ": " + interfaceName);
+
+         // Loop through eligible interfaces
+         for (String eligibleInterface : eligibleInterfaces)
+         {
+            // Get the parents of the eligible interface
+            Collection<String> parents = this.getAllParentInterfaces(eligibleInterface, cl);
+            // If the specified interface name if a parent of this eligible interface
+            if (parents.contains(interfaceName))
+            {
+               // Set the interface name to the resolved
+               log.debug("Resolved specified beanInterface " + interfaceName + " to " + eligibleInterface + " for EJB "
+                     + metadata.getEjbName());
+               interfaceName = eligibleInterface;
+               break;
+            }
+         }
+
+      }
+
+      // Return 
+      String resolvedJndiName = JbossSessionBeanJndiNameResolver.resolveJndiName(metadata, interfaceName);
+      log.debug("Resolved JNDI Name for " + reference + " of EJB " + metadata.getEjbName() + ": " + resolvedJndiName);
+      return resolvedJndiName;
    }
 
    /**
@@ -219,9 +374,10 @@
     * reference, validating its presence along the way
     * 
     * @param reference
+    * @param cl
     * @return
     */
-   private String getBeanInterfaceName(EjbReference reference)
+   private String getBeanInterfaceName(EjbReference reference, ClassLoader cl)
    {
       // Get the bean interface
       String interfaceName = reference.getBeanInterface();
@@ -232,4 +388,16 @@
 
    }
 
+   /**
+    * Obtains the root deployment unit 
+    * 
+    * @param du
+    * @return
+    */
+   protected DeploymentUnit getRoot(DeploymentUnit du)
+   {
+      // Recurse until we hit the root
+      return du.getParent() == null ? du : this.getRoot(du.getParent());
+   }
+
 }

Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1CommonBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1CommonBusiness.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1CommonBusiness.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * CommonBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child1CommonBusiness
+{
+
+}
\ No newline at end of file

Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalBusiness.java	2008-12-09 05:14:16 UTC (rev 82127)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1LocalBusiness.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -27,7 +27,7 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public interface Child1LocalBusiness
+public interface Child1LocalBusiness extends Child1CommonBusiness, InterDuCommonBusiness
 {
 
 }
\ No newline at end of file

Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteBusiness.java	2008-12-09 05:14:16 UTC (rev 82127)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child1RemoteBusiness.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -27,7 +27,7 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public interface Child1RemoteBusiness
+public interface Child1RemoteBusiness extends Child1CommonBusiness
 {
 
 }
\ No newline at end of file

Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2And3CommonBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2And3CommonBusiness.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2And3CommonBusiness.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * CommonBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child2And3CommonBusiness extends InterDuCommonBusiness
+{
+
+}
\ No newline at end of file

Modified: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2LocalBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2LocalBusiness.java	2008-12-09 05:14:16 UTC (rev 82127)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child2LocalBusiness.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -27,7 +27,7 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public interface Child2LocalBusiness
+public interface Child2LocalBusiness extends Child2And3CommonBusiness
 {
 
 }
\ No newline at end of file

Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child3Bean.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child3Bean.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child3Bean.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -0,0 +1,38 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * Child3Bean
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(Child3LocalBusiness.class)
+public class Child3Bean
+{
+
+}

Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child3LocalBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child3LocalBusiness.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/Child3LocalBusiness.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -0,0 +1,33 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * Child3LocalBusiness
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface Child3LocalBusiness extends Child2And3CommonBusiness
+{
+
+}
\ No newline at end of file

Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/InterDuCommonBusiness.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/InterDuCommonBusiness.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/InterDuCommonBusiness.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -0,0 +1,36 @@
+/*
+ * 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.ejb3.test.common.resolvers;
+
+/**
+ * InterDuCommonBusiness
+ * 
+ * A common business interface which is used across 
+ * many DeploymentUnits
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface InterDuCommonBusiness
+{
+
+}
\ No newline at end of file

Deleted: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java	2008-12-09 05:14:16 UTC (rev 82127)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -1,433 +0,0 @@
-/*
- * 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.
- */
-/*
- * 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.ejb3.test.common.resolvers.unit;
-
-import java.lang.reflect.AnnotatedElement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
-import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
-import org.jboss.ejb3.common.metadata.MetadataUtil;
-import org.jboss.ejb3.common.resolvers.plugins.FirstMatchEjbReferenceResolver;
-import org.jboss.ejb3.common.resolvers.spi.EjbReference;
-import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
-import org.jboss.ejb3.test.common.resolvers.Child1Bean;
-import org.jboss.ejb3.test.common.resolvers.Child1LocalBusiness;
-import org.jboss.ejb3.test.common.resolvers.Child1LocalHome;
-import org.jboss.ejb3.test.common.resolvers.Child1RemoteBusiness;
-import org.jboss.ejb3.test.common.resolvers.Child1RemoteHome;
-import org.jboss.ejb3.test.common.resolvers.Child2Bean;
-import org.jboss.ejb3.test.common.resolvers.Child2LocalBusiness;
-import org.jboss.ejb3.test.common.resolvers.NestedChildBean;
-import org.jboss.ejb3.test.common.resolvers.NestedChildLocalBusiness;
-import org.jboss.ejb3.test.common.resolvers.ParentBean;
-import org.jboss.ejb3.test.common.resolvers.ParentLocalBusiness;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
-import org.jboss.metadata.annotation.finder.AnnotationFinder;
-import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
-import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
-import org.jboss.metadata.ejb.jboss.JBossMetaData;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * EjbReferenceResolverUnitTestCase
- * 
- * Test Cases to validate the pluggable EjbReferenceResolver
- * 
- * Uses DUs with the following structure:
- * 
- * Parent
- * |
- * |------ Child1
- * |         |
- * |         |------NestedChild
- * |
- * |------ Child2
- * 
- * ...where each DU has an EJB w/ Local Business interface.  
- * "Child1" has bean interfaces for 
- * local business, remote business, home, and local home.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public class EjbReferenceResolverUnitTestCase
-{
-   // --------------------------------------------------------------------------------||
-   // Class Members ------------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   private static final Logger log = Logger.getLogger(EjbReferenceResolverUnitTestCase.class);
-
-   private static MockDeploymentUnit parentDu;
-
-   private static MockDeploymentUnit child1Du;
-
-   private static MockDeploymentUnit child2Du;
-
-   private static MockDeploymentUnit nestedChildDu;
-
-   private static EjbReferenceResolver resolver;
-
-   // --------------------------------------------------------------------------------||
-   // Lifecycle Methods --------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   /**
-    * Ensures that the DeploymentUnit relationships are as expected for this
-    * test.  In place to validate that the test setup is correct
-    */
-   @Test
-   public void testDeploymentUnitRelationships() throws Throwable
-   {
-      // Parent should have 2 children
-      TestCase.assertEquals("Parent DU does not have expected number of children", 2, parentDu.getChildren().size());
-
-      // Children should have parent of parentDU
-      TestCase.assertEquals("Child1 DU should have parent of Parent DU", parentDu, child1Du.getParent());
-      TestCase.assertEquals("Child2 DU should have parent of Parent DU", parentDu, child2Du.getParent());
-
-      // Tests for no children
-      TestCase.assertTrue("Child2 DU should have no children", child2Du.getChildren() == null
-            || child2Du.getChildren().size() == 0);
-      TestCase.assertTrue("NestedChild DU should have no children", nestedChildDu.getChildren() == null
-            || nestedChildDu.getChildren().size() == 0);
-
-      // Parent should have one child (Nested Child)
-      TestCase.assertEquals("Child1 DU should have 1 child", 1, child1Du.getChildren().size());
-      TestCase.assertEquals("Child1 DU should have child of Nested Child", nestedChildDu, child1Du.getChildren()
-            .iterator().next());
-
-      // Nested Child should have parent of Child 1
-      TestCase.assertEquals("Nested Child DU should have parent of Child1 DU", child1Du, nestedChildDu.getParent());
-   }
-
-   /**
-    * Ensures that the parent can resolve itself and children by bean 
-    * interface alone (business and homes)
-    * 
-    * @throws Throwable
-    */
-   @Test
-   public void testParentCanResolveItselfAndChildrenByBeanInterface() throws Throwable
-   {
-      // Initialize
-      String parentBeanInterfaceName = ParentLocalBusiness.class.getName();
-      String child1LocalBusinessBeanInterfaceName = Child1LocalBusiness.class.getName();
-      String child1RemoteBusinessBeanInterfaceName = Child1RemoteBusiness.class.getName();
-      String child1LocalHomeBeanInterfaceName = Child1LocalHome.class.getName();
-      String child1RemoteHomeBeanInterfaceName = Child1RemoteHome.class.getName();
-      String child2BeanInterfaceName = Child2LocalBusiness.class.getName();
-      String nestedChildBeanInterfaceName = NestedChildLocalBusiness.class.getName();
-
-      // Create references
-      EjbReference parentReference = new EjbReference(null, parentBeanInterfaceName, null);
-      EjbReference child1LocalBusinessReference = new EjbReference(null, child1LocalBusinessBeanInterfaceName, null);
-      EjbReference child1RemoteBusinessReference = new EjbReference(null, child1RemoteBusinessBeanInterfaceName, null);
-      EjbReference child1LocalHomeReference = new EjbReference(null, child1LocalHomeBeanInterfaceName, null);
-      EjbReference child1RemoteHomeReference = new EjbReference(null, child1RemoteHomeBeanInterfaceName, null);
-      EjbReference child2Reference = new EjbReference(null, child2BeanInterfaceName, null);
-      EjbReference nestedChildReference = new EjbReference(null, nestedChildBeanInterfaceName, null);
-
-      // Resolve
-      DeploymentUnit fromDu = parentDu;
-      String jndiNameParentLocalBusiness = resolver.resolveEjb(fromDu, parentReference);
-      String jndiNameChild1LocalBusiness = resolver.resolveEjb(fromDu, child1LocalBusinessReference);
-      log.debug("Resolved " + child1LocalBusinessReference + " from " + fromDu + " to " + jndiNameChild1LocalBusiness);
-      String jndiNameChild1RemoteBusiness = resolver.resolveEjb(fromDu, child1RemoteBusinessReference);
-      log
-            .debug("Resolved " + child1RemoteBusinessReference + " from " + fromDu + " to "
-                  + jndiNameChild1RemoteBusiness);
-      String jndiNameChild1LocalHome = resolver.resolveEjb(fromDu, child1LocalHomeReference);
-      log.debug("Resolved " + child1LocalHomeReference + " from " + fromDu + " to " + jndiNameChild1LocalHome);
-      String jndiNameChild1RemoteHome = resolver.resolveEjb(fromDu, child1RemoteHomeReference);
-      log.debug("Resolved " + child1RemoteHomeReference + " from " + fromDu + " to " + jndiNameChild1RemoteHome);
-      String jndiNameChild2 = resolver.resolveEjb(fromDu, child2Reference);
-      log.debug("Resolved " + child2Reference + " from " + fromDu + " to " + jndiNameChild2);
-      String jndiNameNestedChild = resolver.resolveEjb(fromDu, nestedChildReference);
-      log.debug("Resolved " + nestedChildReference + " from " + fromDu + " to " + jndiNameNestedChild);
-
-      // Declare expected
-      String expectedParent = ParentBean.class.getSimpleName() + "/local-" + parentBeanInterfaceName;
-      String child1EjbName = Child1Bean.class.getSimpleName();
-      String expectedChild1LocalBusiness = child1EjbName + "/local-" + child1LocalBusinessBeanInterfaceName;
-      String expectedChild1RemoteBusiness = child1EjbName + "/remote-" + child1RemoteBusinessBeanInterfaceName;
-      String expectedChild1LocalHome = child1EjbName + "/localHome";
-      String expectedChild1RemoteHome = child1EjbName + "/home";
-      String expectedChild2 = Child2Bean.class.getSimpleName() + "/local-" + child2BeanInterfaceName;
-      String expectedNestedChild = NestedChildBean.class.getSimpleName() + "/local-" + nestedChildBeanInterfaceName;
-
-      // Test
-      TestCase.assertEquals(expectedParent, jndiNameParentLocalBusiness);
-      TestCase.assertEquals(expectedChild1LocalBusiness, jndiNameChild1LocalBusiness);
-      TestCase.assertEquals(expectedChild1RemoteBusiness, jndiNameChild1RemoteBusiness);
-      TestCase.assertEquals(expectedChild1LocalHome, jndiNameChild1LocalHome);
-      TestCase.assertEquals(expectedChild1RemoteHome, jndiNameChild1RemoteHome);
-      TestCase.assertEquals(expectedChild2, jndiNameChild2);
-      TestCase.assertEquals(expectedNestedChild, jndiNameNestedChild);
-   }
-
-   /**
-    * Ensures that a child can resolve a parent by bean interface
-    * 
-    * @throws Throwable
-    */
-   @Test
-   public void testChildCanResolveParentByBeanInterface() throws Throwable
-   {
-      /*
-       * In this case, "child1" is the parent of "nestedChild", so we refer to 
-       * it as "parent"
-       */
-
-      // Initialize
-      String parentLocalBusinessBeanInterfaceName = Child1LocalBusiness.class.getName();
-      String parentRemoteBusinessBeanInterfaceName = Child1RemoteBusiness.class.getName();
-      String parentLocalHomeBeanInterfaceName = Child1LocalHome.class.getName();
-      String parentRemoteHomeBeanInterfaceName = Child1RemoteHome.class.getName();
-
-      // Create references
-      EjbReference parentLocalBusinessReference = new EjbReference(null, parentLocalBusinessBeanInterfaceName, null);
-      EjbReference parentRemoteBusinessReference = new EjbReference(null, parentRemoteBusinessBeanInterfaceName, null);
-      EjbReference parentLocalHomeReference = new EjbReference(null, parentLocalHomeBeanInterfaceName, null);
-      EjbReference parentRemoteHomeReference = new EjbReference(null, parentRemoteHomeBeanInterfaceName, null);
-
-      // Resolve
-      DeploymentUnit fromDu = nestedChildDu;
-      String jndiNameParentLocalBusiness = resolver.resolveEjb(fromDu, parentLocalBusinessReference);
-      log.debug("Resolved " + parentLocalBusinessReference + " from " + fromDu + " to " + jndiNameParentLocalBusiness);
-      String jndiNameParentRemoteBusiness = resolver.resolveEjb(fromDu, parentRemoteBusinessReference);
-      log
-            .debug("Resolved " + parentRemoteBusinessReference + " from " + fromDu + " to "
-                  + jndiNameParentRemoteBusiness);
-      String jndiNameParentLocalHome = resolver.resolveEjb(fromDu, parentLocalHomeReference);
-      log.debug("Resolved " + parentLocalHomeReference + " from " + fromDu + " to " + jndiNameParentLocalHome);
-      String jndiNameParentRemoteHome = resolver.resolveEjb(fromDu, parentRemoteHomeReference);
-      log.debug("Resolved " + parentRemoteHomeReference + " from " + fromDu + " to " + jndiNameParentRemoteHome);
-
-      // Declare expected
-      String parentEjbName = Child1Bean.class.getSimpleName();
-      String expectedParentLocalBusiness = parentEjbName + "/local-" + parentLocalBusinessBeanInterfaceName;
-      String expectedParentRemoteBusiness = parentEjbName + "/remote-" + parentRemoteBusinessBeanInterfaceName;
-      String expectedParentLocalHome = parentEjbName + "/localHome";
-      String expectedParentRemoteHome = parentEjbName + "/home";
-
-      // Test
-      TestCase.assertEquals(expectedParentLocalBusiness, jndiNameParentLocalBusiness);
-      TestCase.assertEquals(expectedParentRemoteBusiness, jndiNameParentRemoteBusiness);
-      TestCase.assertEquals(expectedParentLocalHome, jndiNameParentLocalHome);
-      TestCase.assertEquals(expectedParentRemoteHome, jndiNameParentRemoteHome);
-   }
-
-   // --------------------------------------------------------------------------------||
-   // Lifecycle Methods --------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   @BeforeClass
-   public static void beforeClass() throws Exception
-   {
-
-      // Make an annotation finder
-      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
-      JBoss50Creator creator = new JBoss50Creator(finder);
-
-      // Configure to scan the test EJBs
-      Collection<Class<?>> parentClasses, child1Classes, child2Classes, nestedChildClasses;
-      parentClasses = new ArrayList<Class<?>>();
-      child1Classes = new ArrayList<Class<?>>();
-      child2Classes = new ArrayList<Class<?>>();
-      nestedChildClasses = new ArrayList<Class<?>>();
-      parentClasses.add(ParentBean.class);
-      child1Classes.add(Child1Bean.class);
-      child2Classes.add(Child2Bean.class);
-      nestedChildClasses.add(NestedChildBean.class);
-
-      // Make the metadata
-      JBoss50MetaData parentMd = creator.create(parentClasses);
-      JBoss50MetaData child1Md = creator.create(child1Classes);
-      JBoss50MetaData child2Md = creator.create(child2Classes);
-      JBoss50MetaData nestedChildMd = creator.create(nestedChildClasses);
-      Collection<JBossMetaData> mds = new ArrayList<JBossMetaData>();
-      mds.add(parentMd);
-      mds.add(child1Md);
-      mds.add(child2Md);
-      mds.add(nestedChildMd);
-
-      // Decorate all EJBs w/ JNDI Policy
-      for (JBossMetaData md : mds)
-      {
-         // Decorate
-         MetadataUtil.decorateEjbsWithJndiPolicy(md, Thread.currentThread().getContextClassLoader());
-      }
-
-      // Parent DU
-      parentDu = new MockDeploymentUnit("Parent");
-      parentDu.addAttachment(AttachmentNames.PROCESSED_METADATA, parentMd);
-
-      // Child1 DU
-      child1Du = new MockDeploymentUnit("Child 1", parentDu);
-      child1Du.addAttachment(AttachmentNames.PROCESSED_METADATA, child1Md);
-
-      // Child1 DU
-      child2Du = new MockDeploymentUnit("Child 2", parentDu);
-      child2Du.addAttachment(AttachmentNames.PROCESSED_METADATA, child2Md);
-
-      // Nested Child DU
-      nestedChildDu = new MockDeploymentUnit("Nested Child", child1Du);
-      nestedChildDu.addAttachment(AttachmentNames.PROCESSED_METADATA, nestedChildMd);
-
-      // Set children of parents for bi-directional support
-      parentDu.addChild(child1Du);
-      parentDu.addChild(child2Du);
-      child1Du.addChild(nestedChildDu);
-
-      // Set Resolver
-      resolver = new FirstMatchEjbReferenceResolver();
-
-   }
-
-   // --------------------------------------------------------------------------------||
-   // Inner Classes ------------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   /**
-    * A Mock DeploymentUnit with support to:
-    * 
-    * - Add attachements
-    * - Manage the parent/child relationship
-    * - toString()
-    */
-   private static class MockDeploymentUnit extends AbstractDeploymentUnit implements DeploymentUnit
-   {
-
-      // --------------------------------------------------------------------------------||
-      // Instance Members ---------------------------------------------------------------||
-      // --------------------------------------------------------------------------------||
-
-      private String name;
-
-      private DeploymentUnit parent;
-
-      private List<DeploymentUnit> children;
-
-      private Map<String, Object> attachments;
-
-      // --------------------------------------------------------------------------------||
-      // Constructors -------------------------------------------------------------------||
-      // --------------------------------------------------------------------------------||
-
-      public MockDeploymentUnit(String name)
-      {
-         this.name = name;
-         this.children = new ArrayList<DeploymentUnit>();
-         this.attachments = new HashMap<String, Object>();
-      }
-
-      public MockDeploymentUnit(String name, DeploymentUnit parent)
-      {
-         this(name);
-         this.parent = parent;
-      }
-
-      // --------------------------------------------------------------------------------||
-      // Functional Methods -------------------------------------------------------------||
-      // --------------------------------------------------------------------------------||
-
-      public void addChild(DeploymentUnit child)
-      {
-         this.children.add(child);
-      }
-
-      // --------------------------------------------------------------------------------||
-      // Overridden Implementations -----------------------------------------------------||
-      // --------------------------------------------------------------------------------||
-
-      @Override
-      public List<DeploymentUnit> getChildren()
-      {
-         return this.children;
-      }
-
-      @Override
-      public DeploymentUnit getParent()
-      {
-         return this.parent;
-      }
-
-      @Override
-      public Object addAttachment(String name, Object attachment)
-      {
-         return this.attachments.put(name, attachment);
-      }
-
-      @Override
-      public Object getAttachment(String name)
-      {
-         return this.attachments.get(name);
-      }
-
-      @Override
-      public Map<String, Object> getAttachments()
-      {
-         return Collections.unmodifiableMap(this.attachments);
-      }
-
-      @Override
-      public String toString()
-      {
-         return this.getClass().getName() + ": " + this.name;
-      }
-
-   }
-
-}

Copied: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java (from rev 82106, projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCase.java)
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -0,0 +1,536 @@
+/*
+ * 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.
+ */
+/*
+ * 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.ejb3.test.common.resolvers.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
+import org.jboss.ejb3.common.metadata.MetadataUtil;
+import org.jboss.ejb3.common.resolvers.plugins.FirstMatchEjbReferenceResolver;
+import org.jboss.ejb3.common.resolvers.spi.EjbReference;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
+import org.jboss.ejb3.common.resolvers.spi.NonDeterministicInterfaceException;
+import org.jboss.ejb3.test.common.resolvers.Child1Bean;
+import org.jboss.ejb3.test.common.resolvers.Child1CommonBusiness;
+import org.jboss.ejb3.test.common.resolvers.Child1LocalBusiness;
+import org.jboss.ejb3.test.common.resolvers.Child1LocalHome;
+import org.jboss.ejb3.test.common.resolvers.Child1RemoteBusiness;
+import org.jboss.ejb3.test.common.resolvers.Child1RemoteHome;
+import org.jboss.ejb3.test.common.resolvers.Child2And3CommonBusiness;
+import org.jboss.ejb3.test.common.resolvers.Child2Bean;
+import org.jboss.ejb3.test.common.resolvers.Child2LocalBusiness;
+import org.jboss.ejb3.test.common.resolvers.Child3Bean;
+import org.jboss.ejb3.test.common.resolvers.Child3LocalBusiness;
+import org.jboss.ejb3.test.common.resolvers.NestedChildBean;
+import org.jboss.ejb3.test.common.resolvers.NestedChildLocalBusiness;
+import org.jboss.ejb3.test.common.resolvers.ParentBean;
+import org.jboss.ejb3.test.common.resolvers.ParentLocalBusiness;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.annotation.creator.ejb.jboss.JBoss50Creator;
+import org.jboss.metadata.annotation.finder.AnnotationFinder;
+import org.jboss.metadata.annotation.finder.DefaultAnnotationFinder;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * EjbReferenceResolverUnitTestCaseBase
+ * 
+ * Test Cases to validate the pluggable EjbReferenceResolver
+ * 
+ * Uses DUs with the following structure:
+ * 
+ * Parent (Parent EJB)
+ * |
+ * |------ Child1 (Child EJB)
+ * |         |
+ * |         |------NestedChild (NestedChild EJB)
+ * |
+ * |------ Child2 (Child2 and Child3 EJBs)
+ * 
+ * ...where each DU has an EJB w/ Local Business interface.  
+ * "Child1" has bean interfaces for 
+ * local business, remote business, home, and local home.  "Child2" DU
+ * has "child2" and "Child3" EJBs.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class EjbReferenceResolverUnitTestCaseBase
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(EjbReferenceResolverUnitTestCaseBase.class);
+
+   protected static MockDeploymentUnit parentDu;
+
+   protected static MockDeploymentUnit child1Du;
+
+   protected static MockDeploymentUnit child2Du;
+
+   protected static MockDeploymentUnit nestedChildDu;
+
+   protected static EjbReferenceResolver resolver;
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that the DeploymentUnit relationships are as expected for this
+    * test.  In place to validate that the test setup is correct
+    */
+   @Test
+   public void testDeploymentUnitRelationships() throws Throwable
+   {
+      // Parent should have 2 children
+      TestCase.assertEquals("Parent DU does not have expected number of children", 2, parentDu.getChildren().size());
+
+      // Children should have parent of parentDU
+      TestCase.assertEquals("Child1 DU should have parent of Parent DU", parentDu, child1Du.getParent());
+      TestCase.assertEquals("Child2 DU should have parent of Parent DU", parentDu, child2Du.getParent());
+
+      // Tests for no children
+      TestCase.assertTrue("Child2 DU should have no children", child2Du.getChildren() == null
+            || child2Du.getChildren().size() == 0);
+      TestCase.assertTrue("NestedChild DU should have no children", nestedChildDu.getChildren() == null
+            || nestedChildDu.getChildren().size() == 0);
+
+      // Parent should have one child (Nested Child)
+      TestCase.assertEquals("Child1 DU should have 1 child", 1, child1Du.getChildren().size());
+      TestCase.assertEquals("Child1 DU should have child of Nested Child", nestedChildDu, child1Du.getChildren()
+            .iterator().next());
+
+      // Nested Child should have parent of Child 1
+      TestCase.assertEquals("Nested Child DU should have parent of Child1 DU", child1Du, nestedChildDu.getParent());
+   }
+
+   /**
+    * Ensures that the parent can resolve itself and children by bean 
+    * interface alone (business and homes)
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testParentCanResolveItselfAndChildrenByBeanInterface() throws Throwable
+   {
+      // Initialize
+      String parentBeanInterfaceName = ParentLocalBusiness.class.getName();
+      String child1LocalBusinessBeanInterfaceName = Child1LocalBusiness.class.getName();
+      String child1RemoteBusinessBeanInterfaceName = Child1RemoteBusiness.class.getName();
+      String child1LocalHomeBeanInterfaceName = Child1LocalHome.class.getName();
+      String child1RemoteHomeBeanInterfaceName = Child1RemoteHome.class.getName();
+      String child2BeanInterfaceName = Child2LocalBusiness.class.getName();
+      String child3BeanInterfaceName = Child3LocalBusiness.class.getName();
+      String nestedChildBeanInterfaceName = NestedChildLocalBusiness.class.getName();
+
+      // Create references
+      EjbReference parentReference = new EjbReference(null, parentBeanInterfaceName, null);
+      EjbReference child1LocalBusinessReference = new EjbReference(null, child1LocalBusinessBeanInterfaceName, null);
+      EjbReference child1RemoteBusinessReference = new EjbReference(null, child1RemoteBusinessBeanInterfaceName, null);
+      EjbReference child1LocalHomeReference = new EjbReference(null, child1LocalHomeBeanInterfaceName, null);
+      EjbReference child1RemoteHomeReference = new EjbReference(null, child1RemoteHomeBeanInterfaceName, null);
+      EjbReference child2Reference = new EjbReference(null, child2BeanInterfaceName, null);
+      EjbReference child3Reference = new EjbReference(null, child3BeanInterfaceName, null);
+      EjbReference nestedChildReference = new EjbReference(null, nestedChildBeanInterfaceName, null);
+
+      // Resolve
+      DeploymentUnit fromDu = parentDu;
+      String jndiNameParentLocalBusiness = resolver.resolveEjb(fromDu, parentReference);
+      String jndiNameChild1LocalBusiness = resolver.resolveEjb(fromDu, child1LocalBusinessReference);
+      log.debug("Resolved " + child1LocalBusinessReference + " from " + fromDu + " to " + jndiNameChild1LocalBusiness);
+      String jndiNameChild1RemoteBusiness = resolver.resolveEjb(fromDu, child1RemoteBusinessReference);
+      log
+            .debug("Resolved " + child1RemoteBusinessReference + " from " + fromDu + " to "
+                  + jndiNameChild1RemoteBusiness);
+      String jndiNameChild1LocalHome = resolver.resolveEjb(fromDu, child1LocalHomeReference);
+      log.debug("Resolved " + child1LocalHomeReference + " from " + fromDu + " to " + jndiNameChild1LocalHome);
+      String jndiNameChild1RemoteHome = resolver.resolveEjb(fromDu, child1RemoteHomeReference);
+      log.debug("Resolved " + child1RemoteHomeReference + " from " + fromDu + " to " + jndiNameChild1RemoteHome);
+      String jndiNameChild2 = resolver.resolveEjb(fromDu, child2Reference);
+      log.debug("Resolved " + child2Reference + " from " + fromDu + " to " + jndiNameChild2);
+      String jndiNameChild3 = resolver.resolveEjb(fromDu, child3Reference);
+      log.debug("Resolved " + child3Reference + " from " + fromDu + " to " + jndiNameChild3);
+      String jndiNameNestedChild = resolver.resolveEjb(fromDu, nestedChildReference);
+      log.debug("Resolved " + nestedChildReference + " from " + fromDu + " to " + jndiNameNestedChild);
+
+      // Declare expected
+      String expectedParent = ParentBean.class.getSimpleName() + "/local-" + parentBeanInterfaceName;
+      String child1EjbName = Child1Bean.class.getSimpleName();
+      String expectedChild1LocalBusiness = child1EjbName + "/local-" + child1LocalBusinessBeanInterfaceName;
+      String expectedChild1RemoteBusiness = child1EjbName + "/remote-" + child1RemoteBusinessBeanInterfaceName;
+      String expectedChild1LocalHome = child1EjbName + "/localHome";
+      String expectedChild1RemoteHome = child1EjbName + "/home";
+      String expectedChild2 = Child2Bean.class.getSimpleName() + "/local-" + child2BeanInterfaceName;
+      String expectedChild3 = Child3Bean.class.getSimpleName() + "/local-" + child3BeanInterfaceName;
+      String expectedNestedChild = NestedChildBean.class.getSimpleName() + "/local-" + nestedChildBeanInterfaceName;
+
+      // Test
+      TestCase.assertEquals(expectedParent, jndiNameParentLocalBusiness);
+      TestCase.assertEquals(expectedChild1LocalBusiness, jndiNameChild1LocalBusiness);
+      TestCase.assertEquals(expectedChild1RemoteBusiness, jndiNameChild1RemoteBusiness);
+      TestCase.assertEquals(expectedChild1LocalHome, jndiNameChild1LocalHome);
+      TestCase.assertEquals(expectedChild1RemoteHome, jndiNameChild1RemoteHome);
+      TestCase.assertEquals(expectedChild2, jndiNameChild2);
+      TestCase.assertEquals(expectedChild3, jndiNameChild3);
+      TestCase.assertEquals(expectedNestedChild, jndiNameNestedChild);
+   }
+
+   /**
+    * Ensures that a child can resolve a parent by bean interface
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testChildCanResolveParentByBeanInterface() throws Throwable
+   {
+      /*
+       * In this case, "child1" is the parent of "nestedChild", so we refer to 
+       * it as "parent"
+       */
+
+      // Initialize
+      String parentLocalBusinessBeanInterfaceName = Child1LocalBusiness.class.getName();
+      String parentRemoteBusinessBeanInterfaceName = Child1RemoteBusiness.class.getName();
+      String parentLocalHomeBeanInterfaceName = Child1LocalHome.class.getName();
+      String parentRemoteHomeBeanInterfaceName = Child1RemoteHome.class.getName();
+
+      // Create references
+      EjbReference parentLocalBusinessReference = new EjbReference(null, parentLocalBusinessBeanInterfaceName, null);
+      EjbReference parentRemoteBusinessReference = new EjbReference(null, parentRemoteBusinessBeanInterfaceName, null);
+      EjbReference parentLocalHomeReference = new EjbReference(null, parentLocalHomeBeanInterfaceName, null);
+      EjbReference parentRemoteHomeReference = new EjbReference(null, parentRemoteHomeBeanInterfaceName, null);
+
+      // Resolve
+      DeploymentUnit fromDu = nestedChildDu;
+      String jndiNameParentLocalBusiness = resolver.resolveEjb(fromDu, parentLocalBusinessReference);
+      log.debug("Resolved " + parentLocalBusinessReference + " from " + fromDu + " to " + jndiNameParentLocalBusiness);
+      String jndiNameParentRemoteBusiness = resolver.resolveEjb(fromDu, parentRemoteBusinessReference);
+      log
+            .debug("Resolved " + parentRemoteBusinessReference + " from " + fromDu + " to "
+                  + jndiNameParentRemoteBusiness);
+      String jndiNameParentLocalHome = resolver.resolveEjb(fromDu, parentLocalHomeReference);
+      log.debug("Resolved " + parentLocalHomeReference + " from " + fromDu + " to " + jndiNameParentLocalHome);
+      String jndiNameParentRemoteHome = resolver.resolveEjb(fromDu, parentRemoteHomeReference);
+      log.debug("Resolved " + parentRemoteHomeReference + " from " + fromDu + " to " + jndiNameParentRemoteHome);
+
+      // Declare expected
+      String parentEjbName = Child1Bean.class.getSimpleName();
+      String expectedParentLocalBusiness = parentEjbName + "/local-" + parentLocalBusinessBeanInterfaceName;
+      String expectedParentRemoteBusiness = parentEjbName + "/remote-" + parentRemoteBusinessBeanInterfaceName;
+      String expectedParentLocalHome = parentEjbName + "/localHome";
+      String expectedParentRemoteHome = parentEjbName + "/home";
+
+      // Test
+      TestCase.assertEquals(expectedParentLocalBusiness, jndiNameParentLocalBusiness);
+      TestCase.assertEquals(expectedParentRemoteBusiness, jndiNameParentRemoteBusiness);
+      TestCase.assertEquals(expectedParentLocalHome, jndiNameParentLocalHome);
+      TestCase.assertEquals(expectedParentRemoteHome, jndiNameParentRemoteHome);
+   }
+
+   /**
+    * Ensures that looking up by a non-unique beanInterface
+    * results in the expected exception 
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testExceptionOnNonDeterministicInterfaceReference() throws Throwable
+   {
+      // Initialize
+      boolean exceptionReceived = false;
+      String commonBeanInterfaceName = Child1CommonBusiness.class.getName();
+
+      // Create reference
+      EjbReference commonReference = new EjbReference(null, commonBeanInterfaceName, null);
+
+      // Resolve
+      DeploymentUnit fromDu = parentDu;
+      try
+      {
+         resolver.resolveEjb(fromDu, commonReference);
+      }
+      // Expected
+      catch (NonDeterministicInterfaceException ndie)
+      {
+         exceptionReceived = true;
+         log.info("Got expected exception: " + ndie);
+      }
+
+      // Test
+      TestCase.assertTrue("Expected exception was not received", exceptionReceived);
+
+   }
+
+   /**
+    * Ensures that a NonDeterministicInterfaceException may be avoiding by specifying 
+    * beanName in the reference
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testNonDeterministicExceptionAvoidedBySpecifyingBeanName() throws Throwable
+   {
+      // Initialize
+      String beanName = Child3Bean.class.getSimpleName();
+      String commonBeanInterfaceName = Child2And3CommonBusiness.class.getName();
+
+      // Create reference (to explicit bean)
+      EjbReference commonReference = new EjbReference(beanName, commonBeanInterfaceName, null);
+
+      // Resolve
+      DeploymentUnit fromDu = parentDu;
+      String jndiName = resolver.resolveEjb(fromDu, commonReference);
+
+      // Set expected
+      String expected = beanName + "/local-" + Child3LocalBusiness.class.getName();
+
+      // Test
+      TestCase.assertEquals(expected, jndiName);
+   }
+
+   /**
+    * Ensures that a reference honors mappedName above all else
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testMappedNameOverridesAllElse() throws Throwable
+   {
+      // Create a reference
+      String mappedName = "ExplicitMappedName";
+      String beanName = "IgnoredBeanName";
+      String beanInterface = "IgnoredBeanInterface";
+      EjbReference reference = new EjbReference(beanName, beanInterface, mappedName);
+
+      // Resolve
+      String resolved = resolver.resolveEjb(parentDu, reference);
+
+      // Test
+      TestCase.assertEquals("Use of mapped-name in EJB Reference should override all other properties", mappedName,
+            resolved);
+
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+
+      // Make an annotation finder
+      AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
+      JBoss50Creator creator = new JBoss50Creator(finder);
+
+      // Configure to scan the test EJBs
+      Collection<Class<?>> parentClasses, child1Classes, child2Classes, nestedChildClasses;
+      parentClasses = new ArrayList<Class<?>>();
+      child1Classes = new ArrayList<Class<?>>();
+      child2Classes = new ArrayList<Class<?>>();
+      nestedChildClasses = new ArrayList<Class<?>>();
+      parentClasses.add(ParentBean.class);
+      child1Classes.add(Child1Bean.class);
+      child2Classes.add(Child2Bean.class);
+      child2Classes.add(Child3Bean.class); // Child2 DU has both Child2 and Child3 EJBs
+      nestedChildClasses.add(NestedChildBean.class);
+
+      // Make the metadata
+      JBoss50MetaData parentMd = creator.create(parentClasses);
+      JBoss50MetaData child1Md = creator.create(child1Classes);
+      JBoss50MetaData child2Md = creator.create(child2Classes);
+      JBoss50MetaData nestedChildMd = creator.create(nestedChildClasses);
+      Collection<JBossMetaData> mds = new ArrayList<JBossMetaData>();
+      mds.add(parentMd);
+      mds.add(child1Md);
+      mds.add(child2Md);
+      mds.add(nestedChildMd);
+
+      // Decorate all EJBs w/ JNDI Policy
+      for (JBossMetaData md : mds)
+      {
+         // Decorate
+         MetadataUtil.decorateEjbsWithJndiPolicy(md, Thread.currentThread().getContextClassLoader());
+      }
+
+      // Parent DU
+      parentDu = new MockDeploymentUnit("Parent");
+      parentDu.addAttachment(AttachmentNames.PROCESSED_METADATA, parentMd);
+
+      // Child1 DU
+      child1Du = new MockDeploymentUnit("Child 1", parentDu);
+      child1Du.addAttachment(AttachmentNames.PROCESSED_METADATA, child1Md);
+
+      // Child1 DU
+      child2Du = new MockDeploymentUnit("Child 2", parentDu);
+      child2Du.addAttachment(AttachmentNames.PROCESSED_METADATA, child2Md);
+
+      // Nested Child DU
+      nestedChildDu = new MockDeploymentUnit("Nested Child", child1Du);
+      nestedChildDu.addAttachment(AttachmentNames.PROCESSED_METADATA, nestedChildMd);
+
+      // Set children of parents for bi-directional support
+      parentDu.addChild(child1Du);
+      parentDu.addChild(child2Du);
+      child1Du.addChild(nestedChildDu);
+
+      // Set Resolver
+      resolver = new FirstMatchEjbReferenceResolver();
+
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Inner Classes ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * A Mock DeploymentUnit with support to:
+    * 
+    * - Add attachments
+    * - Manage the parent/child relationship
+    * - toString()
+    * - Get the ClassLoader
+    */
+   private static class MockDeploymentUnit extends AbstractDeploymentUnit implements DeploymentUnit
+   {
+
+      // --------------------------------------------------------------------------------||
+      // Instance Members ---------------------------------------------------------------||
+      // --------------------------------------------------------------------------------||
+
+      private String name;
+
+      private DeploymentUnit parent;
+
+      private List<DeploymentUnit> children;
+
+      private Map<String, Object> attachments;
+
+      // --------------------------------------------------------------------------------||
+      // Constructors -------------------------------------------------------------------||
+      // --------------------------------------------------------------------------------||
+
+      public MockDeploymentUnit(String name)
+      {
+         this.name = name;
+         this.children = new ArrayList<DeploymentUnit>();
+         this.attachments = new HashMap<String, Object>();
+      }
+
+      public MockDeploymentUnit(String name, DeploymentUnit parent)
+      {
+         this(name);
+         this.parent = parent;
+      }
+
+      // --------------------------------------------------------------------------------||
+      // Functional Methods -------------------------------------------------------------||
+      // --------------------------------------------------------------------------------||
+
+      public void addChild(DeploymentUnit child)
+      {
+         this.children.add(child);
+      }
+
+      // --------------------------------------------------------------------------------||
+      // Overridden Implementations -----------------------------------------------------||
+      // --------------------------------------------------------------------------------||
+
+      @Override
+      public List<DeploymentUnit> getChildren()
+      {
+         return this.children;
+      }
+
+      @Override
+      public DeploymentUnit getParent()
+      {
+         return this.parent;
+      }
+
+      @Override
+      public Object addAttachment(String name, Object attachment)
+      {
+         return this.attachments.put(name, attachment);
+      }
+
+      @Override
+      public Object getAttachment(String name)
+      {
+         return this.attachments.get(name);
+      }
+
+      @Override
+      public Map<String, Object> getAttachments()
+      {
+         return Collections.unmodifiableMap(this.attachments);
+      }
+
+      @Override
+      public String toString()
+      {
+         return this.getClass().getName() + ": " + this.name;
+      }
+
+      @Override
+      public ClassLoader getClassLoader()
+      {
+         return Thread.currentThread().getContextClassLoader();
+      }
+   }
+
+}


Property changes on: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Added: projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/FirstMatchEjbReferenceResolverUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/FirstMatchEjbReferenceResolverUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/FirstMatchEjbReferenceResolverUnitTestCase.java	2008-12-09 06:26:10 UTC (rev 82128)
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+/*
+ * 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.ejb3.test.common.resolvers.unit;
+
+import junit.framework.TestCase;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.resolvers.plugins.FirstMatchEjbReferenceResolver;
+import org.jboss.ejb3.common.resolvers.spi.EjbReference;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
+import org.jboss.ejb3.test.common.resolvers.InterDuCommonBusiness;
+import org.jboss.logging.Logger;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * FirstMatchEjbReferenceResolverUnitTestCase
+ * 
+ * Test Cases to validate the EjbReferenceResolver 
+ * implementation:  
+ * FirstMatchEjbReferenceResolverUnitTestCase
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class FirstMatchEjbReferenceResolverUnitTestCase extends EjbReferenceResolverUnitTestCaseBase
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(FirstMatchEjbReferenceResolverUnitTestCase.class);
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Tests that a non-deterministic reference across deployment units may be resolved.
+    * This is due to the "first match" nature of this resolver, whereas other implementations
+    * may throw an exception if detected that a reference is not unique within a deployment scope
+    */
+   @Test
+   public void testCanResolveNondeterministicBeanInterfaceAcrossDeploymentUnits() throws Throwable
+   {
+      // Initialize
+      String commonBeanInterfaceName = InterDuCommonBusiness.class.getName();
+
+      // Create reference (to explicit bean)
+      EjbReference commonReference = new EjbReference(null, commonBeanInterfaceName, null);
+
+      // Resolve
+      DeploymentUnit fromDu = parentDu;
+      String jndiName = resolver.resolveEjb(fromDu, commonReference);
+
+      // Test
+      TestCase.assertNotNull("Shoudld have been able to resolve non-unique reference", jndiName);
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      // Do common init
+      EjbReferenceResolverUnitTestCaseBase.beforeClass();
+
+      // Set Resolver
+      resolver = new FirstMatchEjbReferenceResolver();
+      log.info("Using " + EjbReferenceResolver.class.getSimpleName() + ": " + resolver.getClass().getName());
+   }
+}




More information about the jboss-cvs-commits mailing list