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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 25 14:49:04 EST 2008


Author: ALRubinger
Date: 2008-11-25 14:49:04 -0500 (Tue, 25 Nov 2008)
New Revision: 81568

Added:
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/ImplementsSessionSynchronizationBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/ImplementsSessionSynchronizationRemoteBusiness.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/unit/
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/unit/ImplementsSessionSynchronizationUnitTestCase.java
Log:
[EJBTHREE-995] Added tests, expose no problem

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/ImplementsSessionSynchronizationBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/ImplementsSessionSynchronizationBean.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/ImplementsSessionSynchronizationBean.java	2008-11-25 19:49:04 UTC (rev 81568)
@@ -0,0 +1,103 @@
+/*
+ * 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.core.test.ejbthree995;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBException;
+import javax.ejb.Remote;
+import javax.ejb.SessionSynchronization;
+import javax.ejb.Stateful;
+
+/**
+ * ImplementsSessionSynchronizationBean
+ * 
+ * A test SFSB that directly implements SessionSynchronization
+ * 
+ * EJBTHREE-995
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateful
+ at Remote(ImplementsSessionSynchronizationRemoteBusiness.class)
+public class ImplementsSessionSynchronizationBean
+      implements
+         ImplementsSessionSynchronizationRemoteBusiness,
+         SessionSynchronization
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /*
+    * Define some counters to be used by the test.  Ensure that
+    * we're only testing *one instance at a time* because these are 
+    * in class scope
+    */
+   public static int CALLS_AFTER_BEGIN = 0;
+
+   public static int CALLS_AFTER_COMPLETION = 0;
+
+   public static int CALLS_BEFORE_COMPLETION = 0;
+
+   // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * A simple invocation that implements no business logic
+    */
+   public void call()
+   {
+   }
+
+   public void afterBegin() throws EJBException, RemoteException
+   {
+      CALLS_AFTER_BEGIN++;
+   }
+
+   public void afterCompletion(boolean committed) throws EJBException, RemoteException
+   {
+      CALLS_AFTER_COMPLETION++;
+   }
+
+   public void beforeCompletion() throws EJBException, RemoteException
+   {
+      CALLS_BEFORE_COMPLETION++;
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Helper Methods -----------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Resets the SessionSynchronization counters
+    */
+   public static void resetCounters()
+   {
+      CALLS_AFTER_BEGIN = 0;
+      CALLS_AFTER_COMPLETION = 0;
+      CALLS_BEFORE_COMPLETION = 0;
+   }
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/ImplementsSessionSynchronizationRemoteBusiness.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/ImplementsSessionSynchronizationRemoteBusiness.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/ImplementsSessionSynchronizationRemoteBusiness.java	2008-11-25 19:49:04 UTC (rev 81568)
@@ -0,0 +1,43 @@
+/*
+ * 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.core.test.ejbthree995;
+
+/**
+ * ImplementsSessionSynchronizationRemoteBusiness
+ * 
+ * Remote Business interface for an EJB directly implementing
+ * SessionSynchronization
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface ImplementsSessionSynchronizationRemoteBusiness
+{
+   // --------------------------------------------------------------------------------||
+   // Contracts ----------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * A simple invocation that implements no business logic
+    */
+   void call();
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/unit/ImplementsSessionSynchronizationUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/unit/ImplementsSessionSynchronizationUnitTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/ejbthree995/unit/ImplementsSessionSynchronizationUnitTestCase.java	2008-11-25 19:49:04 UTC (rev 81568)
@@ -0,0 +1,166 @@
+/*
+ * 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.core.test.ejbthree995.unit;
+
+import javax.ejb.SessionSynchronization;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
+import org.jboss.ejb3.core.test.ejbthree995.ImplementsSessionSynchronizationBean;
+import org.jboss.ejb3.core.test.ejbthree995.ImplementsSessionSynchronizationRemoteBusiness;
+import org.jboss.ejb3.session.SessionContainer;
+import org.jboss.logging.Logger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ImplementsSessionSynchronizationUnitTestCase
+ * 
+ * Test Cases to validate EJBTHREE-995
+ * is resolved
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ImplementsSessionSynchronizationUnitTestCase extends AbstractEJB3TestCase
+{
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   private static final Logger log = Logger.getLogger(ImplementsSessionSynchronizationUnitTestCase.class);
+
+   private static SessionContainer container;
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Tests that an invocation to a SFSB implementing SessionSynchronization
+    * does not result in 2 calls to any of the SessionSynchronization callbacks
+    */
+   @Test
+   public void testSfsbImplementingSessionSynchronizationForDoubleCallbacks() throws Throwable
+   {
+      // Define JNDI Target for Lookup
+      String jndiName = ImplementsSessionSynchronizationBean.class.getSimpleName() + "/" + "remote";
+
+      // Get JNDI Context
+      Context context = new InitialContext();
+
+      // Obtain
+      ImplementsSessionSynchronizationRemoteBusiness sfsb = (ImplementsSessionSynchronizationRemoteBusiness) context
+            .lookup(jndiName);
+
+      // Check callbacks are reset
+      this.assertCallbacksReset();
+
+      // Invoke
+      sfsb.call();
+
+      // Check callbacks have been made exactly once
+      this.assertCallsExpected(1);
+
+      // Reset
+      ImplementsSessionSynchronizationBean.resetCounters();
+
+      // Check callbacks are reset
+      this.assertCallbacksReset();
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Helper Methods -----------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that all SessionSynchronization callbacks are reset to 0
+    */
+   protected void assertCallbacksReset()
+   {
+      int expectedCalls = 0;
+      this.assertCallsExpected(expectedCalls);
+   }
+
+   /**
+    * Ensures that all SessionSynchronization callbacks have been
+    * made the specified number of times
+    * 
+    * @param numCalls
+    */
+   protected void assertCallsExpected(int numCalls)
+   {
+      TestCase.assertEquals(numCalls, ImplementsSessionSynchronizationBean.CALLS_AFTER_BEGIN);
+      TestCase.assertEquals(numCalls, ImplementsSessionSynchronizationBean.CALLS_AFTER_COMPLETION);
+      TestCase.assertEquals(numCalls, ImplementsSessionSynchronizationBean.CALLS_BEFORE_COMPLETION);
+      log.info("All " + SessionSynchronization.class.getSimpleName() + " callbacks were obtained expected " + numCalls
+            + " times.");
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @BeforeClass
+   public static void beforeClass() throws Exception
+   {
+      AbstractEJB3TestCase.beforeClass();
+
+      // Deploy the test SLSB
+      container = deploySessionEjb(ImplementsSessionSynchronizationBean.class);
+   }
+
+   @AfterClass
+   public static void afterClass() throws Exception
+   {
+      // Undeploy the test SLSB
+      undeployEjb(container);
+
+      AbstractEJB3TestCase.afterClass();
+   }
+
+}




More information about the jboss-cvs-commits mailing list