Source Code Cross Referenced for TestSampleTag.java in  » Testing » jakarta-cactus » org » apache » cactus » sample » servlet » 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 » jakarta cactus » org.apache.cactus.sample.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2001-2003 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus.sample.servlet;
021:
022:        import javax.servlet.jsp.tagext.Tag;
023:
024:        import org.apache.cactus.JspTestCase;
025:        import org.apache.cactus.WebResponse;
026:
027:        /**
028:         * Tests of the <code>SampleTag</code> class.
029:         *
030:         * @version $Id: TestSampleTag.java 238816 2004-02-29 16:36:46Z vmassol $
031:         */
032:        public class TestSampleTag extends JspTestCase {
033:            /**
034:             * Our tag instance to unit test
035:             */
036:            private SampleTag tag;
037:
038:            /**
039:             * @see TestCase#setUp()
040:             */
041:            public void setUp() {
042:                this .tag = new SampleTag();
043:                this .tag.setPageContext(this .pageContext);
044:            }
045:
046:            //-------------------------------------------------------------------------
047:
048:            /**
049:             * Tests whether doStartTag() will skip the body if the corresponding tag
050:             * attribute is set. Also tests whether an attribute put into page scope
051:             * before the tag executes will be output to the response.
052:             * 
053:             * @exception Exception if the test fails for an unexpected reason
054:             */
055:            public void testDoStartTag() throws Exception {
056:                //put something in page scope to see if it shows up in the response...
057:                this .pageContext.setAttribute("test-key", "test-value");
058:
059:                this .tag.setShowBody("false");
060:
061:                int result = this .tag.doStartTag();
062:
063:                //body should not show up
064:                assertEquals(Tag.SKIP_BODY, result);
065:            }
066:
067:            /**
068:             * Verifies that the output includes the output from doStartTag (a message
069:             * from the tag and the attribute set into page scope).
070:             * 
071:             * @param theResponse the response from the server side.
072:             */
073:            public void endDoStartTag(WebResponse theResponse) {
074:                // check that two of the lines output by the tag showed up in
075:                // the response
076:                assertContains(theResponse,
077:                        "The following attributes exist in page scope: <BR>");
078:
079:                assertContains(theResponse, "test-key = test-value <BR>");
080:            }
081:
082:            //-------------------------------------------------------------------------
083:
084:            /**
085:             * Test whether the tag's body will be shown if the corresponding attribute
086:             * is set.
087:             * 
088:             * @exception Exception if the test fails for an unexpected reason
089:             */
090:            public void testDoStartTagInclude() throws Exception {
091:                this .tag.setShowBody("true");
092:
093:                int result = this .tag.doStartTag();
094:
095:                //body should show up
096:                assertEquals(Tag.EVAL_BODY_INCLUDE, result);
097:            }
098:
099:            /**
100:             * The tag prints a message before the body is included, here we check that
101:             * the message shows up.
102:             * 
103:             * @param theResponse the response from the server side.
104:             */
105:            public void endDoStartTagInclude(WebResponse theResponse) {
106:                // check that the pre-body message printed by the tag shows up
107:                assertContains(theResponse, "Body Content Follows: <BR>");
108:            }
109:
110:            //-------------------------------------------------------------------------
111:
112:            /**
113:             * Checks if the tag will continue the page correctly if its stopPage
114:             * property is set to false.
115:             * 
116:             * @exception Exception if the test fails for an unexpected reason
117:             */
118:            public void testDoEndTagContinue() throws Exception {
119:                this .tag.setParent(new SampleTag());
120:                this .tag.setStopPage("false");
121:
122:                int result = this .tag.doEndTag();
123:
124:                assertEquals(Tag.EVAL_PAGE, result);
125:            }
126:
127:            /**
128:             * Checks whether the tag has printed a message indicating that it has a
129:             * parent tag.
130:             * 
131:             * @param theResponse the response from the server side.
132:             */
133:            public void endDoEndTagContinue(WebResponse theResponse) {
134:                assertContains(theResponse, "This tag has a parent. <BR>");
135:            }
136:
137:            //-------------------------------------------------------------------------
138:
139:            /**
140:             * Checks if the tag will signal that page processing should stop if
141:             * stopPage is set to "true"
142:             * 
143:             * @exception Exception if the test fails for an unexpected reason
144:             */
145:            public void testDoEndTagStop() throws Exception {
146:                //no parent set
147:                this .tag.setStopPage("true");
148:
149:                int result = this .tag.doEndTag();
150:
151:                assertEquals(Tag.SKIP_PAGE, result);
152:            }
153:
154:            /**
155:             * Checks whether the tag has printed a message indicating that it has a
156:             * parent tag. (In this case it should not.)
157:             * 
158:             * @param theResponse the response from the server side.
159:             */
160:            public void endDoEndTagStop(WebResponse theResponse) {
161:                String target = theResponse.getText();
162:                boolean containsMessage = target
163:                        .indexOf("This tag has a parent. <BR>") > 0;
164:                assertTrue(!containsMessage);
165:            }
166:
167:            //--------------------------------------------------------------------------
168:
169:            /**
170:             * Convenience function that asserts that a substring can be found in a
171:             * the returned HTTP response body.
172:             * 
173:             * @param theResponse the response from the server side.
174:             * @param theSubstring the substring to look for
175:             */
176:            public void assertContains(WebResponse theResponse,
177:                    String theSubstring) {
178:                String target = theResponse.getText();
179:
180:                if (target.indexOf(theSubstring) < 0) {
181:                    fail("Response did not contain the substring: ["
182:                            + theSubstring + "]");
183:                }
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.