Source Code Cross Referenced for ClusteredStatefulContainerTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » openejb » cluster » stateful » container » 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.openejb.cluster.stateful.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         *  http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.geronimo.openejb.cluster.stateful.container;
021:
022:        import java.lang.reflect.Method;
023:        import java.net.URI;
024:        import java.util.Collections;
025:
026:        import javax.transaction.TransactionManager;
027:
028:        import org.apache.geronimo.clustering.wadi.WADISessionManager;
029:        import org.apache.geronimo.openejb.cluster.infra.NetworkConnectorTracker;
030:        import org.apache.openejb.OpenEJBException;
031:        import org.apache.openejb.core.CoreDeploymentInfo;
032:        import org.apache.openejb.spi.SecurityService;
033:        import org.codehaus.wadi.core.contextualiser.Invocation;
034:        import org.codehaus.wadi.core.contextualiser.InvocationException;
035:        import org.codehaus.wadi.core.manager.Manager;
036:        import org.codehaus.wadi.servicespace.ServiceRegistry;
037:        import org.codehaus.wadi.servicespace.ServiceSpace;
038:
039:        import com.agical.rmock.core.Action;
040:        import com.agical.rmock.core.MethodHandle;
041:        import com.agical.rmock.extension.junit.RMockTestCase;
042:
043:        /**
044:         *
045:         * @version $Rev:$ $Date:$
046:         */
047:        public class ClusteredStatefulContainerTest extends RMockTestCase {
048:
049:            private WADISessionManager sessionManager;
050:            private TransactionManager txManager;
051:            private SecurityService securityService;
052:            private ClusteredStatefulContainer container;
053:            private CoreDeploymentInfo deploymentInfo;
054:            private String deploymentId;
055:            private Method callMethod;
056:            private Manager wadiManager;
057:            private NetworkConnectorTracker tracker;
058:            private String primKey;
059:            private Class<Runnable> callInterface;
060:            private Object[] args;
061:
062:            @Override
063:            protected void setUp() throws Exception {
064:                primKey = "primKey";
065:                callInterface = Runnable.class;
066:                callMethod = Runnable.class.getDeclaredMethod("run");
067:                args = new Object[0];
068:
069:                sessionManager = (WADISessionManager) mock(WADISessionManager.class);
070:                wadiManager = sessionManager.getManager();
071:                modify().multiplicity(expect.from(0));
072:
073:                sessionManager.registerListener(null);
074:                modify().multiplicity(expect.from(0)).args(is.NOT_NULL);
075:
076:                ServiceSpace serviceSpace = sessionManager.getServiceSpace();
077:                modify().multiplicity(expect.from(0));
078:                ServiceRegistry serviceRegistry = serviceSpace
079:                        .getServiceRegistry();
080:                modify().multiplicity(expect.from(0));
081:                serviceRegistry.getStartedService(NetworkConnectorTracker.NAME);
082:                modify().multiplicity(expect.from(0));
083:                tracker = (NetworkConnectorTracker) mock(NetworkConnectorTracker.class);
084:                modify().returnValue(tracker);
085:
086:                txManager = (TransactionManager) mock(TransactionManager.class);
087:                securityService = (SecurityService) mock(SecurityService.class);
088:                container = (ClusteredStatefulContainer) intercept(
089:                        ClusteredStatefulContainer.class, new Object[] { "id",
090:                                txManager, securityService, null, 1, 1, 1 });
091:                deploymentId = "deploymentId";
092:                deploymentInfo = new CoreDeploymentInfo(null, SFSB.class, null,
093:                        null, null, null, null, null, null, null, null) {
094:                    @Override
095:                    public Object getDeploymentID() {
096:                        return deploymentId;
097:                    }
098:                };
099:            }
100:
101:            public void testInvokeBusinessMethodForUnknownDeploymentThrowsOEJBE()
102:                    throws Exception {
103:                startVerification();
104:                try {
105:                    container.businessMethod(deploymentInfo, primKey,
106:                            callInterface, callMethod, args);
107:                    fail();
108:                } catch (OpenEJBException e) {
109:                }
110:            }
111:
112:            public void testInvokeRemoteMethodForUnknownDeploymentThrowsOEJBE()
113:                    throws Exception {
114:                startVerification();
115:                try {
116:                    container.removeEJBObject(deploymentInfo, primKey,
117:                            callInterface, callMethod, args);
118:                    fail();
119:                } catch (OpenEJBException e) {
120:                }
121:            }
122:
123:            public void testOEJBIsRethrownForBusinessMethod() throws Exception {
124:                new OEJBIsRethrownTest() {
125:                    @Override
126:                    protected void executeMethod() throws OpenEJBException {
127:                        container.businessMethod(deploymentInfo, primKey,
128:                                callInterface, callMethod, args);
129:                    }
130:
131:                    @Override
132:                    protected void executeSuperMethod() throws OpenEJBException {
133:                        container.super BusinessMethod(deploymentInfo, primKey,
134:                                callInterface, callMethod, args);
135:                    }
136:                }.executeTest();
137:            }
138:
139:            public void testOEJBIsRethrownForRemoveMethod() throws Exception {
140:                new OEJBIsRethrownTest() {
141:                    @Override
142:                    protected void executeMethod() throws OpenEJBException {
143:                        container.removeEJBObject(deploymentInfo, primKey,
144:                                callInterface, callMethod, args);
145:                    }
146:
147:                    @Override
148:                    protected void executeSuperMethod() throws OpenEJBException {
149:                        container.super RemoveEJBObject(deploymentInfo, primKey,
150:                                callInterface, callMethod, args);
151:                    }
152:                }.executeTest();
153:            }
154:
155:            protected abstract class OEJBIsRethrownTest {
156:                public void executeTest() throws Exception {
157:                    recordContextualiseInvocation();
158:
159:                    executeSuperMethod();
160:                    OpenEJBException exception = new OpenEJBException();
161:                    modify().throwException(exception);
162:
163:                    startVerification();
164:
165:                    container.addSessionManager(deploymentId, sessionManager);
166:
167:                    try {
168:                        executeMethod();
169:                        fail();
170:                    } catch (OpenEJBException e) {
171:                        assertSame(exception, e);
172:                    }
173:                }
174:
175:                protected abstract void executeSuperMethod()
176:                        throws OpenEJBException;
177:
178:                protected abstract void executeMethod() throws OpenEJBException;
179:            }
180:
181:            public void testBusinessMethodInvokationOK() throws Exception {
182:                new MethodIsExecutedTest() {
183:                    @Override
184:                    protected Object executeMethod() throws OpenEJBException {
185:                        return container.businessMethod(deploymentInfo,
186:                                primKey, callInterface, callMethod, args);
187:                    }
188:
189:                    @Override
190:                    protected void executeSuperMethod() throws OpenEJBException {
191:                        container.super BusinessMethod(deploymentInfo, primKey,
192:                                callInterface, callMethod, args);
193:                    }
194:                }.executeTest();
195:            }
196:
197:            public void testRemoveMethodInvokationOK() throws Exception {
198:                new MethodIsExecutedTest() {
199:                    @Override
200:                    protected Object executeMethod() throws OpenEJBException {
201:                        return container.removeEJBObject(deploymentInfo,
202:                                primKey, callInterface, callMethod, args);
203:                    }
204:
205:                    @Override
206:                    protected void executeSuperMethod() throws OpenEJBException {
207:                        container.super RemoveEJBObject(deploymentInfo, primKey,
208:                                callInterface, callMethod, args);
209:                    }
210:                }.executeTest();
211:            }
212:
213:            protected abstract class MethodIsExecutedTest {
214:                public void executeTest() throws Exception {
215:                    recordContextualiseInvocation();
216:
217:                    executeSuperMethod();
218:                    Object result = new Object();
219:                    modify().returnValue(result);
220:
221:                    startVerification();
222:
223:                    container.addSessionManager(deploymentId, sessionManager);
224:
225:                    Object actualResult = executeMethod();
226:                    assertSame(result, actualResult);
227:                }
228:
229:                protected abstract void executeSuperMethod()
230:                        throws OpenEJBException;
231:
232:                protected abstract Object executeMethod()
233:                        throws OpenEJBException;
234:            }
235:
236:            public void testGetLocationsRetunsNullWhenDeploymentIsNotRegistered()
237:                    throws Exception {
238:                startVerification();
239:
240:                assertNull(container.getLocations(deploymentInfo));
241:            }
242:
243:            public void testGetLocationsOK() throws Exception {
244:                tracker.getConnectorURIs(deploymentId);
245:                URI location = new URI("ejbd://host:1");
246:                modify().returnValue(Collections.singleton(location));
247:
248:                startVerification();
249:
250:                container.addSessionManager(deploymentId, sessionManager);
251:
252:                URI[] actualLocations = container.getLocations(deploymentInfo);
253:                assertEquals(1, actualLocations.length);
254:                assertSame(location, actualLocations[0]);
255:            }
256:
257:            public static class SFSB implements  Runnable {
258:                public void run() {
259:                }
260:            }
261:
262:            protected void recordContextualiseInvocation()
263:                    throws InvocationException {
264:                wadiManager.contextualise(null);
265:                modify().args(is.NOT_NULL).perform(new Action() {
266:                    public Object invocation(Object[] arg0, MethodHandle arg1)
267:                            throws Throwable {
268:                        ((Invocation) arg0[0]).invoke();
269:                        return true;
270:                    }
271:                });
272:            }
273:
274:        }
w__w_w_.___j__a_v___a__2s__.c___o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.