KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > tm > test > TxTimeoutUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.tm.test;
23
24 import javax.jms.TransactionRolledBackException JavaDoc;
25 import javax.management.Attribute JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27 import javax.transaction.TransactionRolledbackException JavaDoc;
28
29 import junit.framework.Test;
30
31 import org.jboss.mx.util.ObjectNameFactory;
32 import org.jboss.test.JBossTestCase;
33 import org.jboss.test.JBossTestSetup;
34 import org.jboss.test.tm.interfaces.TxTimeout;
35 import org.jboss.test.tm.interfaces.TxTimeoutHome;
36
37 /**
38  * Tests for transaction timeout
39  *
40  * @author adrian@jboss.com
41  * @version $Revision: 37406 $
42  */

43 public class TxTimeoutUnitTestCase
44    extends JBossTestCase
45 {
46    private Integer JavaDoc oldTimeout;
47    
48    private ObjectName JavaDoc tmService = ObjectNameFactory.create("jboss:service=TransactionManager");
49    
50    public TxTimeoutUnitTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55    public void testDefaultTimeout() throws Exception JavaDoc
56    {
57       TxTimeout bean = getBean();
58       try
59       {
60          bean.testDefaultTimeout();
61          fail("Expected TransactionRolledbackException");
62       }
63       catch (TransactionRolledbackException JavaDoc expected)
64       {
65       }
66    }
67
68    public void testOverriddenTimeoutExpires() throws Exception JavaDoc
69    {
70       TxTimeout bean = getBean();
71       try
72       {
73          bean.testOverriddenTimeoutExpires();
74          fail("Expected TransactionRolledbackException");
75       }
76       catch (TransactionRolledbackException JavaDoc expected)
77       {
78       }
79    }
80
81    public void testOverriddenTimeoutDoesNotExpire() throws Exception JavaDoc
82    {
83       TxTimeout bean = getBean();
84       bean.testOverriddenTimeoutDoesNotExpire();
85    }
86    
87    public static Test suite() throws Exception JavaDoc
88    {
89       return new JBossTestSetup(getDeploySetup(TxTimeoutUnitTestCase.class, "txtimeouttest.jar"));
90    }
91
92    protected void setUp() throws Exception JavaDoc
93    {
94       setTxTimeout(new Integer JavaDoc(10));
95    }
96    
97    protected void tearDown() throws Exception JavaDoc
98    {
99       setTxTimeout(oldTimeout);
100    }
101    
102    private void setTxTimeout(Integer JavaDoc timeout) throws Exception JavaDoc
103    {
104       oldTimeout = (Integer JavaDoc) getServer().getAttribute(tmService, "TransactionTimeout");
105       getServer().setAttribute(tmService, new Attribute JavaDoc("TransactionTimeout", timeout));
106    }
107    
108    private TxTimeout getBean() throws Exception JavaDoc
109    {
110       TxTimeoutHome home = (TxTimeoutHome) getInitialContext().lookup("jbosstest/tm/TxTimeout");
111       return home.create();
112    }
113 }
114
Popular Tags