Source Code Cross Referenced for HTMLOutputModule.java in  » Testing » mockrunner-0.4 » com » mockrunner » base » 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 » mockrunner 0.4 » com.mockrunner.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.base;
002:
003:        import java.io.BufferedReader;
004:        import java.io.StringReader;
005:
006:        import com.mockrunner.mock.web.WebMockObjectFactory;
007:        import com.mockrunner.util.common.StringUtil;
008:        import com.mockrunner.util.web.XmlUtil;
009:
010:        /**
011:         * Base class for modules which produce HTML
012:         * code as output. These modules have to implement
013:         * {@link #getOutput}. The HTML code is provided
014:         * in different formats, e.g. as parsed XML
015:         * documents.
016:         */
017:        public abstract class HTMLOutputModule extends WebTestModule {
018:            private boolean caseSensitive;
019:
020:            public HTMLOutputModule(WebMockObjectFactory mockFactory) {
021:                super (mockFactory);
022:                caseSensitive = true;
023:            }
024:
025:            /**
026:             * Returns the output as a string. Concrete modules implement
027:             * this method.
028:             * @return the output
029:             */
030:            public abstract String getOutput();
031:
032:            /**
033:             * Returns the output as a <code>BufferedReader</code>. 
034:             * @return the output
035:             */
036:            public BufferedReader getOutputAsBufferedReader() {
037:                return new BufferedReader(new StringReader(getOutput()));
038:            }
039:
040:            /**
041:             * Parses the output with the NekoHTML parser and returns it
042:             * as a W3C XML document. Throws a {@link NestedApplicationException} 
043:             * if the output is not parsable. NekoHTML is quite good in fixing sloppy
044:             * HTML code. If you want to use a different parser configuration,
045:             * you can use the method {@link com.mockrunner.util.web.XmlUtil#parse} 
046:             * to parse the string output yourself. Please note that
047:             * HTML parsing is not very fast and may slow down
048:             * your test suite.
049:             * @return the output as <code>org.w3c.dom.Document</code>
050:             * @throws RuntimeException if a parsing error occurs
051:             */
052:            public org.w3c.dom.Document getOutputAsW3CDocument() {
053:                return XmlUtil.parseHTML(getOutput());
054:            }
055:
056:            /**
057:             * Parses the output with the NekoHTML parser and returns it
058:             * as a JDOM XML document. Throws a {@link NestedApplicationException} 
059:             * if the output is not parsable. NekoHTML is quite good in fixing sloppy
060:             * HTML code. If you want to use a different parser configuration,
061:             * you can use the method {@link com.mockrunner.util.web.XmlUtil#parse} 
062:             * to parse the string output yourself. Please note that
063:             * HTML parsing is not very fast and may slow down
064:             * your test suite.
065:             * @return the output as <code>org.jdom.Document</code>
066:             * @throws RuntimeException if a parsing error occurs
067:             */
068:            public org.jdom.Document getOutputAsJDOMDocument() {
069:                return XmlUtil.createJDOMDocument(getOutputAsW3CDocument());
070:            }
071:
072:            /**
073:             * Parses the output with the NekoHTML parser and returns it
074:             * as fixed, wellformed XML. Throws a {@link NestedApplicationException} 
075:             * if the output is not parsable. NekoHTML is quite good in fixing sloppy
076:             * HTML code. If you want to use a different parser configuration,
077:             * you can use the method {@link com.mockrunner.util.web.XmlUtil#parse} 
078:             * to parse the string output yourself. Please note that
079:             * HTML parsing is not very fast and may slow down
080:             * your test suite.
081:             * @return the output as wellformed XML
082:             * @throws RuntimeException if a parsing error occurs
083:             */
084:            public String getOutputAsWellformedXML() {
085:                return XmlUtil
086:                        .createStringFromJDOMDocument(getOutputAsJDOMDocument());
087:            }
088:
089:            /**
090:             * Set if {@link #verifyOutput}, {@link #verifyOutputContains}
091:             * and {@link #verifyOutputRegularExpression}.
092:             * should compare case sensitive. Default is <code>true</code>.
093:             * @param caseSensitive enable or disable case sensitivity
094:             */
095:            public void setCaseSensitive(boolean caseSensitive) {
096:                this .caseSensitive = caseSensitive;
097:            }
098:
099:            /**
100:             * Verifies the tag output.
101:             * @param expectedOutput the expected output.
102:             * @throws VerifyFailedException if verification fails
103:             */
104:            public void verifyOutput(String expectedOutput) {
105:                String actualOutput = getOutput();
106:                if (!StringUtil.matchesExact(actualOutput, expectedOutput,
107:                        caseSensitive)) {
108:                    throw new VerifyFailedException("actual output: "
109:                            + actualOutput + " does not match expected output");
110:                }
111:            }
112:
113:            /**
114:             * Verifies if the output contains the specified data.
115:             * @param expectedOutput the data
116:             * @throws VerifyFailedException if verification fails
117:             */
118:            public void verifyOutputContains(String expectedOutput) {
119:                String actualOutput = getOutput();
120:                if (!StringUtil.matchesContains(actualOutput, expectedOutput,
121:                        caseSensitive)) {
122:                    throw new VerifyFailedException("actual output: "
123:                            + actualOutput + " does not match expected output");
124:                }
125:            }
126:
127:            /**
128:             * Verifies if the output matches the specified regular expression.
129:             * @param expression the data
130:             * @throws VerifyFailedException if verification fails
131:             */
132:            public void verifyOutputRegularExpression(String expression) {
133:                String actualOutput = getOutput();
134:                if (!StringUtil.matchesPerl5(actualOutput, expression,
135:                        caseSensitive)) {
136:                    throw new VerifyFailedException("actual output: "
137:                            + actualOutput + " does not match expected output");
138:                }
139:            }
140:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.