1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import java.io.PrintWriter ; 21 import java.security.Principal ; 22 import java.util.Set ; 23 import javax.resource.ResourceException ; 24 import javax.resource.spi.ConnectionEventListener ; 25 import javax.resource.spi.ConnectionRequestInfo ; 26 import javax.resource.spi.DissociatableManagedConnection ; 27 import javax.resource.spi.LocalTransaction ; 28 import javax.resource.spi.ManagedConnection ; 29 import javax.resource.spi.ManagedConnectionMetaData ; 30 import javax.security.auth.Subject ; 31 import javax.transaction.xa.XAResource ; 32 33 import junit.framework.TestCase; 34 35 41 public class ConnectionInterceptorTestUtils extends TestCase implements ConnectionInterceptor { 42 protected Subject subject; 43 protected ConnectionInfo obtainedConnectionInfo; 44 protected ConnectionInfo returnedConnectionInfo; 45 protected ManagedConnection managedConnection; 46 47 protected void setUp() throws Exception { 48 } 49 50 protected void tearDown() throws Exception { 51 subject = null; 52 obtainedConnectionInfo = null; 53 returnedConnectionInfo = null; 54 managedConnection = null; 55 } 56 57 public void testNothing() throws Exception { 58 } 59 60 public void getConnection(ConnectionInfo connectionInfo) throws ResourceException { 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 principalName) { 78 subject = new Subject (); 79 Set 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 { 89 90 private final String name; 91 92 public TestPrincipal(String name) { 93 this.name = name; 94 } 95 96 public String getName() { 97 return name; 98 } 99 100 } 101 102 protected static class TestPlainManagedConnection implements ManagedConnection { 103 public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { 104 return null; 105 } 106 107 public void destroy() throws ResourceException { 108 } 109 110 public void cleanup() throws ResourceException { 111 } 112 113 public void associateConnection(Object connection) throws ResourceException { 114 } 115 116 public void addConnectionEventListener(ConnectionEventListener listener) { 117 } 118 119 public void removeConnectionEventListener(ConnectionEventListener listener) { 120 } 121 122 public XAResource getXAResource() throws ResourceException { 123 return null; 124 } 125 126 public LocalTransaction getLocalTransaction() throws ResourceException { 127 return null; 128 } 129 130 public ManagedConnectionMetaData getMetaData() throws ResourceException { 131 return null; 132 } 133 134 public void setLogWriter(PrintWriter out) throws ResourceException { 135 } 136 137 public PrintWriter getLogWriter() throws ResourceException { 138 return null; 139 } 140 141 } 142 143 protected static class TestDissociatableManagedConnection implements ManagedConnection , DissociatableManagedConnection { 144 public void dissociateConnections() throws ResourceException { 145 } 146 147 public Object getConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { 148 return null; 149 } 150 151 public void destroy() throws ResourceException { 152 } 153 154 public void cleanup() throws ResourceException { 155 } 156 157 public void associateConnection(Object connection) throws ResourceException { 158 } 159 160 public void addConnectionEventListener(ConnectionEventListener listener) { 161 } 162 163 public void removeConnectionEventListener(ConnectionEventListener listener) { 164 } 165 166 public XAResource getXAResource() throws ResourceException { 167 return null; 168 } 169 170 public LocalTransaction getLocalTransaction() throws ResourceException { 171 return null; 172 } 173 174 public ManagedConnectionMetaData getMetaData() throws ResourceException { 175 return null; 176 } 177 178 public void setLogWriter(PrintWriter out) throws ResourceException { 179 } 180 181 public PrintWriter getLogWriter() throws ResourceException { 182 return null; 183 } 184 185 } 186 } 187 | Popular Tags |