KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > outbound > XAResourceInsertionInterceptorTest


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.connector.outbound;
19
20 import javax.resource.ResourceException JavaDoc;
21 import javax.transaction.xa.XAException JavaDoc;
22 import javax.transaction.xa.XAResource JavaDoc;
23 import javax.transaction.xa.Xid JavaDoc;
24
25 /**
26  *
27  *
28  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
29  *
30  * */

31 public class XAResourceInsertionInterceptorTest extends ConnectionInterceptorTestUtils {
32
33     private XAResourceInsertionInterceptor xaResourceInsertionInterceptor;
34     private XAResource JavaDoc xaResource;
35     private String JavaDoc name = "XAResource";
36
37     protected void setUp() throws Exception JavaDoc {
38         super.setUp();
39         xaResourceInsertionInterceptor = new XAResourceInsertionInterceptor(this, name);
40     }
41
42     protected void tearDown() throws Exception JavaDoc {
43         super.tearDown();
44         xaResourceInsertionInterceptor = null;
45     }
46
47     public void testInsertXAResource() throws Exception JavaDoc {
48         ConnectionInfo connectionInfo = makeConnectionInfo();
49         xaResource = new TestXAResource();
50         managedConnection = new TestManagedConnection(xaResource);
51         xaResourceInsertionInterceptor.getConnection(connectionInfo);
52         xaResource.setTransactionTimeout(200);
53         //xaresource is wrapped, so we do something to ours to make it distinguishable.
54
assertEquals("Expected the same XAResource", 200, connectionInfo.getManagedConnectionInfo().getXAResource().getTransactionTimeout());
55     }
56
57
58     private static class TestXAResource implements XAResource JavaDoc {
59         private int txTimeout;
60
61         public void commit(Xid JavaDoc xid, boolean onePhase) throws XAException JavaDoc {
62         }
63
64         public void end(Xid JavaDoc xid, int flags) throws XAException JavaDoc {
65         }
66
67         public void forget(Xid JavaDoc xid) throws XAException JavaDoc {
68         }
69
70         public int getTransactionTimeout() throws XAException JavaDoc {
71             return txTimeout;
72         }
73
74         public boolean isSameRM(XAResource JavaDoc xaResource) throws XAException JavaDoc {
75             return false;
76         }
77
78         public int prepare(Xid JavaDoc xid) throws XAException JavaDoc {
79             return 0;
80         }
81
82         public Xid JavaDoc[] recover(int flag) throws XAException JavaDoc {
83             return new Xid JavaDoc[0];
84         }
85
86         public void rollback(Xid JavaDoc xid) throws XAException JavaDoc {
87         }
88
89         public boolean setTransactionTimeout(int seconds) throws XAException JavaDoc {
90             this.txTimeout = seconds;
91             return false;
92         }
93
94         public void start(Xid JavaDoc xid, int flags) throws XAException JavaDoc {
95         }
96
97     }
98
99     private static class TestManagedConnection extends TestPlainManagedConnection {
100
101         private final XAResource JavaDoc xaResource;
102
103         public TestManagedConnection(XAResource JavaDoc xaResource) {
104             this.xaResource = xaResource;
105         }
106
107         public XAResource JavaDoc getXAResource() throws ResourceException JavaDoc {
108             return xaResource;
109         }
110
111
112     }
113 }
114
Popular Tags