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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 2 03:16:55 EST 2009


Author: jaikiran
Date: 2009-02-02 03:16:55 -0500 (Mon, 02 Feb 2009)
New Revision: 83762

Added:
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyRemote.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyStatefulBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyStatelessBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/SimplePojo.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/unit/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/unit/IntraJvmRemoteInvocationPassByValueTestCase.java
Log:
EJBTHREE-1401 Tests for @Remote pass-by-value within local JVM

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyRemote.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyRemote.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyRemote.java	2009-02-02 08:16:55 UTC (rev 83762)
@@ -0,0 +1,55 @@
+/*
+ * 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.spec_3_2_1;
+
+/**
+ * MyStateless
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface MyRemote
+{
+   /**
+    * Change the <code>transientField</code> value of the passed SimplePojo
+    * and return back the changed SimplePojo
+    * 
+    * @param sp The {@link SimplePojo}
+    * @return
+    */
+   SimplePojo changeAndReturn(SimplePojo sp);
+
+   /**
+    * Just return back the passed SimplePojo without doing
+    * anything
+    * 
+    * @param sp The {@link SimplePojo}
+    * @return
+    */
+   SimplePojo doNothingAndReturn(SimplePojo sp);
+
+   /**
+    * Returns a new SimplePojo
+    * @return
+    */
+   SimplePojo getPojo();
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyStatefulBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyStatefulBean.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyStatefulBean.java	2009-02-02 08:16:55 UTC (rev 83762)
@@ -0,0 +1,76 @@
+/*
+ * 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.spec_3_2_1;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+/**
+ * MyStatefulBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateful
+ at Remote(MyRemote.class)
+public class MyStatefulBean implements MyRemote
+{
+
+   // No state maintained in this bean. Just a dummy SFSB for testing
+   
+   /**
+    * @see {@link MyRemote#changeAndReturn(SimplePojo)}
+    */
+   public SimplePojo changeAndReturn(SimplePojo sp)
+   {
+      if (sp == null)
+      {
+         return null;
+      }
+      // set the transient field to some random value.
+      // See the org.jboss.ejb3.test.spec_3_2_1.unit.IntraJvmRemoteInvocationPassByValueTestCase for 
+      // more details about how this "transientField" value is interpreted in the testcase
+      sp.setTransientField(432);
+
+      return sp;
+   }
+
+   /**
+    * @see {@link MyRemote#doNothingAndReturn(SimplePojo)}
+    */
+   public SimplePojo doNothingAndReturn(SimplePojo sp)
+   {
+      return sp;
+   }
+
+   /**
+    * @see {@link MyRemote#getPojo()}
+    */
+   public SimplePojo getPojo()
+   {
+      SimplePojo sp = new SimplePojo();
+      // remember, the default constructor of SimplePojo sets the 
+      // transient field value to non-default. 
+      // See the org.jboss.ejb3.test.spec_3_2_1.unit.IntraJvmRemoteInvocationPassByValueTestCase for 
+      // more details about how this "transientField" value is interpreted in the testcase
+      return sp;
+   }
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyStatelessBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyStatelessBean.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/MyStatelessBean.java	2009-02-02 08:16:55 UTC (rev 83762)
@@ -0,0 +1,81 @@
+/*
+ * 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.spec_3_2_1;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+
+/**
+ * MyStatelessBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Remote(MyRemote.class)
+ at RemoteBinding(jndiBinding = MyStatelessBean.JNDI_NAME)
+public class MyStatelessBean implements MyRemote
+{
+   /**
+    * JNDI name of the bean
+    */
+   public static final String JNDI_NAME = "EJB3_Spec_2_1 Test Bean";
+
+   /**
+    * @see {@link MyRemote#changeAndReturn(SimplePojo)}
+    */
+   public SimplePojo changeAndReturn(SimplePojo sp)
+   {
+      if (sp == null)
+      {
+         return null;
+      }
+      // set the transient field to some random value.
+      // See the org.jboss.ejb3.test.spec_3_2_1.unit.IntraJvmRemoteInvocationPassByValueTestCase for 
+      // more details about how this "transientField" value is interpreted in the testcase
+      sp.setTransientField(1234);
+      return sp;
+   }
+
+   /**
+    * @see {@link MyRemote#doNothingAndReturn(SimplePojo)}
+    */
+   public SimplePojo doNothingAndReturn(SimplePojo sp)
+   {
+      return sp;
+   }
+
+   /**
+    * @see {@link MyRemote#getPojo()}
+    */
+   public SimplePojo getPojo()
+   {
+      SimplePojo sp = new SimplePojo();
+      // remember, the default constructor of SimplePojo sets the 
+      // transient field value to non-default. 
+      // See the org.jboss.ejb3.test.spec_3_2_1.unit.IntraJvmRemoteInvocationPassByValueTestCase for 
+      // more details about how this "transientField" value is interpreted in the testcase
+      return sp;
+   }
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/SimplePojo.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/SimplePojo.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/SimplePojo.java	2009-02-02 08:16:55 UTC (rev 83762)
@@ -0,0 +1,83 @@
+/*
+ * 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.spec_3_2_1;
+
+import java.io.Serializable;
+
+import org.jboss.ejb3.test.spec_3_2_1.unit.IntraJvmRemoteInvocationPassByValueTestCase;
+
+/**
+ * SimplePojo
+ * 
+ * Used in the {@link IntraJvmRemoteInvocationPassByValueTestCase}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class SimplePojo implements Serializable
+{
+
+   public static final long UPDATED_VALUE = 123;
+
+   private transient long transientField;
+
+   /**
+    * Default constructor which sets the transient field value to some 
+    * non-default value.
+    * See the {@link IntraJvmRemoteInvocationPassByValueTestCase} for details
+    * about how the value of {@link #transientField} is interpreted in the test case
+    */
+   public SimplePojo()
+   {
+      this.transientField = UPDATED_VALUE;
+   }
+
+   /**
+    * Returns the value of {@link #transientField}
+    * @return
+    */
+   public long getTransientField()
+   {
+      return this.transientField;
+   }
+
+   /**
+    * Sets the value of {@link #transientField}. 
+    * @param val The value to be set
+    * @throws IllegalArgumentException If the <code>val</code> to be set 
+    *           is 0. We reserve 0 to test the serailization of this {@link SimplePojo}, so
+    *           we don't allow the value to be 0.
+    *           
+    * @see {@link IntraJvmRemoteInvocationPassByValueTestCase}           
+    * 
+    */
+   public void setTransientField(long val)
+   {
+      if (val == 0)
+      {
+         throw new IllegalArgumentException(
+               "Setting 0 to transient field is NOT allowed in this testcase (0 is considered for a special case in this testcase");
+      }
+      this.transientField = val;
+   }
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/unit/IntraJvmRemoteInvocationPassByValueTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/unit/IntraJvmRemoteInvocationPassByValueTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/spec_3_2_1/unit/IntraJvmRemoteInvocationPassByValueTestCase.java	2009-02-02 08:16:55 UTC (rev 83762)
@@ -0,0 +1,249 @@
+/*
+ * 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.spec_3_2_1.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.session.SessionContainer;
+import org.jboss.ejb3.test.spec_3_2_1.MyRemote;
+import org.jboss.ejb3.test.spec_3_2_1.MyStatefulBean;
+import org.jboss.ejb3.test.spec_3_2_1.MyStatelessBean;
+import org.jboss.ejb3.test.spec_3_2_1.SimplePojo;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * IntraJvmRemoteInvocationPassByValueTestCase
+ * 
+ * Tests for EJB 3.0 Core Specification 3.2.1:
+ * 
+ * "The arguments and results of the methods of 
+ * the remote business interface are passed by value."
+ * 
+ * EJBTHREE-1401
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class IntraJvmRemoteInvocationPassByValueTestCase extends AbstractEJB3TestCase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(IntraJvmRemoteInvocationPassByValueTestCase.class);
+
+   /**
+    * The session container for the beans that are deployed during the tests  
+    */
+   private SessionContainer sessionContainer;
+
+   /**
+    * This method takes care of any cleanup required after each test.
+    */
+   @After
+   public void cleanupAfterEachTest()
+   {
+      if (this.sessionContainer != null)
+      {
+         undeployEjb(sessionContainer);
+      }
+   }
+
+   /**
+    * Test that the params that are passed to the method of a remote SLS bean
+    * are passed by value.
+    *  
+    * @throws Throwable
+    */
+   @Test
+   public void testPassByValueForMethodParametersForSlsb() throws Throwable
+   {
+
+      this.sessionContainer = deploySessionEjb(MyStatelessBean.class);
+
+      // get metadata
+      JBossSessionBeanMetaData metadata = this.sessionContainer.getMetaData();
+
+      // Lookup the remote bean
+      Context ctx = new InitialContext();
+      MyRemote remote = (MyRemote) ctx.lookup(metadata.getJndiName());
+
+      testPassByValueForMethodParameters(remote);
+
+   }
+
+   /**
+    * Tests that the returned object from the remote SLS bean method is 
+    * passed by value.
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testPassByValueForReturnedObjectSlsb() throws Throwable
+   {
+      this.sessionContainer = deploySessionEjb(MyStatelessBean.class);
+
+      // get metadata
+      JBossSessionBeanMetaData metadata = this.sessionContainer.getMetaData();
+
+      // Lookup the remote bean
+      Context ctx = new InitialContext();
+      MyRemote remote = (MyRemote) ctx.lookup(metadata.getJndiName());
+
+      testPassByValueForReturnedObject(remote);
+
+   }
+
+   /**
+    * Test that the params that are passed to the method of a remote SFS bean
+    * are passed by value.
+    *  
+    * @throws Throwable
+    */
+   @Test
+   public void testPassByValueForMethodParametersForSfsb() throws Throwable
+   {
+
+      this.sessionContainer = deploySessionEjb(MyStatefulBean.class);
+
+      // get metadata
+      JBossSessionBeanMetaData metadata = this.sessionContainer.getMetaData();
+
+      // Lookup the remote bean
+      Context ctx = new InitialContext();
+      MyRemote remote = (MyRemote) ctx.lookup(metadata.getJndiName());
+
+      testPassByValueForMethodParameters(remote);
+
+   }
+
+   /**
+    * Tests that the returned object from the remote SFS bean method is 
+    * passed by value.
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testPassByValueForReturnedObjectSfsb() throws Throwable
+   {
+      this.sessionContainer = deploySessionEjb(MyStatefulBean.class);
+
+      // get metadata
+      JBossSessionBeanMetaData metadata = this.sessionContainer.getMetaData();
+
+      // Lookup the remote bean
+      Context ctx = new InitialContext();
+      MyRemote remote = (MyRemote) ctx.lookup(metadata.getJndiName());
+
+      testPassByValueForReturnedObject(remote);
+
+   }
+
+   /**
+    * Utility method for testing that the returned object from a remote bean
+    * method is passed by value
+    * 
+    * Important note on how this works:
+    *   1) This method invokes the {@link MyRemote#getPojo()} method on the bean
+    *   2) The {@link MyRemote#getPojo()} creates a new {@link SimplePojo} and 
+    *       sets the value of a "transient" field of type 'long' to non-zero
+    *   3) This new {@link SimplePojo} is then returned back to this method
+    *   4) This method then checks the transient field value in the pojo that was returned
+    *   5) Since transient fields are NOT serialized/deserialized, its expected that this
+    *       field will have a value 0 (= default 'long' value) and NOT the value which was
+    *       set during the construction of the pojo. The test succeeds if the transient field
+    *       value is 0 (which indicates that the pojo was serialized while being returned), else
+    *       it fails.
+    *      
+    * 
+    * @param remote
+    * @throws Throwable
+    */
+   private void testPassByValueForReturnedObject(MyRemote remote) throws Throwable
+   {
+      SimplePojo returnedPojo = remote.getPojo();
+      log.info("Returned object has value = " + returnedPojo.getTransientField());
+      assertTrue("The object returned from the remote bean is passed by reference",
+            returnedPojo.getTransientField() == 0);
+
+   }
+
+   /**
+    * Utility method for testing that the params passed to the remote bean
+    * method are passed by value
+    * 
+    * Important note on how this works:
+    *   1) Creates a {@link SimplePojo} and sets the value of the "transient" field of type 'long'
+    *       to some non-zero value
+    *   2) Then invokes the {@link MyRemote#changeAndReturn(SimplePojo)} and {@link MyRemote#doNothingAndReturn(SimplePojo)}
+    *       methods on the bean, passing it the pojo which was created earlier
+    *   3) The returned pojo is then checked with the local instance for object identity check (which is expected not to be equal)
+    *   4) The returned pojo is also checked for the transient field value.
+    *       Since transient fields are NOT serialized/deserialized, its expected that this
+    *       field will have a value 0 (= default 'long' value) and NOT the value which was
+    *       set in this testcase.
+    * 
+    * @param remote
+    * @throws Throwable
+    */
+   private void testPassByValueForMethodParameters(MyRemote remote) throws Throwable
+   {
+      SimplePojo localSimplePojo = new SimplePojo();
+
+      // set some initial value
+      int value = 3;
+      localSimplePojo.setTransientField(value);
+      // call the method on the bean
+      SimplePojo returnedPojo = remote.changeAndReturn(localSimplePojo);
+
+      // The passed and the returned objects should not be the same
+      assertFalse(
+            "The object passed to the method of the remote bean and the object returned from the bean are both the same",
+            localSimplePojo == returnedPojo);
+
+      // Any value changed in the method of the remote bean should not 
+      // affect the local object - Confirms pass by value
+      assertEquals("The object passed to a method of remote bean was modified(passed by reference)", localSimplePojo
+            .getTransientField(), value);
+
+      SimplePojo anotherPojo = new SimplePojo();
+      SimplePojo returnedObj = remote.doNothingAndReturn(anotherPojo);
+
+      // The passed and the returned objects should not be the same
+      assertFalse(
+            "The object passed to the method of the remote bean and the object returned from the bean are both the same",
+            anotherPojo == returnedObj);
+
+   }
+
+}




More information about the jboss-cvs-commits mailing list