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: TestEngineExtending.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import com.meterware.httpunit.*;
011: import com.uwyn.rife.TestCaseServerside;
012:
013: public class TestEngineExtending extends TestCaseServerside {
014: public TestEngineExtending(int siteType, String name) {
015: super (siteType, name);
016: }
017:
018: public void testExtendingSimple() throws Exception {
019: setupSite("site/extending.xml");
020: WebConversation conversation = new WebConversation();
021: WebRequest request = null;
022: WebResponse response = null;
023:
024: conversation.addCookie("incookie1", "incookie1requestvalue");
025: request = new PostMethodWebRequest(
026: "http://localhost:8181/extending/simple");
027: request.setParameter("input1", "input1requestvalue");
028: request.setParameter(ReservedParameters.SUBMISSION,
029: "submission1");
030: request.setParameter("param1", "param1requestvalue");
031: response = conversation.getResponse(request);
032: assertEquals("outcookie1elementvalue", conversation
033: .getCookieValue("outcookie1"));
034: assertEquals("outcookiedefault", conversation
035: .getCookieValue("outcookie2"));
036: assertEquals("Blueprint" + "value1" + "value2"
037: + "input1requestvalue" + "inputdefault"
038: + "incookie1requestvalue" + "incookiedefault"
039: + "param1requestvalue" + "paramdefault", response
040: .getText());
041:
042: request = new GetMethodWebRequest(
043: "http://localhost:8181/extending/simple");
044: request.setParameter("switch", "exit1");
045: response = conversation.getResponse(request);
046: assertEquals("Blueprint" + "value1" + "value2" + "output1exit1"
047: + "outputdefault" + "incookie1requestvalue"
048: + "incookiedefault", response.getText());
049:
050: request = new GetMethodWebRequest(
051: "http://localhost:8181/extending/simple");
052: request.setParameter("switch", "exit2");
053: response = conversation.getResponse(request);
054: assertEquals("Blueprint" + "value1" + "value2" + "output1exit2"
055: + "outputdefault" + "incookie1requestvalue"
056: + "incookiedefault", response.getText());
057: }
058:
059: public void testExtendingClassOverriding() throws Exception {
060: setupSite("site/extending.xml");
061: WebConversation conversation = new WebConversation();
062: WebRequest request = null;
063: WebResponse response = null;
064:
065: conversation.addCookie("incookie1", "incookie1requestvalue");
066: request = new PostMethodWebRequest(
067: "http://localhost:8181/extending/classoverriding");
068: request.setParameter("input1", "input1requestvalue");
069: request.setParameter(ReservedParameters.SUBMISSION,
070: "submission1");
071: request.setParameter("param1", "param1requestvalue");
072: response = conversation.getResponse(request);
073: assertEquals("outcookie1elementvalue", conversation
074: .getCookieValue("outcookie1"));
075: assertEquals("outcookiedefault", conversation
076: .getCookieValue("outcookie2"));
077: assertEquals("ClassOverriding" + "value1" + "value2"
078: + "input1requestvalue" + "inputdefault"
079: + "incookie1requestvalue" + "incookiedefault"
080: + "param1requestvalue" + "paramdefault", response
081: .getText());
082:
083: request = new GetMethodWebRequest(
084: "http://localhost:8181/extending/classoverriding");
085: request.setParameter("switch", "exit1");
086: response = conversation.getResponse(request);
087: assertEquals("ClassOverriding" + "value1" + "value2"
088: + "output1exit1" + "outputdefault"
089: + "incookie1requestvalue" + "incookiedefault", response
090: .getText());
091:
092: request = new GetMethodWebRequest(
093: "http://localhost:8181/extending/classoverriding");
094: request.setParameter("switch", "exit2");
095: response = conversation.getResponse(request);
096: assertEquals("ClassOverriding" + "value1" + "value2"
097: + "output1exit2" + "outputdefault"
098: + "incookie1requestvalue" + "incookiedefault", response
099: .getText());
100: }
101:
102: public void testExtendingStaticPropertiesOverriding()
103: throws Exception {
104: setupSite("site/extending.xml");
105: WebConversation conversation = new WebConversation();
106: WebRequest request = null;
107: WebResponse response = null;
108:
109: conversation.addCookie("incookie1", "incookie1requestvalue");
110: request = new PostMethodWebRequest(
111: "http://localhost:8181/extending/staticpropertiesoverriding");
112: request.setParameter("input1", "input1requestvalue");
113: request.setParameter(ReservedParameters.SUBMISSION,
114: "submission1");
115: request.setParameter("param1", "param1requestvalue");
116: response = conversation.getResponse(request);
117: assertEquals("outcookie1elementvalue", conversation
118: .getCookieValue("outcookie1"));
119: assertEquals("outcookiedefault", conversation
120: .getCookieValue("outcookie2"));
121: assertEquals("Blueprint" + "overriddenvalue1"
122: + "overriddenvalue2" + "input1requestvalue"
123: + "inputdefault" + "incookie1requestvalue"
124: + "incookiedefault" + "param1requestvalue"
125: + "paramdefault", response.getText());
126: }
127:
128: public void testExtendingAdding() throws Exception {
129: setupSite("site/extending.xml");
130: WebConversation conversation = new WebConversation();
131: WebRequest request = null;
132: WebResponse response = null;
133:
134: conversation.addCookie("incookie1", "incookie1requestvalue");
135: conversation.addCookie("incookie3", "incookie3requestvalue");
136: request = new PostMethodWebRequest(
137: "http://localhost:8181/extending/adding");
138: request.setParameter("input1", "input1requestvalue");
139: request.setParameter("input3", "input3requestvalue");
140: request.setParameter(ReservedParameters.SUBMISSION,
141: "submission2");
142: request.setParameter("param1", "param1requestvalue");
143: response = conversation.getResponse(request);
144: assertEquals("outcookie1elementvalue", conversation
145: .getCookieValue("outcookie1"));
146: assertEquals("outcookiedefault", conversation
147: .getCookieValue("outcookie2"));
148: assertEquals("outcookie3elementvalue", conversation
149: .getCookieValue("outcookie3"));
150: assertEquals("outcookiedefault", conversation
151: .getCookieValue("outcookie4"));
152: assertEquals("Adding" + "value1" + "value2" + "value3"
153: + "value4" + "input1requestvalue" + "inputdefault"
154: + "input3requestvalue" + "inputdefault"
155: + "incookie1requestvalue" + "incookiedefault"
156: + "incookie3requestvalue" + "incookiedefault"
157: + "param1requestvalue" + "submission2paramdefault",
158: response.getText());
159:
160: request = new GetMethodWebRequest(
161: "http://localhost:8181/extending/adding");
162: request.setParameter("switch", "exit1");
163: response = conversation.getResponse(request);
164: assertEquals("Adding" + "value1" + "value2" + "value3"
165: + "value4" + "output1exit1" + "outputdefault"
166: + "output3exit1" + "outputdefault"
167: + "incookie1requestvalue" + "incookiedefault"
168: + "incookie3requestvalue" + "incookiedefault", response
169: .getText());
170:
171: request = new GetMethodWebRequest(
172: "http://localhost:8181/extending/adding");
173: request.setParameter("switch", "exit2");
174: response = conversation.getResponse(request);
175: assertEquals("Adding" + "value1" + "value2" + "value3"
176: + "value4" + "output1exit2" + "outputdefault"
177: + "output3exit2" + "outputdefault"
178: + "incookie1requestvalue" + "incookiedefault"
179: + "incookie3requestvalue" + "incookiedefault", response
180: .getText());
181:
182: request = new GetMethodWebRequest(
183: "http://localhost:8181/extending/adding");
184: request.setParameter("switch", "exit3");
185: response = conversation.getResponse(request);
186: assertEquals("Adding" + "value1" + "value2" + "value3"
187: + "value4" + "output1exit3" + "outputdefault"
188: + "output3exit3" + "outputdefault"
189: + "incookie1requestvalue" + "incookiedefault"
190: + "incookie3requestvalue" + "incookiedefault", response
191: .getText());
192:
193: request = new GetMethodWebRequest(
194: "http://localhost:8181/extending/adding");
195: request.setParameter("switch", "exit4");
196: response = conversation.getResponse(request);
197: assertEquals("Adding" + "value1" + "value2" + "value3"
198: + "value4" + "output1exit4" + "outputdefault"
199: + "output3exit4" + "outputdefault"
200: + "incookie1requestvalue" + "incookiedefault"
201: + "incookie3requestvalue" + "incookiedefault", response
202: .getText());
203: }
204:
205: public void testExtendingMultipleLevels() throws Exception {
206: setupSite("site/extending.xml");
207: WebConversation conversation = new WebConversation();
208: WebRequest request = null;
209: WebResponse response = null;
210:
211: conversation.addCookie("incookie1", "incookie1requestvalue");
212: conversation.addCookie("incookie3", "incookie3requestvalue");
213: request = new PostMethodWebRequest(
214: "http://localhost:8181/extending/multiplelevels");
215: request.setParameter("input1", "input1requestvalue");
216: request.setParameter("input3", "input3requestvalue");
217: request.setParameter(ReservedParameters.SUBMISSION,
218: "submission2");
219: request.setParameter("param1", "param1requestvalue");
220: response = conversation.getResponse(request);
221: assertEquals("outcookie1elementvalue", conversation
222: .getCookieValue("outcookie1"));
223: assertEquals("outcookiedefault", conversation
224: .getCookieValue("outcookie2"));
225: assertEquals("outcookie3elementvalue", conversation
226: .getCookieValue("outcookie3"));
227: assertEquals("outcookiedefault", conversation
228: .getCookieValue("outcookie4"));
229: assertEquals("MultipleLevels" + "value1" + "value2" + "value3"
230: + "value4" + "input1requestvalue" + "inputdefault"
231: + "input3requestvalue" + "inputdefault"
232: + "incookie1requestvalue" + "incookiedefault"
233: + "incookie3requestvalue" + "incookiedefault"
234: + "param1requestvalue" + "submission2paramdefault",
235: response.getText());
236:
237: request = new GetMethodWebRequest(
238: "http://localhost:8181/extending/multiplelevels");
239: request.setParameter("switch", "exit1");
240: response = conversation.getResponse(request);
241: assertEquals("MultipleLevels" + "value1" + "value2" + "value3"
242: + "value4" + "output1exit1" + "outputdefault"
243: + "output3exit1" + "outputdefault"
244: + "incookie1requestvalue" + "incookiedefault"
245: + "incookie3requestvalue" + "incookiedefault", response
246: .getText());
247:
248: request = new GetMethodWebRequest(
249: "http://localhost:8181/extending/multiplelevels");
250: request.setParameter("switch", "exit2");
251: response = conversation.getResponse(request);
252: assertEquals("MultipleLevels" + "value1" + "value2" + "value3"
253: + "value4" + "output1exit2" + "outputdefault"
254: + "output3exit2" + "outputdefault"
255: + "incookie1requestvalue" + "incookiedefault"
256: + "incookie3requestvalue" + "incookiedefault", response
257: .getText());
258:
259: request = new GetMethodWebRequest(
260: "http://localhost:8181/extending/multiplelevels");
261: request.setParameter("switch", "exit3");
262: response = conversation.getResponse(request);
263: assertEquals("MultipleLevels" + "value1" + "value2" + "value3"
264: + "value4" + "output1exit3" + "outputdefault"
265: + "output3exit3" + "outputdefault"
266: + "incookie1requestvalue" + "incookiedefault"
267: + "incookie3requestvalue" + "incookiedefault", response
268: .getText());
269:
270: request = new GetMethodWebRequest(
271: "http://localhost:8181/extending/multiplelevels");
272: request.setParameter("switch", "exit4");
273: response = conversation.getResponse(request);
274: assertEquals("MultipleLevels" + "value1" + "value2" + "value3"
275: + "value4" + "output1exit4" + "outputdefault"
276: + "output3exit4" + "outputdefault"
277: + "incookie1requestvalue" + "incookiedefault"
278: + "incookie3requestvalue" + "incookiedefault", response
279: .getText());
280: }
281: }
|