Source Code Cross Referenced for TestCookieVersionSupport.java in  » Net » Apache-common-HttpClient » org » apache » commons » httpclient » cookie » 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 » Apache common HttpClient » org.apache.commons.httpclient.cookie 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $HeadURL: https://svn.apache.org/repos/asf/jakarta/httpcomponents/oac.hc3x/tags/HTTPCLIENT_3_1/src/test/org/apache/commons/httpclient/cookie/TestCookieVersionSupport.java $
003:         * $Revision: 480424 $
004:         * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005:         * ====================================================================
006:         *
007:         *  Licensed to the Apache Software Foundation (ASF) under one or more
008:         *  contributor license agreements.  See the NOTICE file distributed with
009:         *  this work for additional information regarding copyright ownership.
010:         *  The ASF licenses this file to You under the Apache License, Version 2.0
011:         *  (the "License"); you may not use this file except in compliance with
012:         *  the License.  You may obtain a copy of the License at
013:         *
014:         *      http://www.apache.org/licenses/LICENSE-2.0
015:         *
016:         *  Unless required by applicable law or agreed to in writing, software
017:         *  distributed under the License is distributed on an "AS IS" BASIS,
018:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019:         *  See the License for the specific language governing permissions and
020:         *  limitations under the License.
021:         * ====================================================================
022:         *
023:         * This software consists of voluntary contributions made by many
024:         * individuals on behalf of the Apache Software Foundation.  For more
025:         * information on the Apache Software Foundation, please see
026:         * <http://www.apache.org/>.
027:         */
028:
029:        package org.apache.commons.httpclient.cookie;
030:
031:        import java.io.IOException;
032:
033:        import junit.framework.Test;
034:        import junit.framework.TestSuite;
035:
036:        import org.apache.commons.httpclient.Cookie;
037:        import org.apache.commons.httpclient.Header;
038:        import org.apache.commons.httpclient.HttpClientTestBase;
039:        import org.apache.commons.httpclient.HttpState;
040:        import org.apache.commons.httpclient.HttpStatus;
041:        import org.apache.commons.httpclient.HttpVersion;
042:        import org.apache.commons.httpclient.methods.GetMethod;
043:        import org.apache.commons.httpclient.server.HttpService;
044:        import org.apache.commons.httpclient.server.SimpleRequest;
045:        import org.apache.commons.httpclient.server.SimpleResponse;
046:
047:        /**
048:         * Cookie version support tests.
049:         *
050:         * @author Oleg Kalnichevski
051:         * 
052:         * @version $Revision: 480424 $
053:         */
054:        public class TestCookieVersionSupport extends HttpClientTestBase {
055:
056:            // ------------------------------------------------------------ Constructor
057:            public TestCookieVersionSupport(final String testName)
058:                    throws IOException {
059:                super (testName);
060:            }
061:
062:            // ------------------------------------------------------------------- Main
063:            public static void main(String args[]) {
064:                String[] testCaseName = { TestCookieVersionSupport.class
065:                        .getName() };
066:                junit.textui.TestRunner.main(testCaseName);
067:            }
068:
069:            // ------------------------------------------------------- TestCase Methods
070:
071:            public static Test suite() {
072:                return new TestSuite(TestCookieVersionSupport.class);
073:            }
074:
075:            private static class CookieVer0Service implements  HttpService {
076:
077:                public CookieVer0Service() {
078:                    super ();
079:                }
080:
081:                public boolean process(final SimpleRequest request,
082:                        final SimpleResponse response) throws IOException {
083:                    HttpVersion httpversion = request.getRequestLine()
084:                            .getHttpVersion();
085:                    response.setStatusLine(httpversion, HttpStatus.SC_OK);
086:                    response.addHeader(new Header("Set-Cookie",
087:                            "name1=value1; path=/test"));
088:                    response.setBodyString("whatever");
089:                    return true;
090:                }
091:            }
092:
093:            public void testCookieVersionSupportHeader1() throws IOException {
094:                this .server.setHttpService(new CookieVer0Service());
095:                this .client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
096:                GetMethod httpget1 = new GetMethod("/test/");
097:                try {
098:                    this .client.executeMethod(httpget1);
099:                } finally {
100:                    httpget1.releaseConnection();
101:                }
102:                GetMethod httpget2 = new GetMethod("/test/");
103:                try {
104:                    this .client.executeMethod(httpget2);
105:                } finally {
106:                    httpget2.releaseConnection();
107:                }
108:                Header cookiesupport = httpget2.getRequestHeader("Cookie2");
109:                assertNotNull(cookiesupport);
110:                assertEquals("$Version=\"1\"", cookiesupport.getValue());
111:            }
112:
113:            private static class CookieVer1Service implements  HttpService {
114:
115:                public CookieVer1Service() {
116:                    super ();
117:                }
118:
119:                public boolean process(final SimpleRequest request,
120:                        final SimpleResponse response) throws IOException {
121:                    HttpVersion httpversion = request.getRequestLine()
122:                            .getHttpVersion();
123:                    response.setStatusLine(httpversion, HttpStatus.SC_OK);
124:                    response.addHeader(new Header("Set-Cookie",
125:                            "name1=value1; Path=\"/test\"; Version=\"1\""));
126:                    response.addHeader(new Header("Set-Cookie2",
127:                            "name2=value2; Path=\"/test\"; Version=\"1\""));
128:                    response.setBodyString("whatever");
129:                    return true;
130:                }
131:            }
132:
133:            public void testCookieVersionSupportHeader2() throws IOException {
134:                this .server.setHttpService(new CookieVer1Service());
135:                this .client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
136:                GetMethod httpget1 = new GetMethod("/test/");
137:                try {
138:                    this .client.executeMethod(httpget1);
139:                } finally {
140:                    httpget1.releaseConnection();
141:                }
142:                GetMethod httpget2 = new GetMethod("/test/");
143:                try {
144:                    this .client.executeMethod(httpget2);
145:                } finally {
146:                    httpget2.releaseConnection();
147:                }
148:                Header cookiesupport = httpget2.getRequestHeader("Cookie2");
149:                assertNull(cookiesupport);
150:            }
151:
152:            private static class CookieVer2Service implements  HttpService {
153:
154:                public CookieVer2Service() {
155:                    super ();
156:                }
157:
158:                public boolean process(final SimpleRequest request,
159:                        final SimpleResponse response) throws IOException {
160:                    HttpVersion httpversion = request.getRequestLine()
161:                            .getHttpVersion();
162:                    response.setStatusLine(httpversion, HttpStatus.SC_OK);
163:                    response.addHeader(new Header("Set-Cookie2",
164:                            "name2=value2; Path=\"/test\"; Version=\"2\""));
165:                    response.setBodyString("whatever");
166:                    return true;
167:                }
168:            }
169:
170:            public void testCookieVersionSupportHeader3() throws IOException {
171:                this .server.setHttpService(new CookieVer2Service());
172:                this .client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
173:                GetMethod httpget1 = new GetMethod("/test/");
174:                try {
175:                    this .client.executeMethod(httpget1);
176:                } finally {
177:                    httpget1.releaseConnection();
178:                }
179:                GetMethod httpget2 = new GetMethod("/test/");
180:                try {
181:                    this .client.executeMethod(httpget2);
182:                } finally {
183:                    httpget2.releaseConnection();
184:                }
185:                Header cookiesupport = httpget2.getRequestHeader("Cookie2");
186:                assertNotNull(cookiesupport);
187:                assertEquals("$Version=\"1\"", cookiesupport.getValue());
188:            }
189:
190:            private static class SetCookieVersionMixService implements 
191:                    HttpService {
192:
193:                public SetCookieVersionMixService() {
194:                    super ();
195:                }
196:
197:                public boolean process(final SimpleRequest request,
198:                        final SimpleResponse response) throws IOException {
199:                    HttpVersion httpversion = request.getRequestLine()
200:                            .getHttpVersion();
201:                    response.setStatusLine(httpversion, HttpStatus.SC_OK);
202:                    response.addHeader(new Header("Set-Cookie",
203:                            "name=wrong; Path=/test"));
204:                    response.addHeader(new Header("Set-Cookie2",
205:                            "name=right; Path=\"/test\"; Version=\"1\""));
206:                    response.setBodyString("whatever");
207:                    return true;
208:                }
209:            }
210:
211:            public static class TestHttpState extends HttpState {
212:
213:                public synchronized void addCookie(Cookie cookie) {
214:                    if (cookie != null) {
215:                        if ("localhost.local".equals(cookie.getDomain())) {
216:                            cookie.setDomain("localhost");
217:                        }
218:                        super .addCookie(cookie);
219:                    }
220:                }
221:            }
222:
223:            public void testSetCookieVersionMix() throws IOException {
224:                this .server.setHttpService(new SetCookieVersionMixService());
225:                this .client.setState(new TestHttpState());
226:                this .client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
227:                GetMethod httpget1 = new GetMethod("/test/");
228:                try {
229:                    this .client.executeMethod(httpget1);
230:                } finally {
231:                    httpget1.releaseConnection();
232:                }
233:                Cookie[] cookies = this .client.getState().getCookies();
234:                assertNotNull(cookies);
235:                assertEquals(1, cookies.length);
236:                assertEquals("right", cookies[0].getValue());
237:                assertTrue(cookies[0] instanceof  Cookie2);
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.