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


001:        // Copyright © 2002-2007 Canoo Engineering AG, Switzerland.
002:        package com.canoo.webtest.steps.request;
003:
004:        import java.net.SocketTimeoutException;
005:
006:        import org.apache.log4j.Level;
007:        import org.apache.log4j.Logger;
008:        import org.apache.tools.ant.Project;
009:
010:        import com.agical.rmock.extension.junit.RMockTestCase;
011:        import com.canoo.webtest.engine.Configuration;
012:        import com.canoo.webtest.engine.Context;
013:        import com.canoo.webtest.engine.StepExecutionException;
014:        import com.canoo.webtest.engine.StepFailedException;
015:        import com.canoo.webtest.interfaces.IConnectionInitializer;
016:        import com.canoo.webtest.interfaces.IPropertyHandler;
017:        import com.canoo.webtest.security.ConnectionInitializationException;
018:        import com.canoo.webtest.self.BufferingAppender;
019:        import com.canoo.webtest.self.ContextStub;
020:        import com.canoo.webtest.self.TestBlock;
021:        import com.canoo.webtest.self.ThrowAssert;
022:        import com.canoo.webtest.steps.AbstractBrowserAction;
023:        import com.canoo.webtest.steps.BaseStepTestCase;
024:        import com.canoo.webtest.steps.StepUtil;
025:
026:        /**
027:         * @author Paul King
028:         * @author Marc Guillemot
029:         */
030:        public class TargetHelperTest extends RMockTestCase {
031:            private static final String OK_CUSTOM_INITIALIZER_CLASS_NAME = "com.canoo.webtest.steps.request.TargetHelperTest$NullConnectionInitializer";
032:            private static final String BAD_CUSTOM_INITIALIZER_CLASS_NAME = "com.canoo.webtest.steps.request.TargetHelperTest$ExceptionConnectionInitializer";
033:
034:            private AbstractBrowserAction fBrowserAction = new AbstractBrowserAction() {
035:                public void doExecute() {
036:                }
037:            };
038:            private TargetHelper fTargetHelper = new TargetHelper(
039:                    fBrowserAction);
040:            private final Context fTestContext = createContextStupWithoutSteps();
041:            private final BufferingAppender fBuffAppender = new BufferingAppender();
042:
043:            static ContextStub createContextStupWithoutSteps() {
044:                return new ContextStub() {
045:                    protected void initTestStepSequence(Project project) {
046:                        // nothing, we want to skip it here
047:                    }
048:                };
049:            }
050:
051:            protected void setUp() throws Exception {
052:                final Configuration testConfig = new Configuration();
053:                testConfig.setShowhtmlparseroutput(false);
054:                final IPropertyHandler handler = (IPropertyHandler) mock(
055:                        IPropertyHandler.class, "handler");
056:                testConfig.setPropertyHandler(handler);
057:                fTestContext.getWebtest().addConfig(testConfig);
058:
059:                BaseStepTestCase.executeStep(fBrowserAction); // coverage
060:
061:                Logger.getRootLogger().setLevel(Level.INFO); // ensure that the logged event we want to catch is not discarded
062:                Logger.getRootLogger().addAppender(fBuffAppender);
063:            }
064:
065:            protected void tearDown() throws Exception {
066:                super .tearDown();
067:                Logger.getRootLogger().removeAppender(fBuffAppender);
068:            }
069:
070:            public void testGotoTargetByUrl() throws Exception {
071:                startVerification();
072:                fBuffAppender.getEvents().clear();
073:                try {
074:                    fTargetHelper.getResponse(fTestContext, "targetUrl");
075:                } catch (final Exception e) {
076:                    /* ignore */
077:                }
078:                assertTrue("should be called by url", fBuffAppender
079:                        .allMessagesToString().indexOf("url") > -1);
080:            }
081:
082:            /**
083:             * Tests that SocketTimeoutException is catched and that a StepFailedException is rethrown
084:             * @throws Exception
085:             */
086:            public void testSocketTimeoutException() throws Exception {
087:                final String message = ThrowAssert.assertThrows(
088:                        StepFailedException.class, new TestBlock() {
089:                            public void call() throws Exception {
090:                                final Throwable t = new SocketTimeoutException(
091:                                        "blah SocketTimeoutException message");
092:                                StepUtil.handleException(t);
093:                            }
094:                        });
095:                assertEquals(
096:                        "Server took to long to answer: blah SocketTimeoutException message",
097:                        message);
098:            }
099:
100:            public void testInvokeCustomInitializer() throws Exception {
101:                ThrowAssert.assertThrows(StepExecutionException.class,
102:                        new TestBlock() {
103:                            public void call() throws Exception {
104:                                fTargetHelper.invokeCustomInitializer(
105:                                        fTestContext, "no.such.class");
106:                            }
107:                        });
108:                final String message = ThrowAssert.assertThrows(
109:                        StepExecutionException.class, new TestBlock() {
110:                            public void call() throws Exception {
111:                                fTargetHelper.invokeCustomInitializer(
112:                                        fTestContext,
113:                                        BAD_CUSTOM_INITIALIZER_CLASS_NAME);
114:                            }
115:                        });
116:                assertTrue(message
117:                        .startsWith("ConnectionInitializer raised exception"));
118:            }
119:
120:            public void testPrepareConversationWithProperCustomInitializer()
121:                    throws Exception {
122:                final IPropertyHandler customHandler = (IPropertyHandler) mock(
123:                        IPropertyHandler.class, "customHandler");
124:                customHandler
125:                        .getProperty(TargetHelper.CONNECTION_INITIALIZER_KEY);
126:                modify().returnValue(OK_CUSTOM_INITIALIZER_CLASS_NAME);
127:                startVerification();
128:                fTestContext.getConfig().setPropertyHandler(customHandler);
129:                ThrowAssert.assertPasses("normal pass", new TestBlock() {
130:                    public void call() throws Exception {
131:                        fTargetHelper.prepareConversationIfNeeded(fTestContext);
132:                    }
133:                });
134:            }
135:
136:            public static class ExceptionConnectionInitializer implements 
137:                    IConnectionInitializer {
138:                public void initializeConnection(final Configuration config)
139:                        throws ConnectionInitializationException {
140:                    throw new ConnectionInitializationException("xxx");
141:                }
142:            }
143:
144:            public static class NullConnectionInitializer implements 
145:                    IConnectionInitializer {
146:                public void initializeConnection(final Configuration config)
147:                        throws ConnectionInitializationException {
148:                    // just pass
149:                }
150:            }
151:
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.