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: TestEngineInputs.java 3846 2007-07-11 11:33:53Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import java.util.Calendar;
011:
012: import com.meterware.httpunit.*;
013: import com.uwyn.rife.TestCaseServerside;
014: import com.uwyn.rife.config.RifeConfig;
015: import com.uwyn.rife.engine.exceptions.InputUnknownException;
016: import com.uwyn.rife.tools.BeanUtils;
017:
018: public class TestEngineInputs extends TestCaseServerside {
019: public TestEngineInputs(int siteType, String name) {
020: super (siteType, name);
021: }
022:
023: public void testValid() throws Exception {
024: setupSite("site/inputs.xml");
025: WebConversation conversation = new WebConversation();
026: WebRequest request = new GetMethodWebRequest(
027: "http://localhost:8181/inputs/valid");
028: WebResponse response = conversation.getResponse(request);
029: assertEquals("another response", response.getText());
030: }
031:
032: public void testTyped() throws Exception {
033: setupSite("site/inputs.xml");
034: WebConversation conversation = new WebConversation();
035: WebRequest request = null;
036: WebResponse response = null;
037:
038: request = new GetMethodWebRequest(
039: "http://localhost:8181/inputs/typed");
040: request.setParameter("inputstring1", "astring");
041: request.setParameter("inputint1", "" + Integer.MAX_VALUE);
042: request.setParameter("inputlong1", "" + Long.MAX_VALUE);
043: request.setParameter("inputdouble1", "9873434.4334");
044: request.setParameter("inputfloat1", "23.12");
045: Calendar cal = Calendar.getInstance();
046: cal.set(2007, 6, 11, 12, 58, 22);
047: cal.set(Calendar.MILLISECOND, 666);
048: cal.setTimeZone(RifeConfig.Tools.getDefaultTimeZone());
049: request.setParameter("inputdate1", BeanUtils
050: .getConcisePreciseDateFormat().format(cal.getTime()));
051: response = conversation.getResponse(request);
052: assertEquals("inputstring1:astring" + "inputstring2:null"
053: + "inputstring2default:stringdefault" + "inputint1:"
054: + Integer.MAX_VALUE + "inputint2:0"
055: + "inputint2default:123" + "inputlong1:"
056: + Long.MAX_VALUE + "inputlong2:0"
057: + "inputlong2default:983749876"
058: + "inputdouble1:9873434.4334" + "inputdouble2:0.0"
059: + "inputdouble2default:34778.34" + "inputfloat1:23.12"
060: + "inputfloat2:0.0" + "inputfloat2default:324.34"
061: + "inputdate1:Wed Jul 11 12:58:22 CEST 2007"
062: + "inputdate2:null"
063: + "inputdate2default:Sat Jun 10 11:57:11 CEST 2006",
064: response.getText());
065: }
066:
067: public void testInputsBean() throws Exception {
068: setupSite("site/inputs.xml");
069:
070: WebConversation conversation = new WebConversation();
071: WebRequest request = new GetMethodWebRequest(
072: "http://localhost:8181/inputs/bean/normal");
073: WebResponse response = null;
074: request.setParameter("string", "the string");
075: request.setParameter("boolean", "y");
076: request.setParameter("string", "the string");
077: request.setParameter("stringbuffer", "the stringbuffer");
078: request.setParameter("int", "23154");
079: request.setParameter("integer", "893749");
080: request.setParameter("char", "u");
081: request.setParameter("character", "R");
082: request.setParameter("boolean", "y");
083: request.setParameter("booleanObject", "no");
084: request.setParameter("byte", "120");
085: request.setParameter("byteObject", "21");
086: request.setParameter("double", "34878.34");
087: request.setParameter("doubleObject", "25435.98");
088: request.setParameter("float", "3434.76");
089: request.setParameter("floatObject", "6534.8");
090: request.setParameter("long", "34347897");
091: request.setParameter("longObject", "2335454");
092: request.setParameter("short", "32");
093: request.setParameter("shortObject", "12");
094:
095: response = conversation.getResponse(request);
096:
097: assertEquals(
098: "the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
099: response.getText());
100:
101: request = new GetMethodWebRequest(
102: "http://localhost:8181/inputs/bean/normal");
103: request.setParameter("string", "the string");
104: request.setParameter("boolean", "y");
105: request.setParameter("string", "the string");
106: request.setParameter("stringbuffer", "the stringbuffer");
107: request.setParameter("int", "23fd33");
108: request.setParameter("char", "u");
109: request.setParameter("character", "R");
110: request.setParameter("boolean", "y");
111: request.setParameter("booleanObject", "no");
112: request.setParameter("byte", "120");
113: request.setParameter("byteObject", "21");
114: request.setParameter("double", "zef.34");
115: request.setParameter("doubleObject", "25435.98");
116: request.setParameter("float", "3434.76");
117: request.setParameter("floatObject", "6534.8");
118: request.setParameter("long", "34347897");
119: request.setParameter("longObject", "233f5454");
120: request.setParameter("short", "32");
121: request.setParameter("shortObject", "");
122: response = conversation.getResponse(request);
123:
124: assertEquals(
125: "NOTNUMERIC : int\nNOTNUMERIC : double\nNOTNUMERIC : longObject\nthe string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
126: response.getText());
127: }
128:
129: public void testInputsBeanPrefix() throws Exception {
130: setupSite("site/inputs.xml");
131:
132: WebConversation conversation = new WebConversation();
133: WebRequest request = new GetMethodWebRequest(
134: "http://localhost:8181/inputs/bean/prefix");
135: WebResponse response = null;
136: request.setParameter("prefix_string", "the string");
137: request.setParameter("prefix_boolean", "y");
138: request.setParameter("prefix_string", "the string");
139: request.setParameter("prefix_stringbuffer", "the stringbuffer");
140: request.setParameter("prefix_int", "23154");
141: request.setParameter("prefix_integer", "893749");
142: request.setParameter("prefix_char", "u");
143: request.setParameter("prefix_character", "R");
144: request.setParameter("prefix_boolean", "y");
145: request.setParameter("prefix_booleanObject", "no");
146: request.setParameter("prefix_byte", "120");
147: request.setParameter("prefix_byteObject", "21");
148: request.setParameter("prefix_double", "34878.34");
149: request.setParameter("prefix_doubleObject", "25435.98");
150: request.setParameter("prefix_float", "3434.76");
151: request.setParameter("prefix_floatObject", "6534.8");
152: request.setParameter("prefix_long", "34347897");
153: request.setParameter("prefix_longObject", "2335454");
154: request.setParameter("prefix_short", "32");
155: request.setParameter("prefix_shortObject", "12");
156:
157: response = conversation.getResponse(request);
158:
159: assertEquals(
160: "the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
161: response.getText());
162:
163: request = new GetMethodWebRequest(
164: "http://localhost:8181/inputs/bean/prefix");
165: request.setParameter("prefix_string", "the string");
166: request.setParameter("prefix_boolean", "y");
167: request.setParameter("prefix_string", "the string");
168: request.setParameter("prefix_stringbuffer", "the stringbuffer");
169: request.setParameter("prefix_int", "23fd33");
170: request.setParameter("prefix_char", "u");
171: request.setParameter("prefix_character", "R");
172: request.setParameter("prefix_boolean", "y");
173: request.setParameter("prefix_booleanObject", "no");
174: request.setParameter("prefix_byte", "120");
175: request.setParameter("prefix_byteObject", "21");
176: request.setParameter("prefix_double", "zef.34");
177: request.setParameter("prefix_doubleObject", "25435.98");
178: request.setParameter("prefix_float", "3434.76");
179: request.setParameter("prefix_floatObject", "6534.8");
180: request.setParameter("prefix_long", "34347897");
181: request.setParameter("prefix_longObject", "233f5454");
182: request.setParameter("prefix_short", "32");
183: request.setParameter("prefix_shortObject", "");
184: response = conversation.getResponse(request);
185:
186: assertEquals(
187: "NOTNUMERIC : int\nNOTNUMERIC : double\nNOTNUMERIC : longObject\nthe string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
188: response.getText());
189: }
190:
191: public void testNamedInputsBean() throws Exception {
192: setupSite("site/inputs.xml");
193:
194: WebConversation conversation = new WebConversation();
195: WebRequest request = new GetMethodWebRequest(
196: "http://localhost:8181/inputs/named_bean/normal");
197: WebResponse response = null;
198: request.setParameter("string", "the string");
199: request.setParameter("boolean", "y");
200: request.setParameter("string", "the string");
201: request.setParameter("stringbuffer", "the stringbuffer");
202: request.setParameter("int", "23154");
203: request.setParameter("integer", "893749");
204: request.setParameter("char", "u");
205: request.setParameter("character", "R");
206: request.setParameter("boolean", "y");
207: request.setParameter("booleanObject", "no");
208: request.setParameter("byte", "120");
209: request.setParameter("byteObject", "21");
210: request.setParameter("double", "34878.34");
211: request.setParameter("doubleObject", "25435.98");
212: request.setParameter("float", "3434.76");
213: request.setParameter("floatObject", "6534.8");
214: request.setParameter("long", "34347897");
215: request.setParameter("longObject", "2335454");
216: request.setParameter("short", "32");
217: request.setParameter("shortObject", "12");
218:
219: response = conversation.getResponse(request);
220:
221: assertEquals(
222: "the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
223: response.getText());
224:
225: request = new GetMethodWebRequest(
226: "http://localhost:8181/inputs/named_bean/normal");
227: request.setParameter("string", "the string");
228: request.setParameter("boolean", "y");
229: request.setParameter("string", "the string");
230: request.setParameter("stringbuffer", "the stringbuffer");
231: request.setParameter("int", "23fd33");
232: request.setParameter("char", "u");
233: request.setParameter("character", "R");
234: request.setParameter("boolean", "y");
235: request.setParameter("booleanObject", "no");
236: request.setParameter("byte", "120");
237: request.setParameter("byteObject", "21");
238: request.setParameter("double", "zef.34");
239: request.setParameter("doubleObject", "25435.98");
240: request.setParameter("float", "3434.76");
241: request.setParameter("floatObject", "6534.8");
242: request.setParameter("long", "34347897");
243: request.setParameter("longObject", "233f5454");
244: request.setParameter("short", "32");
245: request.setParameter("shortObject", "");
246: response = conversation.getResponse(request);
247:
248: assertEquals(
249: "NOTNUMERIC : int\nNOTNUMERIC : double\nNOTNUMERIC : longObject\nthe string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
250: response.getText());
251: }
252:
253: public void testNamedInputsBeanPrefix() throws Exception {
254: setupSite("site/inputs.xml");
255:
256: WebConversation conversation = new WebConversation();
257: WebRequest request = new GetMethodWebRequest(
258: "http://localhost:8181/inputs/named_bean/prefix");
259: WebResponse response = null;
260: request.setParameter("prefix_string", "the string");
261: request.setParameter("prefix_boolean", "y");
262: request.setParameter("prefix_string", "the string");
263: request.setParameter("prefix_stringbuffer", "the stringbuffer");
264: request.setParameter("prefix_int", "23154");
265: request.setParameter("prefix_integer", "893749");
266: request.setParameter("prefix_char", "u");
267: request.setParameter("prefix_character", "R");
268: request.setParameter("prefix_boolean", "y");
269: request.setParameter("prefix_booleanObject", "no");
270: request.setParameter("prefix_byte", "120");
271: request.setParameter("prefix_byteObject", "21");
272: request.setParameter("prefix_double", "34878.34");
273: request.setParameter("prefix_doubleObject", "25435.98");
274: request.setParameter("prefix_float", "3434.76");
275: request.setParameter("prefix_floatObject", "6534.8");
276: request.setParameter("prefix_long", "34347897");
277: request.setParameter("prefix_longObject", "2335454");
278: request.setParameter("prefix_short", "32");
279: request.setParameter("prefix_shortObject", "12");
280:
281: response = conversation.getResponse(request);
282:
283: assertEquals(
284: "the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
285: response.getText());
286:
287: request = new GetMethodWebRequest(
288: "http://localhost:8181/inputs/named_bean/prefix");
289: request.setParameter("prefix_string", "the string");
290: request.setParameter("prefix_boolean", "y");
291: request.setParameter("prefix_string", "the string");
292: request.setParameter("prefix_stringbuffer", "the stringbuffer");
293: request.setParameter("prefix_int", "23fd33");
294: request.setParameter("prefix_char", "u");
295: request.setParameter("prefix_character", "R");
296: request.setParameter("prefix_boolean", "y");
297: request.setParameter("prefix_booleanObject", "no");
298: request.setParameter("prefix_byte", "120");
299: request.setParameter("prefix_byteObject", "21");
300: request.setParameter("prefix_double", "zef.34");
301: request.setParameter("prefix_doubleObject", "25435.98");
302: request.setParameter("prefix_float", "3434.76");
303: request.setParameter("prefix_floatObject", "6534.8");
304: request.setParameter("prefix_long", "34347897");
305: request.setParameter("prefix_longObject", "233f5454");
306: request.setParameter("prefix_short", "32");
307: request.setParameter("prefix_shortObject", "");
308: response = conversation.getResponse(request);
309:
310: assertEquals(
311: "NOTNUMERIC : int\nNOTNUMERIC : double\nNOTNUMERIC : longObject\nthe string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
312: response.getText());
313: }
314:
315: public void testGenerated() throws Exception {
316: setupSite("site/inputs.xml");
317:
318: WebConversation conversation = new WebConversation();
319: WebRequest request = null;
320: WebResponse response = null;
321:
322: request = new GetMethodWebRequest(
323: "http://localhost:8181/inputs/generated");
324: request.setParameter("wantsupdates", "on");
325: request.setParameter("colors", new String[] { "orange", "blue",
326: "green" });
327: request.setParameter("firstname", "Geert");
328: request.setParameter("lastname", "Bevin");
329: response = conversation.getResponse(request);
330: assertEquals(
331: "Geert, Bevin\n"
332: + "<input type=\"checkbox\" name=\"wantsupdates\" checked=\"checked\"> I want updates<br />\n"
333: + "<input type=\"checkbox\" name=\"colors\" value=\"orange\" checked=\"checked\">orange<br />\n"
334: + "<input type=\"checkbox\" name=\"colors\" value=\"blue\" checked=\"checked\">blue<br />\n"
335: + "<input type=\"checkbox\" name=\"colors\" value=\"red\">red<br />\n"
336: + "<input type=\"radio\" name=\"firstname\" checked=\"checked\"> Geert\n"
337: + "<input type=\"radio\" name=\"firstname\"> Nathalie\n"
338: + "<select name=\"lastname\">\n"
339: + "\t<option value=\"Bevin\" selected=\"selected\">Bevin</option>\n"
340: + "\t<option value=\"Mafessoni\">Mafessoni</option>\n"
341: + "</select>\n", response.getText());
342:
343: request = new GetMethodWebRequest(
344: "http://localhost:8181/inputs/generated");
345: response = conversation.getResponse(request);
346: assertEquals(
347: "<!--V 'INPUT:firstname'/-->, <!--V 'INPUT:lastname'/-->\n"
348: + "<input type=\"checkbox\" name=\"wantsupdates\"> I want updates<br />\n"
349: + "<input type=\"checkbox\" name=\"colors\" value=\"orange\">orange<br />\n"
350: + "<input type=\"checkbox\" name=\"colors\" value=\"blue\">blue<br />\n"
351: + "<input type=\"checkbox\" name=\"colors\" value=\"red\">red<br />\n"
352: + "<input type=\"radio\" name=\"firstname\"> Geert\n"
353: + "<input type=\"radio\" name=\"firstname\"> Nathalie\n"
354: + "<select name=\"lastname\">\n"
355: + "\t<option value=\"Bevin\">Bevin</option>\n"
356: + "\t<option value=\"Mafessoni\">Mafessoni</option>\n"
357: + "</select>\n", response.getText());
358: }
359:
360: public void testDirectAccess() throws Exception {
361: setupSite("site/inputs.xml");
362: WebConversation conversation = new WebConversation();
363: WebRequest request = new GetMethodWebRequest(
364: "http://localhost:8181/inputs/valid");
365: request.setParameter("input1", "first");
366: request.setParameter("input3", "third");
367: request.setParameter("input2", "second");
368: WebResponse response = conversation.getResponse(request);
369: assertEquals("another responsefirstsecondthird", response
370: .getText());
371: }
372:
373: public void testDirectAccessInjection() throws Exception {
374: Calendar cal = Calendar.getInstance(RifeConfig.Tools
375: .getDefaultTimeZone());
376: cal.clear();
377:
378: setupSite("site/inputs.xml");
379: WebConversation conversation = new WebConversation();
380: WebRequest request = new GetMethodWebRequest(
381: "http://localhost:8181/inputs/valid_injection");
382: request.setParameter("input1", "first");
383: cal.set(2006, 9, 23, 10, 23, 11);
384: request.setParameter("input3", BeanUtils
385: .getConcisePreciseDateFormat().format(cal.getTime()));
386: cal.set(2007, 2, 11, 15, 4, 54);
387: request.setParameter("input2", String.valueOf(cal
388: .getTimeInMillis()));
389: WebResponse response = conversation.getResponse(request);
390: assertEquals(
391: "another responsefirst,20070311150454000+0100,1161591791000",
392: response.getText());
393:
394: request = new GetMethodWebRequest(
395: "http://localhost:8181/inputs/valid_injection");
396: request.setParameter("input1", "first");
397: cal.set(2006, 9, 23, 10, 23, 11);
398: request.setParameter("input3", String.valueOf(cal
399: .getTimeInMillis()));
400: cal.set(2007, 2, 11, 15, 4, 54);
401: request.setParameter("input2", RifeConfig.Tools
402: .getDefaultInputDateFormat().format(
403: cal.getTimeInMillis()));
404: response = conversation.getResponse(request);
405: assertEquals(
406: "another responsefirst,20070311150400000+0100,1161591791000",
407: response.getText());
408: }
409:
410: public void testNamedInputsBeanInjection() throws Throwable {
411: setupSite("site/inputs.xml");
412:
413: WebConversation conversation = new WebConversation();
414: WebRequest request = new GetMethodWebRequest(
415: "http://localhost:8181/inputs/named_bean/normal/injection");
416: WebResponse response = null;
417: request.setParameter("string", "the string");
418: request.setParameter("boolean", "y");
419: request.setParameter("string", "the string");
420: request.setParameter("stringbuffer", "the stringbuffer");
421: request.setParameter("int", "23154");
422: request.setParameter("integer", "893749");
423: request.setParameter("char", "u");
424: request.setParameter("character", "R");
425: request.setParameter("boolean", "y");
426: request.setParameter("booleanObject", "no");
427: request.setParameter("byte", "120");
428: request.setParameter("byteObject", "21");
429: request.setParameter("double", "34878.34");
430: request.setParameter("doubleObject", "25435.98");
431: request.setParameter("float", "3434.76");
432: request.setParameter("floatObject", "6534.8");
433: request.setParameter("long", "34347897");
434: request.setParameter("longObject", "2335454");
435: request.setParameter("short", "32");
436: request.setParameter("shortObject", "12");
437:
438: response = conversation.getResponse(request);
439:
440: assertEquals(
441: "the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
442: response.getText());
443:
444: request = new GetMethodWebRequest(
445: "http://localhost:8181/inputs/named_bean/normal/injection");
446: request.setParameter("string", "the string");
447: request.setParameter("boolean", "y");
448: request.setParameter("string", "the string");
449: request.setParameter("stringbuffer", "the stringbuffer");
450: request.setParameter("int", "23fd33");
451: request.setParameter("char", "u");
452: request.setParameter("character", "R");
453: request.setParameter("boolean", "y");
454: request.setParameter("booleanObject", "no");
455: request.setParameter("byte", "120");
456: request.setParameter("byteObject", "21");
457: request.setParameter("double", "zef.34");
458: request.setParameter("doubleObject", "25435.98");
459: request.setParameter("float", "3434.76");
460: request.setParameter("floatObject", "6534.8");
461: request.setParameter("long", "34347897");
462: request.setParameter("longObject", "233f5454");
463: request.setParameter("short", "32");
464: request.setParameter("shortObject", "");
465: response = conversation.getResponse(request);
466:
467: assertEquals(
468: "NOTNUMERIC : int\nNOTNUMERIC : double\nNOTNUMERIC : longObject\nthe string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
469: response.getText());
470: }
471:
472: public void testNamedInputsBeanPrefixInjection() throws Throwable {
473: setupSite("site/inputs.xml");
474:
475: WebConversation conversation = new WebConversation();
476: WebRequest request = new GetMethodWebRequest(
477: "http://localhost:8181/inputs/named_bean/prefix/injection");
478: WebResponse response = null;
479: request.setParameter("prefix_string", "the string");
480: request.setParameter("prefix_boolean", "y");
481: request.setParameter("prefix_string", "the string");
482: request.setParameter("prefix_stringbuffer", "the stringbuffer");
483: request.setParameter("prefix_int", "23154");
484: request.setParameter("prefix_integer", "893749");
485: request.setParameter("prefix_char", "u");
486: request.setParameter("prefix_character", "R");
487: request.setParameter("prefix_boolean", "y");
488: request.setParameter("prefix_booleanObject", "no");
489: request.setParameter("prefix_byte", "120");
490: request.setParameter("prefix_byteObject", "21");
491: request.setParameter("prefix_double", "34878.34");
492: request.setParameter("prefix_doubleObject", "25435.98");
493: request.setParameter("prefix_float", "3434.76");
494: request.setParameter("prefix_floatObject", "6534.8");
495: request.setParameter("prefix_long", "34347897");
496: request.setParameter("prefix_longObject", "2335454");
497: request.setParameter("prefix_short", "32");
498: request.setParameter("prefix_shortObject", "12");
499:
500: response = conversation.getResponse(request);
501:
502: assertEquals(
503: "the string,the stringbuffer,23154,893749,u,null,true,false,0,21,34878.34,25435.98,3434.76,6534.8,34347897,2335454,32,12",
504: response.getText());
505:
506: request = new GetMethodWebRequest(
507: "http://localhost:8181/inputs/named_bean/prefix/injection");
508: request.setParameter("prefix_string", "the string");
509: request.setParameter("prefix_boolean", "y");
510: request.setParameter("prefix_string", "the string");
511: request.setParameter("prefix_stringbuffer", "the stringbuffer");
512: request.setParameter("prefix_int", "23fd33");
513: request.setParameter("prefix_char", "u");
514: request.setParameter("prefix_character", "R");
515: request.setParameter("prefix_boolean", "y");
516: request.setParameter("prefix_booleanObject", "no");
517: request.setParameter("prefix_byte", "120");
518: request.setParameter("prefix_byteObject", "21");
519: request.setParameter("prefix_double", "zef.34");
520: request.setParameter("prefix_doubleObject", "25435.98");
521: request.setParameter("prefix_float", "3434.76");
522: request.setParameter("prefix_floatObject", "6534.8");
523: request.setParameter("prefix_long", "34347897");
524: request.setParameter("prefix_longObject", "233f5454");
525: request.setParameter("prefix_short", "32");
526: request.setParameter("prefix_shortObject", "");
527: response = conversation.getResponse(request);
528:
529: assertEquals(
530: "NOTNUMERIC : int\nNOTNUMERIC : double\nNOTNUMERIC : longObject\nthe string,the stringbuffer,0,null,u,null,true,false,0,21,0.0,25435.98,3434.76,6534.8,34347897,null,32,null",
531: response.getText());
532: }
533:
534: public void testInvalid() throws Exception {
535: setupSite("site/inputs.xml");
536: WebConversation conversation = new WebConversation();
537: WebRequest request = new GetMethodWebRequest(
538: "http://localhost:8181/inputs/invalid");
539: try {
540: WebResponse response = conversation.getResponse(request);
541: fail();
542: assertNotNull(response);
543: } catch (HttpInternalErrorException e) {
544: assertTrue(getLogSink().getInternalException() instanceof InputUnknownException);
545:
546: InputUnknownException e2 = (InputUnknownException) getLogSink()
547: .getInternalException();
548: assertEquals("input1", e2.getInputName());
549: assertEquals(e2.getDeclarationName(),
550: "element/inputs/invalid.xml");
551: }
552: }
553:
554: public void testDefaults() throws Exception {
555: setupSite("site/inputs.xml");
556: WebConversation conversation = new WebConversation();
557: WebRequest request = new GetMethodWebRequest(
558: "http://localhost:8181/inputs/defaults");
559: request.setParameter("input1", "overridden");
560: WebResponse response = conversation.getResponse(request);
561: assertEquals("overridden" + "the second value"
562: + "3rda-3rdd-3rdc-3rdb" + "the element config value",
563: response.getText());
564: }
565:
566: public void testTargetChild() throws Exception {
567: setupSite("site/inputs.xml");
568: WebConversation conversation = new WebConversation();
569: WebRequest request = new GetMethodWebRequest(
570: "http://localhost:8181/inputs/targetchild");
571: request.setParameter("childinput", "requestvalue");
572: request.setParameter("overridden", "requestvalue");
573: request.setParameter("aninput", "requestvalue");
574: WebResponse response = conversation.getResponse(request);
575: assertEquals(
576: "globalvalue,requestvalue,middleparentvalue,requestvalue",
577: response.getText());
578: }
579:
580: public void testMiddleParent() throws Exception {
581: setupSite("site/inputs.xml");
582: WebConversation conversation = new WebConversation();
583: WebRequest request = new GetMethodWebRequest(
584: "http://localhost:8181/inputs/targetchild");
585: request.setParameter("middleparentinput", "requestvalue");
586: request.setParameter("overridden", "requestvalue");
587: request.setParameter("aninput", "requestvalue");
588: WebResponse response = conversation.getResponse(request);
589: assertEquals(
590: "globalvalue,requestvalue,topparentvalue,requestvalue",
591: response.getText());
592: }
593:
594: public void testTopParent() throws Exception {
595: setupSite("site/inputs.xml");
596: WebConversation conversation = new WebConversation();
597: WebRequest request = new GetMethodWebRequest(
598: "http://localhost:8181/inputs/targetchild");
599: request.setParameter("topparentinput", "requestvalue");
600: request.setParameter("overridden", "requestvalue");
601: request.setParameter("aninput", "requestvalue");
602: WebResponse response = conversation.getResponse(request);
603: assertEquals(
604: "globalvalue,requestvalue,requestvalue,requestvalue",
605: response.getText());
606: }
607:
608: public void testThroughExit() throws Exception {
609: setupSite("site/inputs.xml");
610: WebConversation conversation = new WebConversation();
611: WebRequest request = new GetMethodWebRequest(
612: "http://localhost:8181/inputs/exitsource");
613: request.setParameter("exitinput", "requestvalue");
614: request.setParameter("aninput", "requestvalue");
615: WebResponse response = conversation.getResponse(request);
616: assertEquals("exitsourcevalue,null", response.getText());
617: }
618:
619: public void testPathInfoMapping() throws Throwable {
620: setupSite("site/inputs.xml");
621:
622: WebConversation conversation = new WebConversation();
623: WebRequest request;
624: WebResponse response;
625:
626: request = new GetMethodWebRequest(
627: "http://localhost:8181/inputs/pathinfosource?switch=1");
628: response = conversation.getResponse(request);
629: response = response.getLinkWith("go").click();
630: assertEquals("/anotherinput/523exitsourcevalue1/suffix\n"
631: + "exitsourcevalue1,523,null,null,exitsourcevalue5",
632: response.getText());
633:
634: request = new GetMethodWebRequest(
635: "http://localhost:8181/inputs/pathinfosource?switch=2");
636: response = conversation.getResponse(request);
637: response = response.getLinkWith("go").click();
638: assertEquals(
639: "/\n"
640: + "exitsourcevalue1,exitsourcevalue2,null,null,exitsourcevalue5",
641: response.getText());
642:
643: request = new GetMethodWebRequest(
644: "http://localhost:8181/inputs/pathinfosource?switch=3");
645: response = conversation.getResponse(request);
646: response = response.getLinkWith("go").click();
647: assertEquals("/myinput/value1/222122/bacacdd\n"
648: + "value1,222122,baca,cdd,exitsourcevalue5", response
649: .getText());
650:
651: request = new GetMethodWebRequest(
652: "http://localhost:8181/inputs/pathinfosource?switch=4");
653: response = conversation.getResponse(request);
654: response = response.getForms()[0].submit();
655: assertEquals("/anotherinput/523exitsourcevalue1/suffix\n"
656: + "exitsourcevalue1,523,null,null,exitsourcevalue5",
657: response.getText());
658:
659: request = new GetMethodWebRequest(
660: "http://localhost:8181/inputs/pathinfosource?switch=5");
661: response = conversation.getResponse(request);
662: response = response.getForms()[0].submit();
663: assertEquals(
664: "/\n"
665: + "exitsourcevalue1,exitsourcevalue2,null,null,exitsourcevalue5",
666: response.getText());
667:
668: request = new GetMethodWebRequest(
669: "http://localhost:8181/inputs/pathinfosource?switch=6");
670: response = conversation.getResponse(request);
671: response = response.getForms()[0].submit();
672: assertEquals("/myinput/value1/222122/bacacdd\n"
673: + "value1,222122,baca,cdd,exitsourcevalue5", response
674: .getText());
675: }
676:
677: public void testPathInfoMappingDirectAccess() throws Throwable {
678: setupSite("site/inputs.xml");
679:
680: WebConversation conversation = new WebConversation();
681: WebRequest request;
682: WebResponse response;
683:
684: request = new GetMethodWebRequest(
685: "http://localhost:8181/inputs/pathinfotarget/myinput/value1/222122/bacacdd?exitinput3=yoyo");
686: response = conversation.getResponse(request);
687: assertEquals("/myinput/value1/222122/bacacdd\n"
688: + "value1,222122,yoyo,cdd,null", response.getText());
689:
690: request = new GetMethodWebRequest(
691: "http://localhost:8181/inputs/pathinfotarget/anotherinput/6786chars/suffix");
692: response = conversation.getResponse(request);
693: assertEquals("/anotherinput/6786chars/suffix\n"
694: + "chars,6786,null,null,null", response.getText());
695: }
696:
697: public void testPathInfoMappingReflexive() throws Throwable {
698: setupSite("site/inputs.xml");
699:
700: WebConversation conversation = new WebConversation();
701: WebRequest request;
702: WebResponse response;
703:
704: request = new GetMethodWebRequest(
705: "http://localhost:8181/inputs/pathinforeflexive/890");
706: response = conversation.getResponse(request);
707: assertEquals(
708: "/inputs/pathinforeflexive?overridden=globalvalue&globalvar=globalvalue",
709: response.getText());
710: }
711:
712: public void testPathInfoMappingStrict() throws Throwable {
713: setupSite("site/inputs.xml");
714:
715: WebConversation conversation = new WebConversation();
716: WebRequest request;
717: WebResponse response;
718:
719: request = new GetMethodWebRequest(
720: "http://localhost:8181/inputs/pathinfostrict/theid1/890");
721: response = conversation.getResponse(request);
722: assertEquals(".PATHINFOSTRICT1,890", response.getText());
723:
724: request = new GetMethodWebRequest(
725: "http://localhost:8181/inputs/pathinfostrict/theid1/in/valid");
726: try {
727: response = conversation.getResponse(request);
728: fail();
729: } catch (HttpNotFoundException e) {
730: assertTrue(true);
731: }
732:
733: request = new GetMethodWebRequest(
734: "http://localhost:8181/inputs/pathinfostrict/9456/theid2");
735: response = conversation.getResponse(request);
736: assertEquals(".PATHINFOSTRICT2,9456", response.getText());
737:
738: request = new GetMethodWebRequest(
739: "http://localhost:8181/inputs/pathinfostrict/in/valid/theid2");
740: try {
741: response = conversation.getResponse(request);
742: fail();
743: } catch (HttpNotFoundException e) {
744: assertTrue(true);
745: }
746: }
747:
748: public void testReflexiveSubmission() throws Throwable {
749: setupSite("site/inputs.xml");
750:
751: WebConversation conversation = new WebConversation();
752: WebRequest request;
753: WebResponse response;
754:
755: request = new GetMethodWebRequest(
756: "http://localhost:8181/inputs/reflexivesubmission?inputreflexive=requestvalue1&inputnormal=requestvalue2");
757: response = conversation.getResponse(request);
758: assertEquals("requestvalue1", response.getElementWithID(
759: "inputreflexive").getText());
760: assertEquals("requestvalue2", response.getElementWithID(
761: "inputnormal").getText());
762:
763: WebForm form = response.getForms()[0];
764: form.setParameter("param", "paramvalue");
765: response = form.submit();
766: assertEquals("paramvalue\n" + "outputreflexivevalue\n"
767: + "requestvalue2", response.getText());
768: }
769: }
|