001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.tests;
016:
017: import java.text.SimpleDateFormat;
018: import java.util.Date;
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.Map;
022: import junit.framework.TestCase;
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.araneaframework.core.ApplicationWidget;
026: import org.araneaframework.core.StandardPath;
027: import org.araneaframework.http.core.StandardServletInputData;
028: import org.araneaframework.mock.MockHttpInputData;
029: import org.araneaframework.mock.MockOutputData;
030: import org.araneaframework.tests.mock.MockEnvironment;
031: import org.araneaframework.tests.util.RequestUtil;
032: import org.araneaframework.uilib.event.OnClickEventListener;
033: import org.araneaframework.uilib.form.Control;
034: import org.araneaframework.uilib.form.FormElement;
035: import org.araneaframework.uilib.form.FormWidget;
036: import org.araneaframework.uilib.form.constraint.ConstraintGroupHelper;
037: import org.araneaframework.uilib.form.constraint.GroupedConstraint;
038: import org.araneaframework.uilib.form.constraint.NotEmptyConstraint;
039: import org.araneaframework.uilib.form.control.ButtonControl;
040: import org.araneaframework.uilib.form.control.CheckboxControl;
041: import org.araneaframework.uilib.form.control.DateTimeControl;
042: import org.araneaframework.uilib.form.control.NumberControl;
043: import org.araneaframework.uilib.form.control.SelectControl;
044: import org.araneaframework.uilib.form.control.StringArrayRequestControl;
045: import org.araneaframework.uilib.form.control.TextControl;
046: import org.araneaframework.uilib.form.control.TextareaControl;
047: import org.araneaframework.uilib.form.converter.IdenticalConverter;
048: import org.araneaframework.uilib.form.converter.StringToLongConverter;
049: import org.araneaframework.uilib.form.converter.TimestampToDateConverter;
050: import org.araneaframework.uilib.form.data.BooleanData;
051: import org.araneaframework.uilib.form.data.DateData;
052: import org.araneaframework.uilib.form.data.IntegerData;
053: import org.araneaframework.uilib.form.data.LongData;
054: import org.araneaframework.uilib.form.data.StringData;
055: import org.araneaframework.uilib.support.DisplayItem;
056: import org.springframework.mock.web.MockHttpServletRequest;
057:
058: /**
059: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
060: *
061: */
062: public class FormTest extends TestCase {
063:
064: private static final Log log = LogFactory.getLog(FormTest.class);
065:
066: boolean eventsWork = false;
067:
068: public FormTest(String name) {
069: super (name);
070: }
071:
072: private FormWidget makeUsualForm() throws Exception {
073:
074: //Creating form :-)
075: FormWidget testForm = new FormWidget();
076:
077: //Adding elements to form
078: testForm.addElement("myCheckBox", "my checkbox",
079: new CheckboxControl(), new BooleanData(), true);
080: testForm.addElement("myLongText", "my long text",
081: new TextControl(), new LongData(), true);
082: testForm.addElement("myDateTime", "my date and time",
083: new DateTimeControl(), new DateData(), false);
084: testForm.addElement("myButton", "my button",
085: new ButtonControl(), null, false);
086:
087: //Adding a composite element
088: FormWidget hierarchyTest = testForm.addSubForm("hierarchyTest");
089: hierarchyTest.addElement("myTextarea", "my text area",
090: new TextareaControl(), new StringData(), true);
091:
092: //Filling in select control (which is under a composite element)
093: FormElement mySelectElement = hierarchyTest.addElement(
094: "mySelect", "my drop down", new SelectControl(),
095: new LongData(), true);
096: SelectControl mySelect = (SelectControl) mySelectElement
097: .getControl();
098: mySelect.addItem(new DisplayItem("1", "one"));
099: mySelect.addItem(new DisplayItem("2", "two"));
100: mySelect.addItem(new DisplayItem("3", "three"));
101: mySelect.addItem(new DisplayItem("4", "four"));
102:
103: testForm._getComponent().init(null, new MockEnvironment());
104:
105: return testForm;
106: }
107:
108: /**
109: * Tests converter picking
110: */
111: public void testConverters() throws Exception {
112:
113: FormWidget testForm = makeUsualForm();
114:
115: FormWidget hierarchyTest = (FormWidget) testForm
116: .getElement("hierarchyTest");
117:
118: //Checking that converter is picked right
119: assertTrue(((FormElement) testForm.getElement("myCheckBox"))
120: .getConverter() instanceof IdenticalConverter);
121: assertTrue(((FormElement) testForm.getElement("myLongText"))
122: .getConverter() instanceof StringToLongConverter);
123: assertTrue(((FormElement) testForm.getElement("myDateTime"))
124: .getConverter() instanceof TimestampToDateConverter);
125: assertTrue(((FormElement) hierarchyTest.getElement("mySelect"))
126: .getConverter() instanceof StringToLongConverter);
127: assertTrue(((FormElement) hierarchyTest
128: .getElement("myTextarea")).getConverter() instanceof IdenticalConverter);
129: }
130:
131: /**
132: * Tests value assigning.
133: */
134: public void testValueAssigning() throws Exception {
135:
136: FormWidget testForm = makeUsualForm();
137:
138: FormWidget hierarchyTest = (FormWidget) testForm
139: .getElement("hierarchyTest");
140:
141: //Setting initial form data
142: ((FormElement) testForm.getElement("myCheckBox")).getData()
143: .setValue(Boolean.TRUE);
144: ((FormElement) testForm.getElement("myLongText")).getData()
145: .setValue(new Long(16));
146:
147: Date now = new Date(System.currentTimeMillis());
148:
149: ((FormElement) testForm.getElement("myDateTime")).getData()
150: .setValue(now);
151: ((FormElement) hierarchyTest.getElement("mySelect")).getData()
152: .setValue(new Long(12637));
153: ((FormElement) hierarchyTest.getElement("myTextarea"))
154: .getData().setValue("MIB");
155:
156: //Checking that the data assigning works
157: assertTrue(((FormElement) testForm.getElement("myCheckBox"))
158: .getData().getValue().equals(Boolean.TRUE));
159: assertTrue(((FormElement) testForm.getElement("myLongText"))
160: .getData().getValue().equals(new Long(16)));
161: assertTrue(((FormElement) testForm.getElement("myDateTime"))
162: .getData().getValue().equals(now));
163: assertTrue(((FormElement) hierarchyTest.getElement("mySelect"))
164: .getData().getValue().equals(new Long(12637)));
165: assertTrue(((FormElement) hierarchyTest
166: .getElement("myTextarea")).getData().getValue().equals(
167: "MIB"));
168: }
169:
170: /**
171: * Testing reading from valid request.
172: */
173: public void testFormValidRequestReading() throws Exception {
174:
175: FormWidget testForm = makeUsualForm();
176:
177: FormWidget hierarchyTest = (FormWidget) testForm
178: .getElement("hierarchyTest");
179:
180: MockHttpServletRequest validRequest = RequestUtil
181: .markSubmitted(new MockHttpServletRequest());
182:
183: validRequest.addParameter("myCheckBox", (String) null);
184: ((FormElement) testForm.getElement("myCheckBox")).rendered();
185:
186: validRequest.addParameter("myLongText", "108");
187: ((FormElement) testForm.getElement("myLongText")).rendered();
188:
189: ((FormElement) testForm.getElement("myDateTime")).rendered();
190: validRequest.addParameter("myDateTime.date", "11.10.2015");
191: validRequest.addParameter("myDateTime.time", "01:01");
192:
193: (((FormElement) ((FormWidget) testForm
194: .getElement("hierarchyTest")).getElement("myTextarea")))
195: .rendered();
196: validRequest.addParameter("hierarchyTest.myTextarea", "blah");
197:
198: (((FormElement) ((FormWidget) testForm
199: .getElement("hierarchyTest")).getElement("mySelect")))
200: .rendered();
201: validRequest.addParameter("hierarchyTest.mySelect", "2");
202:
203: //Trying to read from a valid request
204: StandardServletInputData input = new StandardServletInputData(
205: validRequest);
206:
207: // Test in lifecycle order, without calling event and render.
208: testForm._getWidget().update(input);
209: assertTrue(
210: "Test form must be valid after reading from request",
211: testForm.convertAndValidate());
212: testForm._getWidget().render(new MockOutputData());
213:
214: Date reqDate = (new SimpleDateFormat("dd.MM.yyyy hh:mm"))
215: .parse("11.10.2015 01:01");
216:
217: //Checking that reading from request works
218:
219: assertTrue(testForm.getValueByFullName("myCheckBox").equals(
220: Boolean.FALSE));
221: assertTrue(testForm.getValueByFullName("myLongText").equals(
222: new Long(108)));
223: assertTrue(testForm.getValueByFullName("myDateTime").equals(
224: reqDate));
225: assertTrue(hierarchyTest.getValueByFullName("mySelect").equals(
226: new Long(2)));
227: assertTrue(hierarchyTest.getValueByFullName("myTextarea")
228: .equals("blah"));
229:
230: StringArrayRequestControl.ViewModel vm1 = ((StringArrayRequestControl.ViewModel) ((CheckboxControl) testForm
231: .getControlByFullName("myCheckBox")).getViewModel());
232:
233: assertTrue((Boolean.valueOf(vm1.getSimpleValue())
234: .equals(Boolean.FALSE)));
235:
236: TextControl.ViewModel vm2 = ((TextControl.ViewModel) ((TextControl) testForm
237: .getControlByFullName("myLongText")).getViewModel());
238: assertTrue(Long.valueOf(vm2.getSimpleValue()).equals(
239: new Long(108)));
240:
241: assertTrue(((FormElement) testForm.getElement("myCheckBox"))
242: .getData().getValue().equals(Boolean.FALSE));
243: assertTrue(((FormElement) testForm.getElement("myLongText"))
244: .getData().getValue().equals(new Long(108)));
245: assertTrue(((FormElement) testForm.getElement("myDateTime"))
246: .getData().getValue().equals(reqDate));
247: assertTrue(((FormElement) hierarchyTest.getElement("mySelect"))
248: .getData().getValue().equals(new Long(2)));
249: assertTrue(((FormElement) hierarchyTest
250: .getElement("myTextarea")).getData().getValue().equals(
251: "blah"));
252: }
253:
254: /**
255: * Testing reading from invalid request.
256: */
257: public void testFormInvalidRequestReading() throws Exception {
258: FormWidget testForm = makeUsualForm();
259:
260: MockHttpServletRequest invalidRequest = RequestUtil
261: .markSubmitted(new MockHttpServletRequest());
262:
263: invalidRequest.addParameter("myCheckBox", "ksjf");
264: ((FormElement) testForm.getElement("myCheckBox")).rendered();
265:
266: ((FormElement) testForm.getElement("myDateTime")).rendered();
267: invalidRequest.addParameter("myDateTime.date", "HA-HA");
268: invalidRequest.addParameter("myDateTime.time", "BLAH");
269:
270: (((FormElement) ((FormWidget) testForm
271: .getElement("hierarchyTest")).getElement("myTextarea")))
272: .rendered();
273: invalidRequest.addParameter("hierarchyTest.myTextarea", "");
274:
275: //Testing that invalid requests are read right
276: StandardServletInputData input = new StandardServletInputData(
277: invalidRequest);
278: testForm._getWidget().update(input);
279:
280: assertTrue(
281: "Test form must not be valid after reading from request",
282: !testForm.convertAndValidate());
283: }
284:
285: /**
286: * Testing reading from request with a mandatory element missing.
287: */
288: public void testFormMandatoryMissingRequestReading()
289: throws Exception {
290:
291: FormWidget testForm = makeUsualForm();
292:
293: MockHttpServletRequest mandatoryMissingRequest = RequestUtil
294: .markSubmitted(new MockHttpServletRequest());
295:
296: mandatoryMissingRequest.addParameter("myCheckBox", "true");
297: mandatoryMissingRequest.addParameter("myLongText", "108");
298: mandatoryMissingRequest.addParameter("myDateTime.date",
299: "11.10.2015");
300: mandatoryMissingRequest
301: .addParameter("myDateTime.time", "01:01");
302: mandatoryMissingRequest.addParameter("hierarchyTest.mySelect",
303: "2");
304:
305: //Testing that mandatory items are processed right
306: StandardServletInputData input = new StandardServletInputData(
307: mandatoryMissingRequest);
308: testForm._getWidget().update(input);
309:
310: assertTrue(
311: "Test form must not be valid after reading from request",
312: !testForm.convertAndValidate());
313: }
314:
315: /**
316: * Testing reading from request with a not mandatory element missing.
317: */
318: public void testFormNotMandatoryMissingRequestReading()
319: throws Exception {
320:
321: FormWidget testForm = makeUsualForm();
322:
323: MockHttpServletRequest notMandatoryMissingRequest = RequestUtil
324: .markSubmitted(new MockHttpServletRequest());
325:
326: notMandatoryMissingRequest.addParameter("myCheckBox",
327: (String) null);
328: ((FormElement) testForm.getElement("myCheckBox")).rendered();
329:
330: notMandatoryMissingRequest.addParameter("myLongText", "108");
331: ((FormElement) testForm.getElement("myLongText")).rendered();
332:
333: notMandatoryMissingRequest.addParameter(
334: "hierarchyTest.myTextarea", "blah");
335: (((FormElement) ((FormWidget) testForm
336: .getElement("hierarchyTest")).getElement("myTextarea")))
337: .rendered();
338:
339: notMandatoryMissingRequest.addParameter(
340: "hierarchyTest.mySelect", "3");
341: (((FormElement) ((FormWidget) testForm
342: .getElement("hierarchyTest")).getElement("mySelect")))
343: .rendered();
344:
345: StandardServletInputData input = new StandardServletInputData(
346: notMandatoryMissingRequest);
347: testForm._getWidget().update(input);
348:
349: assertTrue(
350: "Test form must be valid after reading from request",
351: testForm.convertAndValidate());
352: }
353:
354: /**
355: * Testing reading from request with a grouped constraint set.
356: */
357: public void testFormActiveGroupedConstraintInvalidates()
358: throws Exception {
359: FormWidget testForm = makeUsualForm();
360:
361: MockHttpServletRequest notMandatoryMissingRequest = RequestUtil
362: .markSubmitted(new MockHttpServletRequest());
363:
364: notMandatoryMissingRequest.addParameter("myCheckBox", "true");
365: ((FormElement) testForm.getElement("myCheckBox")).rendered();
366:
367: notMandatoryMissingRequest.addParameter("myLongText", "108");
368: ((FormElement) testForm.getElement("myLongText")).rendered();
369:
370: ((FormElement) testForm.getElement("myDateTime")).rendered();
371: notMandatoryMissingRequest.addParameter("myDateTime",
372: (String) null);
373:
374: notMandatoryMissingRequest.addParameter(
375: "hierarchyTest.myTextarea", "blah");
376: (((FormElement) ((FormWidget) testForm
377: .getElement("hierarchyTest")).getElement("myTextarea")))
378: .rendered();
379: notMandatoryMissingRequest.addParameter(
380: "hierarchyTest.mySelect", "2");
381: (((FormElement) ((FormWidget) testForm
382: .getElement("hierarchyTest")).getElement("mySelect")))
383: .rendered();
384:
385: // create helper
386: ConstraintGroupHelper groupHelper = new ConstraintGroupHelper();
387: testForm.getElement("myDateTime").setConstraint(
388: groupHelper.createGroupedConstraint(
389: new NotEmptyConstraint(), "active"));
390:
391: StandardServletInputData input = new StandardServletInputData(
392: notMandatoryMissingRequest);
393: testForm._getWidget().update(input);
394:
395: groupHelper.setActiveGroup("active");
396:
397: assertTrue(
398: "Test form must not be valid after reading from request",
399: !testForm.convertAndValidate());
400: }
401:
402: /**
403: * Testing reading from request with a grouped constraint set.
404: */
405: public void testFormActiveGroupedConstraintValidates()
406: throws Exception {
407:
408: FormWidget testForm = makeUsualForm();
409:
410: MockHttpServletRequest notMandatoryMissingRequest = RequestUtil
411: .markSubmitted(new MockHttpServletRequest());
412:
413: notMandatoryMissingRequest.addParameter("myCheckBox", "true");
414: ((FormElement) testForm.getElement("myCheckBox")).rendered();
415:
416: notMandatoryMissingRequest.addParameter("myLongText", "108");
417: ((FormElement) testForm.getElement("myLongText")).rendered();
418:
419: ((FormElement) testForm.getElement("myDateTime")).rendered();
420: notMandatoryMissingRequest.addParameter("myDateTime.date",
421: "11.10.2015");
422: notMandatoryMissingRequest.addParameter("myDateTime.time",
423: "01:01");
424:
425: notMandatoryMissingRequest.addParameter(
426: "hierarchyTest.myTextarea", "blah");
427: (((FormElement) ((FormWidget) testForm
428: .getElement("hierarchyTest")).getElement("myTextarea")))
429: .rendered();
430: notMandatoryMissingRequest.addParameter(
431: "hierarchyTest.mySelect", "2");
432: (((FormElement) ((FormWidget) testForm
433: .getElement("hierarchyTest")).getElement("mySelect")))
434: .rendered();
435:
436: // create helper
437: ConstraintGroupHelper groupHelper = new ConstraintGroupHelper();
438: GroupedConstraint groupedConstraint = (GroupedConstraint) groupHelper
439: .createGroupedConstraint(new NotEmptyConstraint(),
440: "active");
441: testForm.getElement("myDateTime").setConstraint(
442: groupedConstraint);
443:
444: StandardServletInputData input = new StandardServletInputData(
445: notMandatoryMissingRequest);
446: testForm._getWidget().update(input);
447:
448: groupHelper.setActiveGroup("active");
449: assertTrue(
450: "Test form must be valid after reading from request",
451: testForm.convertAndValidate());
452: }
453:
454: /**
455: * Testing reading from request with a grouped constraint set.
456: */
457: public void testFormInactiveGroupedConstraintValidates()
458: throws Exception {
459:
460: FormWidget testForm = makeUsualForm();
461:
462: MockHttpServletRequest notMandatoryMissingRequest = RequestUtil
463: .markSubmitted(new MockHttpServletRequest());
464:
465: notMandatoryMissingRequest.addParameter("myCheckBox", "true");
466: ((FormElement) testForm.getElement("myCheckBox")).rendered();
467:
468: notMandatoryMissingRequest.addParameter("myLongText", "108");
469: ((FormElement) testForm.getElement("myLongText")).rendered();
470:
471: ((FormElement) testForm.getElement("myDateTime")).rendered();
472: notMandatoryMissingRequest.addParameter("myDateTime.date",
473: "11.10.2015");
474: notMandatoryMissingRequest.addParameter("myDateTime.time",
475: "01:01");
476:
477: notMandatoryMissingRequest.addParameter(
478: "hierarchyTest.myTextarea", "blah");
479: (((FormElement) ((FormWidget) testForm
480: .getElement("hierarchyTest")).getElement("myTextarea")))
481: .rendered();
482: notMandatoryMissingRequest.addParameter(
483: "hierarchyTest.mySelect", "2");
484: (((FormElement) ((FormWidget) testForm
485: .getElement("hierarchyTest")).getElement("mySelect")))
486: .rendered();
487:
488: // create helper
489: ConstraintGroupHelper groupHelper = new ConstraintGroupHelper();
490: testForm.getElement("myDateTime").setConstraint(
491: groupHelper.createGroupedConstraint(
492: new NotEmptyConstraint(), "active"));
493:
494: StandardServletInputData input = new StandardServletInputData(
495: notMandatoryMissingRequest);
496: testForm._getWidget().update(input);
497:
498: assertTrue(
499: "Test form must be valid after reading from request",
500: testForm.convertAndValidate());
501: }
502:
503: /**
504: * Testing events.
505: */
506: public void testFormEventProcessing() throws Exception {
507: FormWidget testForm = makeUsualForm();
508:
509: //Simple event
510: ((FormElement) testForm.getElement("myButton")).rendered();
511: ((ButtonControl) ((FormElement) testForm.getElement("myButton"))
512: .getControl())
513: .addOnClickEventListener(new TestOnClickEventHandler());
514:
515: Map data = new HashMap();
516: data.put(ApplicationWidget.EVENT_HANDLER_ID_KEY, "onClicked");
517: MockHttpInputData input = new MockHttpInputData(data);
518:
519: ((FormElement) testForm.getElement("myButton"))._getWidget()
520: .update(input);
521: testForm._getWidget()
522: .event(new StandardPath("myButton"), input);
523:
524: assertTrue("Event succeeded", eventsWork);
525: }
526:
527: /**
528: * Testcase: http://changelogic.araneaframework.org/index.php?event=Show_task&task_id=316&project_id=0
529: * Disabled <select> is created, initial value set. Request does not contain this select (disabled
530: * HTML elements are not submitted). FormElement must be considered valid.
531: */
532: public void testDisabledNonNullMandatorySelectValidates()
533: throws Exception {
534: FormWidget testForm = new FormWidget();
535:
536: SelectControl selectControl = new SelectControl();
537: selectControl.addItem(new DisplayItem(null, "- choose -"));
538: selectControl.addItem(new DisplayItem("1", "one"));
539: selectControl.addItem(new DisplayItem("2", "two"));
540:
541: testForm.addElement("select", "#Select", selectControl,
542: new StringData(), true);
543: FormElement selectElement = (FormElement) testForm
544: .getElement("select");
545: selectElement.setValue("1");
546: selectElement.setDisabled(true);
547: selectElement.rendered();
548:
549: testForm._getComponent().init(null, new MockEnvironment());
550:
551: MockHttpServletRequest almostEmptyRequest = RequestUtil
552: .markSubmitted(new MockHttpServletRequest());
553:
554: almostEmptyRequest.addParameter("dummyParam", "true");
555:
556: StandardServletInputData input = new StandardServletInputData(
557: almostEmptyRequest);
558:
559: testForm._getWidget().update(input);
560:
561: testForm.getValueByFullName("select");
562: assertTrue(
563: "Test form disabled select element with assigned value must be valid after reading from request.",
564: testForm.convertAndValidate());
565: }
566:
567: /** Test that form addElement methods accept hierarchical ids creating subforms on demand */
568: public void testHierarchicalSubformCreation() throws Exception {
569: FormWidget form = new FormWidget();
570: FormElement element = form.addElement("1.2", "dummyLabel",
571: new CheckboxControl(), new BooleanData(), false);
572:
573: assertTrue("Created element should be accessible", form
574: .getElementByFullName("1.2").equals(element));
575: assertTrue("Subform should have been created", form
576: .getElement("1") instanceof FormWidget);
577:
578: // flat addElementAfter after nested form
579: FormElement afterElement = form.createElement("dumbLabel",
580: new TextControl(), new StringData(), false);
581: form.addElementAfter("after", afterElement, "1");
582:
583: Iterator iterator = form.getElements().values().iterator();
584: assertTrue("First should be the first nested form", iterator
585: .next() instanceof FormWidget);
586: assertTrue("Second should be the 'afterElement'", iterator
587: .next().equals(afterElement));
588: assertTrue("Should be no more elements in that form", !iterator
589: .hasNext());
590:
591: // addElementAfter with nested afterid is supported
592: FormElement nestedAfterElement = form.createElement(
593: "dumbdumbLabel", new TextControl(), new StringData(),
594: false);
595: form.addElementAfter("3", nestedAfterElement, "1.2");
596:
597: iterator = form.getSubFormByFullName("1").getElements()
598: .values().iterator();
599: assertTrue("First should be the first 'element'", element
600: .equals(iterator.next()));
601: assertTrue("Second should be the 'nestedAfterElement'",
602: nestedAfterElement.equals(iterator.next()));
603:
604: // addElementAfter with nested id is not supported
605: boolean failure = false;
606: try {
607: FormElement nextElement = form.createElement("dumbLabel",
608: new NumberControl(), new IntegerData(), false);
609: form.addElementAfter("x.y", nextElement, "1");
610: } catch (Exception e) {
611: failure = true;
612: }
613:
614: assertTrue(
615: "addElementAfter() with nested added element id is not supported",
616: failure);
617: }
618:
619: /**
620: * Tests helper functions that access form parts by their full name.
621: */
622: public void testFormTraversal() throws Exception {
623: FormWidget form = makeUsualForm();
624:
625: assertTrue(
626: "'myCheckBox' must contain a CheckboxControl!",
627: form.getControlByFullName("myCheckBox") instanceof CheckboxControl);
628: assertTrue(
629: "'hierarchyTest.myTextarea' must contain a TextareaControl!",
630: form.getControlByFullName("hierarchyTest.myTextarea") instanceof TextareaControl);
631:
632: Control result = form
633: .getControlByFullName("hierarchyTestm.yTextarea");
634:
635: assertTrue(
636: "An exception must be thrown if wrong element name is given!",
637: result == null);
638: }
639:
640: /**
641: * Tests that uninitialized form conversion works (that should be a no-op)
642: */
643: public void testUnInitializedFormConversion() throws Exception {
644: FormWidget form = new FormWidget();
645: form.addElement("elementName", "labelId", new TextControl(),
646: new StringData(), true);
647:
648: // should succeed
649: form.convert();
650: }
651:
652: private class TestOnClickEventHandler implements
653: OnClickEventListener {
654:
655: public void onClick() {
656: log.debug("Received onClick event!");
657: eventsWork = true;
658: }
659: }
660: }
|