Source Code Cross Referenced for ManagedConnectionFactoryWrapperTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » connector » outbound » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.connector.outbound 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.connector.outbound;
017:
018:        import java.io.ByteArrayInputStream;
019:        import java.io.ByteArrayOutputStream;
020:        import java.io.ObjectInputStream;
021:        import java.io.ObjectOutputStream;
022:        import java.io.Serializable;
023:        import java.util.HashMap;
024:        import java.util.Map;
025:        import javax.resource.cci.Connection;
026:        import javax.resource.cci.ConnectionFactory;
027:
028:        import junit.framework.TestCase;
029:        import org.apache.geronimo.connector.mock.ConnectionFactoryExtension;
030:        import org.apache.geronimo.connector.mock.MockConnection;
031:        import org.apache.geronimo.connector.mock.MockConnectionFactory;
032:        import org.apache.geronimo.connector.mock.MockManagedConnectionFactory;
033:        import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool;
034:        import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions;
035:        import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
036:        import org.apache.geronimo.gbean.AbstractName;
037:        import org.apache.geronimo.gbean.GBeanData;
038:        import org.apache.geronimo.gbean.GBeanInfo;
039:        import org.apache.geronimo.gbean.GBeanInfoBuilder;
040:        import org.apache.geronimo.kernel.Kernel;
041:        import org.apache.geronimo.kernel.KernelFactory;
042:        import org.apache.geronimo.kernel.repository.Artifact;
043:
044:        /**
045:         * @version $Rev: 539952 $ $Date: 2007-05-20 14:40:58 -0700 (Sun, 20 May 2007) $
046:         */
047:        public class ManagedConnectionFactoryWrapperTest extends TestCase {
048:
049:            private Kernel kernel;
050:            private AbstractName managedConnectionFactoryName;
051:            private static final String KERNEL_NAME = "testKernel";
052:            private static final String TARGET_NAME = "testCFName";
053:
054:            public void testProxy() throws Exception {
055:                Object proxy = kernel.invoke(managedConnectionFactoryName,
056:                        "$getResource");
057:                assertNotNull(proxy);
058:                assertTrue(proxy instanceof  ConnectionFactory);
059:                Connection connection = ((ConnectionFactory) proxy)
060:                        .getConnection();
061:                assertNotNull(connection);
062:                kernel.stopGBean(managedConnectionFactoryName);
063:                try {
064:                    ((ConnectionFactory) proxy).getConnection();
065:                    //            fail();
066:                } catch (IllegalStateException ise) {
067:                }
068:                kernel.startGBean(managedConnectionFactoryName);
069:                ((ConnectionFactory) proxy).getConnection();
070:                //check implemented interfaces
071:                assertTrue(proxy instanceof  Serializable);
072:                assertTrue(proxy instanceof  ConnectionFactoryExtension);
073:                assertEquals("SomethingElse",
074:                        ((ConnectionFactoryExtension) proxy).doSomethingElse());
075:            }
076:
077:            public void XtestSerialization() throws Exception {
078:                ConnectionFactory proxy = (ConnectionFactory) kernel.invoke(
079:                        managedConnectionFactoryName, "$getResource");
080:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
081:                ObjectOutputStream oos = new ObjectOutputStream(baos);
082:                oos.writeObject(proxy);
083:                oos.flush();
084:                byte[] bytes = baos.toByteArray();
085:                oos.close();
086:                ObjectInputStream ois = new ObjectInputStream(
087:                        new ByteArrayInputStream(bytes));
088:                Object proxy2 = ois.readObject();
089:                assertNotNull(proxy2);
090:                assertTrue(proxy instanceof  ConnectionFactory);
091:                Connection connection = proxy.getConnection();
092:                assertNotNull(connection);
093:                kernel.stopGBean(managedConnectionFactoryName);
094:                ObjectInputStream ois2 = new ObjectInputStream(
095:                        new ByteArrayInputStream(bytes));
096:                ConnectionFactory proxy3 = (ConnectionFactory) ois2
097:                        .readObject();
098:                try {
099:                    proxy3.getConnection();
100:                    fail();
101:                } catch (IllegalStateException ise) {
102:                }
103:                kernel.startGBean(managedConnectionFactoryName);
104:                proxy3.getConnection();
105:
106:            }
107:
108:            protected void setUp() throws Exception {
109:                super .setUp();
110:                kernel = KernelFactory.newInstance().createKernel(KERNEL_NAME);
111:                kernel.boot();
112:                ClassLoader cl = MockConnectionTrackingCoordinator.class
113:                        .getClassLoader();
114:
115:                GBeanData ctc = buildGBeanData("name",
116:                        "ConnectionTrackingCoordinator",
117:                        MockConnectionTrackingCoordinator.getGBeanInfo());
118:                AbstractName ctcName = ctc.getAbstractName();
119:                kernel.loadGBean(ctc, cl);
120:
121:                GBeanData cmf = buildGBeanData("name",
122:                        "ConnectionManagerContainer",
123:                        GenericConnectionManagerGBean.getGBeanInfo());
124:                AbstractName cmfName = cmf.getAbstractName();
125:                cmf.setAttribute("transactionSupport", NoTransactions.INSTANCE);
126:                cmf.setAttribute("pooling", new NoPool());
127:                cmf.setReferencePattern("ConnectionTracker", ctcName);
128:                kernel.loadGBean(cmf, cl);
129:
130:                GBeanData mcfw = buildGBeanData("name", TARGET_NAME,
131:                        ManagedConnectionFactoryWrapperGBean.getGBeanInfo());
132:                managedConnectionFactoryName = mcfw.getAbstractName();
133:                mcfw.setAttribute("managedConnectionFactoryClass",
134:                        MockManagedConnectionFactory.class.getName());
135:                mcfw.setAttribute("connectionFactoryInterface",
136:                        ConnectionFactory.class.getName());
137:                mcfw.setAttribute("implementedInterfaces", new String[] {
138:                        Serializable.class.getName(),
139:                        ConnectionFactoryExtension.class.getName() });
140:                mcfw.setAttribute("connectionFactoryImplClass",
141:                        MockConnectionFactory.class.getName());
142:                mcfw.setAttribute("connectionInterface", Connection.class
143:                        .getName());
144:                mcfw.setAttribute("connectionImplClass", MockConnection.class
145:                        .getName());
146:                //"ResourceAdapterWrapper",
147:                mcfw.setReferencePattern("ConnectionManagerContainer", cmfName);
148:                //"ManagedConnectionFactoryListener",
149:                kernel.loadGBean(mcfw, cl);
150:
151:                kernel.startGBean(ctcName);
152:                kernel.startGBean(cmfName);
153:                kernel.startGBean(managedConnectionFactoryName);
154:            }
155:
156:            private GBeanData buildGBeanData(String key, String value,
157:                    GBeanInfo info) {
158:                AbstractName abstractName = buildAbstractName(key, value);
159:                return new GBeanData(abstractName, info);
160:            }
161:
162:            private AbstractName buildAbstractName(String key, String value) {
163:                Map names = new HashMap();
164:                names.put(key, value);
165:                return new AbstractName(
166:                        new Artifact("test", "foo", "1", "car"), names);
167:            }
168:
169:            protected void tearDown() throws Exception {
170:                kernel.stopGBean(managedConnectionFactoryName);
171:                kernel.shutdown();
172:                super .tearDown();
173:            }
174:
175:            public static class MockConnectionTrackingCoordinator implements 
176:                    ConnectionTracker {
177:                public void handleObtained(
178:                        ConnectionTrackingInterceptor connectionTrackingInterceptor,
179:                        ConnectionInfo connectionInfo, boolean reassociate) {
180:                }
181:
182:                public void handleReleased(
183:                        ConnectionTrackingInterceptor connectionTrackingInterceptor,
184:                        ConnectionInfo connectionInfo,
185:                        ConnectionReturnAction connectionReturnAction) {
186:                }
187:
188:                public void setEnvironment(ConnectionInfo connectionInfo,
189:                        String key) {
190:                }
191:
192:                static final GBeanInfo GBEAN_INFO;
193:
194:                static {
195:                    GBeanInfoBuilder infoFactory = GBeanInfoBuilder
196:                            .createStatic(MockConnectionTrackingCoordinator.class);
197:                    infoFactory.addInterface(ConnectionTracker.class);
198:                    GBEAN_INFO = infoFactory.getBeanInfo();
199:                }
200:
201:                public static GBeanInfo getGBeanInfo() {
202:                    return GBEAN_INFO;
203:                }
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.