Source Code Cross Referenced for EnhydraAppTestCase.java in  » J2EE » Enhydra-Demos » org » hamletsoft » enhydra » cactus » business » 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 
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;
058:
059:        import java.lang.reflect.*;
060:        import javax.servlet.*;
061:        import javax.servlet.http.*;
062:        import java.net.*;
063:        import junit.framework.*;
064:        import org.apache.cactus.client.*;
065:        import org.apache.cactus.server.*;
066:        import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
067:        import com.lutris.appserver.server.Application;
068:        import com.lutris.appserver.server.httpPresentation.HttpPresentationResponse;
069:        import com.lutris.appserver.server.httpPresentation.HttpPresentationRequest;
070:        import org.hamletsoft.enhydra.cactus.business.*;
071:        import org.apache.cactus.AbstractTestCase;
072:        import org.apache.cactus.AbstractWebTestCase;
073:        import javax.servlet.http.HttpServletRequest;
074:        import org.apache.cactus.ServletTestCase;
075:        import java.net.MalformedURLException;
076:        import java.net.URL;
077:        import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
078:        import java.util.Hashtable;
079:
080:        /**
081:         * Test classes that need access to valid EnhydraApp implicit objects (such as the
082:         * the HTTP request, the HTTP response, the servlet config, ...) must subclass
083:         * this class.
084:         *
085:         * @author <a href="mailto:hattori@hitachizosen.co.jp">Ryuji "The Hamlet" Hattori</a>
086:         *
087:         * @version $Id: EnhydraAppTestCase.java,v 1.1 2006-09-11 12:30:51 sinisa Exp $
088:         */
089:        public class EnhydraAppTestCase extends AbstractWebTestCase {
090:            /**
091:             * Valid <code>HttpPresentationComms</code> object that you can access from
092:             * the <code>testXXX()</code>, <code>setUp</code> and
093:             * <code>tearDown()</code> methods. If you try to access it from either the
094:             * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
095:             * have the <code>null</code> value.
096:             */
097:            public HttpPresentationComms comms;
098:            /**
099:             * Valid <code>Application</code> object that you can access from
100:             * the <code>testXXX()</code>, <code>setUp</code> and
101:             * <code>tearDown()</code> methods. If you try to access it from either the
102:             * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
103:             * have the <code>null</code> value.
104:             */
105:            public Application application;
106:            /**
107:             * Valid <code>HttpPresentationRequest</code> object that you can access from
108:             * the <code>testXXX()</code>, <code>setUp</code> and
109:             * <code>tearDown()</code> methods. If you try to access it from either the
110:             * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
111:             * have the <code>null</code> value.
112:             */
113:            public HttpPresentationRequest request;
114:            /**
115:             * Valid <code>HttpPresentationResponse</code> object that you can access from
116:             * the <code>testXXX()</code>, <code>setUp</code> and
117:             * <code>tearDown()</code> methods. If you try to access it from either the
118:             * <code>beginXXX()</code> or <code>endXXX()</code> methods it will
119:             * have the <code>null</code> value.
120:             */
121:            public HttpPresentationResponse response;
122:
123:            /**
124:             * Constructs a JUnit test case with the given name.
125:             *
126:             * @param theName the name of the test case
127:             */
128:            public EnhydraAppTestCase(String theName) {
129:                super (theName);
130:            }
131:
132:            /**
133:             * Runs a test case. This method is overriden from the JUnit
134:             * <code>TestCase</code> class in order to seamlessly call the
135:             * Cactus redirection servlet.
136:             */
137:            protected void runTest() throws Throwable {
138:                runGenericTest(new EnhydraAppHttpClient());
139:            }
140:
141:            /**
142:             * Overwrite Methods. because of need to handle ClinetSideRedirection
143:             *
144:             * Run the test that was specified in the constructor on the server side,
145:             */
146:            protected void runServerTest() throws Throwable {
147:                try {
148:                    super .runServerTest();
149:                } catch (ClientPageRedirectException cpre) {
150:                    clientSideRedirect(cpre.getUrl());
151:                }
152:            }
153:
154:            private void clientSideRedirect(String url) throws Throwable {
155:                url = makeAbsolute(url, comms.request.getHttpServletRequest());
156:                hookForClientPageRedirect(url, getRedirectParameters(url));
157:                comms.response.setHeader("Location", url);
158:                comms.response.setStatus(
159:                        HttpPresentationResponse.SC_MOVED_TEMPORARILY,
160:                        "Redirected to new location.");
161:            }
162:
163:            private String makeAbsolute(String location,
164:                    HttpServletRequest request) {
165:                URL url = null;
166:                try {
167:                    // Try making a URL out of the location
168:                    // Throws an exception if the location is relative
169:                    url = new URL(location);
170:                } catch (MalformedURLException e) {
171:                    String requrl = HttpUtils.getRequestURL(request).toString();
172:                    try {
173:                        url = new URL(new URL(requrl), location);
174:                    } catch (MalformedURLException ignored) {
175:                        return location; // Give up
176:                    }
177:                }
178:                return url.toString();
179:            }
180:
181:            /**
182:             * getting Parameter table for the url of client page redirection.
183:             *
184:             * @param url URL of Page Redirection.
185:             * @return HTTP parameter table for the URL of Page Redirection.<br>
186:             *          (Class of the Hashtable's value is <b>not String but String[]</b>)<br>
187:             *         if the url has no parameter, this returns null.
188:             */
189:            protected Hashtable getRedirectParameters(String url) {
190:                Hashtable ht = null;
191:                if (url.indexOf("?") > -1)
192:                    ht = HttpUtils.parseQueryString(url.substring(url
193:                            .indexOf("?") + 1));
194:                return ht;
195:            }
196:
197:            /**
198:             * Hook method for all Test on server side for client page redirection.
199:             *
200:             * @param url URL of Page Redirection.
201:             * @param ht HTTP parameter table for the URL of Page Redirection.<br>
202:             *          (Class of the Hashtable's value is <b>not String but String[]</b>)
203:             */
204:            protected void hookForClientPageRedirect(String url, Hashtable ht) {
205:                ;
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.