Source Code Cross Referenced for CookieSettingTest.java in  » Net » Terracotta » com » tctest » server » appserver » unit » 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 » Net » Terracotta » com.tctest.server.appserver.unit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tctest.server.appserver.unit;
006:
007:        import com.meterware.httpunit.WebResponse;
008:        import com.tc.test.server.appserver.AppServerFactory;
009:        import com.tc.test.server.appserver.deployment.AbstractDeploymentTest;
010:        import com.tc.test.server.appserver.deployment.Deployment;
011:        import com.tc.test.server.appserver.deployment.DeploymentBuilder;
012:        import com.tc.test.server.appserver.deployment.GenericServer;
013:        import com.tc.test.server.appserver.deployment.ServerTestSetup;
014:        import com.tc.test.server.appserver.deployment.WebApplicationServer;
015:        import com.tc.test.server.appserver.was6x.Was6xAppServer;
016:        import com.tc.test.server.util.TcConfigBuilder;
017:        import com.tc.util.io.TCFileUtils;
018:        import com.tctest.webapp.servlets.OkServlet;
019:
020:        import java.io.File;
021:        import java.text.SimpleDateFormat;
022:        import java.util.Date;
023:        import java.util.HashMap;
024:        import java.util.Iterator;
025:        import java.util.Map;
026:        import java.util.Set;
027:
028:        import junit.framework.Test;
029:
030:        /**
031:         * @author hhuynh
032:         */
033:        public class CookieSettingTest extends AbstractDeploymentTest {
034:            private static final String CONTEXT = "CookieSettingTest";
035:            private static Deployment deployment;
036:            private static TcConfigBuilder tcConfigBuilder;
037:            private static WebApplicationServer server0;
038:            private static WebApplicationServer server1;
039:
040:            public CookieSettingTest() {
041:                //
042:            }
043:
044:            public static Test suite() {
045:                return new ServerTestSetup(CookieSettingTest.class);
046:            }
047:
048:            protected boolean shouldKillAppServersEachRun() {
049:                return false;
050:            }
051:
052:            public void setUp() throws Exception {
053:                super .setUp();
054:
055:                if (deployment == null) {
056:                    tcConfigBuilder = new TcConfigBuilder();
057:                    tcConfigBuilder.addWebApplication(CONTEXT);
058:
059:                    deployment = makeDeployment();
060:
061:                    // server0 is NOT enabled with DSO
062:                    GenericServer.setDsoEnabled(false);
063:                    server0 = makeWebApplicationServer(tcConfigBuilder);
064:                    server0.addWarDeployment(deployment, CONTEXT);
065:                    setCookieForWebsphere(server0);
066:                    server0.start();
067:
068:                    // server1 is enabled with DSO
069:                    GenericServer.setDsoEnabled(true);
070:                    server1 = makeWebApplicationServer(tcConfigBuilder);
071:                    server1.addWarDeployment(deployment, CONTEXT);
072:                    setCookieForWebsphere(server1);
073:                    server1.start();
074:                }
075:            }
076:
077:            public void testCookieSetting() throws Exception {
078:                System.out.println("Hitting server0...");
079:                WebResponse response0 = server0.ping("/" + CONTEXT + "/ok");
080:                System.out.println("Cookie from server0 w/o DSO: "
081:                        + response0.getHeaderField("Set-Cookie"));
082:
083:                System.out.println("Hitting server1...");
084:                WebResponse response1 = server1.ping("/" + CONTEXT + "/ok");
085:                System.out.println("Cookie from server1 w/ DSO: "
086:                        + response1.getHeaderField("Set-Cookie"));
087:
088:                assertCookie(response0.getHeaderField("Set-Cookie"), response1
089:                        .getHeaderField("Set-Cookie"));
090:            }
091:
092:            private Deployment makeDeployment() throws Exception {
093:                DeploymentBuilder builder = makeDeploymentBuilder(CONTEXT
094:                        + ".war");
095:                builder.addServlet("OkServlet", "/ok/*", OkServlet.class, null,
096:                        false);
097:                builder.addSessionConfig("session-timeout", "69");
098:
099:                // add container specific descriptor
100:                if (AppServerFactory.getCurrentAppServerId() == AppServerFactory.WEBLOGIC) {
101:                    if (AppServerFactory.getCurrentAppServerMajorVersion()
102:                            .equals("8")) {
103:                        builder
104:                                .addResourceFullpath(
105:                                        "/com/tctest/server/appserver/unit/cookiesettingtest",
106:                                        "weblogic81.xml",
107:                                        "WEB-INF/weblogic.xml");
108:                    }
109:                    if (AppServerFactory.getCurrentAppServerMajorVersion()
110:                            .equals("9")) {
111:                        builder
112:                                .addResourceFullpath(
113:                                        "/com/tctest/server/appserver/unit/cookiesettingtest",
114:                                        "weblogic92.xml",
115:                                        "WEB-INF/weblogic.xml");
116:                    }
117:                }
118:
119:                return builder.makeDeployment();
120:            }
121:
122:            private void setCookieForWebsphere(WebApplicationServer server)
123:                    throws Exception {
124:                if (AppServerFactory.getCurrentAppServerId() == AppServerFactory.WEBSPHERE) {
125:                    System.out.println("Setting cookie for websphere...");
126:                    File cookieSettingsScript = TCFileUtils
127:                            .getResourceFile("/com/tctest/server/appserver/unit/cookiesettingtest/cookiesettings.py");
128:                    Was6xAppServer wasServer = (Was6xAppServer) ((GenericServer) server)
129:                            .getAppServer();
130:                    wasServer.setExtraScript(cookieSettingsScript);
131:                }
132:            }
133:
134:            private void assertCookie(String expected, String actual)
135:                    throws Exception {
136:                SimpleDateFormat formatter = new SimpleDateFormat(
137:                        "EEE, dd MMM yyyy HH:mm:ss z");
138:
139:                Map expectedCookie = toHash(expected);
140:                Map actualCookie = toHash(actual);
141:
142:                // all keys are matched
143:                assertEquals(expectedCookie.keySet(), actualCookie.keySet());
144:
145:                // all content are matched exception [J]SESSIONID
146:                Set keys = expectedCookie.keySet();
147:                for (Iterator it = keys.iterator(); it.hasNext();) {
148:                    String key = (String) it.next();
149:
150:                    // expires time need to match appromixately within 15s of each other
151:                    if (key.equalsIgnoreCase("expires")) {
152:                        // websphere doesn't use "-" between date when the other webapps do
153:                        // strip them out to be consistent
154:                        Date expectedDate = formatter
155:                                .parse(((String) expectedCookie.get(key))
156:                                        .replace('-', ' '));
157:                        Date actualDate = formatter
158:                                .parse(((String) actualCookie.get(key))
159:                                        .replace('-', ' '));
160:                        assertTrue(Math.abs(actualDate.getTime()
161:                                - expectedDate.getTime()) < 15 * 1000);
162:                        continue;
163:                    }
164:
165:                    if (key.toUpperCase().endsWith("SESSIONID")) {
166:                        switch (AppServerFactory.getCurrentAppServerId()) {
167:                        case AppServerFactory.WEBLOGIC:
168:                        case AppServerFactory.WEBSPHERE:
169:                            assertEquals(key.toUpperCase(), "CUSTOMSESSIONID");
170:                            break;
171:                        default:
172:                            assertEquals(key.toUpperCase(), "JSESSIONID");
173:                        }
174:                    } else {
175:                        assertEquals(expectedCookie.get(key), actualCookie
176:                                .get(key));
177:                    }
178:                }
179:
180:            }
181:
182:            private Map toHash(String cookieString) {
183:                Map map = new HashMap();
184:                String[] tokens = cookieString.split(";");
185:                for (int i = 0; i < tokens.length; i++) {
186:                    String[] name_value = tokens[i].trim().split("=");
187:                    if (name_value.length == 2) {
188:                        map.put(name_value[0], name_value[1]);
189:                    } else {
190:                        map.put(name_value[0], "");
191:                    }
192:                }
193:                return map;
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.