001: /*
002: * ====================================================================
003: * JAFFA - Java Application Framework For All
004: *
005: * Copyright (C) 2002 JAFFA Development Group
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Redistribution and use of this software and associated documentation ("Software"),
022: * with or without modification, are permitted provided that the following conditions are met:
023: * 1. Redistributions of source code must retain copyright statements and notices.
024: * Redistributions must also contain a copy of this document.
025: * 2. Redistributions in binary form must reproduce the above copyright notice,
026: * this list of conditions and the following disclaimer in the documentation
027: * and/or other materials provided with the distribution.
028: * 3. The name "JAFFA" must not be used to endorse or promote products derived from
029: * this Software without prior written permission. For written permission,
030: * please contact mail to: jaffagroup@yahoo.com.
031: * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032: * appear in their names without prior written permission.
033: * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034: *
035: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: */
049:
050: package org.jaffa.persistence.blackboxtests;
051:
052: import junit.framework.TestCase;
053: import org.jaffa.persistence.domainobjects.*;
054: import org.jaffa.persistence.UOW;
055: import org.jaffa.persistence.Criteria;
056: import java.util.*;
057: import org.jaffa.datatypes.exceptions.*;
058: import org.jaffa.rules.RulesEngine;
059: import org.jaffa.security.VariationContext;
060: import org.jaffa.datatypes.Currency;
061: import org.jaffa.datatypes.*;
062:
063: /** This class has various tests for the Dynamic Rules Engine
064: *
065: * @author GautamJ
066: */
067: public class DynamicRulesTest extends TestCase {
068:
069: private UOW m_uow = null;
070:
071: /** Creates new QueryTest
072: * @param name The name of the test case.
073: */
074: public DynamicRulesTest(String name) {
075: super (name);
076: }
077:
078: /** Sets up the fixture, by creating the UOW. This method is called before a test is executed.
079: */
080: protected void setUp() {
081: try {
082: m_uow = new UOW();
083: } catch (Exception e) {
084: e.printStackTrace();
085: fail("Failed to create a UOW: " + e.toString());
086: }
087: }
088:
089: /** Tears down the fixture, by closing the UOW. This method is called after a test is executed.
090: */
091: protected void tearDown() {
092: try {
093: if (m_uow != null)
094: m_uow.rollback();
095: m_uow = null;
096: } catch (Exception e) {
097: e.printStackTrace();
098: fail("Failed to rollback a UOW: " + e.toString());
099: }
100: }
101:
102: /** This will directly invoke the doAllValidationsForDomainField() method of the RulesEngine, for validating the rules for the ItemId field of the class Item.
103: * The ItemId field has been defined to be mandatory in the core-rules.xml file.
104: */
105: public void testMandatoryFieldValidator() {
106: try {
107:
108: // An exception should be raised while updating a mandatory field with a null value
109: try {
110: RulesEngine.doAllValidationsForDomainField(ItemMeta
111: .getName(), "ItemId", null, m_uow);
112: fail("No exception was raised while updating a mandatory field with a null value");
113: } catch (MandatoryFieldException e) {
114: // the exception is expected
115: }
116:
117: // An exception should be raised while updating a mandatory field with an empty string
118: try {
119: RulesEngine.doAllValidationsForDomainField(ItemMeta
120: .getName(), "ItemId", "", m_uow);
121: fail("No exception was raised while updating a mandatory field with an empty string");
122: } catch (MandatoryFieldException e) {
123: // the exception is expected
124: }
125:
126: // The following update should flow through without any exceptions
127: try {
128: RulesEngine.doAllValidationsForDomainField(ItemMeta
129: .getName(), "ItemId", "IID1", m_uow);
130: } catch (MandatoryFieldException e) {
131: e.printStackTrace();
132: fail("Exception was raised while updating a mandatory field with a non-null value");
133: }
134:
135: } catch (Exception e) {
136: e.printStackTrace();
137: fail();
138: }
139: }
140:
141: /** This will create an instance of the Item domain class and update its Condition field, which internally will invoke the RulesEngine for validating the field.
142: * The Condition field has been defined to be a valid foreign-key in the core-rules.xml file.
143: */
144: public void testForeignKeyFieldValidator() {
145: try {
146: Item item = (Item) m_uow.newPersistentInstance(Item.class);
147:
148: // The following update should flow through without any exceptions
149: try {
150: item.updateCondition("Z-TESTSYCD-01");
151: } catch (InvalidForeignKeyException e) {
152: e.printStackTrace();
153: fail("Exception was raised while updating the field with a valid foreign-key value");
154: }
155:
156: // The following invalid foreign-key should raise an exception
157: try {
158: item.updateCondition("ZZZZZZ");
159: fail("No exception was raised while updating a field with an invalid foreign-key value");
160: } catch (InvalidForeignKeyException e) {
161: // the exception is expected
162: }
163:
164: // No checks should be performed while updating a non-mandatory field with a null value
165: try {
166: item.updateCondition(null);
167: } catch (InvalidForeignKeyException e) {
168: e.printStackTrace();
169: fail("Exception was raised while updating a non-mandatory field with a null value");
170: }
171:
172: } catch (Exception e) {
173: e.printStackTrace();
174: fail();
175: }
176: }
177:
178: /** This will create an instance of the Item domain class and update its Status1 field, which internally will invoke the RulesEngine for validating the field.
179: * The Status1 field has been defined to be a valid generic-foreign-key in the core-rules.xml file.
180: */
181: public void testGenericForeignKeyFieldValidator() {
182: try {
183: Item item = (Item) m_uow.newPersistentInstance(Item.class);
184:
185: // The following update should flow through without any exceptions
186: try {
187: item.updateStatus1("Y");
188: } catch (InvalidGenericForeignKeyException e) {
189: e.printStackTrace();
190: fail("Exception was raised while updating the field with a valid generic-foreign-key value");
191: }
192:
193: // The following invalid value should raise an exception
194: try {
195: item.updateStatus1("Z");
196: fail("No exception was raised while updating a field with an invalid generic-foreign-key value");
197: } catch (InvalidGenericForeignKeyException e) {
198: // the exception is expected
199: }
200:
201: } catch (Exception e) {
202: e.printStackTrace();
203: fail();
204: }
205: }
206:
207: /** This will create an instance of the Item domain class and update its Status3 field, which internally will invoke the RulesEngine for validating the field.
208: * The Status3 field has been assigned a list of valid values in the core-rules.xml file.
209: */
210: public void testInListFieldValidator() {
211: try {
212: Item item = (Item) m_uow.newPersistentInstance(Item.class);
213:
214: // The following update should flow through without any exceptions
215: try {
216: item.updateStatus3("P");
217: } catch (PatternMismatchException e) {
218: e.printStackTrace();
219: fail("Exception was raised while updating the field with a valid in-list value");
220: }
221:
222: // The following invalid value should raise an exception
223: try {
224: item.updateStatus3("K");
225: fail("No exception was raised while updating a field with an invalid in-list value");
226: } catch (PatternMismatchException e) {
227: // the exception is expected
228: }
229:
230: } catch (Exception e) {
231: e.printStackTrace();
232: fail();
233: }
234: }
235:
236: /** This will create an instance of the Item domain class and update its Status2 field, which internally will invoke the RulesEngine for validating the field.
237: * The Status2 field has been defined to extend the Status1 rules, which in turn has been defined to be a valid generic-foreign-key value in the core-rules.xml file.
238: */
239: public void testExtendsFieldValidation() {
240: try {
241: Item item = (Item) m_uow.newPersistentInstance(Item.class);
242:
243: // The following update should flow through without any exceptions
244: try {
245: item.updateStatus2("Y");
246: } catch (InvalidGenericForeignKeyException e) {
247: e.printStackTrace();
248: fail("Exception was raised while updating the field with a valid generic-foreign-key value");
249: }
250:
251: // The following invalid value should raise an exception
252: try {
253: item.updateStatus2("Z");
254: fail("No exception was raised while updating a field with an invalid generic-foreign-key value");
255: } catch (InvalidGenericForeignKeyException e) {
256: // the exception is expected
257: }
258:
259: } catch (Exception e) {
260: e.printStackTrace();
261: fail();
262: }
263: }
264:
265: /** This will set the variation to 'VAR1' and then invoke the rules for the Status1, Status2 and Status3 fields of Item
266: */
267: public void testOverridesFieldValidation() {
268: try {
269: VariationContext.setVariation("VAR1");
270: Item item = (Item) m_uow.newPersistentInstance(Item.class);
271:
272: // *** The Status1 field is defined only in the core-rules.xml file ***
273: // The following update should flow through without any exceptions
274: try {
275: item.updateStatus1("Y");
276: } catch (InvalidGenericForeignKeyException e) {
277: e.printStackTrace();
278: fail("Exception was raised while updating the field with a valid generic-foreign-key value");
279: }
280:
281: // The following invalid value should raise an exception
282: try {
283: item.updateStatus1("Z");
284: fail("No exception was raised while updating a field with an invalid generic-foreign-key value");
285: } catch (InvalidGenericForeignKeyException e) {
286: // the exception is expected
287: }
288:
289: // *** The Status2 field is also defined in the VAR1-rules.xml file ***
290: // The following update should pass the generic-field-key rule, but should fail the integer rule
291: try {
292: item.updateStatus2("Y");
293: fail("No exception was raised while updating a field with an invalid integer value");
294: } catch (FormatIntegerException e) {
295: // the exception is expected
296: }
297:
298: // The following invalid value should raise an exception
299: try {
300: item.updateStatus2("3");
301: fail("No exception was raised while updating a field with an invalid generic-foreign-key value");
302: } catch (InvalidGenericForeignKeyException e) {
303: // the exception is expected
304: }
305:
306: // The following update should pass the generic-field-key rule, as well as the integer rule
307: try {
308: item.updateStatus2("1");
309: } catch (InvalidGenericForeignKeyException e) {
310: e.printStackTrace();
311: fail("Exception was raised while updating the field with a valid generic-foreign-key value");
312: } catch (FormatIntegerException e) {
313: e.printStackTrace();
314: fail("Exception was raised while updating the field with a valid integer value");
315: }
316:
317: // *** The Status3 field is also defined in the VAR1-rules.xml file, but it overrides the core-rules.xml ***
318: // The following update should flow through without any exceptions
319: try {
320: item.updateStatus3("I");
321: } catch (PatternMismatchException e) {
322: e.printStackTrace();
323: fail("Exception was raised while updating the field with a valid in-list value");
324: }
325:
326: // The following invalid value (though it is valid in core-rules.xml) should raise an exception
327: try {
328: item.updateStatus3("P");
329: fail("No exception was raised while updating a field with an invalid in-list value");
330: } catch (PatternMismatchException e) {
331: // the exception is expected
332: }
333:
334: } catch (Exception e) {
335: e.printStackTrace();
336: fail();
337: }
338: }
339:
340: /** This should perform the mandatory field validations for a domain object
341: */
342: public void testDomainObjectValidation() {
343: try {
344: Item item = (Item) m_uow.newPersistentInstance(Item.class);
345: try {
346: RulesEngine.doMandatoryValidationsForDomainObject(item,
347: m_uow);
348: fail("No exception was raised while trying to validate a domain object with null values for the mandatory fields");
349: } catch (Exception e) {
350: // the exception is expected
351: }
352:
353: item.updateItemId("IID1");
354: try {
355: RulesEngine.doMandatoryValidationsForDomainObject(item,
356: m_uow);
357: } catch (Exception e) {
358: e.printStackTrace();
359: fail("Exception was raised while trying to validate a domain object with non-null values for the mandatory fields");
360: }
361: } catch (Exception e) {
362: e.printStackTrace();
363: fail();
364: }
365: }
366:
367: /** This tests the StringFieldValidator.
368: */
369: public void testStringFieldValidator() {
370: try {
371: // The following update should flow through without any exceptions
372: try {
373: RulesEngine.doAllValidationsForDomainField("Dummy",
374: "StringField", "ABCDE", m_uow);
375: } catch (ValidationException e) {
376: e.printStackTrace();
377: fail("Exception was raised while updating the field with a valid string value");
378: }
379:
380: // The following invalid value should raise an exception
381: try {
382: RulesEngine.doAllValidationsForDomainField("Dummy",
383: "StringField", "PQRSTU", m_uow);
384: fail("No exception was raised while updating a field with an invalid string value");
385: } catch (TooMuchDataException e) {
386: // the exception is expected
387: }
388:
389: // The following invalid value should raise an exception
390: try {
391: RulesEngine.doAllValidationsForDomainField("Dummy",
392: "StringField", "XYZ", m_uow);
393: fail("No exception was raised while updating a field with an invalid string value");
394: } catch (PatternMismatchException e) {
395: // the exception is expected
396: }
397:
398: } catch (Exception e) {
399: e.printStackTrace();
400: fail();
401: }
402: }
403:
404: /** This tests the BooleanFieldValidator.
405: */
406: public void testBooleanFieldValidator() {
407: try {
408: // The following update should flow through without any exceptions
409: try {
410: RulesEngine.doAllValidationsForDomainField("Dummy",
411: "BooleanField", "true", m_uow);
412: } catch (ValidationException e) {
413: e.printStackTrace();
414: fail("Exception was raised while updating the field with a valid boolean value");
415: }
416:
417: // The following update should flow through without any exceptions
418: try {
419: RulesEngine.doAllValidationsForDomainField("Dummy",
420: "BooleanField", Boolean.FALSE, m_uow);
421: } catch (ValidationException e) {
422: e.printStackTrace();
423: fail("Exception was raised while updating the field with a valid boolean value");
424: }
425:
426: // The following invalid value should raise an exception
427: try {
428: RulesEngine.doAllValidationsForDomainField("Dummy",
429: "BooleanField", "zzzzz", m_uow);
430: fail("No exception was raised while updating a field with an invalid boolean value");
431: } catch (PatternMismatchException e) {
432: // the exception is expected
433: }
434:
435: } catch (Exception e) {
436: e.printStackTrace();
437: fail();
438: }
439: }
440:
441: /** This tests the CurrencyFieldValidator.
442: */
443: public void testCurrencyFieldValidator() {
444: try {
445: // The following update should flow through without any exceptions
446: try {
447: RulesEngine.doAllValidationsForDomainField("Dummy",
448: "CurrencyField", "101", m_uow);
449: } catch (ValidationException e) {
450: e.printStackTrace();
451: fail("Exception was raised while updating the field with a valid Currency value");
452: }
453:
454: // The following update should flow through without any exceptions
455: try {
456: RulesEngine.doAllValidationsForDomainField("Dummy",
457: "CurrencyField", new Currency(101), m_uow);
458: } catch (ValidationException e) {
459: e.printStackTrace();
460: fail("Exception was raised while updating the field with a valid Currency value");
461: }
462:
463: // The following invalid value should raise an exception
464: try {
465: RulesEngine.doAllValidationsForDomainField("Dummy",
466: "CurrencyField", "zzzzz", m_uow);
467: fail("No exception was raised while updating a field with an invalid Currency value");
468: } catch (FormatCurrencyException e) {
469: // the exception is expected
470: }
471:
472: // The following invalid value should raise an exception
473: try {
474: RulesEngine.doAllValidationsForDomainField("Dummy",
475: "CurrencyField", "99", m_uow);
476: fail("No exception was raised while updating a field with an invalid Currency value");
477: } catch (BelowMinimumException e) {
478: // the exception is expected
479: }
480:
481: // The following invalid value should raise an exception
482: try {
483: RulesEngine.doAllValidationsForDomainField("Dummy",
484: "CurrencyField", "5001", m_uow);
485: fail("No exception was raised while updating a field with an invalid Currency value");
486: } catch (ExceedsMaximumException e) {
487: // the exception is expected
488: }
489:
490: // The following invalid value should raise an exception
491: try {
492: RulesEngine.doAllValidationsForDomainField("Dummy",
493: "CurrencyField", "101.12345678", m_uow);
494: fail("No exception was raised while updating a field with an invalid Currency value");
495: } catch (TooMuchDataException e) {
496: // the exception is expected
497: }
498:
499: } catch (Exception e) {
500: e.printStackTrace();
501: fail();
502: }
503: }
504:
505: /** This tests the DateOnlyFieldValidator.
506: */
507: public void testDateOnlyFieldValidator() {
508: try {
509: // The following update should flow through without any exceptions
510: try {
511: RulesEngine.doAllValidationsForDomainField("Dummy",
512: "DateOnlyField", "4/22/2003", m_uow);
513: } catch (ValidationException e) {
514: e.printStackTrace();
515: fail("Exception was raised while updating the field with a valid DateOnly value");
516: }
517:
518: // The following update should flow through without any exceptions
519: try {
520: RulesEngine.doAllValidationsForDomainField("Dummy",
521: "DateOnlyField", new DateOnly(2003,
522: DateOnly.APRIL, 22), m_uow);
523: } catch (ValidationException e) {
524: e.printStackTrace();
525: fail("Exception was raised while updating the field with a valid DateOnly value");
526: }
527:
528: // The following invalid value should raise an exception
529: try {
530: RulesEngine.doAllValidationsForDomainField("Dummy",
531: "DateOnlyField", "zzzzz", m_uow);
532: fail("No exception was raised while updating a field with an invalid DateOnly value");
533: } catch (FormatDateOnlyException e) {
534: // the exception is expected
535: }
536:
537: // The following invalid value should raise an exception
538: try {
539: RulesEngine.doAllValidationsForDomainField("Dummy",
540: "DateOnlyField", "4/22/1999", m_uow);
541: fail("No exception was raised while updating a field with an invalid DateOnly value");
542: } catch (BelowMinimumException e) {
543: // the exception is expected
544: }
545:
546: // The following invalid value should raise an exception
547: try {
548: RulesEngine.doAllValidationsForDomainField("Dummy",
549: "DateOnlyField", "4/22/2013", m_uow);
550: fail("No exception was raised while updating a field with an invalid DateOnly value");
551: } catch (ExceedsMaximumException e) {
552: // the exception is expected
553: }
554:
555: } catch (Exception e) {
556: e.printStackTrace();
557: fail();
558: }
559: }
560:
561: /** This tests the DateTimeFieldValidator.
562: */
563: public void testDateTimeFieldValidator() {
564: try {
565: // The following update should flow through without any exceptions
566: try {
567: RulesEngine.doAllValidationsForDomainField("Dummy",
568: "DateTimeField", "4/22/2003", m_uow);
569: } catch (ValidationException e) {
570: e.printStackTrace();
571: fail("Exception was raised while updating the field with a valid DateTime value");
572: }
573:
574: // The following update should flow through without any exceptions
575: try {
576: RulesEngine.doAllValidationsForDomainField("Dummy",
577: "DateTimeField", new DateTime(2003,
578: DateTime.APRIL, 22), m_uow);
579: } catch (ValidationException e) {
580: e.printStackTrace();
581: fail("Exception was raised while updating the field with a valid DateTime value");
582: }
583:
584: // The following invalid value should raise an exception
585: try {
586: RulesEngine.doAllValidationsForDomainField("Dummy",
587: "DateTimeField", "zzzzz", m_uow);
588: fail("No exception was raised while updating a field with an invalid DateTime value");
589: } catch (FormatDateTimeException e) {
590: // the exception is expected
591: }
592:
593: // The following invalid value should raise an exception
594: try {
595: RulesEngine.doAllValidationsForDomainField("Dummy",
596: "DateTimeField", "4/22/1999", m_uow);
597: fail("No exception was raised while updating a field with an invalid DateTime value");
598: } catch (BelowMinimumException e) {
599: // the exception is expected
600: }
601:
602: // The following invalid value should raise an exception
603: try {
604: RulesEngine.doAllValidationsForDomainField("Dummy",
605: "DateTimeField", "4/22/2013", m_uow);
606: fail("No exception was raised while updating a field with an invalid DateTime value");
607: } catch (ExceedsMaximumException e) {
608: // the exception is expected
609: }
610:
611: } catch (Exception e) {
612: e.printStackTrace();
613: fail();
614: }
615: }
616:
617: /** This tests the DecimalFieldValidator.
618: */
619: public void testDecimalFieldValidator() {
620: try {
621: // The following update should flow through without any exceptions
622: try {
623: RulesEngine.doAllValidationsForDomainField("Dummy",
624: "DecimalField", "101", m_uow);
625: } catch (ValidationException e) {
626: e.printStackTrace();
627: fail("Exception was raised while updating the field with a valid Decimal value");
628: }
629:
630: // The following update should flow through without any exceptions
631: try {
632: RulesEngine.doAllValidationsForDomainField("Dummy",
633: "DecimalField", new Double(101), m_uow);
634: } catch (ValidationException e) {
635: e.printStackTrace();
636: fail("Exception was raised while updating the field with a valid Decimal value");
637: }
638:
639: // The following invalid value should raise an exception
640: try {
641: RulesEngine.doAllValidationsForDomainField("Dummy",
642: "DecimalField", "zzzzz", m_uow);
643: fail("No exception was raised while updating a field with an invalid Decimal value");
644: } catch (FormatDecimalException e) {
645: // the exception is expected
646: }
647:
648: // The following invalid value should raise an exception
649: try {
650: RulesEngine.doAllValidationsForDomainField("Dummy",
651: "DecimalField", "99", m_uow);
652: fail("No exception was raised while updating a field with an invalid Decimal value");
653: } catch (BelowMinimumException e) {
654: // the exception is expected
655: }
656:
657: // The following invalid value should raise an exception
658: try {
659: RulesEngine.doAllValidationsForDomainField("Dummy",
660: "DecimalField", "5001", m_uow);
661: fail("No exception was raised while updating a field with an invalid Decimal value");
662: } catch (ExceedsMaximumException e) {
663: // the exception is expected
664: }
665:
666: // The following invalid value should raise an exception
667: try {
668: RulesEngine.doAllValidationsForDomainField("Dummy",
669: "DecimalField", "101.12345678", m_uow);
670: fail("No exception was raised while updating a field with an invalid Decimal value");
671: } catch (TooMuchDataException e) {
672: // the exception is expected
673: }
674:
675: } catch (Exception e) {
676: e.printStackTrace();
677: fail();
678: }
679: }
680:
681: /** This tests the IntegerFieldValidator.
682: */
683: public void testIntegerFieldValidator() {
684: try {
685: // The following update should flow through without any exceptions
686: try {
687: RulesEngine.doAllValidationsForDomainField("Dummy",
688: "IntegerField", "101", m_uow);
689: } catch (ValidationException e) {
690: e.printStackTrace();
691: fail("Exception was raised while updating the field with a valid Integer value");
692: }
693:
694: // The following update should flow through without any exceptions
695: try {
696: RulesEngine.doAllValidationsForDomainField("Dummy",
697: "IntegerField", new Long(101), m_uow);
698: } catch (ValidationException e) {
699: e.printStackTrace();
700: fail("Exception was raised while updating the field with a valid Integer value");
701: }
702:
703: // The following invalid value should raise an exception
704: try {
705: RulesEngine.doAllValidationsForDomainField("Dummy",
706: "IntegerField", "zzzzz", m_uow);
707: fail("No exception was raised while updating a field with an invalid Integer value");
708: } catch (FormatIntegerException e) {
709: // the exception is expected
710: }
711:
712: // The following invalid value should raise an exception
713: try {
714: RulesEngine.doAllValidationsForDomainField("Dummy",
715: "IntegerField", "99", m_uow);
716: fail("No exception was raised while updating a field with an invalid Integer value");
717: } catch (BelowMinimumException e) {
718: // the exception is expected
719: }
720:
721: // The following invalid value should raise an exception
722: try {
723: RulesEngine.doAllValidationsForDomainField("Dummy",
724: "IntegerField", "5001", m_uow);
725: fail("No exception was raised while updating a field with an invalid Integer value");
726: } catch (ExceedsMaximumException e) {
727: // the exception is expected
728: }
729:
730: // The following invalid value should raise an exception
731: try {
732: RulesEngine.doAllValidationsForDomainField("Dummy",
733: "IntegerField", "50000", m_uow);
734: fail("No exception was raised while updating a field with an invalid Integer value");
735: } catch (TooMuchDataException e) {
736: // the exception is expected
737: }
738:
739: } catch (Exception e) {
740: e.printStackTrace();
741: fail();
742: }
743: }
744:
745: }
|