[jboss-cvs] JBossAS SVN: r65300 - in branches/Branch_4_2/testsuite: src/main/org/jboss/test/tm/test and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 11 13:02:26 EDT 2007


Author: adrian at jboss.org
Date: 2007-09-11 13:02:26 -0400 (Tue, 11 Sep 2007)
New Revision: 65300

Added:
   branches/Branch_4_2/testsuite/src/resources/tm/test/
   branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/
   branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/ejb-jar.xml
   branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/jboss.xml
Modified:
   branches/Branch_4_2/testsuite/imports/sections/tm.xml
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/test/TransactionLocalUnitTestCase.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java
Log:
JBAS-4690 - Move the TransactionLocal unit test to the appserver

Modified: branches/Branch_4_2/testsuite/imports/sections/tm.xml
===================================================================
--- branches/Branch_4_2/testsuite/imports/sections/tm.xml	2007-09-11 15:50:44 UTC (rev 65299)
+++ branches/Branch_4_2/testsuite/imports/sections/tm.xml	2007-09-11 17:02:26 UTC (rev 65300)
@@ -66,5 +66,19 @@
             <include name="webbmtcleanuptest.war"/>
          </fileset>
       </jar>
+      
+      <jar destfile="${build.lib}/transaction-test.jar">
+         <fileset dir="${build.classes}">
+            <patternset refid="common.test.client.classes"/>
+            <include name="org/jboss/test/tm/**"/>
+            <include name="org/jboss/test/util/ejb/*"/>
+         </fileset>
+         <fileset dir="${build.resources}/tm/test">
+            <include name="**/*.*"/>
+         </fileset>
+         <zipfileset src="${junit.junit.lib}/junit.jar">
+            <patternset refid="ejbrunner.set"/>
+         </zipfileset>
+      </jar>
    </target>
 </project>

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/test/TransactionLocalUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/test/TransactionLocalUnitTestCase.java	2007-09-11 15:50:44 UTC (rev 65299)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/test/TransactionLocalUnitTestCase.java	2007-09-11 17:02:26 UTC (rev 65300)
@@ -24,14 +24,16 @@
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 
+import junit.framework.Test;
+
 import org.jboss.test.JBossTestCase;
+import org.jboss.test.util.ejb.EJBTestCase;
 import org.jboss.tm.TransactionLocal;
-import org.jboss.tm.TxManager;
+import org.jboss.tm.TransactionManagerLocator;
 
-public class TransactionLocalUnitTestCase extends JBossTestCase
+public class TransactionLocalUnitTestCase extends EJBTestCase
 {
-   //protected TransactionManager tm = TransactionManagerLocator.getInstance().locate();
-   protected TransactionManager tm = TxManager.getInstance();
+   protected TransactionManager tm = TransactionManagerLocator.getInstance().locate();
    
    public void testSimpleSetGet() throws Exception
    {
@@ -398,4 +400,9 @@
    {
       super(name);
    }
+
+   public static Test suite() throws Exception
+   {
+      return JBossTestCase.getDeploySetup(TransactionLocalUnitTestCase.class, "transaction-test.jar");
+   }
 }

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java	2007-09-11 15:50:44 UTC (rev 65299)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java	2007-09-11 17:02:26 UTC (rev 65300)
@@ -32,7 +32,12 @@
 import javax.naming.NamingEnumeration;
 import javax.transaction.Status;
 import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
 
+import org.jboss.logging.Logger;
+import org.jboss.tm.TransactionManagerLocator;
+
 /**
  * Implementation of the ejb test runner.
  *
@@ -44,6 +49,7 @@
  */
 public class EJBTestRunnerBean implements SessionBean
 {
+   private static final Logger log = Logger.getLogger(EJBTestRunnerBean.class);
    transient private SessionContext ctx;
    private String runnerJndiName;
 
@@ -125,6 +131,11 @@
       }
    }
 
+   private static boolean wantUserTransaction(Properties props)
+   {
+      return props.get("NO_USER_TRANSACTION") == null;
+   }
+   
    /**
     * Runs the setUpEJB method on the specified test case
     * @param testCase the actual test case that will be run
@@ -134,9 +145,11 @@
    private void setUpEJB(EJBTestCase testCase, Properties props)
       throws RemoteTestException
    {
+      boolean wantUserTransaction = wantUserTransaction(props);
       try
       {
-         ctx.getUserTransaction().begin();
+         if (wantUserTransaction)
+            ctx.getUserTransaction().begin();
          try
          {
             testCase.setUpEJB(props);
@@ -145,7 +158,7 @@
          {
             throw new RemoteTestException(e);
          }
-         if (ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
+         if (wantUserTransaction && ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
          {
             ctx.getUserTransaction().commit();
          }
@@ -154,7 +167,8 @@
       {
          try
          {
-            ctx.getUserTransaction().rollback();
+            if (wantUserTransaction)
+               ctx.getUserTransaction().rollback();
          }
          catch (SystemException unused)
          {
@@ -178,35 +192,65 @@
    {
       try
       {
-         ctx.getUserTransaction().begin();
+         boolean wantUserTransaction = wantUserTransaction(testCase.getProps());
          try
          {
-            testCase.runBare();
+            if (wantUserTransaction)
+               ctx.getUserTransaction().begin();
+            try
+            {
+               testCase.runBare();
+            }
+            catch (Throwable e)
+            {
+               throw new RemoteTestException(e);
+            }
+            if (wantUserTransaction && ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
+            {
+               ctx.getUserTransaction().commit();
+            }
          }
          catch (Throwable e)
          {
+            try
+            {
+               if (wantUserTransaction)
+                  ctx.getUserTransaction().rollback();
+            }
+            catch (SystemException unused)
+            {
+               // eat the exception we are exceptioning out anyway
+            }
+            if (e instanceof RemoteTestException)
+            {
+               throw (RemoteTestException) e;
+            }
             throw new RemoteTestException(e);
          }
-         if (ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
-         {
-            ctx.getUserTransaction().commit();
-         }
       }
-      catch (Throwable e)
+      finally
       {
+         Transaction tx = null;
+         TransactionManager tm = TransactionManagerLocator.getInstance().locate();
          try
          {
-            ctx.getUserTransaction().rollback();
+            tx = tm.getTransaction();
+            if (tx != null)
+            {
+               try
+               {
+                  tx.rollback();
+               }
+               finally
+               {
+                  tm.suspend();
+               }
+            }
          }
-         catch (SystemException unused)
+         catch (Exception e)
          {
-            // eat the exception we are exceptioning out anyway
+            log.error("Error rolling back incomplete transaction: " + tx, e);
          }
-         if (e instanceof RemoteTestException)
-         {
-            throw (RemoteTestException) e;
-         }
-         throw new RemoteTestException(e);
       }
    }
 
@@ -219,10 +263,11 @@
    private void tearDownEJB(EJBTestCase testCase, Properties props)
       throws RemoteTestException
    {
-
+      boolean wantUserTransaction = wantUserTransaction(props);
       try
       {
-         ctx.getUserTransaction().begin();
+         if (wantUserTransaction)
+            ctx.getUserTransaction().begin();
          try
          {
             testCase.tearDownEJB(props);
@@ -231,7 +276,7 @@
          {
             throw new RemoteTestException(e);
          }
-         if (ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
+         if (wantUserTransaction && ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
          {
             ctx.getUserTransaction().commit();
          }
@@ -240,7 +285,8 @@
       {
          try
          {
-            ctx.getUserTransaction().rollback();
+            if (wantUserTransaction)
+               ctx.getUserTransaction().rollback();
          }
          catch (SystemException unused)
          {

Added: branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/ejb-jar.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/ejb-jar.xml	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/ejb-jar.xml	2007-09-11 17:02:26 UTC (rev 65300)
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<!DOCTYPE ejb-jar PUBLIC
+   "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+   "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+   <enterprise-beans>
+      <session>
+         <description>JUnit Session Bean Test Runner</description>
+         <ejb-name>EJBTestRunnerEJB</ejb-name>
+         <home>org.jboss.test.util.ejb.EJBTestRunnerHome</home>
+         <remote>org.jboss.test.util.ejb.EJBTestRunner</remote>
+         <ejb-class>org.jboss.test.util.ejb.EJBTestRunnerBean</ejb-class>
+         <session-type>Stateless</session-type>
+         <transaction-type>Bean</transaction-type>
+         <env-entry>
+            <env-entry-name>NO_USER_TRANSACTION</env-entry-name>
+            <env-entry-type>java.lang.String</env-entry-type>
+            <env-entry-value>true</env-entry-value>
+         </env-entry>
+      </session>
+   </enterprise-beans>
+</ejb-jar>

Added: branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/jboss.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/jboss.xml	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/tm/test/META-INF/jboss.xml	2007-09-11 17:02:26 UTC (rev 65300)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE jboss PUBLIC
+   "-//JBoss//DTD JBOSS 3.2//EN"
+   "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
+
+<jboss>
+   <enterprise-beans>
+      <session>
+         <ejb-name>EJBTestRunnerEJB</ejb-name>
+         <jndi-name>ejb/EJBTestRunner</jndi-name>
+      </session>
+   </enterprise-beans>
+</jboss>




More information about the jboss-cvs-commits mailing list