KickJava   Java API By Example, From Geeks To Geeks.

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


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.resource.spi.LocalTransaction JavaDoc;
22
23 /**
24  *
25  *
26  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
27  *
28  * */

29 public class LocalXAResourceInsertionInterceptorTest extends ConnectionInterceptorTestUtils {
30
31     private LocalXAResourceInsertionInterceptor localXAResourceInsertionInterceptor;
32     private LocalTransaction JavaDoc localTransaction;
33     private String JavaDoc name = "LocalXAResource";
34
35     protected void setUp() throws Exception JavaDoc {
36         super.setUp();
37         localXAResourceInsertionInterceptor = new LocalXAResourceInsertionInterceptor(this, name);
38     }
39
40     protected void tearDown() throws Exception JavaDoc {
41         super.tearDown();
42         localXAResourceInsertionInterceptor = null;
43     }
44
45     public void testInsertLocalXAResource() throws Exception JavaDoc {
46         ConnectionInfo connectionInfo = makeConnectionInfo();
47         localXAResourceInsertionInterceptor.getConnection(connectionInfo);
48         LocalXAResource returnedLocalXAResource = (LocalXAResource) connectionInfo.getManagedConnectionInfo().getXAResource();
49         assertTrue("Expected the same LocalTransaction", localTransaction == returnedLocalXAResource.localTransaction);
50     }
51
52     public void getConnection(ConnectionInfo connectionInfo) throws ResourceException JavaDoc {
53         super.getConnection(connectionInfo);
54         localTransaction = new TestLocalTransaction();
55         TestManagedConnection managedConnection = new TestManagedConnection(localTransaction);
56         ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo();
57         managedConnectionInfo.setManagedConnection(managedConnection);
58     }
59
60     private static class TestLocalTransaction implements LocalTransaction JavaDoc {
61         public void begin() throws ResourceException JavaDoc {
62         }
63
64         public void commit() throws ResourceException JavaDoc {
65         }
66
67         public void rollback() throws ResourceException JavaDoc {
68         }
69
70     }
71
72     private static class TestManagedConnection extends TestPlainManagedConnection {
73
74         private final LocalTransaction JavaDoc localTransaction;
75
76         public TestManagedConnection(LocalTransaction JavaDoc localTransaction) {
77             this.localTransaction = localTransaction;
78         }
79
80         public LocalTransaction JavaDoc getLocalTransaction() throws ResourceException JavaDoc {
81             return localTransaction;
82         }
83     }
84 }
85
Popular Tags