KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > transaction > context > TransactionContextManagerTest


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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.context;
19
20 import javax.transaction.xa.Xid JavaDoc;
21 import javax.transaction.xa.XAResource JavaDoc;
22
23 import junit.framework.TestCase;
24 import org.apache.geronimo.transaction.ImportedTransactionActiveException;
25 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
26 import org.apache.geronimo.transaction.manager.XidFactory;
27 import org.apache.geronimo.transaction.manager.XidFactoryImpl;
28
29 /**
30  *
31  *
32  * @version $Rev: 54013 $ $Date: 2004-10-07 13:49:55 -0700 (Thu, 07 Oct 2004) $
33  *
34  */

35 public class TransactionContextManagerTest extends TestCase {
36
37     private TransactionContextManager transactionContextManager;
38     private XidFactory xidFactory = new XidFactoryImpl("geronimo.test.tm".getBytes());
39
40     protected void setUp() throws Exception JavaDoc {
41         TransactionManagerImpl tm = new TransactionManagerImpl(1000, null, null);
42         transactionContextManager = new TransactionContextManager(tm, tm);
43     }
44
45     protected void tearDown() throws Exception JavaDoc {
46         transactionContextManager = null;
47     }
48
49     public void testImportedTxLifecycle() throws Exception JavaDoc {
50         Xid JavaDoc xid = xidFactory.createXid();
51         transactionContextManager.begin(xid, 1000);
52         transactionContextManager.end(xid);
53         transactionContextManager.begin(xid, 1000);
54         transactionContextManager.end(xid);
55         int readOnly = transactionContextManager.prepare(xid);
56         assertEquals(XAResource.XA_RDONLY, readOnly);
57 // transactionContextManager.commit(xid, false);
58
}
59
60     public void testNoConcurrentWorkSameXid() throws Exception JavaDoc {
61         Xid JavaDoc xid = xidFactory.createXid();
62         transactionContextManager.begin(xid, 1000);
63         try {
64             transactionContextManager.begin(xid, 1000);
65             fail("should not be able begin same xid twice");
66         } catch (ImportedTransactionActiveException e) {
67             //expected
68
} finally {
69             transactionContextManager.end(xid);
70             transactionContextManager.rollback(xid);
71         }
72     }
73
74     public void testOnlyOneImportedTxAtATime() throws Exception JavaDoc {
75         Xid JavaDoc xid1 = xidFactory.createXid();
76         Xid JavaDoc xid2 = xidFactory.createXid();
77         transactionContextManager.begin(xid1, 1000);
78         try {
79             transactionContextManager.begin(xid2, 1000);
80             fail("should not be able to begin a 2nd tx without ending the first");
81         } catch (IllegalStateException JavaDoc e) {
82             //expected
83
} finally {
84             transactionContextManager.end(xid1);
85             transactionContextManager.rollback(xid1);
86         }
87     }
88 }
89
Popular Tags