[jboss-cvs] JBossAS SVN: r107592 - in projects/ejb3/trunk/core/src: test/java/org/jboss/ejb3/core/test and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 13 09:56:51 EDT 2010


Author: jaikiran
Date: 2010-08-13 09:56:51 -0400 (Fri, 13 Aug 2010)
New Revision: 107592

Added:
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/Calculator.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/Echo.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/EchoBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/MockDeploymentUnit.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/NotSoSimpleCalculator.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/SimpleCalculator.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/unit/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/unit/ScopedEjbReferenceResolverUnitTestCase.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/ScopedEJBReferenceResolver.java
Log:
EJBTHREE-2145 Fixed the StackOverFlowError in ScopedEjbReferenceResolver

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/ScopedEJBReferenceResolver.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/ScopedEJBReferenceResolver.java	2010-08-13 11:54:06 UTC (rev 107591)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/core/resolvers/ScopedEJBReferenceResolver.java	2010-08-13 13:56:51 UTC (rev 107592)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.core.resolvers;
 
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 
 import org.jboss.deployers.structure.spi.DeploymentUnit;
@@ -53,7 +55,9 @@
     * @param du
     * @param reference
     * @return
+    * @deprecated Use {@link #resolveWithinDeploymentUnit(DeploymentUnit, Collection, EjbReference)}
     */
+   @Deprecated
    protected String findWithin(DeploymentUnit du, DeploymentUnit excludeChild, EjbReference reference)
    {
       String jndiName = find(du, reference);
@@ -81,11 +85,86 @@
       return null;
    }
    
+   /**
+    * {@inheritDoc}
+    */
+   @Override
    public String resolveEjb(DeploymentUnit du, EjbReference reference) throws UnresolvableReferenceException
    {
-      String jndiName = findWithin(du, null, reference);
+      String jndiName = resolveWithinDeploymentUnit(du, new HashSet<DeploymentUnit>(), reference);
       if(jndiName == null)
          throw new UnresolvableReferenceException("Could not resolve reference " + reference + " in " + du);
       return jndiName;
    }
+   
+   /**
+    * This method first tries to resolve the passed {@link EjbReference} in the passed <code>du</code>.
+    * If the jndi name cannot be resolved in that {@link DeploymentUnit}, then it tries to <i>recursively</i> resolve the reference
+    * in the child {@link DeploymentUnit}s of that {@link DeploymentUnit}. If the jndi-name still can't be resolved, then
+    * this method recursively repeats the resolution steps with the parent of the passed {@link DeploymentUnit}
+    * 
+    * <p>
+    *   If the jndi-name cannot be resolved in any of the {@link DeploymentUnit}s in the hierarchy, then this method
+    *   returns null. Else it returns the resolved jndi-name.
+    * </p>
+    *  
+    * @param du The deployment unit within which the {@link EjbReference} will be resolved
+    * @param alreadyScannedDUs The {@link DeploymentUnit}s which have already been scanned for resolving the {@link EjbReference}
+    * @param reference The {@link EjbReference} which is being resolved
+    * @return Returns the jndi-name resolved out the {@link EjbReference}. If the jndi-name cannot be resolved, then this
+    *           method returns null.
+    */
+   protected String resolveWithinDeploymentUnit(DeploymentUnit du, Collection<DeploymentUnit> alreadyScannedDUs, EjbReference reference)
+   {
+      // first find in the passed DU
+      String jndiName = find(du, reference);
+      // found, just return it
+      if(jndiName != null)
+      {
+         return jndiName;
+      }
+      
+      if (alreadyScannedDUs == null)
+      {
+         alreadyScannedDUs = new HashSet<DeploymentUnit>();
+      }
+      
+      // jndi-name not resolved in the passed DU, so let's
+      // check try resolving in its children DUs
+      List<DeploymentUnit> children = du.getChildren();
+      if(children != null)
+      {
+         for(DeploymentUnit child : children)
+         {
+            // already searched that one
+            if(alreadyScannedDUs.contains(child))
+            {
+               continue;
+            }
+            // try resolving in this child DU
+            jndiName = resolveWithinDeploymentUnit(child, alreadyScannedDUs, reference);
+            // found in this child DU (or its nested child), return the jndi name
+            if(jndiName != null)
+            {
+               return jndiName;
+            }
+            // add the child DU to the already scanned DU collection
+            // so that we don't scan it again
+            alreadyScannedDUs.add(child);
+         }
+      }
+      
+      // add this DU to the already scanned DU collection
+      alreadyScannedDUs.add(du);
+      
+      // we haven't yet resolved the jndi-name, so let's
+      // try resolving in our parent (and any of its children)
+      DeploymentUnit parent = du.getParent();
+      if(parent != null)
+      {
+         return resolveWithinDeploymentUnit(parent, alreadyScannedDUs, reference);
+      }
+      // couldn't resolve in the entire DU hierarchy, return null
+      return null;
+   }
 }

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/Calculator.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/Calculator.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/Calculator.java	2010-08-13 13:56:51 UTC (rev 107592)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.ejbreference.resolver;
+
+/**
+ * Calculator
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface Calculator
+{
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/Echo.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/Echo.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/Echo.java	2010-08-13 13:56:51 UTC (rev 107592)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.ejbreference.resolver;
+
+/**
+ * Echo
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface Echo
+{
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/EchoBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/EchoBean.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/EchoBean.java	2010-08-13 13:56:51 UTC (rev 107592)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.ejbreference.resolver;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * EchoBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local (Echo.class)
+public class EchoBean
+{
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/MockDeploymentUnit.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/MockDeploymentUnit.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/MockDeploymentUnit.java	2010-08-13 13:56:51 UTC (rev 107592)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.ejbreference.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.helpers.AbstractDeploymentUnit;
+
+/**
+ * A Mock DeploymentUnit with support to:
+ * 
+ * - Add attachments
+ * - Manage the parent/child relationship
+ * - toString()
+ * - Get the ClassLoader
+ */
+public 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();
+   }
+}
\ No newline at end of file

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/NotSoSimpleCalculator.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/NotSoSimpleCalculator.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/NotSoSimpleCalculator.java	2010-08-13 13:56:51 UTC (rev 107592)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.ejbreference.resolver;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * NotSoSimpleCalculator
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local (Calculator.class)
+public class NotSoSimpleCalculator
+{
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/SimpleCalculator.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/SimpleCalculator.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/SimpleCalculator.java	2010-08-13 13:56:51 UTC (rev 107592)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.ejbreference.resolver;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+/**
+ * SimpleCalculator
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local (Calculator.class)
+public class SimpleCalculator
+{
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/unit/ScopedEjbReferenceResolverUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/unit/ScopedEjbReferenceResolverUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbreference/resolver/unit/ScopedEjbReferenceResolverUnitTestCase.java	2010-08-13 13:56:51 UTC (rev 107592)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.core.test.ejbreference.resolver.unit;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
+import org.jboss.ejb3.common.metadata.MetadataUtil;
+import org.jboss.ejb3.common.resolvers.spi.EjbReference;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
+import org.jboss.ejb3.core.resolvers.ScopedEJBReferenceResolver;
+import org.jboss.ejb3.core.test.ejbreference.resolver.Echo;
+import org.jboss.ejb3.core.test.ejbreference.resolver.EchoBean;
+import org.jboss.ejb3.core.test.ejbreference.resolver.MockDeploymentUnit;
+import org.jboss.ejb3.core.test.ejbreference.resolver.NotSoSimpleCalculator;
+import org.jboss.ejb3.core.test.ejbreference.resolver.SimpleCalculator;
+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.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests that the {@link ScopedEJBReferenceResolver} functions as expected.
+ * 
+ * 
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ScopedEjbReferenceResolverUnitTestCase
+{
+
+   private EjbReferenceResolver scopedResolver;
+
+   @Before
+   public void before()
+   {
+      scopedResolver = new ScopedEJBReferenceResolver();
+   }
+
+   /**
+    * Tests that the {@link ScopedEJBReferenceResolver} returns the expected 
+    * jndi name when a Deployment unit consists more than 2 child deployment units.
+    * 
+    * This test is to make sure that the bug fix for https://jira.jboss.org/browse/EJBTHREE-2145 
+    * works.
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testParentDUWithMoreThanTwoChildDU() 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<?>> echoBeanDUClasses = new ArrayList<Class<?>>();
+      echoBeanDUClasses.add(EchoBean.class);
+
+      Collection<Class<?>> childOneDUClasses = new ArrayList<Class<?>>();
+      childOneDUClasses.add(SimpleCalculator.class);
+
+      Collection<Class<?>> childTwoDUClasses = new ArrayList<Class<?>>();
+      childTwoDUClasses.add(NotSoSimpleCalculator.class);
+
+      // Make the metadata
+      JBoss50MetaData echoBeanMetaData = creator.create(echoBeanDUClasses);
+      JBoss50MetaData childOneBeanMetaData = creator.create(childOneDUClasses);
+      JBoss50MetaData childTwoBeanMetaData = creator.create(childTwoDUClasses);
+
+      // Decorate all EJBs w/ JNDI Policy
+      MetadataUtil.decorateEjbsWithJndiPolicy(echoBeanMetaData, Thread.currentThread().getContextClassLoader());
+      MetadataUtil.decorateEjbsWithJndiPolicy(childOneBeanMetaData, Thread.currentThread().getContextClassLoader());
+      MetadataUtil.decorateEjbsWithJndiPolicy(childTwoBeanMetaData, Thread.currentThread().getContextClassLoader());
+
+      // create a parent DU
+      MockDeploymentUnit parentDU = new MockDeploymentUnit("Parent DU");
+      // Child1 DU
+      DeploymentUnit childOneDU = new MockDeploymentUnit("Child One DU", parentDU);
+      childOneDU.addAttachment(AttachmentNames.PROCESSED_METADATA, childOneBeanMetaData);
+
+      // Child2 DU
+      DeploymentUnit childTwoDU = new MockDeploymentUnit("Child One DU", parentDU);
+      childTwoDU.addAttachment(AttachmentNames.PROCESSED_METADATA, childTwoBeanMetaData);
+
+      // the DU with the echo bean
+      DeploymentUnit duWithEchoBean = new MockDeploymentUnit("DU With Echo bean", parentDU);
+      duWithEchoBean.addAttachment(AttachmentNames.PROCESSED_METADATA, echoBeanMetaData);
+
+      // Set children of parents for bi-directional support
+      parentDU.addChild(childOneDU);
+      parentDU.addChild(childTwoDU);
+      parentDU.addChild(duWithEchoBean);
+
+      // Create reference to the Echo bean
+      EjbReference echoEjbReference = new EjbReference(null, Echo.class.getName(), null);
+      // resolve it from the child1 DU
+      String jndiNameResolvedFromChildOneDU = this.scopedResolver.resolveEjb(childOneDU, echoEjbReference);
+
+      // Test
+      Assert.assertNotNull("Could not resolve jndi name for " + Echo.class.getName()
+            + " business interface from child1 DU", jndiNameResolvedFromChildOneDU);
+
+      // now resolve the jndi name for the same reference from the other DUs.
+      // Note that since there's only one Echo business interface and bean in the entire DU hierarchy
+      // we should always get back the same jndi name, irrespective of from which DU we start the resolution
+
+      // resolve from child2 DU
+      String jndiNameResolvedFromChildTwoDU = this.scopedResolver.resolveEjb(childTwoDU, echoEjbReference);
+      Assert.assertEquals("Unexpected jndi name for " + Echo.class.getName() + " business interface from child2 DU",
+            jndiNameResolvedFromChildOneDU, jndiNameResolvedFromChildTwoDU);
+
+      // resolve from parent DU
+      String jndiNameResolvedFromParentDU = this.scopedResolver.resolveEjb(parentDU, echoEjbReference);
+      Assert.assertEquals("Unexpected jndi name for " + Echo.class.getName() + " business interface from parent DU",
+            jndiNameResolvedFromChildOneDU, jndiNameResolvedFromParentDU);
+
+      // resolve from the DU which has the EchoBean
+      String jndiNameResolvedFromDUContainingEchoBean = this.scopedResolver
+            .resolveEjb(duWithEchoBean, echoEjbReference);
+      Assert.assertEquals("Unexpected jndi name for " + Echo.class.getName()
+            + " business interface from the DU containing the EchoBean", jndiNameResolvedFromChildOneDU,
+            jndiNameResolvedFromDUContainingEchoBean);
+
+   }
+}



More information about the jboss-cvs-commits mailing list