Source Code Cross Referenced for ClusteredManagerTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » tomcat » cluster » 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.tomcat.cluster 
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.tomcat.cluster;
021:
022:        import java.io.IOException;
023:        import java.util.HashMap;
024:        import java.util.Map;
025:
026:        import javax.servlet.http.HttpSession;
027:
028:        import org.apache.catalina.Context;
029:        import org.apache.catalina.Session;
030:        import org.apache.geronimo.clustering.SessionListener;
031:        import org.apache.geronimo.clustering.SessionManager;
032:
033:        import com.agical.rmock.core.describe.ExpressionDescriber;
034:        import com.agical.rmock.core.match.operator.AbstractExpression;
035:        import com.agical.rmock.extension.junit.RMockTestCase;
036:
037:        /**
038:         *
039:         * @version $Rev:$ $Date:$
040:         */
041:        public class ClusteredManagerTest extends RMockTestCase {
042:            private SessionManager sessionManager;
043:            private SessionListener sessionListener;
044:            private String sessionId;
045:            private Context context;
046:
047:            @Override
048:            protected void setUp() throws Exception {
049:                sessionId = "sessionId";
050:
051:                sessionManager = (SessionManager) mock(SessionManager.class);
052:                sessionManager.registerListener(null);
053:                modify().args(new AbstractExpression() {
054:                    public void describeWith(ExpressionDescriber arg0)
055:                            throws IOException {
056:                    }
057:
058:                    public boolean passes(Object arg0) {
059:                        sessionListener = (SessionListener) arg0;
060:                        return true;
061:                    }
062:                });
063:
064:                context = (Context) mock(Context.class);
065:
066:                context.getSessionTimeout();
067:                modify().returnValue(10);
068:
069:                context.addPropertyChangeListener(null);
070:                modify().args(is.NOT_NULL);
071:
072:                context.getApplicationLifecycleListeners();
073:                modify().multiplicity(expect.from(0));
074:
075:                context.getApplicationEventListeners();
076:                modify().multiplicity(expect.from(0));
077:            }
078:
079:            public void testCreatedSession() throws Exception {
080:                recordCreateUnderlyingSession();
081:
082:                startVerification();
083:
084:                ClusteredManager manager = newManager();
085:                Session createdSession = manager.createSession(null);
086:                assertTrue(createdSession.isValid());
087:
088:                HttpSession httpSession = createdSession.getSession();
089:                assertEquals("value", httpSession.getAttribute("key"));
090:                assertTrue(httpSession.isNew());
091:
092:                assertSame(createdSession, manager.findSession(sessionId));
093:            }
094:
095:            public void testSessionDestructionRemovesSession() throws Exception {
096:                org.apache.geronimo.clustering.Session underlyingSession = recordCreateUnderlyingSession();
097:
098:                startVerification();
099:
100:                ClusteredManager manager = newManager();
101:                manager.createSession(null);
102:
103:                sessionListener.notifySessionDestruction(underlyingSession);
104:
105:                assertNull(manager.findSession(sessionId));
106:            }
107:
108:            public void testOutboundSessionDestructionRemovesSession()
109:                    throws Exception {
110:                org.apache.geronimo.clustering.Session underlyingSession = recordCreateUnderlyingSession();
111:
112:                startVerification();
113:
114:                ClusteredManager manager = newManager();
115:                manager.createSession(null);
116:
117:                sessionListener
118:                        .notifyOutboundSessionMigration(underlyingSession);
119:
120:                assertNull(manager.findSession(sessionId));
121:            }
122:
123:            public void testInboundSessionMigrationAddsSession()
124:                    throws Exception {
125:                org.apache.geronimo.clustering.Session underlyingSession = (org.apache.geronimo.clustering.Session) mock(org.apache.geronimo.clustering.Session.class);
126:                recordUnderlyingSessionState(underlyingSession);
127:
128:                startVerification();
129:
130:                ClusteredManager manager = newManager();
131:
132:                sessionListener
133:                        .notifyInboundSessionMigration(underlyingSession);
134:
135:                Session foundSession = manager.findSession(sessionId);
136:                assertNotNull(foundSession);
137:
138:                assertTrue(foundSession.isValid());
139:
140:                HttpSession httpSession = foundSession.getSession();
141:                assertEquals("value", httpSession.getAttribute("key"));
142:                assertFalse(httpSession.isNew());
143:            }
144:
145:            public void testInvalidateSessionReleasesUnderlyingSession()
146:                    throws Exception {
147:                org.apache.geronimo.clustering.Session underlyingSession = recordCreateUnderlyingSession();
148:                underlyingSession.release();
149:
150:                startVerification();
151:
152:                ClusteredManager manager = newManager();
153:                Session session = manager.createSession(null);
154:                HttpSession httpSession = session.getSession();
155:                httpSession.invalidate();
156:            }
157:
158:            public void testSessionEndAccessTriggersOnEndAccess()
159:                    throws Exception {
160:                org.apache.geronimo.clustering.Session underlyingSession = recordCreateUnderlyingSession();
161:                underlyingSession.onEndAccess();
162:
163:                startVerification();
164:
165:                ClusteredManager manager = newManager();
166:                Session session = manager.createSession(null);
167:                session.endAccess();
168:            }
169:
170:            private org.apache.geronimo.clustering.Session recordCreateUnderlyingSession()
171:                    throws Exception {
172:                org.apache.geronimo.clustering.Session underlyingSession = sessionManager
173:                        .createSession(sessionId);
174:                recordUnderlyingSessionState(underlyingSession);
175:
176:                return underlyingSession;
177:            }
178:
179:            private void recordUnderlyingSessionState(
180:                    org.apache.geronimo.clustering.Session underlyingSession) {
181:                underlyingSession.getSessionId();
182:                modify().multiplicity(expect.from(0)).returnValue(sessionId);
183:
184:                underlyingSession.getState();
185:                Map attributes = new HashMap();
186:                attributes.put("key", "value");
187:                modify().returnValue(attributes);
188:            }
189:
190:            private ClusteredManager newManager() {
191:                ClusteredManager manager = new ClusteredManager(sessionManager) {
192:                    @Override
193:                    protected synchronized String generateSessionId() {
194:                        return sessionId;
195:                    }
196:                };
197:                manager.setContainer(context);
198:                return manager;
199:            }
200:
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.