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


001:        // Copyright © 2002-2007 Canoo Engineering AG, Switzerland.
002:        package com.canoo.webtest.engine;
003:
004:        import java.util.Collections;
005:        import java.util.HashMap;
006:        import java.util.Map;
007:
008:        import org.apache.log4j.Logger;
009:
010:        import com.canoo.webtest.ant.WebtestTask;
011:        import com.canoo.webtest.boundary.ResetScriptRunner;
012:        import com.canoo.webtest.engine.xpath.XPathHelper;
013:        import com.canoo.webtest.steps.Step;
014:        import com.gargoylesoftware.htmlunit.Page;
015:        import com.gargoylesoftware.htmlunit.WebClient;
016:        import com.gargoylesoftware.htmlunit.html.HtmlForm;
017:        import com.gargoylesoftware.htmlunit.html.HtmlPage;
018:
019:        /**
020:         * Represents context information for a webtest.
021:         *
022:         * @author unknown
023:         * @author Marc Guillemot
024:         * @author Paul King
025:         */
026:        public class Context {
027:            private static final Logger LOG = Logger.getLogger(Context.class);
028:            /**
029:             * The name identifiying the default {@link WebClientContext} that is the current one at test startup.
030:             */
031:            public static final String KEY_DEFAULT_WEBCLIENTCONTEXT = "default";
032:
033:            private int fCurrentStepIndex;
034:            private WebtestTask fWebtest;
035:            private boolean fPrepared;
036:            private Map fContextStore = new HashMap();
037:            private ResetScriptRunner fSavedRunner;
038:
039:            private final XPathHelper fXPathHelper = new XPathHelper();
040:
041:            private WebClientContext fCurrentWebClientContext = new WebClientContext();
042:            private final Map fWebClientContexts = new HashMap();
043:
044:            public Context(final WebtestTask webtest) {
045:                fWebtest = webtest;
046:                fWebClientContexts.put(KEY_DEFAULT_WEBCLIENTCONTEXT,
047:                        fCurrentWebClientContext);
048:            }
049:
050:            public boolean containsKey(final String key) {
051:                return fContextStore.containsKey(key);
052:            }
053:
054:            public Object get(final String key) {
055:                return fContextStore.get(key);
056:            }
057:
058:            /**
059:             * Shortcut method to get the configuration of the
060:             *
061:             * @return the configuration
062:             * @see WebtestTask
063:             */
064:            public Configuration getConfig() {
065:                return getWebtest().getConfig();
066:            }
067:
068:            /**
069:             * Delegates to current {@link WebClientContext}
070:             *
071:             * @see #getCurrentWebClientContext()
072:             * @see WebClientContext#getCurrentForm
073:             */
074:            public HtmlForm getCurrentForm() {
075:                return getCurrentWebClientContext().getCurrentForm();
076:            }
077:
078:            /**
079:             * /**
080:             * Delegates to current {@link WebClientContext}
081:             *
082:             * @see #getCurrentWebClientContext()
083:             * @see WebClientContext#getCurrentHtmlResponse(Step)
084:             */
085:            public HtmlPage getCurrentHtmlResponse(final Step step) {
086:                return getCurrentWebClientContext()
087:                        .getCurrentHtmlResponse(step);
088:            }
089:
090:            /**
091:             * Delegates to current {@link WebClientContext}
092:             *
093:             * @see #getCurrentWebClientContext()
094:             * @see WebClientContext#getCurrentResponse()
095:             */
096:            public Page getCurrentResponse() {
097:                return getCurrentWebClientContext().getCurrentResponse();
098:            }
099:
100:            /**
101:             * Delegates to current {@link WebClientContext}
102:             *
103:             * @see #getCurrentResponseFile()
104:             * @see WebClientContext#getCurrentResponseFile()
105:             */
106:            public String getCurrentResponseFile() {
107:                return getCurrentWebClientContext().getCurrentResponseFile();
108:            }
109:
110:            public int getCurrentStepNumber() {
111:                return fCurrentStepIndex + 1;
112:            }
113:
114:            /**
115:             * Gets the currently active {@link WebClientContext}.
116:             *
117:             * @return the web client context
118:             */
119:            public WebClientContext getCurrentWebClientContext() {
120:                return fCurrentWebClientContext;
121:            }
122:
123:            public int getNumberOfSteps() {
124:                return getWebtest().getStepSequence().getSteps().size();
125:            }
126:
127:            /**
128:             * Gets the currently available {@link WebClientContext}
129:             *
130:             * @return an unmodifiable Map of (key, {@link WebClientContext})
131:             */
132:            public Map getWebClientContexts() {
133:                return Collections.unmodifiableMap(fWebClientContexts);
134:            }
135:
136:            /**
137:             * Defines the current {@link WebClientContext} creating it if none was previously registered
138:             * under this name.
139:             *
140:             * @param name the name of the {@link WebClientContext} to activate.
141:             *             The default {@link WebClientContext} is registered under the key {@link #KEY_DEFAULT_WEBCLIENTCONTEXT}.
142:             * @return the new current context
143:             */
144:            public WebClientContext defineCurrentWebClientContext(
145:                    final String name) {
146:                WebClientContext webClientContext = (WebClientContext) fWebClientContexts
147:                        .get(name);
148:                if (webClientContext == null) {
149:                    webClientContext = new WebClientContext();
150:                    webClientContext
151:                            .setWebClient(getConfig().createWebClient());
152:                    fWebClientContexts.put(name, webClientContext);
153:                    LOG.info("Created new WebClientContext for \"" + name
154:                            + "\"");
155:                }
156:                fCurrentWebClientContext = webClientContext;
157:                return webClientContext;
158:            }
159:
160:            /**
161:             * Delegates to current {@link WebClientContext}
162:             *
163:             * @see #getCurrentWebClientContext()
164:             * @see WebClientContext#getResponses()
165:             */
166:            public WebClientContext.StoredResponses getResponses() {
167:                return getCurrentWebClientContext().getResponses();
168:            }
169:
170:            public ResetScriptRunner getRunner() {
171:                return fSavedRunner;
172:            }
173:
174:            /**
175:             * Delegates to current {@link WebClientContext}
176:             *
177:             * @see #getCurrentWebClientContext()
178:             * @see WebClientContext#getSavedPassword()
179:             */
180:            public String getSavedPassword() {
181:                return getCurrentWebClientContext().getSavedPassword();
182:            }
183:
184:            /**
185:             * Delegates to current {@link WebClientContext}
186:             *
187:             * @see #getCurrentWebClientContext()
188:             * @see WebClientContext#getSavedUserName()
189:             */
190:            public String getSavedUserName() {
191:                return getCurrentWebClientContext().getSavedUserName();
192:            }
193:
194:            /**
195:             * Delegates to current {@link WebClientContext}
196:             *
197:             * @see #getCurrentWebClientContext()
198:             * @see WebClientContext#getWebClient()
199:             */
200:            public WebClient getWebClient() {
201:                return getCurrentWebClientContext().getWebClient();
202:            }
203:
204:            /**
205:             * Gets the <webtest> for this context.
206:             *
207:             * @return the task
208:             */
209:            public WebtestTask getWebtest() {
210:                return fWebtest;
211:            }
212:
213:            /**
214:             * Gets the XPath helper used for this test. It will be responsible to
215:             * create the xpath objects with the right custom functions and variables.
216:             *
217:             * @return the helper
218:             */
219:            public XPathHelper getXPathHelper() {
220:                return fXPathHelper;
221:            }
222:
223:            public void increaseStepNumber() {
224:                fCurrentStepIndex += 1;
225:            }
226:
227:            public boolean isPrepared() {
228:                return fPrepared;
229:            }
230:
231:            // generic mechanism to extend context information
232:            public void put(final String key, final Object value) {
233:                LOG.debug("put(" + key + ", " + value + ")");
234:                fContextStore.put(key, value);
235:            }
236:
237:            public void remove(final String key) {
238:                fContextStore.remove(key);
239:            }
240:
241:            /**
242:             * Delegates to current {@link WebClientContext}
243:             *
244:             * @see #getCurrentWebClientContext()
245:             * @see WebClientContext#restorePreviousResponse()
246:             */
247:            public void restorePreviousResponse() {
248:                getCurrentWebClientContext().restorePreviousResponse();
249:            }
250:
251:            /**
252:             * Delegates to current {@link WebClientContext}
253:             *
254:             * @see #getCurrentWebClientContext()
255:             * @see WebClientContext#restoreResponses(com.canoo.webtest.engine.WebClientContext.StoredResponses)
256:             */
257:            public void restoreResponses(
258:                    final WebClientContext.StoredResponses savedResponses) {
259:                getCurrentWebClientContext().restoreResponses(savedResponses);
260:            }
261:
262:            /**
263:             * Delegates to current {@link WebClientContext}
264:             *
265:             * @see #getCurrentWebClientContext()
266:             * @see WebClientContext#restoreWindowListener()
267:             */
268:            public void restoreWindowListener() {
269:                getCurrentWebClientContext().restoreWindowListener();
270:            }
271:
272:            /**
273:             * Delegates to current {@link WebClientContext}
274:             *
275:             * @see #getCurrentWebClientContext()
276:             * @see WebClientContext#saveResponseAsCurrent(Page)
277:             */
278:            public void saveResponseAsCurrent(final Page page) {
279:                getCurrentWebClientContext().saveResponseAsCurrent(page);
280:            }
281:
282:            /**
283:             * Delegates to current {@link WebClientContext}
284:             *
285:             * @see #getCurrentWebClientContext()
286:             * @see WebClientContext#setCurrentForm(HtmlForm)
287:             */
288:            public void setCurrentForm(final HtmlForm form) {
289:                getCurrentWebClientContext().setCurrentForm(form);
290:            }
291:
292:            public void setPrepared(final boolean prepared) {
293:                fPrepared = prepared;
294:            }
295:
296:            public void setRunner(final ResetScriptRunner sr) {
297:                fSavedRunner = sr;
298:            }
299:
300:            /**
301:             * Delegates to current {@link WebClientContext}
302:             *
303:             * @see #getCurrentWebClientContext()
304:             * @see WebClientContext#setSavedPassword(String)
305:             */
306:            public void setSavedPassword(final String password) {
307:                getCurrentWebClientContext().setSavedPassword(password);
308:            }
309:
310:            /**
311:             * Delegates to current {@link WebClientContext}
312:             *
313:             * @see #getCurrentWebClientContext()
314:             * @see WebClientContext#setSavedUserName(String)
315:             */
316:            public void setSavedUserName(final String userName) {
317:                getCurrentWebClientContext().setSavedUserName(userName);
318:            }
319:
320:            /**
321:             * Delegates to current {@link WebClientContext}
322:             *
323:             * @see #getCurrentWebClientContext()
324:             * @see WebClientContext#setWebClient(WebClient)
325:             */
326:            public void setWebClient(final WebClient webClient) {
327:                getCurrentWebClientContext().setWebClient(webClient);
328:            }
329:
330:            /**
331:             * Delegates to current {@link WebClientContext}
332:             *
333:             * @see #getCurrentWebClientContext()
334:             * @see WebClientContext#suspendWindowListener()
335:             */
336:            public void suspendWindowListener() {
337:                getCurrentWebClientContext().suspendWindowListener();
338:            }
339:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.