Source Code Cross Referenced for TestOscacheJsp.java in  » Cache » OSCache » com » opensymphony » oscache » web » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » OSCache » com.opensymphony.oscache.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.oscache.web;
006:
007:        import com.meterware.httpunit.WebConversation;
008:        import com.meterware.httpunit.WebResponse;
009:
010:        import junit.framework.Test;
011:        import junit.framework.TestCase;
012:        import junit.framework.TestSuite;
013:
014:        /**
015:         * Test test the JSPs distributed with the package. It checks that the
016:         * cache integration is OK.
017:         *
018:         * $Id: TestOscacheJsp.java 385 2006-10-07 06:57:10Z larst $
019:         * @version        $Revision: 385 $
020:         * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
021:         */
022:        public final class TestOscacheJsp extends TestCase {
023:            // The instance of a webconversation to invoke pages
024:            WebConversation wc = null;
025:            private final String APPLICATION_SCOPE = "scope=application&";
026:
027:            // Constants definition
028:            private final String BASE_URL_SYSTEM_PRP = "test.web.baseURL";
029:            private final String FIRST_PAGE = "oscacheTest.jsp?";
030:            private final String FORCE_CACHE_USE = "forcecacheuse=yes&";
031:            private final String FORCE_REFRESH = "refresh=true";
032:            //private final String PAGE_SCOPE = "scope=page&";
033:            //private final String REQUEST_SCOPE = "scope=request&";
034:            private final String SECOND_PAGE = "oscacheTestMultipleTagNoKey.jsp?";
035:            private final String SESSION_SCOPE = "scope=session&";
036:            private final int CACHE_TAG_EXPIRATION = 2000;
037:            private final int HALF_CACHE_TAG_EXPIRATION = CACHE_TAG_EXPIRATION / 2;
038:
039:            /**
040:             * Constructor required by JUnit
041:             * <p>
042:             * @param str Test name
043:             */
044:            public TestOscacheJsp(String str) {
045:                super (str);
046:            }
047:
048:            /**
049:             * Returns the test suite for the test class
050:             * <p>
051:             * @return   Test suite for the class
052:             */
053:            public static Test suite() {
054:                return new TestSuite(TestOscacheJsp.class);
055:            }
056:
057:            /**
058:             * Setup method called before each testXXXX of the class
059:             */
060:            public void setUp() {
061:                // Create a web conversation to invoke our JSP
062:                if (wc == null) {
063:                    wc = new WebConversation();
064:                }
065:            }
066:
067:            /**
068:             * Test the cache module under load
069:             */
070:            public void testOscacheBasicForLoad() {
071:                String baseUrl = constructURL(FIRST_PAGE);
072:
073:                // Connect to the JSP using the application scope
074:                String stringResponse = invokeJSP(baseUrl, CACHE_TAG_EXPIRATION);
075:
076:                // Assert that a page was properly generated.
077:                // This does not ensure that the cache is working properly.
078:                // Though, it ensures that no exception or other weird problem occured
079:                assertTrue(stringResponse.indexOf("This is some cache content") > 0);
080:
081:                // Invoke the JSP page containing 2 cache tag
082:                baseUrl = constructURL(SECOND_PAGE);
083:
084:                // Connect to the JSP using the application scope
085:                stringResponse = invokeJSP(baseUrl, CACHE_TAG_EXPIRATION);
086:
087:                // Assert that a page was properly generated.
088:                // This does not ensure that the cache is working properly.
089:                // Though, it ensures that no exception or other weird problem occured
090:                assertTrue(stringResponse.indexOf("This is some cache content") > 0);
091:            }
092:
093:            /**
094:             * Test the cache module using a JSP
095:             */
096:            public void testOscacheJsp() {
097:                String baseUrl = constructURL(FIRST_PAGE);
098:
099:                // Connect to a session scope to allow the JSP compilation
100:                compileJSP(baseUrl + SESSION_SCOPE);
101:
102:                // Connect to the JSP using the application scope
103:                String stringResponse = invokeJSP(baseUrl,
104:                        HALF_CACHE_TAG_EXPIRATION);
105:
106:                // Connect again, we should have the same content since it expires
107:                // only each 2 seconds
108:                assertTrue(stringResponse.equals(invokeJSP(baseUrl,
109:                        HALF_CACHE_TAG_EXPIRATION)));
110:
111:                // Connect again, the content should be different
112:                String newResponse = invokeJSP(baseUrl, CACHE_TAG_EXPIRATION
113:                        + (CACHE_TAG_EXPIRATION / 4));
114:                assertTrue(!stringResponse.equals(newResponse));
115:                stringResponse = newResponse;
116:
117:                // Connect again, but request the cache content so no refresh should occur
118:                assertTrue(stringResponse.equals(invokeJSP(baseUrl,
119:                        FORCE_CACHE_USE, 0)));
120:
121:                // Connect again, the content should have changed
122:                newResponse = invokeJSP(baseUrl, HALF_CACHE_TAG_EXPIRATION);
123:                assertTrue(!stringResponse.equals(newResponse));
124:                stringResponse = newResponse;
125:
126:                // Connect for the last time, force the cache
127:                // refresh so the content should have changed
128:                assertTrue(!stringResponse.equals(invokeJSP(baseUrl,
129:                        FORCE_REFRESH, 0)));
130:
131:                // Invoke the JSP page containing 2 cache tag
132:                baseUrl = constructURL(SECOND_PAGE);
133:                compileJSP(baseUrl + SESSION_SCOPE);
134:                stringResponse = invokeJSP(baseUrl, CACHE_TAG_EXPIRATION);
135:
136:                // Invoke the same page en check if it's identical
137:                assertTrue(stringResponse.equals(invokeJSP(baseUrl,
138:                        CACHE_TAG_EXPIRATION)));
139:            }
140:
141:            /**
142:             * Compile a JSP page by invoking it. We compile the page first to avoid
143:             * the compilation delay when testing since the time is a crucial factor
144:             * <p>
145:             * @param URL The JSP url to invoke
146:             */
147:            private void compileJSP(String URL) {
148:                try {
149:                    // Invoke the JSP
150:                    wc.getResponse(URL);
151:                } catch (Exception ex) {
152:                    ex.printStackTrace();
153:                    fail("Exception raised!!");
154:                }
155:            }
156:
157:            /**
158:             *  Reads the base url from the test.web.baseURL system property and
159:             *  append the given URL.
160:             *  <p>
161:             *  @param Url  Url to append to the base.
162:             *  @return Complete URL
163:             */
164:            private String constructURL(String Url) {
165:                String base = System.getProperty(BASE_URL_SYSTEM_PRP);
166:                String constructedUrl = null;
167:
168:                if (base != null) {
169:                    if (!base.endsWith("/")) {
170:                        base = base + "/";
171:                    }
172:
173:                    constructedUrl = base + Url;
174:                } else {
175:                    fail("System property test.web.baseURL needs to be set to the proper server to use.");
176:                }
177:
178:                return constructedUrl;
179:            }
180:
181:            /**
182:             * Utility method to invoke a JSP page and then sleep some time before returning
183:             * <p>
184:             * @param baseUrl     The URL of the JSP to invoke
185:             * @param sleepTime   THe time to sleep before returning
186:             * @return The text value of the reponse (HTML code)
187:             */
188:            private String invokeJSP(String baseUrl, int sleepTime) {
189:                return invokeJSP(baseUrl, "", sleepTime);
190:            }
191:
192:            /**
193:             * Utility method to invoke a JSP page and then sleep some time before returning
194:             * <p>
195:             * @param baseUrl     The URL of the JSP to invoke
196:             * @param URLparam    The URL parameters of the JSP to invoke
197:             * @param sleepTime   The time to sleep before returning
198:             * @return The text value of the reponse (HTML code)
199:             */
200:            private String invokeJSP(String baseUrl, String URLparam,
201:                    int sleepTime) {
202:                try {
203:                    // Invoke the JSP and wait the specified sleepTime
204:                    WebResponse resp = wc.getResponse(baseUrl
205:                            + APPLICATION_SCOPE + URLparam);
206:                    Thread.sleep(sleepTime);
207:
208:                    return resp.getText();
209:                } catch (Exception ex) {
210:                    ex.printStackTrace();
211:                    fail("Exception raised!!");
212:
213:                    return null;
214:                }
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.