[jboss-cvs] JBossAS SVN: r65326 - in trunk/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
Wed Sep 12 06:49:11 EDT 2007
Author: adrian at jboss.org
Date: 2007-09-12 06:49:11 -0400 (Wed, 12 Sep 2007)
New Revision: 65326
Added:
trunk/testsuite/src/resources/tm/test/
trunk/testsuite/src/resources/tm/test/META-INF/
trunk/testsuite/src/resources/tm/test/META-INF/ejb-jar.xml
trunk/testsuite/src/resources/tm/test/META-INF/jboss.xml
Modified:
trunk/testsuite/imports/sections/tm.xml
trunk/testsuite/src/main/org/jboss/test/tm/test/TransactionLocalUnitTestCase.java
trunk/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java
Log:
Port JBAS-4690 from jboss-4.2
Modified: trunk/testsuite/imports/sections/tm.xml
===================================================================
--- trunk/testsuite/imports/sections/tm.xml 2007-09-12 03:40:18 UTC (rev 65325)
+++ trunk/testsuite/imports/sections/tm.xml 2007-09-12 10:49:11 UTC (rev 65326)
@@ -65,5 +65,22 @@
<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>
+ <zipfileset src="${jboss.test.lib}/jboss-test.jar">
+ <patternset refid="jboss.test.set"/>
+ </zipfileset>
+ </jar>
</target>
</project>
Modified: trunk/testsuite/src/main/org/jboss/test/tm/test/TransactionLocalUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/tm/test/TransactionLocalUnitTestCase.java 2007-09-12 03:40:18 UTC (rev 65325)
+++ trunk/testsuite/src/main/org/jboss/test/tm/test/TransactionLocalUnitTestCase.java 2007-09-12 10:49:11 UTC (rev 65326)
@@ -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: trunk/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java 2007-09-12 03:40:18 UTC (rev 65325)
+++ trunk/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java 2007-09-12 10:49:11 UTC (rev 65326)
@@ -1,24 +1,24 @@
/*
- * 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.
- */
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.test.util.ejb;
import java.lang.reflect.Constructor;
@@ -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,8 +49,7 @@
*/
public class EJBTestRunnerBean implements SessionBean
{
- private static final long serialVersionUID = 1;
-
+ private static final Logger log = Logger.getLogger(EJBTestRunnerBean.class);
transient private SessionContext ctx;
private String runnerJndiName;
@@ -127,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
@@ -136,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);
@@ -147,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();
}
@@ -156,7 +167,8 @@
{
try
{
- ctx.getUserTransaction().rollback();
+ if (wantUserTransaction)
+ ctx.getUserTransaction().rollback();
}
catch (SystemException unused)
{
@@ -180,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);
}
}
@@ -221,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);
@@ -233,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();
}
@@ -242,7 +285,8 @@
{
try
{
- ctx.getUserTransaction().rollback();
+ if (wantUserTransaction)
+ ctx.getUserTransaction().rollback();
}
catch (SystemException unused)
{
Added: trunk/testsuite/src/resources/tm/test/META-INF/ejb-jar.xml
===================================================================
--- trunk/testsuite/src/resources/tm/test/META-INF/ejb-jar.xml (rev 0)
+++ trunk/testsuite/src/resources/tm/test/META-INF/ejb-jar.xml 2007-09-12 10:49:11 UTC (rev 65326)
@@ -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: trunk/testsuite/src/resources/tm/test/META-INF/jboss.xml
===================================================================
--- trunk/testsuite/src/resources/tm/test/META-INF/jboss.xml (rev 0)
+++ trunk/testsuite/src/resources/tm/test/META-INF/jboss.xml 2007-09-12 10:49:11 UTC (rev 65326)
@@ -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