KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.PrintWriter JavaDoc;
21 import java.security.Principal JavaDoc;
22 import java.util.Set JavaDoc;
23 import javax.resource.ResourceException JavaDoc;
24 import javax.resource.spi.ConnectionEventListener JavaDoc;
25 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
26 import javax.resource.spi.DissociatableManagedConnection JavaDoc;
27 import javax.resource.spi.LocalTransaction JavaDoc;
28 import javax.resource.spi.ManagedConnection JavaDoc;
29 import javax.resource.spi.ManagedConnectionMetaData JavaDoc;
30 import javax.security.auth.Subject JavaDoc;
31 import javax.transaction.xa.XAResource JavaDoc;
32
33 import junit.framework.TestCase;
34
35 /**
36  *
37  *
38  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
39  *
40  * */

41 public class ConnectionInterceptorTestUtils extends TestCase implements ConnectionInterceptor {
42     protected Subject JavaDoc subject;
43     protected ConnectionInfo obtainedConnectionInfo;
44     protected ConnectionInfo returnedConnectionInfo;
45     protected ManagedConnection JavaDoc managedConnection;
46
47     protected void setUp() throws Exception JavaDoc {
48     }
49
50     protected void tearDown() throws Exception JavaDoc {
51         subject = null;
52         obtainedConnectionInfo = null;
53         returnedConnectionInfo = null;
54         managedConnection = null;
55     }
56
57     public void testNothing() throws Exception JavaDoc {
58     }
59
60     //ConnectorInterceptor implementation
61
public void getConnection(ConnectionInfo connectionInfo) throws ResourceException JavaDoc {
62         ManagedConnectionInfo managedConnectionInfo = connectionInfo.getManagedConnectionInfo();
63         if (managedConnectionInfo.getManagedConnection() == null) {
64             managedConnectionInfo.setManagedConnection(managedConnection);
65         }
66         obtainedConnectionInfo = connectionInfo;
67     }
68
69     public void returnConnection(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
70         returnedConnectionInfo = connectionInfo;
71     }
72     
73     public void destroy() {
74         
75     }
76
77     protected void makeSubject(String JavaDoc principalName) {
78         subject = new Subject JavaDoc();
79         Set JavaDoc principals = subject.getPrincipals();
80         principals.add(new TestPrincipal(principalName));
81     }
82
83     protected ConnectionInfo makeConnectionInfo() {
84         ManagedConnectionInfo managedConnectionInfo = new ManagedConnectionInfo(null, null);
85         return new ConnectionInfo(managedConnectionInfo);
86     }
87
88     private static class TestPrincipal implements Principal JavaDoc {
89
90         private final String JavaDoc name;
91
92         public TestPrincipal(String JavaDoc name) {
93             this.name = name;
94         }
95
96         public String JavaDoc getName() {
97             return name;
98         }
99
100     }
101
102     protected static class TestPlainManagedConnection implements ManagedConnection JavaDoc {
103         public Object JavaDoc getConnection(Subject JavaDoc subject, ConnectionRequestInfo JavaDoc cxRequestInfo) throws ResourceException JavaDoc {
104             return null;
105         }
106
107         public void destroy() throws ResourceException JavaDoc {
108         }
109
110         public void cleanup() throws ResourceException JavaDoc {
111         }
112
113         public void associateConnection(Object JavaDoc connection) throws ResourceException JavaDoc {
114         }
115
116         public void addConnectionEventListener(ConnectionEventListener JavaDoc listener) {
117         }
118
119         public void removeConnectionEventListener(ConnectionEventListener JavaDoc listener) {
120         }
121
122         public XAResource JavaDoc getXAResource() throws ResourceException JavaDoc {
123             return null;
124         }
125
126         public LocalTransaction JavaDoc getLocalTransaction() throws ResourceException JavaDoc {
127             return null;
128         }
129
130         public ManagedConnectionMetaData JavaDoc getMetaData() throws ResourceException JavaDoc {
131             return null;
132         }
133
134         public void setLogWriter(PrintWriter JavaDoc out) throws ResourceException JavaDoc {
135         }
136
137         public PrintWriter JavaDoc getLogWriter() throws ResourceException JavaDoc {
138             return null;
139         }
140
141     }
142
143     protected static class TestDissociatableManagedConnection implements ManagedConnection JavaDoc, DissociatableManagedConnection JavaDoc {
144         public void dissociateConnections() throws ResourceException JavaDoc {
145         }
146
147         public Object JavaDoc getConnection(Subject JavaDoc subject, ConnectionRequestInfo JavaDoc cxRequestInfo) throws ResourceException JavaDoc {
148             return null;
149         }
150
151         public void destroy() throws ResourceException JavaDoc {
152         }
153
154         public void cleanup() throws ResourceException JavaDoc {
155         }
156
157         public void associateConnection(Object JavaDoc connection) throws ResourceException JavaDoc {
158         }
159
160         public void addConnectionEventListener(ConnectionEventListener JavaDoc listener) {
161         }
162
163         public void removeConnectionEventListener(ConnectionEventListener JavaDoc listener) {
164         }
165
166         public XAResource JavaDoc getXAResource() throws ResourceException JavaDoc {
167             return null;
168         }
169
170         public LocalTransaction JavaDoc getLocalTransaction() throws ResourceException JavaDoc {
171             return null;
172         }
173
174         public ManagedConnectionMetaData JavaDoc getMetaData() throws ResourceException JavaDoc {
175             return null;
176         }
177
178         public void setLogWriter(PrintWriter JavaDoc out) throws ResourceException JavaDoc {
179         }
180
181         public PrintWriter JavaDoc getLogWriter() throws ResourceException JavaDoc {
182             return null;
183         }
184
185     }
186 }
187
Popular Tags