1 17 18 package org.apache.geronimo.connector.outbound; 19 20 import java.util.HashSet ; 21 import java.util.Set ; 22 import javax.security.auth.Subject ; 23 import javax.transaction.TransactionManager ; 24 import javax.transaction.UserTransaction ; 25 26 import org.apache.geronimo.connector.mock.MockConnection; 27 import org.apache.geronimo.connector.mock.MockConnectionFactory; 28 import org.apache.geronimo.connector.mock.MockManagedConnection; 29 import org.apache.geronimo.connector.mock.MockManagedConnectionFactory; 30 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool; 31 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport; 32 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport; 33 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions; 34 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator; 35 import org.apache.geronimo.connector.outbound.connectiontracking.DefaultComponentInterceptor; 36 import org.apache.geronimo.connector.outbound.connectiontracking.DefaultInterceptor; 37 import org.apache.geronimo.security.ContextManager; 38 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContextImpl; 39 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext; 40 import org.apache.geronimo.connector.outbound.connectiontracking.GeronimoTransactionListener; 41 import org.apache.geronimo.transaction.manager.TransactionManagerImpl; 42 import org.apache.geronimo.testsupport.TestSupport; 43 44 49 public class ConnectionManagerTestUtils extends TestSupport implements DefaultInterceptor { 50 protected boolean useTransactionCaching = true; 51 protected boolean useLocalTransactions = false; 52 protected boolean useThreadCaching = false; 53 protected boolean useTransactions = true; 54 protected int maxSize = 10; 55 protected int minSize = 0; 56 protected int blockingTimeout = 100; 57 protected int idleTimeoutMinutes = 15; 58 protected boolean useConnectionRequestInfo = false; 59 protected boolean useSubject = true; 60 private boolean matchOne = true; 61 private boolean matchAll = false; 62 private boolean selectOneNoMatch = false; 63 protected String name = "testCF"; 64 protected ConnectionTrackingCoordinator connectionTrackingCoordinator; 66 protected TransactionManager transactionManager; 67 protected AbstractConnectionManager connectionManagerDeployment; 68 protected MockConnectionFactory connectionFactory; 69 protected MockManagedConnectionFactory mockManagedConnectionFactory; 70 protected ConnectorInstanceContextImpl connectorInstanceContext; 71 protected DefaultComponentInterceptor defaultComponentInterceptor; 72 protected Set unshareableResources = new HashSet (); 73 protected Set applicationManagedSecurityResources = new HashSet (); 74 protected MockManagedConnection mockManagedConnection; 75 protected Subject subject; 76 protected UserTransaction userTransaction; 77 protected TransactionSupport transactionSupport = new XATransactions(useTransactionCaching, useThreadCaching); 78 protected PoolingSupport poolingSupport = new PartitionedPool(maxSize, minSize, blockingTimeout, idleTimeoutMinutes, matchOne, matchAll, selectOneNoMatch, useConnectionRequestInfo, useSubject); 79 protected boolean containerManagedSecurity = true; 80 81 protected DefaultInterceptor mockComponent = new DefaultInterceptor() { 82 public Object invoke(ConnectorInstanceContext newConnectorInstanceContext) throws Throwable { 83 MockConnection mockConnection = (MockConnection) connectionFactory.getConnection(); 84 mockManagedConnection = mockConnection.getManagedConnection(); 85 mockConnection.close(); 86 return null; 87 } 88 }; 89 private ClassLoader classLoader = this.getClass().getClassLoader(); 90 91 protected void setUp() throws Exception { 92 TransactionManagerImpl transactionManager = new TransactionManagerImpl(); 93 this.transactionManager = transactionManager; 94 95 connectionTrackingCoordinator = new ConnectionTrackingCoordinator(); 96 transactionManager.addTransactionAssociationListener(new GeronimoTransactionListener(connectionTrackingCoordinator)); 97 98 mockManagedConnectionFactory = new MockManagedConnectionFactory(); 99 subject = new Subject (); 100 ContextManager.setCallers(subject, subject); 101 connectionManagerDeployment = new GenericConnectionManager( 102 transactionSupport, 103 poolingSupport, 104 containerManagedSecurity, 105 connectionTrackingCoordinator, 106 this.transactionManager, 107 name, 108 classLoader); 109 connectionFactory = (MockConnectionFactory) connectionManagerDeployment.createConnectionFactory(mockManagedConnectionFactory); 110 connectorInstanceContext = new ConnectorInstanceContextImpl(unshareableResources, applicationManagedSecurityResources); 111 defaultComponentInterceptor = new DefaultComponentInterceptor(this, connectionTrackingCoordinator); 112 } 113 114 protected void tearDown() throws Exception { 115 connectionTrackingCoordinator = null; 116 transactionManager = null; 117 mockManagedConnectionFactory = null; 118 connectionManagerDeployment = null; 119 connectionFactory = null; 120 connectorInstanceContext = null; 121 } 122 123 public Object invoke(ConnectorInstanceContext newConnectorInstanceContext) throws Throwable { 124 return mockComponent.invoke(newConnectorInstanceContext); 125 } 126 } 127 | Popular Tags |