Source Code Cross Referenced for StoreCookie.java in  » Testing » webtest » com » canoo » webtest » steps » store » 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 » Testing » webtest » com.canoo.webtest.steps.store 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright © 2004-2005 ASERT.
002:        // Parts Copyright © 2005 Canoo Engineering AG, Switzerland.
003:        // Released under the Canoo Webtest license.
004:        package com.canoo.webtest.steps.store;
005:
006:        import java.net.URL;
007:        import java.util.Map;
008:
009:        import org.apache.commons.httpclient.Cookie;
010:        import org.apache.commons.httpclient.HttpState;
011:        import org.apache.log4j.Logger;
012:
013:        import com.canoo.webtest.boundary.HttpClientBoundary;
014:        import com.canoo.webtest.engine.Context;
015:        import com.canoo.webtest.engine.StepFailedException;
016:        import com.canoo.webtest.util.MapUtil;
017:        import com.gargoylesoftware.htmlunit.WebClient;
018:
019:        /**
020:         * Stores a cookie value (from the Http Response) into a property.<p>
021:         * <p/>
022:         * Either ant or dynamic properties are supported. The property can
023:         * be checked subsequently with \"verifyProperty\".
024:         *
025:         * @author Paul King, ASERT
026:         * @author Denis N. Antonioli
027:         * @author Marc Guillemot
028:         * @webtest.step category="Core"
029:         * name="storeCookie"
030:         * description="Provides the ability to store an <key>HTTP</key> Cookie value for later checking."
031:         */
032:        public class StoreCookie extends BaseStoreStep {
033:            private static final Logger LOG = Logger
034:                    .getLogger(StoreCookie.class);
035:            private String fCookieName;
036:            private String fCookieValue; // will hold the value of the found cookie to give it to the report
037:
038:            /**
039:             * Sets the Name of the cookie of interest.<p>
040:             *
041:             * @param name The cookie Name
042:             * @webtest.parameter required="yes"
043:             * description="The name of the cookie of interest.
044:             * If the property name is not specified, the cookie name is used as key to store the value found."
045:             */
046:            public void setName(final String name) {
047:                fCookieName = name;
048:            }
049:
050:            public String getName() {
051:                return fCookieName;
052:            }
053:
054:            public void doExecute() {
055:                final Cookie[] cookies = getCookies(getContext());
056:                LOG.debug("Found " + cookies.length + " cookie(s)");
057:                if (cookies.length == 0) {
058:                    throw new StepFailedException("No cookies set!", this );
059:                }
060:                final Cookie cookie = findCookie(cookies);
061:                if (cookie == null)
062:                    throw new StepFailedException("Cookie \"" + fCookieName
063:                            + "\" not set!", this );
064:                else {
065:                    storeProperty(cookie.getValue(), getName());
066:                    fCookieValue = cookie.getValue();
067:                }
068:            }
069:
070:            /**
071:             * Adds the value of the found cookie
072:             */
073:            protected void addComputedParameters(final Map map) {
074:                MapUtil.putIfNotNull(map, "-> cookie value", fCookieValue);
075:            }
076:
077:            /**
078:             * Search the cookie with the requested property
079:             * @param cookies the cookies to search in
080:             * @return the first cookie found, <code>null</code> if none is found 
081:             */
082:            Cookie findCookie(final Cookie[] cookies) {
083:                for (int i = 0; i < cookies.length; i++) {
084:                    final Cookie cookie = cookies[i];
085:                    if (cookie.getName().equals(fCookieName)) {
086:                        return cookie;
087:                    }
088:                }
089:                return null;
090:            }
091:
092:            /**
093:             * Gets the cookies for the current page of the context
094:             * @param context the context
095:             * @return the cookies
096:             */
097:            public static Cookie[] getCookies(final Context context) {
098:                final URL url = context.getCurrentResponse().getWebResponse()
099:                        .getUrl();
100:                WebClient webClient = context.getWebClient();
101:                final HttpState stateForUrl = webClient.getWebConnection()
102:                        .getState();
103:                return HttpClientBoundary.getCookiesFromState(stateForUrl, url);
104:            }
105:
106:            /**
107:             * Verifies the parameters
108:             */
109:            protected void verifyParameters() {
110:                super .verifyParameters();
111:                nullParamCheck(fCookieName, "name");
112:                nullResponseCheck();
113:            }
114:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.