Source Code Cross Referenced for TestHttpServletRequestSimulator.java in  » Testing » StrutsTestCase » servletunit » tests » 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 » StrutsTestCase » servletunit.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //  StrutsTestCase - a JUnit extension for testing Struts actions
002:        //  within the context of the ActionServlet.
003:        //  Copyright (C) 2002 Deryl Seale
004:        //
005:        //  This library is free software; you can redistribute it and/or
006:        //  modify it under the terms of the Apache Software License as
007:        //  published by the Apache Software Foundation; either version 1.1
008:        //  of the License, or (at your option) any later version.
009:        //
010:        //  This library is distributed in the hope that it will be useful,
011:        //  but WITHOUT ANY WARRANTY; without even the implied warranty of
012:        //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:        //  Apache Software Foundation Licens for more details.
014:        //
015:        //  You may view the full text here: http://www.apache.org/LICENSE.txt
016:
017:        package servletunit.tests;
018:
019:        import junit.framework.TestCase;
020:        import servletunit.HttpServletRequestSimulator;
021:        import servletunit.ServletContextSimulator;
022:
023:        import javax.servlet.RequestDispatcher;
024:        import java.io.File;
025:        import java.text.ParseException;
026:        import java.text.SimpleDateFormat;
027:        import java.util.Enumeration;
028:        import java.util.Locale;
029:        import java.util.Date;
030:
031:        /**
032:         * A Junit based test of the HttpServletResponseSimulator class
033:         * @author Sean Pritchard
034:         * @version 1.0
035:         */
036:
037:        public class TestHttpServletRequestSimulator extends TestCase {
038:
039:            HttpServletRequestSimulator request;
040:            ServletContextSimulator context;
041:
042:            public TestHttpServletRequestSimulator(String testCase) {
043:                super (testCase);
044:            }
045:
046:            public void setUp() {
047:                context = new ServletContextSimulator();
048:                request = new HttpServletRequestSimulator(context);
049:            }
050:
051:            public void testAddParameterArray() {
052:                String[] values = { "value1", "value2" };
053:                request.addParameter("name1", values);
054:                String[] result = request.getParameterValues("name1");
055:                if (result.length != 2)
056:                    fail();
057:                if (!((result[0].equals("value1")) && (result[1]
058:                        .equals("value2"))))
059:                    fail();
060:            }
061:
062:            public void testGetParameterValuesSingle() {
063:                request.addParameter("name1", "value1");
064:                String[] result = request.getParameterValues("name1");
065:                if (result.length != 1)
066:                    fail();
067:                if (!(result[0].equals("value1")))
068:                    fail();
069:            }
070:
071:            public void testGetParameterWithNullKey() {
072:                String result = request.getParameter(null);
073:                assertNull(result);
074:
075:            }
076:
077:            public void testGetParameterValuesWithNullKey() {
078:                String[] result = request.getParameterValues(null);
079:                assertNull(result);
080:
081:            }
082:
083:            public void testGetParameterWithArray() {
084:                String[] values = { "value1", "value2" };
085:                request.addParameter("name1", values);
086:                String result = request.getParameter("name1");
087:                if (!(result.equals("value1")))
088:                    fail();
089:            }
090:
091:            public void testSetAttributeNullValue() {
092:                request.setAttribute("test1", "value1");
093:                assertEquals(request.getAttribute("test1"), "value1");
094:                request.setAttribute("test1", null);
095:                assertNull(request.getAttribute("test1"));
096:            }
097:
098:            public void testSetAttribute() {
099:                request.setAttribute("test1", "value1");
100:                assertEquals(request.getAttribute("test1"), "value1");
101:            }
102:
103:            public void testIsUserInRole() {
104:                request.setUserRole("role1");
105:                assertTrue(request.isUserInRole("role1"));
106:            }
107:
108:            public void testIsUserInRoleFalse() {
109:                request.setUserRole("role2");
110:                assertTrue(!request.isUserInRole("role1"));
111:            }
112:
113:            public void testGetServerPort() {
114:                request.setServerPort(8080);
115:                assertEquals(request.getServerPort(), 8080);
116:            }
117:
118:            public void testGetRequestURLWithQueryString() {
119:                request
120:                        .setRequestURL("https://server:8080/my/request/url?param=1");
121:                assertEquals("https://server:8080/my/request/url", request
122:                        .getRequestURL().toString());
123:                assertEquals("param=1", request.getQueryString());
124:                assertEquals("https", request.getScheme());
125:                assertTrue(request.isSecure());
126:                assertEquals("/my/request/url", request.getRequestURI());
127:                assertEquals("server", request.getServerName());
128:                assertEquals(8080, request.getServerPort());
129:            }
130:
131:            public void testGetRequestURLWithoutQueryStringOrPort() {
132:                request.setRequestURL("http://server/my/request/url");
133:                assertEquals("http://server/my/request/url", request
134:                        .getRequestURL().toString());
135:                assertNull(request.getQueryString());
136:                assertEquals("http", request.getScheme());
137:                assertTrue(!request.isSecure());
138:                assertEquals("/my/request/url", request.getRequestURI());
139:                assertEquals("server", request.getServerName());
140:                assertEquals(80, request.getServerPort());
141:            }
142:
143:            public void testGetSecurePort() {
144:                request.setRequestURL("https://server/my/request/url?param=1");
145:                assertTrue(request.isSecure());
146:                assertEquals(443, request.getServerPort());
147:            }
148:
149:            public void testGetLocales() {
150:                Enumeration enumeration = request.getLocales();
151:                for (Object enumObject = enumeration.nextElement(); enumeration
152:                        .hasMoreElements(); enumObject = enumeration
153:                        .nextElement()) {
154:                    Locale locale = (Locale) enumObject;
155:                    if (!locale.equals(Locale.US))
156:                        fail();
157:                }
158:            }
159:
160:            public void testGetDateHeaderNoHeader() {
161:                assertEquals(-1, request.getDateHeader("foo"));
162:            }
163:
164:            public void testGetDateHeaderBadHeader() {
165:                request.setHeader("DATE_HEADER", "foofoofoo");
166:                try {
167:                    request.getDateHeader("DATE_HEADER");
168:                } catch (IllegalArgumentException iae) {
169:                    return;
170:                }
171:                fail();
172:            }
173:
174:            public void testGetDateHeader() throws ParseException {
175:                String date = "05/23/73 8:05 PM, PST";
176:                long time = new SimpleDateFormat().parse(date).getTime();
177:                request.setDateHeader("DATE_HEADER", time);
178:                assertEquals(time, request.getDateHeader("DATE_HEADER"));
179:            }
180:
181:            public void testGetRealPath() {
182:                File file = new File(System.getProperty("basedir"));
183:                context.setContextDirectory(file);
184:                assertEquals(new File(file, "test.html").getAbsolutePath(),
185:                        request.getRealPath("/test.html"));
186:            }
187:
188:            public void testGetRealPathNotSet() {
189:                assertNull(request.getRealPath("/test.html"));
190:            }
191:
192:            public void testReturnsRequestDispatcher() {
193:                RequestDispatcher dispatcher = request
194:                        .getRequestDispatcher("/test/login.jsp");
195:                assertNotNull(dispatcher);
196:            }
197:
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.