KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > transaction > manager > TestTransactionManager


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.transaction.manager;
19
20 import javax.transaction.Status JavaDoc;
21 import javax.transaction.Transaction JavaDoc;
22 import javax.transaction.TransactionManager JavaDoc;
23 import javax.transaction.xa.XAResource JavaDoc;
24
25 import junit.framework.TestCase;
26
27 /**
28  *
29  *
30  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
31  */

32 public class TestTransactionManager extends TestCase {
33     TransactionManager JavaDoc tm;
34     MockResourceManager rm1, rm2, rm3;
35
36     public void testNoTransaction() throws Exception JavaDoc {
37         assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
38         assertNull(tm.getTransaction());
39     }
40
41     public void testNoResource() throws Exception JavaDoc {
42         Transaction JavaDoc tx;
43         assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
44         tm.begin();
45         assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
46         tx = tm.getTransaction();
47         assertNotNull(tx);
48         assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
49         tm.rollback();
50         assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
51         assertNull(tm.getTransaction());
52         assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
53
54         tm.begin();
55         assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
56         tm.rollback();
57         assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
58     }
59
60     public void testTxOp() throws Exception JavaDoc {
61         Transaction JavaDoc tx;
62         tm.begin();
63         tx = tm.getTransaction();
64         tx.rollback();
65         assertEquals(Status.STATUS_NO_TRANSACTION, tx.getStatus());
66         assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
67
68         tm.begin();
69         assertFalse(tx.equals(tm.getTransaction()));
70         tm.rollback();
71     }
72
73     public void testSuspend() throws Exception JavaDoc {
74         Transaction JavaDoc tx;
75         assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
76         tm.begin();
77         assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
78         tx = tm.getTransaction();
79         assertNotNull(tx);
80         assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
81
82         tx = tm.suspend();
83         assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
84         assertNull(tm.getTransaction());
85
86         tm.resume(tx);
87         assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
88         assertEquals(tx, tm.getTransaction());
89
90         tm.rollback();
91         assertEquals(Status.STATUS_NO_TRANSACTION, tm.getStatus());
92         assertNull(tm.getTransaction());
93     }
94
95     public void testOneResource() throws Exception JavaDoc {
96         Transaction JavaDoc tx;
97         MockResource res1 = rm1.getResource("rm1");
98         tm.begin();
99         tx = tm.getTransaction();
100         assertNull(res1.getCurrentXid());
101         assertTrue(tx.enlistResource(res1));
102         assertNotNull(res1.getCurrentXid());
103         assertTrue(tx.delistResource(res1, XAResource.TMFAIL));
104         assertNull(res1.getCurrentXid());
105         tm.rollback();
106
107         tm.begin();
108         tx = tm.getTransaction();
109         assertTrue(tx.enlistResource(res1));
110         tm.rollback();
111         assertNull(res1.getCurrentXid());
112     }
113
114     protected void setUp() throws Exception JavaDoc {
115         tm = new TransactionManagerImpl();
116         rm1 = new MockResourceManager(true);
117         rm2 = new MockResourceManager(true);
118         rm3 = new MockResourceManager(false);
119     }
120 }
121
Popular Tags