[jboss-cvs] JBossAS SVN: r91009 - in projects/ejb3/trunk: testsuite and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 9 11:35:08 EDT 2009


Author: jaikiran
Date: 2009-07-09 11:35:08 -0400 (Thu, 09 Jul 2009)
New Revision: 91009

Added:
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/SimpleStateless.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/StatelessBean.java
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/unit/
   projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/unit/ResourceEnvRefTestCase.java
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/ejb-jar.xml
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/jboss.xml
   projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/queue-service.xml
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java
   projects/ejb3/trunk/testsuite/build-test.xml
Log:
EJBTHREE-1858 Fixed the NPE when EJBContext was being configured through resource-env-ref

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java	2009-07-09 15:23:25 UTC (rev 91008)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ResourceHandler.java	2009-07-09 15:35:08 UTC (rev 91009)
@@ -224,8 +224,15 @@
                         return new EJBContextPropertyInjector(property);
                      }
                   };
-                  InjectionUtil.createInjectors(container.getInjectors(), container.getClassloader(), factory, envRef.getInjectionTargets());
-                  continue;
+                  if (envRef.getInjectionTargets() != null)
+                  {
+                     InjectionUtil.createInjectors(container.getInjectors(), container.getClassloader(), factory, envRef.getInjectionTargets());
+                     continue;
+                  }
+                  else
+                  {
+                     mappedName = "java:comp/EJBContext";
+                  }
                }
                else if (resType.equals(UserTransaction.class))
                {
@@ -302,7 +309,7 @@
          {
             throw new RuntimeException("mapped-name is required for " + envRef.getResourceEnvRefName() + " of deployment " + container.getIdentifier());
          }
-         container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, envRef.getMappedName(), "<resource-ref>"));
+         container.getEncInjectors().put(encName, new LinkRefEncInjector(encName, mappedName, "<resource-ref>"));
          InjectionUtil.injectionTarget(encName, envRef, container, container.getEncInjections());
       }
    }

Modified: projects/ejb3/trunk/testsuite/build-test.xml
===================================================================
--- projects/ejb3/trunk/testsuite/build-test.xml	2009-07-09 15:23:25 UTC (rev 91008)
+++ projects/ejb3/trunk/testsuite/build-test.xml	2009-07-09 15:35:08 UTC (rev 91009)
@@ -4312,6 +4312,31 @@
           
     </target>
   
+    <target name="ejbthree1858"
+	    description="Builds the ear and jar file(s) needed for testing EJBTHREE-1858."
+	    >
+	    
+	    <mkdir dir="${build.lib}"/>
+	    <!--  First build the jar file containing the EJBs -->
+	    <jar jarfile="${build.lib}/ejbthree1858.jar">
+		    <fileset dir="${build.classes}">
+			    <include name="org/jboss/ejb3/test/ejbthree1858/*.class"/>
+		    </fileset>
+		    <fileset dir="${resources}/test/ejbthree1858">
+			    <include name="META-INF/ejb-jar.xml"/>
+			    <include name="META-INF/jboss.xml"/>
+		    </fileset>
+	    </jar>
+	    <!--  Now build the EAR and include the EJB jar and the queue-service.xml -->
+	    <jar jarfile="${build.lib}/ejbthree1858.ear">
+		    <fileset dir="${build.lib}">
+			    <include name="ejbthree1858.jar"/>
+		    </fileset>
+		    <fileset dir="${resources}/test/ejbthree1858">
+			    <include name="META-INF/queue-service.xml"/>
+		    </fileset>
+	    </jar>
+    </target>
 
    <target name="jars" depends="statefulproxyfactoryoverride, removedislocal, statelesscreation, defaultremotebindings, localfromremote, clusteredjms, entityoptimisticlocking, concurrentnaming, propertyreplacement, persistenceunits, appclient, tck5sec, invalidtxmdb, descriptortypo, libdeployment, homeinterface, arjuna, mdbtransactions, unauthenticatedprincipal, clusteredservice, invoker, classloader,
       concurrent,
@@ -4343,7 +4368,7 @@
       composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc,
       localcall, interceptors, interceptors2, interceptors3, iiop, clientinterceptor,
       statelesscreation, changexml, externalrefscoped, singleton, ejbthree1671, ejbthree1677, ejbthree1629, 
-   	  ejbthree1807, ejbthree1346, ejbthree1823"/>
+      ejbthree1807, ejbthree1346, ejbthree1823, ejbthree1858"/>
 
    <target name="test" depends="init" if="test"
       description="Execute all tests in the given test directory.">

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/SimpleStateless.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/SimpleStateless.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/SimpleStateless.java	2009-07-09 15:35:08 UTC (rev 91009)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.ejbthree1858;
+
+/**
+ * Stateless
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface SimpleStateless
+{
+
+   boolean isEJBContextAvailableThroughResourceEnvRef();
+
+   boolean isUserTransactionAvailableThroughResourceEnvRef();
+
+   boolean isOtherResourceAvailableThroughResourceEnvRef();
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/StatelessBean.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/StatelessBean.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/StatelessBean.java	2009-07-09 15:35:08 UTC (rev 91009)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.ejbthree1858;
+
+import javax.annotation.Resource;
+import javax.ejb.EJBContext;
+import javax.ejb.SessionContext;
+import javax.jms.Queue;
+import javax.transaction.UserTransaction;
+
+/**
+ * StatelessBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class StatelessBean implements SimpleStateless
+{
+
+   public static final String JNDI_NAME = "EJBTHREE-1858-bean";
+
+   @Resource
+   private SessionContext sessionContext;
+
+   public boolean isEJBContextAvailableThroughResourceEnvRef()
+   {
+      // resource-env-ref which setups up the EJBContext to be
+      // available (also) under java:comp/env/EJBContext
+      EJBContext ejbContext = (EJBContext) this.sessionContext.lookup("EJBContext");
+      // successful if found. An exception (eg: NameNotFound) will be
+      // thrown otherwise
+      return ejbContext != null;
+   }
+
+   public boolean isUserTransactionAvailableThroughResourceEnvRef()
+   {
+      // resource-env-ref which setups up the UserTransaction to be
+      // available (also) under java:comp/env/UserTransaction
+      UserTransaction userTransaction = (UserTransaction) this.sessionContext.lookup("UserTransaction");
+      // successful if found. An exception (eg: NameNotFound) will be
+      // thrown otherwise
+      return userTransaction != null;
+   }
+
+   public boolean isOtherResourceAvailableThroughResourceEnvRef()
+   {
+      // resource-env-ref which setups up the Queue to be
+      // available under java:comp/env/MyQueue
+      Queue queue = (Queue) this.sessionContext.lookup("MyQueue");
+      // successful if found. An exception (eg: NameNotFound) will be
+      // thrown otherwise
+      return queue != null;
+
+   }
+
+}

Added: projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/unit/ResourceEnvRefTestCase.java
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/unit/ResourceEnvRefTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/java/org/jboss/ejb3/test/ejbthree1858/unit/ResourceEnvRefTestCase.java	2009-07-09 15:35:08 UTC (rev 91009)
@@ -0,0 +1,83 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.ejbthree1858.unit;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.ejbthree1858.SimpleStateless;
+import org.jboss.ejb3.test.ejbthree1858.StatelessBean;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * ResourceEnvRefTestCase
+ *
+ * EJBTHREE-1858 exposes a bug where a NPE is thrown when a EJBContext is being
+ * configured through ejb-jar.xml as a resource-env-ref.
+ *
+ * This testcase tests the fix for that issue, by configuring EJBContext through
+ * a resource-env-ref and then looking up that through the bean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class ResourceEnvRefTestCase extends JBossTestCase
+{
+
+   /**
+    * Constructor
+    *
+    * @param name
+    */
+   public ResourceEnvRefTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Test that the resources configured through resource-env-ref are bound
+    * correctly
+    *
+    * @throws Exception
+    */
+   public void testResourceEnvRefWithoutInjectionTarget() throws Exception
+   {
+      SimpleStateless bean = (SimpleStateless) getInitialContext().lookup(StatelessBean.JNDI_NAME);
+      // check EJBContext through resource-env-ref was handled
+      assertTrue("resource-env-ref did not handle EJBContext", bean.isEJBContextAvailableThroughResourceEnvRef());
+      // check UserTransaction through resource-env-ref was handled
+      assertTrue("resource-env-ref did not handle UserTransaction", bean
+            .isUserTransactionAvailableThroughResourceEnvRef());
+      // check some other resource through resource-env-ref was handled
+      assertTrue("resource-env-ref did not setup the other resource in java:comp/env of the bean", bean
+            .isOtherResourceAvailableThroughResourceEnvRef());
+   }
+
+   /**
+    * Deploy the test artifact(s)
+    * @return
+    * @throws Exception
+    */
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ResourceEnvRefTestCase.class, "ejbthree1858.ear");
+   }
+}

Added: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/ejb-jar.xml
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/ejb-jar.xml	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/ejb-jar.xml	2009-07-09 15:35:08 UTC (rev 91009)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar
+        xmlns="http://java.sun.com/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                            http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
+        version="3.0">
+
+   <enterprise-beans>
+
+        <session>
+            <ejb-name>StatelessBean</ejb-name>
+            <business-remote>org.jboss.ejb3.test.ejbthree1858.SimpleStateless</business-remote>
+            <ejb-class>org.jboss.ejb3.test.ejbthree1858.StatelessBean</ejb-class>
+            <resource-env-ref>
+                <resource-env-ref-name>EJBContext</resource-env-ref-name>
+                <resource-env-ref-type>javax.ejb.EJBContext</resource-env-ref-type>
+            </resource-env-ref>
+
+            <resource-env-ref>
+                <resource-env-ref-name>UserTransaction</resource-env-ref-name>
+                <resource-env-ref-type>javax.transaction.UserTransaction</resource-env-ref-type>
+            </resource-env-ref>
+
+            <resource-env-ref>
+                <resource-env-ref-name>MyQueue</resource-env-ref-name>
+                <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
+                <mapped-name>queue/EJBTHREE-1858</mapped-name>
+            </resource-env-ref>
+
+
+        </session>
+
+
+   </enterprise-beans>
+</ejb-jar>
\ No newline at end of file

Added: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/jboss.xml
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/jboss.xml	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/jboss.xml	2009-07-09 15:35:08 UTC (rev 91009)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<jboss
+        xmlns="http://www.jboss.com/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee
+                            http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
+        version="3.0">
+      <enterprise-beans>
+
+         <session>
+            <ejb-name>StatelessBean</ejb-name>
+            <jndi-name>EJBTHREE-1858-bean</jndi-name>
+
+         </session>
+
+
+      </enterprise-beans>
+   </jboss>
\ No newline at end of file

Added: projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/queue-service.xml
===================================================================
--- projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/queue-service.xml	                        (rev 0)
+++ projects/ejb3/trunk/testsuite/src/test/resources/test/ejbthree1858/META-INF/queue-service.xml	2009-07-09 15:35:08 UTC (rev 91009)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+
+   <mbean code="org.jboss.jms.server.destination.QueueService"
+      name="jboss.messaging.destination:service=Queue,name=EJBTHREE-1858"
+      xmbean-dd="xmdesc/Queue-xmbean.xml">
+      <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+      <depends>jboss.messaging:service=PostOffice</depends>
+   </mbean>
+
+
+</server>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list