KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.HashSet JavaDoc;
21 import java.util.Set JavaDoc;
22 import javax.security.auth.Subject JavaDoc;
23 import javax.transaction.TransactionManager JavaDoc;
24 import javax.transaction.UserTransaction JavaDoc;
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 /**
45  * ???
46  *
47  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
48  */

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 JavaDoc name = "testCF";
64     //dependencies
65
protected ConnectionTrackingCoordinator connectionTrackingCoordinator;
66     protected TransactionManager JavaDoc transactionManager;
67     protected AbstractConnectionManager connectionManagerDeployment;
68     protected MockConnectionFactory connectionFactory;
69     protected MockManagedConnectionFactory mockManagedConnectionFactory;
70     protected ConnectorInstanceContextImpl connectorInstanceContext;
71     protected DefaultComponentInterceptor defaultComponentInterceptor;
72     protected Set JavaDoc unshareableResources = new HashSet JavaDoc();
73     protected Set JavaDoc applicationManagedSecurityResources = new HashSet JavaDoc();
74     protected MockManagedConnection mockManagedConnection;
75     protected Subject JavaDoc subject;
76     protected UserTransaction JavaDoc 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 JavaDoc invoke(ConnectorInstanceContext newConnectorInstanceContext) throws Throwable JavaDoc {
83             MockConnection mockConnection = (MockConnection) connectionFactory.getConnection();
84             mockManagedConnection = mockConnection.getManagedConnection();
85             mockConnection.close();
86             return null;
87         }
88     };
89     private ClassLoader JavaDoc classLoader = this.getClass().getClassLoader();
90
91     protected void setUp() throws Exception JavaDoc {
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 JavaDoc();
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 JavaDoc {
115         connectionTrackingCoordinator = null;
116         transactionManager = null;
117         mockManagedConnectionFactory = null;
118         connectionManagerDeployment = null;
119         connectionFactory = null;
120         connectorInstanceContext = null;
121     }
122
123     public Object JavaDoc invoke(ConnectorInstanceContext newConnectorInstanceContext) throws Throwable JavaDoc {
124         return mockComponent.invoke(newConnectorInstanceContext);
125     }
126 }
127
Popular Tags