Source Code Cross Referenced for CookieTest.java in  » Ajax » GWT » com » google » gwt » user » client » 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 » Ajax » GWT » com.google.gwt.user.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package com.google.gwt.user.client;
017:
018:        import com.google.gwt.junit.client.GWTTestCase;
019:
020:        import java.util.Collection;
021:        import java.util.Date;
022:
023:        /**
024:         * Test Case for {@link Cookies}.
025:         */
026:        public class CookieTest extends GWTTestCase {
027:
028:            public String getModuleName() {
029:                return "com.google.gwt.user.User";
030:            }
031:
032:            public void test() {
033:                // Make the cookie expire in one minute, so that they don't hang around
034:                // past the end of this test.
035:                Date expires = new Date(new Date().getTime() + (60 * 1000));
036:
037:                // Test setting a simple cookie.
038:                Cookies.setCookie("foo", "bar", expires);
039:                assertEquals("bar", Cookies.getCookie("foo"));
040:
041:                // Make sure that parsing cookies with embedded '=' works correctly.
042:                Cookies.setCookie("foo1", "foo=bar", expires);
043:                assertEquals("foo=bar", Cookies.getCookie("foo1"));
044:
045:                // Make sure that setting the second cookie doesn't clobber the first.
046:                assertEquals("bar", Cookies.getCookie("foo"));
047:
048:                // Make sure embedded ';' works as well.
049:                Cookies.setCookie("foo2", "foo;bar", expires);
050:
051:                // Differentiate null cookie from '' cookie.
052:                Cookies.setCookie("novalue", "", expires);
053:                assertEquals(Cookies.getCookie("novalue"), "");
054:                assertEquals(Cookies.getCookie("notpresent"), null);
055:            }
056:
057:            /*
058:             * Test that the cookie will expire correctly after a set amount of time,
059:             * but does not expire before that time. 
060:             */
061:            public void testExpires() {
062:                // Test that the cookie expires in 5 seconds
063:                Date expiresEarly = new Date(new Date().getTime() + (5 * 1000));
064:                Date expiresLate = new Date(new Date().getTime() + (60 * 1000));
065:                Cookies.setCookie("shouldExpireEarly", "early", expiresEarly);
066:                Cookies.setCookie("shouldExpireLate", "late", expiresLate);
067:                Cookies.setCookie("shouldNotExpire", "forever", null);
068:
069:                // Wait until the cookie expires before checking it
070:                Timer timer = new Timer() {
071:                    public void run() {
072:                        // Verify that the early expiring cookie does NOT exist
073:                        assertNull(Cookies.getCookie("shouldExpireEarly"));
074:
075:                        // Verify that the late expiring cookie does exist
076:                        assertEquals(Cookies.getCookie("shouldExpireLate"),
077:                                "late");
078:
079:                        // Verify the session cookie doesn't expire
080:                        assertEquals(Cookies.getCookie("shouldNotExpire"),
081:                                "forever");
082:                        Cookies.removeCookie("shouldNotExpire");
083:                        assertNull(Cookies.getCookie("shouldNotExpire"));
084:
085:                        // Finish the test
086:                        finishTest();
087:                    }
088:                };
089:                timer.schedule(5010);
090:                delayTestFinish(6 * 1000);
091:            }
092:
093:            /**
094:             * Test that removing cookies works correctly.
095:             */
096:            public void testRemoveCookie() {
097:                // First clear all cookies
098:                clearCookies();
099:
100:                // Set a few cookies
101:                Cookies.setCookie("test1", "value1");
102:                Cookies.setCookie("test2", "value2");
103:                Cookies.setCookie("test3", "value3");
104:                Collection<String> cookies = Cookies.getCookieNames();
105:                assertEquals(3, cookies.size());
106:
107:                // Remove a cookie
108:                Cookies.removeCookie("test2");
109:                assertEquals("value1", Cookies.getCookie("test1"));
110:                assertEquals(null, Cookies.getCookie("test2"));
111:                assertEquals("value3", Cookies.getCookie("test3"));
112:
113:                // Remove another cookie
114:                Cookies.removeCookie("test1");
115:                assertEquals(null, Cookies.getCookie("test1"));
116:                assertEquals(null, Cookies.getCookie("test2"));
117:                assertEquals("value3", Cookies.getCookie("test3"));
118:
119:                // Remove last cookie
120:                Cookies.removeCookie("test3");
121:                assertEquals(null, Cookies.getCookie("test1"));
122:                assertEquals(null, Cookies.getCookie("test2"));
123:                assertEquals(null, Cookies.getCookie("test3"));
124:                cookies = Cookies.getCookieNames();
125:                assertEquals(0, cookies.size());
126:            }
127:
128:            /**
129:             * Clear out all existing cookies.
130:             */
131:            private void clearCookies() {
132:                Collection<String> cookies = Cookies.getCookieNames();
133:                for (String cookie : cookies) {
134:                    Cookies.removeCookie(cookie);
135:                }
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.