001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestEnginePrecedence.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import com.meterware.httpunit.GetMethodWebRequest;
011: import com.meterware.httpunit.WebConversation;
012: import com.meterware.httpunit.WebRequest;
013: import com.meterware.httpunit.WebResponse;
014: import com.uwyn.rife.TestCaseServerside;
015:
016: public class TestEnginePrecedence extends TestCaseServerside {
017: public TestEnginePrecedence(int siteType, String name) {
018: super (siteType, name);
019: }
020:
021: public void testSimple() throws Exception {
022: setupSite("site/precedence.xml");
023:
024: WebConversation conversation = new WebConversation();
025: WebRequest request = null;
026: WebResponse response = null;
027:
028: request = new GetMethodWebRequest(
029: "http://localhost:8181/simple");
030: response = conversation.getResponse(request);
031: assertEquals("This is the simple pre content"
032: + "This is the simple target content", response
033: .getText());
034: }
035:
036: public void testMultiple() throws Exception {
037: setupSite("site/precedence.xml");
038:
039: WebConversation conversation = new WebConversation();
040: WebRequest request = null;
041: WebResponse response = null;
042:
043: request = new GetMethodWebRequest(
044: "http://localhost:8181/multiple");
045: response = conversation.getResponse(request);
046: assertEquals("This is the multiple pre3 content"
047: + "This is the multiple pre2 content"
048: + "This is the multiple pre1 content"
049: + "This is the multiple target content", response
050: .getText());
051: }
052:
053: public void testTargetinheritance() throws Exception {
054: setupSite("site/precedence.xml");
055:
056: WebConversation conversation = new WebConversation();
057: WebRequest request = null;
058: WebResponse response = null;
059:
060: request = new GetMethodWebRequest(
061: "http://localhost:8181/targetinheritance");
062: response = conversation.getResponse(request);
063: assertEquals("This is the target inheritance parent content",
064: response.getText());
065:
066: request = new GetMethodWebRequest(
067: "http://localhost:8181/targetinheritance");
068: request.setParameter("trigger", "ok");
069: response = conversation.getResponse(request);
070: assertEquals("This is the target inheritance pre content"
071: + "This is the target inheritance target content",
072: response.getText());
073: }
074:
075: public void testPreinheritance() throws Exception {
076: setupSite("site/precedence.xml");
077:
078: WebConversation conversation = new WebConversation();
079: WebRequest request = null;
080: WebResponse response = null;
081:
082: request = new GetMethodWebRequest(
083: "http://localhost:8181/preinheritance");
084: response = conversation.getResponse(request);
085: assertEquals("This is the pre inheritance parent content"
086: + "This is the pre inheritance target content",
087: response.getText());
088:
089: request = new GetMethodWebRequest(
090: "http://localhost:8181/preinheritance");
091: request.setParameter("trigger", "ok");
092: response = conversation.getResponse(request);
093: assertEquals("This is the pre inheritance pre content"
094: + "This is the pre inheritance target content",
095: response.getText());
096: }
097:
098: public void testGlobalvars() throws Exception {
099: setupSite("site/precedence.xml");
100:
101: WebConversation conversation = new WebConversation();
102: WebRequest request = null;
103: WebResponse response = null;
104:
105: request = new GetMethodWebRequest(
106: "http://localhost:8181/globalvars");
107: request.setParameter("globalvar1", "globalvar1_requestvalue");
108: request.setParameter("globalvar2", "globalvar2_requestvalue");
109: request.setParameter("globalvar3", "globalvar3_requestvalue");
110: request.setParameter("globalvar4", "globalvar4_requestvalue");
111: request.setParameter("globalvar5", "globalvar5_requestvalue");
112: request.setParameter("globalvar6", "globalvar6_requestvalue");
113: response = conversation.getResponse(request);
114: assertEquals("This is the globalvars target content"
115: + ":globalvar1_prevalue" + ":null"
116: + ":globalvar3_requestvalue" + ":null"
117: + ":globalvar5_prevalue" + ":globalvar6_requestvalue",
118: response.getText());
119: }
120:
121: public void testCookies() throws Exception {
122: setupSite("site/precedence.xml");
123:
124: WebConversation conversation = new WebConversation();
125: WebRequest request = null;
126: WebResponse response = null;
127:
128: request = new GetMethodWebRequest(
129: "http://localhost:8181/cookies");
130: conversation.addCookie("cookie1", "cookie1_requestvalue");
131: conversation.addCookie("cookie2", "cookie2_requestvalue");
132: conversation.addCookie("cookie3", "cookie3_requestvalue");
133: conversation.addCookie("cookie4", "cookie4_requestvalue");
134: conversation.addCookie("cookie5", "cookie5_requestvalue");
135: conversation.addCookie("cookie6", "cookie6_requestvalue");
136: response = conversation.getResponse(request);
137: assertEquals("This is the cookies target content"
138: + ":cookie1_prevalue" + ":cookie2_requestvalue"
139: + ":cookie3_prevalue" + ":cookie4_prevalue"
140: + ":cookie5_prevalue", response.getText());
141: }
142:
143: public void testInheritanceprecedence() throws Exception {
144: setupSite("site/precedence.xml");
145:
146: WebConversation conversation = new WebConversation();
147: WebRequest request = null;
148: WebResponse response = null;
149:
150: request = new GetMethodWebRequest(
151: "http://localhost:8181/inheritanceprecedence");
152: response = conversation.getResponse(request);
153: assertEquals("This is the inheritance precedence pre content"
154: + "This is the inheritance precedence parent content",
155: response.getText());
156:
157: request = new GetMethodWebRequest(
158: "http://localhost:8181/inheritanceprecedence");
159: request.setParameter("trigger", "ok");
160: response = conversation.getResponse(request);
161: assertEquals(
162: "This is the inheritance precedence target content",
163: response.getText());
164: }
165:
166: public void testGlobalScopeAbsolute() throws Exception {
167: setupSite("site/precedence.xml");
168:
169: WebConversation conversation = new WebConversation();
170: WebRequest request = null;
171: WebResponse response = null;
172:
173: request = new GetMethodWebRequest(
174: "http://localhost:8181/globalscope/absolute");
175: response = conversation.getResponse(request);
176: assertEquals("This is the simple pre content"
177: + "This is the simple target content", response
178: .getText());
179: }
180:
181: public void testGlobalScopeRelative() throws Exception {
182: setupSite("site/precedence.xml");
183:
184: WebConversation conversation = new WebConversation();
185: WebRequest request = null;
186: WebResponse response = null;
187:
188: request = new GetMethodWebRequest(
189: "http://localhost:8181/globalscope/relative");
190: response = conversation.getResponse(request);
191: assertEquals("This is the simple pre content"
192: + "This is the simple target content", response
193: .getText());
194: }
195: }
|