001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of the GNU Lesser General Public License, 2.1 or later
004: * $Id: TestValidationBuilderXhtml.java 3634 2007-01-08 21:42:24Z gbevin $
005: */
006: package com.uwyn.rife.site;
007:
008: import com.uwyn.rife.site.exceptions.MissingMarkingBlockException;
009: import com.uwyn.rife.template.Template;
010: import com.uwyn.rife.template.TemplateFactory;
011: import java.util.ArrayList;
012: import java.util.List;
013: import junit.framework.TestCase;
014:
015: public class TestValidationBuilderXhtml extends TestCase {
016: public TestValidationBuilderXhtml(String name) {
017: super (name);
018: }
019:
020: public void testInstantiate() {
021: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
022: assertNotNull(builder);
023: }
024:
025: public void testClone() {
026: ValidationBuilderXhtml builder1 = new ValidationBuilderXhtml();
027: ValidationBuilderXhtml builder2 = (ValidationBuilderXhtml) builder1
028: .clone();
029: assertNotNull(builder2);
030: assertNotSame(builder1, builder2);
031: }
032:
033: public void testSetFallbackErrorAreaInvalidArguments() {
034: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
035: builder.setFallbackErrorArea(null, null);
036:
037: Template template = TemplateFactory.ENGINEHTML
038: .get("validationbuilder_errors_fallbackarea_basic");
039: builder.setFallbackErrorArea(template, null);
040: assertEquals("\n", template.getContent());
041: }
042:
043: public void testSetFallbackErrorAreaBasic() {
044: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
045:
046: Template template = TemplateFactory.ENGINEHTML
047: .get("validationbuilder_errors_fallbackarea_basic");
048: builder.setFallbackErrorArea(template, "my message");
049: assertEquals(TemplateFactory.ENGINEHTML.get(
050: "validationbuilder_errors_fallbackarea_basic_out")
051: .getContent(), template.getContent());
052: }
053:
054: public void testSetFallbackErrorAreaWildcardFormatted() {
055: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
056:
057: Template template = TemplateFactory.ENGINEHTML
058: .get("validationbuilder_errors_fallbackarea_wildcardformatted");
059: builder.setFallbackErrorArea(template, "my message");
060: assertEquals(
061: TemplateFactory.ENGINEHTML
062: .get(
063: "validationbuilder_errors_fallbackarea_wildcardformatted_out")
064: .getContent(), template.getContent());
065: }
066:
067: public void testSetFallbackErrorAreaFormatted() {
068: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
069:
070: Template template = TemplateFactory.ENGINEHTML
071: .get("validationbuilder_errors_fallbackarea_formatted");
072: builder.setFallbackErrorArea(template, "my message");
073: assertEquals(TemplateFactory.ENGINEHTML.get(
074: "validationbuilder_errors_fallbackarea_formatted_out")
075: .getContent(), template.getContent());
076: }
077:
078: public void testSetFallbackErrorAreaWildcardDecorated() {
079: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
080:
081: Template template = TemplateFactory.ENGINEHTML
082: .get("validationbuilder_errors_fallbackarea_wildcarddecorated");
083: builder.setFallbackErrorArea(template, "my message");
084: assertEquals(
085: TemplateFactory.ENGINEHTML
086: .get(
087: "validationbuilder_errors_fallbackarea_wildcarddecorated_out")
088: .getContent(), template.getContent());
089: }
090:
091: public void testSetFallbackErrorAreaDecorated() {
092: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
093:
094: Template template = TemplateFactory.ENGINEHTML
095: .get("validationbuilder_errors_fallbackarea_decorated");
096: builder.setFallbackErrorArea(template, "my message");
097: assertEquals(TemplateFactory.ENGINEHTML.get(
098: "validationbuilder_errors_fallbackarea_decorated_out")
099: .getContent(), template.getContent());
100: }
101:
102: public void testGenerateValidationErrorsInvalidArguments() {
103: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
104: assertEquals(0, builder.generateValidationErrors(null, null,
105: null, null).size());
106:
107: Template template = TemplateFactory.ENGINEHTML
108: .get("validationbuilder_errors_raw");
109: String raw_content = template.getContent();
110: assertNotNull(template);
111: assertEquals(0, builder.generateValidationErrors(template,
112: null, null, null).size());
113: assertEquals(raw_content, template.getContent());
114: assertEquals(0, builder.generateValidationErrors(template,
115: null, null, null).size());
116: assertEquals(raw_content, template.getContent());
117: assertEquals(0, builder.generateValidationErrors(template,
118: new ArrayList<ValidationError>(), null, null).size());
119: assertEquals(raw_content, template.getContent());
120: }
121:
122: public void testGenerateValidationErrorsNovalues() {
123: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
124:
125: Template template = TemplateFactory.ENGINEHTML
126: .get("validationbuilder_errors_novalues");
127:
128: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
129: bean.validate();
130: builder.generateValidationErrors(template, bean
131: .getValidationErrors(), bean.getValidatedSubjects(),
132: null);
133: assertEquals(TemplateFactory.ENGINEHTML.get(
134: "validationbuilder_errors_novalues").getContent(),
135: template.getContent());
136: }
137:
138: public void testGenerateValidationErrorsRaw() {
139: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
140:
141: Template template = TemplateFactory.ENGINEHTML
142: .get("validationbuilder_errors_raw");
143:
144: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
145: bean.validate();
146: bean
147: .addValidationError(new ValidationError.WRONGFORMAT(
148: "login"));
149: builder.generateValidationErrors(template, bean
150: .getValidationErrors(), bean.getValidatedSubjects(),
151: null);
152: assertEquals(TemplateFactory.ENGINEHTML.get(
153: "validationbuilder_errors_raw_out").getContent(),
154: template.getContent());
155: }
156:
157: public void testGenerateValidationErrorsRawFallbackblock() {
158: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
159:
160: Template template = TemplateFactory.ENGINEHTML
161: .get("validationbuilder_errors_raw_fallbackblock");
162:
163: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
164: bean.validate();
165: bean
166: .addValidationError(new ValidationError.WRONGFORMAT(
167: "login"));
168: builder.generateValidationErrors(template, bean
169: .getValidationErrors(), bean.getValidatedSubjects(),
170: null);
171: assertEquals(TemplateFactory.ENGINEHTML.get(
172: "validationbuilder_errors_raw_fallbackblock_out")
173: .getContent(), template.getContent());
174: }
175:
176: public void testGenerateValidationErrorsMessages() {
177: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
178:
179: Template template = TemplateFactory.ENGINEHTML
180: .get("validationbuilder_errors_messages");
181:
182: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
183: bean.setAnotherlogin("123456789012345678901");
184: bean.setPassword("1234567890");
185: bean.setColors(new String[] { "invalid" });
186: bean.validate();
187: builder.generateValidationErrors(template, bean
188: .getValidationErrors(), bean.getValidatedSubjects(),
189: null);
190: assertEquals(TemplateFactory.ENGINEHTML.get(
191: "validationbuilder_errors_messages_out").getContent(),
192: template.getContent());
193: }
194:
195: public void testGenerateValidationErrorsMessagesPrefix() {
196: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
197:
198: Template template = TemplateFactory.ENGINEHTML
199: .get("validationbuilder_errors_messages_prefix");
200:
201: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
202: bean.setPassword("1234567890");
203: bean.setColors(new String[] { "invalid" });
204: bean.validate();
205: builder.generateValidationErrors(template, bean
206: .getValidationErrors(), bean.getValidatedSubjects(),
207: "prefix_");
208: assertEquals(TemplateFactory.ENGINEHTML.get(
209: "validationbuilder_errors_messages_prefix_out")
210: .getContent(), template.getContent());
211: }
212:
213: public void testGenerateValidationErrorsFormattedmessages() {
214: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
215:
216: Template template = TemplateFactory.ENGINEHTML
217: .get("validationbuilder_errors_formattedmessages");
218:
219: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
220: bean.setAnotherlogin("123456789012345678901");
221: bean.setPassword("1234567890");
222: bean.setColors(new String[] { "invalid" });
223: bean.validate();
224: builder.generateValidationErrors(template, bean
225: .getValidationErrors(), bean.getValidatedSubjects(),
226: null);
227: assertEquals(TemplateFactory.ENGINEHTML.get(
228: "validationbuilder_errors_formattedmessages_out")
229: .getContent(), template.getContent());
230: }
231:
232: public void testGenerateValidationErrorsFormattedmessagesNocontent() {
233: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
234:
235: Template template = TemplateFactory.ENGINEHTML
236: .get("validationbuilder_errors_formattedmessages_nocontent");
237:
238: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
239: bean.setAnotherlogin("123456789012345678901");
240: bean.setPassword("1234567890");
241: bean.setColors(new String[] { "invalid" });
242: bean.validate();
243: builder.generateValidationErrors(template, bean
244: .getValidationErrors(), bean.getValidatedSubjects(),
245: null);
246: assertEquals(
247: TemplateFactory.ENGINEHTML
248: .get(
249: "validationbuilder_errors_formattedmessages_nocontent_out")
250: .getContent(), template.getContent());
251: }
252:
253: public void testGenerateValidationErrorsFormattedmessagesPrefix() {
254: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
255:
256: Template template = TemplateFactory.ENGINEHTML
257: .get("validationbuilder_errors_formattedmessages_prefix");
258:
259: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
260: bean.setAnotherlogin("123456789012345678901");
261: bean.setPassword("1234567890");
262: bean.setColors(new String[] { "invalid" });
263: bean.validate();
264: builder.generateValidationErrors(template, bean
265: .getValidationErrors(), bean.getValidatedSubjects(),
266: "prefix_");
267: assertEquals(
268: TemplateFactory.ENGINEHTML
269: .get(
270: "validationbuilder_errors_formattedmessages_prefix_out")
271: .getContent(), template.getContent());
272: }
273:
274: public void testGenerateValidationErrorsPositionedmessages() {
275: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
276:
277: Template template = TemplateFactory.ENGINEHTML
278: .get("validationbuilder_errors_positionedmessages");
279:
280: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
281: bean.validate();
282: builder.generateValidationErrors(template, bean
283: .getValidationErrors(), bean.getValidatedSubjects(),
284: null);
285: assertEquals(TemplateFactory.ENGINEHTML.get(
286: "validationbuilder_errors_positionedmessages_out1")
287: .getContent(), template.getContent());
288:
289: bean.resetValidation();
290: bean.validate();
291: bean.makeSubjectValid("anotherlogin");
292: bean.makeSubjectValid("anotherpassword");
293: builder.generateValidationErrors(template, bean
294: .getValidationErrors(), bean.getValidatedSubjects(),
295: null);
296: assertEquals(TemplateFactory.ENGINEHTML.get(
297: "validationbuilder_errors_positionedmessages_out2")
298: .getContent(), template.getContent());
299:
300: bean.resetValidation();
301: bean.validate();
302: bean.makeSubjectValid("login");
303: bean.makeSubjectValid("customquestion");
304: builder.generateValidationErrors(template, bean
305: .getValidationErrors(), bean.getValidatedSubjects(),
306: null);
307: assertEquals(TemplateFactory.ENGINEHTML.get(
308: "validationbuilder_errors_positionedmessages_out3")
309: .getContent(), template.getContent());
310: }
311:
312: public void testGenerateValidationErrorsPositionedmessagesPrefix() {
313: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
314:
315: Template template = TemplateFactory.ENGINEHTML
316: .get("validationbuilder_errors_positionedmessages_prefix");
317:
318: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
319: bean.validate();
320: builder.generateValidationErrors(template, bean
321: .getValidationErrors(), bean.getValidatedSubjects(),
322: "prefix_");
323: assertEquals(
324: TemplateFactory.ENGINEHTML
325: .get(
326: "validationbuilder_errors_positionedmessages_prefix_out1")
327: .getContent(), template.getContent());
328:
329: bean.resetValidation();
330: bean.validate();
331: bean.makeSubjectValid("anotherlogin");
332: bean.makeSubjectValid("anotherpassword");
333: builder.generateValidationErrors(template, bean
334: .getValidationErrors(), bean.getValidatedSubjects(),
335: "prefix_");
336: assertEquals(
337: TemplateFactory.ENGINEHTML
338: .get(
339: "validationbuilder_errors_positionedmessages_prefix_out2")
340: .getContent(), template.getContent());
341:
342: bean.resetValidation();
343: bean.validate();
344: bean.makeSubjectValid("login");
345: bean.makeSubjectValid("customquestion");
346: builder.generateValidationErrors(template, bean
347: .getValidationErrors(), bean.getValidatedSubjects(),
348: "prefix_");
349: assertEquals(
350: TemplateFactory.ENGINEHTML
351: .get(
352: "validationbuilder_errors_positionedmessages_prefix_out3")
353: .getContent(), template.getContent());
354: }
355:
356: public void testGenerateValidationErrorsDecoratedmessages() {
357: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
358:
359: Template template = TemplateFactory.ENGINEHTML
360: .get("validationbuilder_errors_decoratedmessages");
361:
362: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
363: bean.validate();
364: builder.generateValidationErrors(template, bean
365: .getValidationErrors(), bean.getValidatedSubjects(),
366: null);
367: assertEquals(TemplateFactory.ENGINEHTML.get(
368: "validationbuilder_errors_decoratedmessages_out1")
369: .getContent(), template.getContent());
370:
371: bean.resetValidation();
372: bean.validate();
373: bean.makeSubjectValid("anotherlogin");
374: bean.makeSubjectValid("anotherpassword");
375: builder.generateValidationErrors(template, bean
376: .getValidationErrors(), bean.getValidatedSubjects(),
377: null);
378: assertEquals(TemplateFactory.ENGINEHTML.get(
379: "validationbuilder_errors_decoratedmessages_out2")
380: .getContent(), template.getContent());
381:
382: bean.resetValidation();
383: bean.validate();
384: bean.makeSubjectValid("login");
385: bean.makeSubjectValid("customquestion");
386: builder.generateValidationErrors(template, bean
387: .getValidationErrors(), bean.getValidatedSubjects(),
388: null);
389: assertEquals(TemplateFactory.ENGINEHTML.get(
390: "validationbuilder_errors_decoratedmessages_out3")
391: .getContent(), template.getContent());
392: }
393:
394: public void testGenerateValidationErrorsDecoratedmessagesPrefix() {
395: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
396:
397: Template template = TemplateFactory.ENGINEHTML
398: .get("validationbuilder_errors_decoratedmessages_prefix");
399:
400: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
401: bean.validate();
402: builder.generateValidationErrors(template, bean
403: .getValidationErrors(), bean.getValidatedSubjects(),
404: "prefix_");
405: assertEquals(
406: TemplateFactory.ENGINEHTML
407: .get(
408: "validationbuilder_errors_decoratedmessages_prefix_out1")
409: .getContent(), template.getContent());
410:
411: bean.resetValidation();
412: bean.validate();
413: bean.makeSubjectValid("anotherlogin");
414: bean.makeSubjectValid("anotherpassword");
415: builder.generateValidationErrors(template, bean
416: .getValidationErrors(), bean.getValidatedSubjects(),
417: "prefix_");
418: assertEquals(
419: TemplateFactory.ENGINEHTML
420: .get(
421: "validationbuilder_errors_decoratedmessages_prefix_out2")
422: .getContent(), template.getContent());
423:
424: bean.resetValidation();
425: bean.validate();
426: bean.makeSubjectValid("login");
427: bean.makeSubjectValid("customquestion");
428: builder.generateValidationErrors(template, bean
429: .getValidationErrors(), bean.getValidatedSubjects(),
430: "prefix_");
431: assertEquals(
432: TemplateFactory.ENGINEHTML
433: .get(
434: "validationbuilder_errors_decoratedmessages_prefix_out3")
435: .getContent(), template.getContent());
436: }
437:
438: public void testRemoveValidationErrorsInvalidArguments() {
439: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
440: builder.removeValidationErrors(null, null, null);
441:
442: Template template = TemplateFactory.ENGINEHTML
443: .get("validationbuilder_errors_raw");
444: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
445: bean.validate();
446: bean
447: .addValidationError(new ValidationError.WRONGFORMAT(
448: "login"));
449: builder.generateValidationErrors(template, bean
450: .getValidationErrors(), bean.getValidatedSubjects(),
451: null);
452: String raw_content = template.getContent();
453: builder.removeValidationErrors(template, null, null);
454: assertEquals(raw_content, template.getContent());
455: builder.removeValidationErrors(template,
456: new ArrayList<String>(), null);
457: assertEquals(raw_content, template.getContent());
458: }
459:
460: public void testRemoveValidationErrorsNovalues() {
461: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
462:
463: Template template = TemplateFactory.ENGINEHTML
464: .get("validationbuilder_errors_novalues");
465:
466: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
467: bean.validate();
468: builder.generateValidationErrors(template, bean
469: .getValidationErrors(), bean.getValidatedSubjects(),
470: null);
471: assertEquals(TemplateFactory.ENGINEHTML.get(
472: "validationbuilder_errors_novalues").getContent(),
473: template.getContent());
474: builder.removeValidationErrors(template, bean
475: .getValidatedSubjects(), null);
476: assertEquals(TemplateFactory.ENGINEHTML.get(
477: "validationbuilder_errors_novalues").getContent(),
478: template.getContent());
479: }
480:
481: public void testRemoveValidationErrorsRaw() {
482: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
483:
484: Template template = TemplateFactory.ENGINEHTML
485: .get("validationbuilder_errors_raw");
486:
487: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
488: bean.validate();
489: bean
490: .addValidationError(new ValidationError.WRONGFORMAT(
491: "login"));
492: builder.generateValidationErrors(template, bean
493: .getValidationErrors(), bean.getValidatedSubjects(),
494: null);
495: assertEquals(TemplateFactory.ENGINEHTML.get(
496: "validationbuilder_errors_raw_out").getContent(),
497: template.getContent());
498:
499: builder.removeValidationErrors(template, bean
500: .getValidatedSubjects(), null);
501: assertEquals(TemplateFactory.ENGINEHTML.get(
502: "validationbuilder_errors_raw").getContent(), template
503: .getContent());
504: }
505:
506: public void testRemoveValidationErrorsDecoratedmessages() {
507: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
508:
509: Template template = TemplateFactory.ENGINEHTML
510: .get("validationbuilder_errors_decoratedmessages");
511:
512: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
513: bean.validate();
514: builder.generateValidationErrors(template, bean
515: .getValidationErrors(), bean.getValidatedSubjects(),
516: null);
517: assertEquals(TemplateFactory.ENGINEHTML.get(
518: "validationbuilder_errors_decoratedmessages_out1")
519: .getContent(), template.getContent());
520:
521: builder.removeValidationErrors(template, bean
522: .getValidatedSubjects(), null);
523: assertEquals(TemplateFactory.ENGINEHTML.get(
524: "validationbuilder_errors_decoratedmessages")
525: .getContent(), template.getContent());
526: }
527:
528: public void testRemoveValidationErrorsDecoratedmessagesMissingSubjects() {
529: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
530:
531: Template template = TemplateFactory.ENGINEHTML
532: .get("validationbuilder_errors_decoratedmessages");
533:
534: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
535: bean.validate();
536: builder.generateValidationErrors(template, bean
537: .getValidationErrors(), bean.getValidatedSubjects(),
538: null);
539: assertEquals(TemplateFactory.ENGINEHTML.get(
540: "validationbuilder_errors_decoratedmessages_out1")
541: .getContent(), template.getContent());
542:
543: List<String> subjects = bean.getValidatedSubjects();
544: subjects.remove(0);
545: subjects.remove(0);
546: subjects.remove(0);
547: subjects.remove(0);
548: subjects.remove(0);
549: builder.removeValidationErrors(template, subjects, null);
550: assertEquals(
551: TemplateFactory.ENGINEHTML
552: .get(
553: "validationbuilder_errors_decoratedmessages_partly_removed")
554: .getContent(), template.getContent());
555: }
556:
557: public void testRemoveValidationErrorsDecoratedmessagesPrefix() {
558: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
559:
560: Template template = TemplateFactory.ENGINEHTML
561: .get("validationbuilder_errors_decoratedmessages_prefix");
562:
563: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
564: bean.validate();
565: builder.generateValidationErrors(template, bean
566: .getValidationErrors(), bean.getValidatedSubjects(),
567: "prefix_");
568: assertEquals(
569: TemplateFactory.ENGINEHTML
570: .get(
571: "validationbuilder_errors_decoratedmessages_prefix_out1")
572: .getContent(), template.getContent());
573:
574: builder.removeValidationErrors(template, bean
575: .getValidatedSubjects(), "prefix_");
576: assertEquals(TemplateFactory.ENGINEHTML.get(
577: "validationbuilder_errors_decoratedmessages_prefix")
578: .getContent(), template.getContent());
579: }
580:
581: public void testGenerateErrorMarkingsInvalidArguments() {
582: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
583: assertEquals(0, builder.generateErrorMarkings(null, null, null,
584: null).size());
585:
586: Template template = TemplateFactory.ENGINEHTML
587: .get("validationbuilder_mark_simple");
588: String raw_content = template.getContent();
589: assertNotNull(template);
590: assertEquals(0, builder.generateErrorMarkings(template, null,
591: null, null).size());
592: assertEquals(raw_content, template.getContent());
593: assertEquals(0, builder.generateErrorMarkings(template,
594: new ArrayList<ValidationError>(), null, null).size());
595: assertEquals(raw_content, template.getContent());
596: }
597:
598: public void testGenerateErrorMarkingsNoValues() {
599: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
600:
601: Template template = TemplateFactory.ENGINEHTML
602: .get("validationbuilder_errors_novalues");
603:
604: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
605: bean.validate();
606: builder.generateErrorMarkings(template, bean
607: .getValidationErrors(), bean.getValidatedSubjects(),
608: null);
609: assertEquals(TemplateFactory.ENGINEHTML.get(
610: "validationbuilder_errors_novalues").getContent(),
611: template.getContent());
612: }
613:
614: public void testGenerateErrorMarkingsMising() {
615: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
616:
617: Template template = TemplateFactory.ENGINEHTML
618: .get("validationbuilder_mark_missing");
619:
620: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
621: bean.validate();
622: try {
623: builder.generateErrorMarkings(template, bean
624: .getValidationErrors(),
625: bean.getValidatedSubjects(), null);
626: fail("exception not thrown");
627: } catch (MissingMarkingBlockException e) {
628: assertEquals("MARK:ERROR", e.getBlockId());
629: }
630: }
631:
632: public void testGenerateErrorMarkingsSimple() {
633: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
634:
635: Template template = TemplateFactory.ENGINEHTML
636: .get("validationbuilder_mark_simple");
637:
638: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
639: bean.validate();
640: builder.generateErrorMarkings(template, bean
641: .getValidationErrors(), bean.getValidatedSubjects(),
642: null);
643: assertEquals(TemplateFactory.ENGINEHTML.get(
644: "validationbuilder_mark_simple_out").getContent(),
645: template.getContent());
646: }
647:
648: public void testGenerateErrorMarkingsPositioned() {
649: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
650:
651: Template template = TemplateFactory.ENGINEHTML
652: .get("validationbuilder_mark_positioned");
653:
654: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
655: bean.validate();
656: builder.generateErrorMarkings(template, bean
657: .getValidationErrors(), bean.getValidatedSubjects(),
658: null);
659: assertEquals(TemplateFactory.ENGINEHTML.get(
660: "validationbuilder_mark_positioned_out1").getContent(),
661: template.getContent());
662:
663: bean.resetValidation();
664: bean.validate();
665: bean.makeSubjectValid("anotherlogin");
666: bean.makeSubjectValid("anotherpassword");
667: bean.makeSubjectValid("anothercustomquestion");
668: bean.addValidationError(new ValidationError.INCOMPLETE(
669: "customoptions"));
670: builder.generateErrorMarkings(template, bean
671: .getValidationErrors(), bean.getValidatedSubjects(),
672: null);
673: assertEquals(TemplateFactory.ENGINEHTML.get(
674: "validationbuilder_mark_positioned_out2").getContent(),
675: template.getContent());
676:
677: bean.resetValidation();
678: bean.validate();
679: bean.makeSubjectValid("login");
680: bean.makeSubjectValid("customquestion");
681: bean.makeSubjectValid("options");
682: bean.addValidationError(new ValidationError.INCOMPLETE(
683: "customoptions"));
684: builder.generateErrorMarkings(template, bean
685: .getValidationErrors(), bean.getValidatedSubjects(),
686: null);
687: assertEquals(TemplateFactory.ENGINEHTML.get(
688: "validationbuilder_mark_positioned_out3").getContent(),
689: template.getContent());
690: }
691:
692: public void testGenerateErrorMarkingsSelective() {
693: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
694:
695: Template template = TemplateFactory.ENGINEHTML
696: .get("validationbuilder_mark_selective");
697:
698: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
699: bean.validate();
700: builder.generateErrorMarkings(template, bean
701: .getValidationErrors(), bean.getValidatedSubjects(),
702: null);
703: assertEquals(TemplateFactory.ENGINEHTML.get(
704: "validationbuilder_mark_selective_out1").getContent(),
705: template.getContent());
706:
707: bean.resetValidation();
708: bean.validate();
709: bean.makeSubjectValid("anotherlogin");
710: bean.makeSubjectValid("anotherpassword");
711: bean.makeSubjectValid("anothercustomquestion");
712: bean.addValidationError(new ValidationError.INCOMPLETE(
713: "customoptions"));
714: builder.generateErrorMarkings(template, bean
715: .getValidationErrors(), bean.getValidatedSubjects(),
716: null);
717: assertEquals(TemplateFactory.ENGINEHTML.get(
718: "validationbuilder_mark_selective_out2").getContent(),
719: template.getContent());
720:
721: bean.resetValidation();
722: bean.validate();
723: bean.makeSubjectValid("login");
724: bean.makeSubjectValid("customquestion");
725: bean.makeSubjectValid("options");
726: bean.addValidationError(new ValidationError.INCOMPLETE(
727: "customoptions"));
728: builder.generateErrorMarkings(template, bean
729: .getValidationErrors(), bean.getValidatedSubjects(),
730: null);
731: assertEquals(TemplateFactory.ENGINEHTML.get(
732: "validationbuilder_mark_selective_out3").getContent(),
733: template.getContent());
734: }
735:
736: public void testGenerateErrorMarkingsSimplePrefix() {
737: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
738:
739: Template template = TemplateFactory.ENGINEHTML
740: .get("validationbuilder_mark_simple_prefix");
741:
742: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
743: bean.validate();
744: builder.generateErrorMarkings(template, bean
745: .getValidationErrors(), bean.getValidatedSubjects(),
746: "prefix_");
747: assertEquals(TemplateFactory.ENGINEHTML.get(
748: "validationbuilder_mark_simple_out").getContent(),
749: template.getContent());
750: }
751:
752: public void testGenerateErrorMarkingsPositionedPrefix() {
753: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
754:
755: Template template = TemplateFactory.ENGINEHTML
756: .get("validationbuilder_mark_positioned_prefix");
757:
758: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
759: bean.validate();
760: builder.generateErrorMarkings(template, bean
761: .getValidationErrors(), bean.getValidatedSubjects(),
762: "prefix_");
763: assertEquals(TemplateFactory.ENGINEHTML.get(
764: "validationbuilder_mark_positioned_out1").getContent(),
765: template.getContent());
766:
767: bean.resetValidation();
768: bean.validate();
769: bean.makeSubjectValid("anotherlogin");
770: bean.makeSubjectValid("anotherpassword");
771: bean.makeSubjectValid("anothercustomquestion");
772: bean.addValidationError(new ValidationError.INCOMPLETE(
773: "customoptions"));
774: builder.generateErrorMarkings(template, bean
775: .getValidationErrors(), bean.getValidatedSubjects(),
776: "prefix_");
777: assertEquals(TemplateFactory.ENGINEHTML.get(
778: "validationbuilder_mark_positioned_out2").getContent(),
779: template.getContent());
780:
781: bean.resetValidation();
782: bean.validate();
783: bean.makeSubjectValid("login");
784: bean.makeSubjectValid("customquestion");
785: bean.makeSubjectValid("options");
786: bean.addValidationError(new ValidationError.INCOMPLETE(
787: "customoptions"));
788: builder.generateErrorMarkings(template, bean
789: .getValidationErrors(), bean.getValidatedSubjects(),
790: "prefix_");
791: assertEquals(TemplateFactory.ENGINEHTML.get(
792: "validationbuilder_mark_positioned_out3").getContent(),
793: template.getContent());
794: }
795:
796: public void testGenerateErrorMarkingsSelectivePrefix() {
797: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
798:
799: Template template = TemplateFactory.ENGINEHTML
800: .get("validationbuilder_mark_selective_prefix");
801:
802: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
803: bean.validate();
804: builder.generateErrorMarkings(template, bean
805: .getValidationErrors(), bean.getValidatedSubjects(),
806: "prefix_");
807: assertEquals(TemplateFactory.ENGINEHTML.get(
808: "validationbuilder_mark_selective_out1").getContent(),
809: template.getContent());
810:
811: bean.resetValidation();
812: bean.validate();
813: bean.makeSubjectValid("anotherlogin");
814: bean.makeSubjectValid("anotherpassword");
815: bean.makeSubjectValid("anothercustomquestion");
816: bean.addValidationError(new ValidationError.INCOMPLETE(
817: "customoptions"));
818: builder.generateErrorMarkings(template, bean
819: .getValidationErrors(), bean.getValidatedSubjects(),
820: "prefix_");
821: assertEquals(TemplateFactory.ENGINEHTML.get(
822: "validationbuilder_mark_selective_out2").getContent(),
823: template.getContent());
824:
825: bean.resetValidation();
826: bean.validate();
827: bean.makeSubjectValid("login");
828: bean.makeSubjectValid("customquestion");
829: bean.makeSubjectValid("options");
830: bean.addValidationError(new ValidationError.INCOMPLETE(
831: "customoptions"));
832: builder.generateErrorMarkings(template, bean
833: .getValidationErrors(), bean.getValidatedSubjects(),
834: "prefix_");
835: assertEquals(TemplateFactory.ENGINEHTML.get(
836: "validationbuilder_mark_selective_out3").getContent(),
837: template.getContent());
838: }
839:
840: public void testRemoveErrorMarkingsInvalidArguments() {
841: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
842: builder.removeErrorMarkings(null, null, null);
843:
844: Template template = TemplateFactory.ENGINEHTML
845: .get("validationbuilder_mark_simple");
846: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
847: bean.validate();
848: builder.generateErrorMarkings(template, bean
849: .getValidationErrors(), bean.getValidatedSubjects(),
850: null);
851: assertEquals(TemplateFactory.ENGINEHTML.get(
852: "validationbuilder_mark_simple_out").getContent(),
853: template.getContent());
854: String raw_content = template.getContent();
855: builder.removeErrorMarkings(template, null, null);
856: assertEquals(raw_content, template.getContent());
857: builder.removeErrorMarkings(template, new ArrayList<String>(),
858: null);
859: assertEquals(raw_content, template.getContent());
860: }
861:
862: public void testRemoveErrorMarkingsNoValues() {
863: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
864:
865: Template template = TemplateFactory.ENGINEHTML
866: .get("validationbuilder_errors_novalues");
867:
868: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
869: bean.validate();
870: builder.generateErrorMarkings(template, bean
871: .getValidationErrors(), bean.getValidatedSubjects(),
872: null);
873: assertEquals(TemplateFactory.ENGINEHTML.get(
874: "validationbuilder_errors_novalues").getContent(),
875: template.getContent());
876: builder.removeErrorMarkings(template, bean
877: .getValidatedSubjects(), null);
878: assertEquals(TemplateFactory.ENGINEHTML.get(
879: "validationbuilder_errors_novalues").getContent(),
880: template.getContent());
881: }
882:
883: public void testRemoveErrorMarkingsPositioned() {
884: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
885:
886: Template template = TemplateFactory.ENGINEHTML
887: .get("validationbuilder_mark_positioned");
888:
889: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
890: bean.validate();
891: builder.generateErrorMarkings(template, bean
892: .getValidationErrors(), bean.getValidatedSubjects(),
893: null);
894: assertEquals(TemplateFactory.ENGINEHTML.get(
895: "validationbuilder_mark_positioned_out1").getContent(),
896: template.getContent());
897: builder.removeErrorMarkings(template, bean
898: .getValidatedSubjects(), null);
899: assertEquals(TemplateFactory.ENGINEHTML.get(
900: "validationbuilder_mark_positioned").getContent(),
901: template.getContent());
902: }
903:
904: public void testRemoveErrorMarkingsPositionedPrefix() {
905: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
906:
907: Template template = TemplateFactory.ENGINEHTML
908: .get("validationbuilder_mark_positioned_prefix");
909:
910: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
911: bean.validate();
912: builder.generateErrorMarkings(template, bean
913: .getValidationErrors(), bean.getValidatedSubjects(),
914: "prefix_");
915: assertEquals(TemplateFactory.ENGINEHTML.get(
916: "validationbuilder_mark_positioned_out1").getContent(),
917: template.getContent());
918: builder.removeErrorMarkings(template, bean
919: .getValidatedSubjects(), "prefix_");
920: assertEquals(TemplateFactory.ENGINEHTML.get(
921: "validationbuilder_mark_positioned_prefix")
922: .getContent(), template.getContent());
923: }
924:
925: public void testRemoveErrorMarkingsPositionedMissingSubjects() {
926: ValidationBuilderXhtml builder = new ValidationBuilderXhtml();
927:
928: Template template = TemplateFactory.ENGINEHTML
929: .get("validationbuilder_mark_positioned");
930:
931: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
932: bean.validate();
933: builder.generateErrorMarkings(template, bean
934: .getValidationErrors(), bean.getValidatedSubjects(),
935: null);
936: assertEquals(TemplateFactory.ENGINEHTML.get(
937: "validationbuilder_mark_positioned_out1").getContent(),
938: template.getContent());
939:
940: List<String> subjects = bean.getValidatedSubjects();
941: subjects.remove(0);
942: subjects.remove(0);
943: subjects.remove(0);
944: subjects.remove(0);
945: subjects.remove(0);
946: builder.removeErrorMarkings(template, bean
947: .getValidatedSubjects(), null);
948: assertEquals(TemplateFactory.ENGINEHTML.get(
949: "validationbuilder_mark_positioned_partly_removed")
950: .getContent(), template.getContent());
951: }
952: }
|