[jboss-cvs] JBossAS SVN: r101780 - in projects/ejb3/tags: jboss-ejb3-common-1.0.3 and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 3 11:28:14 EST 2010


Author: wolfc
Date: 2010-03-03 11:28:13 -0500 (Wed, 03 Mar 2010)
New Revision: 101780

Added:
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/pom.xml
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceBean.java
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceLocal.java
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java
Removed:
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/pom.xml
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java
   projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java
Log:
[maven-release-plugin]  copy for tag jboss-ejb3-common-1.0.3

Copied: projects/ejb3/tags/jboss-ejb3-common-1.0.3 (from rev 101651, projects/ejb3/trunk/common)

Deleted: projects/ejb3/tags/jboss-ejb3-common-1.0.3/pom.xml
===================================================================
--- projects/ejb3/trunk/common/pom.xml	2010-03-01 08:29:14 UTC (rev 101651)
+++ projects/ejb3/tags/jboss-ejb3-common-1.0.3/pom.xml	2010-03-03 16:28:13 UTC (rev 101780)
@@ -1,112 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-  <!-- Define Parent -->
-  <parent>
-    <artifactId>jboss-ejb3-build</artifactId>
-    <groupId>org.jboss.ejb3</groupId>
-    <version>1.0.0</version>
-    <relativePath>../build/pom.xml</relativePath>
-  </parent>
-
-  <!-- Maven POM Model Version -->
-  <modelVersion>4.0.0</modelVersion>
-
-  <!-- Artifact Information -->
-  <groupId>org.jboss.ejb3</groupId>
-  <artifactId>jboss-ejb3-common</artifactId>
-  <version>1.0.3-SNAPSHOT</version>
-  <name>JBoss EJB 3.0 Common Utilities</name>
-  <description>
-    JBoss EJB 3.0 Utilities Common to all Components
-  </description>
-  <url>http://www.jboss.org/jbossejb3/</url>
-  
-  <!-- Build Configuration -->
-  <build>
-
-    <plugins>
-
-      <!-- Assembly Plugin (Common Client) -->
-      <plugin>
-        <artifactId>maven-assembly-plugin</artifactId>
-        <version>2.2-beta-1</version>
-        <executions>
-          <execution>
-            <id>make-assembly</id>
-            <phase>package</phase>
-            <goals>
-              <goal>attached</goal>
-            </goals>
-          </execution>
-        </executions>
-        <configuration>
-          <descriptors>
-            <descriptor>jboss-ejb3-common-client.xml</descriptor>
-          </descriptors>
-          <attach>true</attach>
-        </configuration>
-        <inherited>false</inherited>
-      </plugin>
-
-    </plugins>
-
-  </build>
-
-  <!-- Dependencies -->
-
-  <!-- 
-    
-    Version information is centralized in 
-    the Parent Build POM
-    
-  -->
-
-  <dependencies>
-
-    <!-- JUnit -->
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-    </dependency>
-    
-    <!-- org.jboss.aop:jboss-aop -->
-    <dependency>
-      <groupId>org.jboss.aop</groupId>
-      <artifactId>jboss-aop</artifactId>
-    </dependency>
-
-    <!-- Logging -->
-    <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging-spi</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging-log4j</artifactId>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.microcontainer</groupId>
-      <artifactId>jboss-kernel</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.metadata</groupId>
-      <artifactId>jboss-metadata</artifactId>
-    </dependency>
- 
-    <dependency>
-      <groupId>org.jboss.security</groupId>
-      <artifactId>jboss-security-spi</artifactId>
-      <version>2.0.2.SP1</version>
-    </dependency>
-
-    <dependency>
-      <groupId>org.jboss.deployers</groupId>
-      <artifactId>jboss-deployers-spi</artifactId>
-    </dependency>
-
-  </dependencies>
-</project>

Copied: projects/ejb3/tags/jboss-ejb3-common-1.0.3/pom.xml (from rev 101779, projects/ejb3/trunk/common/pom.xml)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-common-1.0.3/pom.xml	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-common-1.0.3/pom.xml	2010-03-03 16:28:13 UTC (rev 101780)
@@ -0,0 +1,118 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <!-- Define Parent -->
+  <parent>
+    <artifactId>jboss-ejb3-build</artifactId>
+    <groupId>org.jboss.ejb3</groupId>
+    <version>1.0.0</version>
+    <relativePath>../build/pom.xml</relativePath>
+  </parent>
+
+  <!-- Maven POM Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Artifact Information -->
+  <groupId>org.jboss.ejb3</groupId>
+  <artifactId>jboss-ejb3-common</artifactId>
+  <version>1.0.3</version>
+  <name>JBoss EJB 3.0 Common Utilities</name>
+  <description>
+    JBoss EJB 3.0 Utilities Common to all Components
+  </description>
+  <url>http://www.jboss.org/jbossejb3/</url>
+  
+  <!-- Build Configuration -->
+  <build>
+
+    <plugins>
+
+      <!-- Assembly Plugin (Common Client) -->
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <version>2.2-beta-1</version>
+        <executions>
+          <execution>
+            <id>make-assembly</id>
+            <phase>package</phase>
+            <goals>
+              <goal>attached</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <descriptors>
+            <descriptor>jboss-ejb3-common-client.xml</descriptor>
+          </descriptors>
+          <attach>true</attach>
+        </configuration>
+        <inherited>false</inherited>
+      </plugin>
+
+    </plugins>
+
+  </build>
+
+  <!-- Dependencies -->
+
+  <!-- 
+    
+    Version information is centralized in 
+    the Parent Build POM
+    
+  -->
+
+  <dependencies>
+
+    <!-- JUnit -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    
+    <!-- org.jboss.aop:jboss-aop -->
+    <dependency>
+      <groupId>org.jboss.aop</groupId>
+      <artifactId>jboss-aop</artifactId>
+    </dependency>
+
+    <!-- Logging -->
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.metadata</groupId>
+      <artifactId>jboss-metadata</artifactId>
+    </dependency>
+ 
+    <dependency>
+      <groupId>org.jboss.security</groupId>
+      <artifactId>jboss-security-spi</artifactId>
+      <version>2.0.2.SP1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-spi</artifactId>
+    </dependency>
+
+  </dependencies>
+
+  <scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/tags/jboss-ejb3-common-1.0.3</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/ejb3/tags/jboss-ejb3-common-1.0.3</developerConnection>
+    <url>http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/tags/jboss-ejb3-common-1.0.3</url>
+  </scm>
+</project>

Deleted: projects/ejb3/tags/jboss-ejb3-common-1.0.3/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	2010-03-01 08:29:14 UTC (rev 101651)
+++ projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java	2010-03-03 16:28:13 UTC (rev 101780)
@@ -1,394 +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.
- */
-package org.jboss.ejb3.common.resolvers.spi;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
-import org.jboss.metadata.ejb.jboss.JBossMetaData;
-import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
-import org.jboss.metadata.ejb.jboss.jndipolicy.spi.JbossSessionBeanJndiNameResolver;
-import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
-import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
-
-/**
- * EjbReferenceResolverBase
- * 
- * A base upon which EJB Reference Resolvers
- * may build upon.  Provides capabilities expected
- * to be required by providers.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public abstract class EjbReferenceResolverBase
-{
-   // --------------------------------------------------------------------------------||
-   // Class Members ------------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   private static final Logger log = Logger.getLogger(EjbReferenceResolverBase.class);
-
-   /**
-    * The attachment name of the metadata within the DU
-    */
-   public static final String DU_ATTACHMENT_NAME_METADATA = AttachmentNames.PROCESSED_METADATA;
-
-   // --------------------------------------------------------------------------------||
-   // Functional Methods -------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   /**
-    * Obtains the metadata attachment from the specified deployment unit, returning
-    * null if not present
-    * 
-    * @param du
-    * @return
-    */
-   protected JBossMetaData getMetaData(DeploymentUnit du)
-   {
-      return du.getAttachment(EjbReferenceResolverBase.DU_ATTACHMENT_NAME_METADATA, JBossMetaData.class);
-   }
-
-   /**
-    * Returns the session bean within the specified metadata to match the specified reference,
-    * otherwise returns null.
-    * 
-    * @param reference The EJB reference for which a match is being searched for
-    * @param metadata The metadata which will be used for finding any potential match
-    * @param cl The ClassLoader for the specified metadata
-    * @return
-    * 
-    * @throws NullPointerException If either of the passed <code>reference</code> or <code>metadata</code>
-    *   is null.
-    */
-   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 MDB are not targets)
-         if (!bean.isSession())
-         {
-            continue;
-         }
-
-         // Cast our Session Bean
-         JBossSessionBeanMetaData smd = (JBossSessionBeanMetaData) bean;
-
-         // See if this is a match
-         if (this.isMatch(reference, smd, cl))
-         {
-            // Add to the matches found
-            matches.add(smd);
-            log.debug("Found match in EJB " + smd.getEjbName() + " for " + reference);
-            continue;
-         }
-      }
-
-      // Ensure we've only got one match
-      if (matches.size() > 1)
-      {
-         // If more than one match was found while EJB name was specified, there's a problem in resolution
-         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, cl)
-               + ", but EJB Name was explicitly-specified.";
-
-         // Report error
-         throw new NonDeterministicInterfaceException("Specified reference " + reference
-               + " was matched by more than one EJB: " + matches
-               + ".  Specify beanName explciitly or ensure beanInterface is unique.");
-      }
-
-      // Return the JNDI name of the matching metadata if present, otherwise null
-      return matches.size() > 0 ? this.getJndiName(reference, matches.iterator().next(), cl) : null;
-
-   }
-
-   /**
-    * Determines whether the specified session bean is a match for the specified
-    * reference
-    * 
-    * @param reference
-    * @param md
-    * @param cl The ClassLoader for the specified metadata
-    * @return
-    */
-   protected boolean isMatch(EjbReference reference, JBossSessionBeanMetaData md, ClassLoader cl)
-   {
-      // Initialize
-      List<String> interfaces = new ArrayList<String>();
-
-      // Add all eligible bean interfaces
-      interfaces.addAll(this.getAllParentInterfaces(this.getEligibleBeanInterfaces(md), cl));
-
-      // Get the requested bean interface 
-      String requestedInterface = reference.getBeanInterface();
-      assert requestedInterface != null && requestedInterface.trim().length() > 0 : "beanInterface must be specified";
-
-      // 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();
-
-         // If the EJB name is explicitly-provided
-         if (ejbName != null && ejbName.trim().length() > 0)
-         {
-            // Ensure the EJB name matches this EJB
-            if (!ejbName.equals(md.getEjbName()))
-            {
-               return false;
-            }
-         }
-
-         // We've got a match
-         return true;
-      }
-
-      // No preconditions met, return false
-      return false;
-   }
-
-   /**
-    * 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, ClassLoader cl)
-   {
-      // 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;
-   }
-
-   /**
-    * Returns the bean interface described by the specified
-    * reference, validating its presence along the way
-    * 
-    * @param reference
-    * @param cl
-    * @return
-    */
-   private String getBeanInterfaceName(EjbReference reference, ClassLoader cl)
-   {
-      // Get the bean interface
-      String interfaceName = reference.getBeanInterface();
-      assert interfaceName != null && interfaceName.trim().length() > 0 : "beanInterface must be specified";
-
-      // Return
-      return interfaceName;
-
-   }
-
-}

Copied: projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java (from rev 101777, projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/main/java/org/jboss/ejb3/common/resolvers/spi/EjbReferenceResolverBase.java	2010-03-03 16:28:13 UTC (rev 101780)
@@ -0,0 +1,394 @@
+/*
+ * 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.common.resolvers.spi;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.jboss.jndipolicy.spi.JbossSessionBeanJndiNameResolver;
+import org.jboss.metadata.ejb.spec.BusinessLocalsMetaData;
+import org.jboss.metadata.ejb.spec.BusinessRemotesMetaData;
+
+/**
+ * EjbReferenceResolverBase
+ * 
+ * A base upon which EJB Reference Resolvers
+ * may build upon.  Provides capabilities expected
+ * to be required by providers.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class EjbReferenceResolverBase
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(EjbReferenceResolverBase.class);
+
+   /**
+    * The attachment name of the metadata within the DU
+    */
+   public static final String DU_ATTACHMENT_NAME_METADATA = AttachmentNames.PROCESSED_METADATA;
+
+   // --------------------------------------------------------------------------------||
+   // Functional Methods -------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the metadata attachment from the specified deployment unit, returning
+    * null if not present
+    * 
+    * @param du
+    * @return
+    */
+   protected JBossMetaData getMetaData(DeploymentUnit du)
+   {
+      return du.getAttachment(EjbReferenceResolverBase.DU_ATTACHMENT_NAME_METADATA, JBossMetaData.class);
+   }
+
+   /**
+    * Returns the session bean within the specified metadata to match the specified reference,
+    * otherwise returns null.
+    * 
+    * @param reference The EJB reference for which a match is being searched for
+    * @param metadata The metadata which will be used for finding any potential match
+    * @param cl The ClassLoader for the specified metadata
+    * @return
+    * 
+    * @throws NullPointerException If either of the passed <code>reference</code> or <code>metadata</code>
+    *   is null.
+    */
+   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 MDB are not targets)
+         if (!(bean instanceof JBossSessionBeanMetaData))
+         {
+            continue;
+         }
+
+         // Cast our Session Bean
+         JBossSessionBeanMetaData smd = (JBossSessionBeanMetaData) bean;
+
+         // See if this is a match
+         if (this.isMatch(reference, smd, cl))
+         {
+            // Add to the matches found
+            matches.add(smd);
+            log.debug("Found match in EJB " + smd.getEjbName() + " for " + reference);
+            continue;
+         }
+      }
+
+      // Ensure we've only got one match
+      if (matches.size() > 1)
+      {
+         // If more than one match was found while EJB name was specified, there's a problem in resolution
+         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, cl)
+               + ", but EJB Name was explicitly-specified.";
+
+         // Report error
+         throw new NonDeterministicInterfaceException("Specified reference " + reference
+               + " was matched by more than one EJB: " + matches
+               + ".  Specify beanName explciitly or ensure beanInterface is unique.");
+      }
+
+      // Return the JNDI name of the matching metadata if present, otherwise null
+      return matches.size() > 0 ? this.getJndiName(reference, matches.iterator().next(), cl) : null;
+
+   }
+
+   /**
+    * Determines whether the specified session bean is a match for the specified
+    * reference
+    * 
+    * @param reference
+    * @param md
+    * @param cl The ClassLoader for the specified metadata
+    * @return
+    */
+   protected boolean isMatch(EjbReference reference, JBossSessionBeanMetaData md, ClassLoader cl)
+   {
+      // Initialize
+      List<String> interfaces = new ArrayList<String>();
+
+      // Add all eligible bean interfaces
+      interfaces.addAll(this.getAllParentInterfaces(this.getEligibleBeanInterfaces(md), cl));
+
+      // Get the requested bean interface 
+      String requestedInterface = reference.getBeanInterface();
+      assert requestedInterface != null && requestedInterface.trim().length() > 0 : "beanInterface must be specified";
+
+      // 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();
+
+         // If the EJB name is explicitly-provided
+         if (ejbName != null && ejbName.trim().length() > 0)
+         {
+            // Ensure the EJB name matches this EJB
+            if (!ejbName.equals(md.getEjbName()))
+            {
+               return false;
+            }
+         }
+
+         // We've got a match
+         return true;
+      }
+
+      // No preconditions met, return false
+      return false;
+   }
+
+   /**
+    * 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, ClassLoader cl)
+   {
+      // 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;
+   }
+
+   /**
+    * Returns the bean interface described by the specified
+    * reference, validating its presence along the way
+    * 
+    * @param reference
+    * @param cl
+    * @return
+    */
+   private String getBeanInterfaceName(EjbReference reference, ClassLoader cl)
+   {
+      // Get the bean interface
+      String interfaceName = reference.getBeanInterface();
+      assert interfaceName != null && interfaceName.trim().length() > 0 : "beanInterface must be specified";
+
+      // Return
+      return interfaceName;
+
+   }
+
+}

Copied: projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceBean.java (from rev 101777, projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceBean.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceBean.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceBean.java	2010-03-03 16:28:13 UTC (rev 101780)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.common.resolvers;
+
+import org.jboss.ejb3.annotation.Service;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Service
+ at Local(ChildServiceLocal.class)
+public class ChildServiceBean
+{
+}

Copied: projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceLocal.java (from rev 101777, projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceLocal.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceLocal.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/ChildServiceLocal.java	2010-03-03 16:28:13 UTC (rev 101780)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.common.resolvers;
+
+import javax.ejb.Local;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+ at Local
+public interface ChildServiceLocal
+{
+}

Deleted: projects/ejb3/tags/jboss-ejb3-common-1.0.3/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/EjbReferenceResolverUnitTestCaseBase.java	2010-03-01 08:29:14 UTC (rev 101651)
+++ projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java	2010-03-03 16:28:13 UTC (rev 101780)
@@ -1,550 +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.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();
-      }
-      
-      @Override
-      public DeploymentUnit getTopLevel()
-      {
-         // if this is the top most level, then it won't have a parent,
-         // so return this deployment unit as the top most deployment unit
-         if (parent == null)
-         {
-            return this;
-         }
-         // this is not the top most level, so let's go to parent and 
-         // keep traversing till the top most level
-         return parent.getTopLevel();
-      }
-   }
-
-}

Copied: projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java (from rev 101777, projects/ejb3/trunk/common/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java)
===================================================================
--- projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java	                        (rev 0)
+++ projects/ejb3/tags/jboss-ejb3-common-1.0.3/src/test/java/org/jboss/ejb3/test/common/resolvers/unit/EjbReferenceResolverUnitTestCaseBase.java	2010-03-03 16:28:13 UTC (rev 101780)
@@ -0,0 +1,570 @@
+/*
+ * 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.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.ChildServiceBean;
+import org.jboss.ejb3.test.common.resolvers.ChildServiceLocal;
+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;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * 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", 3, 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());
+   }
+
+   @Test
+   public void testEJBTHREE2033()
+   {
+      EjbReference ref = new EjbReference(null, ChildServiceLocal.class.getName(), null);
+
+      String name = resolver.resolveEjb(parentDu, ref);
+      assertEquals("ChildServiceBean/local-org.jboss.ejb3.test.common.resolvers.ChildServiceLocal", name);
+   }
+
+   /**
+    * 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);
+      JBoss50MetaData serviceMd = creator.create(Arrays.<Class<?>>asList(ChildServiceBean.class));
+      Collection<JBossMetaData> mds = new ArrayList<JBossMetaData>();
+      mds.add(parentMd);
+      mds.add(child1Md);
+      mds.add(child2Md);
+      mds.add(nestedChildMd);
+      mds.add(serviceMd);
+
+      // 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);
+
+      // Service Bean DU
+      MockDeploymentUnit serviceDu = new MockDeploymentUnit("Child Service", parentDu);
+      serviceDu.addAttachment(AttachmentNames.PROCESSED_METADATA, serviceMd);
+
+      // 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);
+      parentDu.addChild(serviceDu);
+      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();
+      }
+      
+      @Override
+      public DeploymentUnit getTopLevel()
+      {
+         // if this is the top most level, then it won't have a parent,
+         // so return this deployment unit as the top most deployment unit
+         if (parent == null)
+         {
+            return this;
+         }
+         // this is not the top most level, so let's go to parent and 
+         // keep traversing till the top most level
+         return parent.getTopLevel();
+      }
+   }
+
+}




More information about the jboss-cvs-commits mailing list