Source Code Cross Referenced for SampleEnhydraAppTestCase.java in  » J2EE » Enhydra-Demos » org » hamletsoft » enhydra » cactus » business » sample » 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 » J2EE » Enhydra Demos » org.hamletsoft.enhydra.cactus.business.sample 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Apache Software License, Version 1.1
003:         *
004:         * Copyright (c) 1999 The Apache Software Foundation.  All rights
005:         * reserved.
006:         *
007:         * Redistribution and use in source and binary forms, with or without
008:         * modification, are permitted provided that the following conditions
009:         * are met:
010:         *
011:         * 1. Redistributions of source code must retain the above copyright
012:         *    notice, this list of conditions and the following disclaimer.
013:         *
014:         * 2. Redistributions in binary form must reproduce the above copyright
015:         *    notice, this list of conditions and the following disclaimer in
016:         *    the documentation and/or other materials provided with the
017:         *    distribution.
018:         *
019:         * 3. The end-user documentation included with the redistribution, if
020:         *    any, must include the following acknowlegement:
021:         *       "This product includes software developed by the
022:         *        Apache Software Foundation (http://www.apache.org/)."
023:         *    Alternately, this acknowlegement may appear in the software itself,
024:         *    if and wherever such third-party acknowlegements normally appear.
025:         *
026:         * 4. The names "The Jakarta Project", "Cactus", and "Apache Software
027:         *    Foundation" must not be used to endorse or promote products derived
028:         *    from this software without prior written permission. For written
029:         *    permission, please contact apache@apache.org.
030:         *
031:         * 5. Products derived from this software may not be called "Apache"
032:         *    nor may "Apache" appear in their names without prior written
033:         *    permission of the Apache Group.
034:         *
035:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046:         * SUCH DAMAGE.
047:         * ====================================================================
048:         *
049:         * This software consists of voluntary contributions made by many
050:         * individuals on behalf of the Apache Software Foundation.  For more
051:         * information on the Apache Software Foundation, please see
052:         * <http://www.apache.org/>.
053:         *
054:         * formatted with JxBeauty (c) johann.langhofer@nextra.at
055:         */
056:
057:        package org.hamletsoft.enhydra.cactus.business.sample;
058:
059:        import org.hamletsoft.enhydra.cactus.business.EnhydraAppTestCase;
060:        import org.hamletsoft.enhydra.cactus.presentation.sample.SamplePO;
061:        import junit.framework.Test;
062:        import junit.framework.TestSuite;
063:        import org.apache.cactus.WebResponse;
064:        import java.io.IOException;
065:        import org.apache.cactus.WebRequest;
066:        import java.util.Map;
067:        import org.apache.cactus.client.authentication.BasicAuthentication;
068:        import com.lutris.http.BasicAuth;
069:        import com.lutris.http.BasicAuthResult;
070:        import org.apache.log4j.PropertyConfigurator;
071:
072:        // import junit.ui.*;
073:        /**
074:         * SampleEnhydraAppTestCase.java
075:         *
076:         *
077:         * Created: Thu Jan 31 11:39:48 2002
078:         *
079:         * @author <a href="mailto:hattori@hitachizosen.co.jp">Ryuji Hattori</a>
080:         * @version 1.0
081:         */
082:        public class SampleEnhydraAppTestCase extends EnhydraAppTestCase {
083:            static {
084:                // instructs PropertyConfigurator to parse a configuration file and set up logging accordingly
085:                PropertyConfigurator.configure("log_client.properties");
086:            }
087:
088:            public SampleEnhydraAppTestCase(String name) {
089:                super (name);
090:            }
091:
092:            /**
093:             * Start the tests.
094:             *
095:             * @param theArgs the arguments. Not used
096:             */
097:            public static void main(String[] theArgs) {
098:                junit.awtui.TestRunner
099:                        .main(new String[] { SampleEnhydraAppTestCase.class
100:                                .getName() });
101:            }
102:
103:            /*
104:             public static void main(String[] theArgs) {
105:             TestRunner.main(new String[] {
106:             SampleEnhydraAppTestCase.class.getName()});
107:             }
108:             */
109:            /**
110:             * @return a test suite (<code>TestSuite</code>) that includes all methods
111:             *         starting with "test"
112:             */
113:            public static Test suite() {
114:                // All methods starting with "test" will be executed in the test suite.
115:                return new TestSuite(SampleEnhydraAppTestCase.class);
116:            }
117:
118:            /**
119:             * Verify that we can assert the servlet output stream.
120:             */
121:            public void testReadOutputStream() throws Exception {
122:                SamplePO samplePO = new SamplePO();
123:                samplePO.run(comms);
124:            }
125:
126:            /**
127:             * Verify that we can assert the servlet output stream.
128:             *
129:             * @param theResponse the response from the server side.
130:             */
131:            public void endReadOutputStream(WebResponse theResponse)
132:                    throws IOException {
133:                String expected = SamplePO.Answer1;
134:                //"<html><head/><body>A GET request</body></html>";
135:                String result = theResponse.getText();
136:                assertEquals(expected, result);
137:            }
138:
139:            /**
140:             * Verify that we can simulate a GET request to a PO.
141:             *
142:             * @param theRequest the request object that serves to initialize the
143:             *                   HTTP connection to the server redirector.
144:             */
145:            public void beginPostMethod(WebRequest theRequest) {
146:                theRequest.addParameter("param1", "value1",
147:                        WebRequest.POST_METHOD);
148:            }
149:
150:            /**
151:             * Verify that we can simulate a POST request to a servlet. Note that
152:             * the POST method is the default method so we don't need to initialize
153:             * any parameter in <code>beginPostMethod()</code>.
154:             */
155:            public void testPostMethod() throws Exception {
156:                SamplePO samplePO = new SamplePO();
157:                samplePO.run(comms);
158:                assertEquals("POST", samplePO.checkMethod());
159:            }
160:
161:            //-------------------------------------------------------------------------
162:            /**
163:             * Verify that we can simulate a GET request to a PO.
164:             *
165:             * @param theRequest the request object that serves to initialize the
166:             *                   HTTP connection to the server redirector.
167:             */
168:            public void beginGetMethod(WebRequest theRequest) {
169:            }
170:
171:            /**
172:             * Verify that we can simulate a GET request to a PO
173:             */
174:            public void testGetMethod() throws Exception {
175:                SamplePO samplePO = new SamplePO();
176:                samplePO.run(comms);
177:                assertEquals("GET", samplePO.checkMethod());
178:            }
179:
180:            /**
181:             * Verify that we can simulate HTTP parameters in the HTTP request.
182:             *
183:             * @param theRequest the request object that serves to initialize the
184:             *                   HTTP connection to the server redirector.
185:             */
186:            public void beginSendParams(WebRequest theRequest) {
187:                theRequest.addParameter("param1", "value1");
188:                theRequest.addParameter("param2", "value2");
189:            }
190:
191:            /**
192:             * Verify that we can send several parameters in the HTTP request.
193:             */
194:            public void testSendParams() throws Exception {
195:                SamplePO samplePO = new SamplePO();
196:                samplePO.run(comms);
197:                Map params = samplePO.getRequestParameters();
198:                assertTrue(params.get("param1") != null);
199:                assertTrue(params.get("param2") != null);
200:                assertEquals("value1", params.get("param1"));
201:                assertEquals("value2", params.get("param2"));
202:            }
203:
204:            /**
205:             * Verify that we can simulate HTTP headers in the HTTP request.
206:             *
207:             * @param theRequest the request object that serves to initialize the
208:             *                   HTTP connection to the server redirector.
209:             */
210:            public void beginSendHeader(WebRequest theRequest) {
211:                theRequest.addHeader("testheader", "this is a header test");
212:            }
213:
214:            /**
215:             * Verify that we can simulate HTTP headers in the HTTP request.
216:             */
217:            public void testSendHeader() throws Exception {
218:                SamplePO samplePO = new SamplePO();
219:                samplePO.run(comms);
220:                String headerValue = samplePO.getRequestHeader("testheader");
221:                assertEquals("this is a header test", headerValue);
222:            }
223:
224:            //-------------------------------------------------------------------------
225:            /**
226:             * Verify that we can simulate a single cookie sent in the HTTP request.
227:             *
228:             * @param theRequest the request object that serves to initialize the
229:             *                   HTTP connection to the server redirector.
230:             */
231:            public void beginSendCookie(WebRequest theRequest) {
232:                // Note: The cookie value that was chosen is a string without spaces
233:                // because there is a problem with Resin 1.2.1 which does not support
234:                // quoted cookies. It has been fixed since the 15/12/2000 release of
235:                // Resin.
236:                theRequest.addCookie("testcookie", "thisisacookie");
237:            }
238:
239:            /**
240:             * Verify that we can simulate a single cookie sent in the HTTP request.
241:             */
242:            public void testSendCookie() throws Exception {
243:                SamplePO samplePO = new SamplePO();
244:                samplePO.run(comms);
245:                Map cookies = samplePO.getRequestCookies();
246:                assertTrue("Cannot find [testcookie] cookie in request",
247:                        cookies.get("testcookie") != null);
248:                assertEquals("thisisacookie", cookies.get("testcookie"));
249:            }
250:
251:            /**
252:             * Verify that we can simulate a HTTP Basic Auth in the HTTP request.
253:             */
254:            public void beginBasicAuthentication(WebRequest theRequest) {
255:                theRequest.setAuthentication(new BasicAuthentication(
256:                        "testuser", "testpwd"));
257:            }
258:
259:            /**
260:             * Verify that we can simulate a HTTP Basic Auth in the HTTP request.
261:             */
262:            public void testBasicAuthentication() throws Exception {
263:                BasicAuthResult authResult = BasicAuth
264:                        .getAuthentication(comms.request);
265:                assertEquals("testuser", authResult.username);
266:                assertEquals("testpwd", authResult.password);
267:            }
268:        } // SampleEnhydraAppTestCase
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.