001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.tm.test;
023:
024: import javax.transaction.TransactionRolledbackException;
025:
026: import junit.framework.Test;
027:
028: import org.jboss.test.JBossTestCase;
029: import org.jboss.test.JBossTestSetup;
030: import org.jboss.test.tm.interfaces.TxTimeout;
031: import org.jboss.test.tm.interfaces.TxTimeoutHome;
032:
033: /**
034: * Tests for transaction timeout
035: *
036: * JBAS-4011, the arjuna transaction manager does not allow the
037: * setting of the global default tx timeout after the tx manager
038: * is started, so we won't test the default timeout setting (300secs).
039: *
040: * @author adrian@jboss.com
041: * @version $Revision: 60501 $
042: */
043: public class TxTimeoutUnitTestCase extends JBossTestCase {
044: /*
045: private Integer oldTimeout;
046: private ObjectName tmService = ObjectNameFactory.create("jboss:service=TransactionManager");
047: */
048: public TxTimeoutUnitTestCase(String name) {
049: super (name);
050: }
051:
052: /*
053: public void testDefaultTimeout() throws Exception
054: {
055: TxTimeout bean = getBean();
056: try
057: {
058: bean.testDefaultTimeout();
059: fail("Expected TransactionRolledbackException");
060: }
061: catch (TransactionRolledbackException expected)
062: {
063: }
064: }
065: */
066: public void testOverriddenTimeoutExpires() throws Exception {
067: TxTimeout bean = getBean();
068: try {
069: bean.testOverriddenTimeoutExpires();
070: fail("Expected TransactionRolledbackException");
071: } catch (TransactionRolledbackException expected) {
072: }
073: }
074:
075: public void testOverriddenTimeoutDoesNotExpire() throws Exception {
076: TxTimeout bean = getBean();
077: bean.testOverriddenTimeoutDoesNotExpire();
078: }
079:
080: public static Test suite() throws Exception {
081: return new JBossTestSetup(getDeploySetup(
082: TxTimeoutUnitTestCase.class, "txtimeouttest.jar"));
083: }
084:
085: /*
086: protected void setUp() throws Exception
087: {
088: setTxTimeout(new Integer(10));
089: }
090:
091: protected void tearDown() throws Exception
092: {
093: setTxTimeout(oldTimeout);
094: }
095:
096: private void setTxTimeout(Integer timeout) throws Exception
097: {
098: oldTimeout = (Integer) getServer().getAttribute(tmService, "TransactionTimeout");
099: getServer().setAttribute(tmService, new Attribute("TransactionTimeout", timeout));
100: }
101: */
102: private TxTimeout getBean() throws Exception {
103: TxTimeoutHome home = (TxTimeoutHome) getInitialContext()
104: .lookup("jbosstest/tm/TxTimeout");
105: return home.create();
106: }
107: }
|