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: TestConstrainedProperty.java 3670 2007-02-26 23:31:23Z gbevin $
007: */
008: package com.uwyn.rife.site;
009:
010: import com.uwyn.rife.tools.BeanImpl;
011: import java.text.SimpleDateFormat;
012: import java.util.Date;
013: import junit.framework.TestCase;
014:
015: public class TestConstrainedProperty extends TestCase {
016: public TestConstrainedProperty(String name) {
017: super (name);
018: }
019:
020: public void testIllegalInstantiation() {
021: try {
022: new ConstrainedProperty(null);
023: fail();
024: } catch (IllegalArgumentException e) {
025: assertTrue(true);
026: }
027:
028: try {
029: new ConstrainedProperty("");
030: fail();
031: } catch (IllegalArgumentException e) {
032: assertTrue(true);
033: }
034: }
035:
036: public void testInstantiation() {
037: ConstrainedProperty property = new ConstrainedProperty(
038: "the_name");
039: assertEquals("the_name", property.getPropertyName());
040: assertEquals("the_name", property.getSubjectName());
041: assertFalse(property.isNotNull());
042: assertFalse(property.isNotEmpty());
043: assertFalse(property.isNotEqual());
044: assertFalse(property.isUnique());
045: assertFalse(property.isIdentifier());
046: assertTrue(property.isEditable());
047: assertTrue(property.isSaved());
048: assertFalse(property.isDisplayedRaw());
049: assertTrue(property.isPersistent());
050: assertFalse(property.hasLimitedLength());
051: assertFalse(property.hasPrecision());
052: assertFalse(property.hasScale());
053: assertEquals(-1, property.getMinLength());
054: assertEquals(-1, property.getMaxLength());
055: assertNull(property.getRegexp());
056: assertFalse(property.matchesRegexp());
057: assertFalse(property.isEmail());
058: assertFalse(property.isUrl());
059: assertNull(property.getMinDate());
060: assertNull(property.getMaxDate());
061: assertFalse(property.isLimitedDate());
062: assertNull(property.getFormat());
063: assertFalse(property.isFormatted());
064: assertNull(property.getInList());
065: assertFalse(property.isInList());
066: assertNull(property.getDefaultValue());
067: assertFalse(property.hasDefaultValue());
068: assertFalse(property.hasManyToOne());
069: assertNull(property.getManyToOne());
070: assertFalse(property.isEmail());
071: }
072:
073: public void testSubjectName() {
074: ConstrainedProperty property = new ConstrainedProperty(
075: "the_name");
076: assertSame(property, property.subjectName("subject"));
077: assertEquals("subject", property.getSubjectName());
078:
079: property.subjectName("subject2");
080: assertEquals("subject2", property.getSubjectName());
081: }
082:
083: public void testMandatory() {
084: ConstrainedProperty property = new ConstrainedProperty(
085: "the_name");
086: assertSame(property, property.notNull(true));
087: assertTrue(property.isNotNull());
088:
089: property.setNotNull(false);
090: assertFalse(property.isNotNull());
091: }
092:
093: public void testNotEmpty() {
094: ConstrainedProperty property = new ConstrainedProperty(
095: "the_name");
096: assertSame(property, property.notEmpty(true));
097: assertTrue(property.isNotEmpty());
098:
099: assertSame(property, property.notEmpty(false));
100: assertFalse(property.isNotEmpty());
101: }
102:
103: public void testNotEqualBoolean() {
104: ConstrainedProperty property = new ConstrainedProperty(
105: "the_name");
106: assertSame(property, property.notEqual(true));
107: assertTrue(property.isNotEqual());
108: assertEquals(true, property.getNotEqual());
109:
110: assertSame(property, property.notEqual(null));
111: assertFalse(property.isNotEqual());
112: assertNull(property.getNotEqual());
113: }
114:
115: public void testNotEqualChar() {
116: ConstrainedProperty property = new ConstrainedProperty(
117: "the_name");
118: assertSame(property, property.notEqual('K'));
119: assertTrue(property.isNotEqual());
120: assertEquals('K', property.getNotEqual());
121:
122: assertSame(property, property.notEqual(null));
123: assertFalse(property.isNotEqual());
124: assertNull(property.getNotEqual());
125: }
126:
127: public void testNotEqualByte() {
128: ConstrainedProperty property = new ConstrainedProperty(
129: "the_name");
130: assertSame(property, property.notEqual((byte) 23));
131: assertTrue(property.isNotEqual());
132: assertEquals((byte) 23, property.getNotEqual());
133:
134: assertSame(property, property.notEqual(null));
135: assertFalse(property.isNotEqual());
136: assertNull(property.getNotEqual());
137: }
138:
139: public void testNotEqualShort() {
140: ConstrainedProperty property = new ConstrainedProperty(
141: "the_name");
142: assertSame(property, property.notEqual((short) 432));
143: assertTrue(property.isNotEqual());
144: assertEquals((short) 432, property.getNotEqual());
145:
146: assertSame(property, property.notEqual(null));
147: assertFalse(property.isNotEqual());
148: assertNull(property.getNotEqual());
149: }
150:
151: public void testNotEqualInt() {
152: ConstrainedProperty property = new ConstrainedProperty(
153: "the_name");
154: assertSame(property, property.notEqual(5452));
155: assertTrue(property.isNotEqual());
156: assertEquals(5452, property.getNotEqual());
157:
158: assertSame(property, property.notEqual(null));
159: assertFalse(property.isNotEqual());
160: assertNull(property.getNotEqual());
161: }
162:
163: public void testNotEqualLong() {
164: ConstrainedProperty property = new ConstrainedProperty(
165: "the_name");
166: assertSame(property, property.notEqual(34386434L));
167: assertTrue(property.isNotEqual());
168: assertEquals(34386434L, property.getNotEqual());
169:
170: assertSame(property, property.notEqual(null));
171: assertFalse(property.isNotEqual());
172: assertNull(property.getNotEqual());
173: }
174:
175: public void testNotEqualFloat() {
176: ConstrainedProperty property = new ConstrainedProperty(
177: "the_name");
178: assertSame(property, property.notEqual(435.23f));
179: assertTrue(property.isNotEqual());
180: assertEquals(435.23f, property.getNotEqual());
181:
182: assertSame(property, property.notEqual(null));
183: assertFalse(property.isNotEqual());
184: assertNull(property.getNotEqual());
185: }
186:
187: public void testNotEqualDouble() {
188: ConstrainedProperty property = new ConstrainedProperty(
189: "the_name");
190: assertSame(property, property.notEqual(3983498.234d));
191: assertTrue(property.isNotEqual());
192: assertEquals(3983498.234d, property.getNotEqual());
193:
194: assertSame(property, property.notEqual(null));
195: assertFalse(property.isNotEqual());
196: assertNull(property.getNotEqual());
197: }
198:
199: public void testNotEqual() {
200: ConstrainedProperty property = new ConstrainedProperty(
201: "the_name");
202: assertSame(property, property.notEqual("value"));
203: assertTrue(property.isNotEqual());
204: assertEquals("value", property.getNotEqual());
205:
206: assertSame(property, property.notEqual(null));
207: assertFalse(property.isNotEqual());
208: assertNull(property.getNotEqual());
209: }
210:
211: public void testUnique() {
212: ConstrainedProperty property = new ConstrainedProperty(
213: "the_name");
214: assertSame(property, property.unique(true));
215: assertTrue(property.isUnique());
216:
217: assertSame(property, property.unique(false));
218: assertFalse(property.isUnique());
219: }
220:
221: public void testIdentifier() {
222: ConstrainedProperty property = new ConstrainedProperty(
223: "the_name");
224: assertSame(property, property.identifier(true));
225: assertTrue(property.isIdentifier());
226:
227: assertSame(property, property.identifier(false));
228: assertFalse(property.isIdentifier());
229: }
230:
231: public void testEditable() {
232: ConstrainedProperty property = new ConstrainedProperty(
233: "the_name");
234: assertSame(property, property.editable(false));
235: assertFalse(property.isEditable());
236:
237: assertSame(property, property.editable(true));
238: assertTrue(property.isEditable());
239: }
240:
241: public void testSaved() {
242: ConstrainedProperty property = new ConstrainedProperty(
243: "the_name");
244: assertSame(property, property.saved(false));
245: assertFalse(property.isSaved());
246:
247: assertSame(property, property.saved(true));
248: assertTrue(property.isSaved());
249: }
250:
251: public void testDisplayedRaw() {
252: ConstrainedProperty property = new ConstrainedProperty(
253: "the_name");
254: assertSame(property, property.displayedRaw(true));
255: assertTrue(property.isDisplayedRaw());
256:
257: assertSame(property, property.displayedRaw(false));
258: assertFalse(property.isDisplayedRaw());
259: }
260:
261: public void testPersistent() {
262: ConstrainedProperty property = new ConstrainedProperty(
263: "the_name");
264: assertSame(property, property.persistent(false));
265: assertFalse(property.isPersistent());
266:
267: assertSame(property, property.persistent(true));
268: assertTrue(property.isPersistent());
269: }
270:
271: public void testLimitedLength() {
272: ConstrainedProperty property = new ConstrainedProperty(
273: "the_name");
274:
275: assertSame(property, property.minLength(5));
276: assertTrue(property.hasLimitedLength());
277: assertEquals(5, property.getMinLength());
278:
279: assertSame(property, property.minLength(0));
280: assertFalse(property.hasLimitedLength());
281:
282: assertSame(property, property.maxLength(0));
283: assertTrue(property.hasLimitedLength());
284: assertTrue(property.hasPrecision());
285: assertEquals(0, property.getMaxLength());
286: assertEquals(0, property.getPrecision());
287:
288: assertSame(property, property.maxLength(10));
289: assertTrue(property.hasLimitedLength());
290: assertTrue(property.hasPrecision());
291: assertEquals(10, property.getMaxLength());
292: assertEquals(10, property.getPrecision());
293:
294: assertSame(property, property.maxLength(-1));
295: assertFalse(property.hasLimitedLength());
296: assertFalse(property.hasPrecision());
297: assertEquals(-1, property.getMaxLength());
298: assertEquals(-1, property.getPrecision());
299:
300: assertSame(property, property.minLength(7));
301: assertSame(property, property.maxLength(27));
302: assertTrue(property.hasLimitedLength());
303: assertEquals(7, property.getMinLength());
304: assertEquals(27, property.getMaxLength());
305: }
306:
307: public void testPrecision() {
308: ConstrainedProperty property = new ConstrainedProperty(
309: "the_name");
310:
311: assertSame(property, property.precision(0));
312: assertTrue(property.hasPrecision());
313: assertTrue(property.hasLimitedLength());
314: assertEquals(0, property.getPrecision());
315: assertEquals(0, property.getMaxLength());
316:
317: assertSame(property, property.precision(10));
318: assertTrue(property.hasPrecision());
319: assertTrue(property.hasLimitedLength());
320: assertEquals(10, property.getPrecision());
321: assertEquals(10, property.getMaxLength());
322:
323: assertSame(property, property.precision(-1));
324: assertFalse(property.hasPrecision());
325: assertFalse(property.hasLimitedLength());
326: assertEquals(-1, property.getPrecision());
327: assertEquals(-1, property.getMaxLength());
328: }
329:
330: public void testScale() {
331: ConstrainedProperty property = new ConstrainedProperty(
332: "the_name");
333:
334: assertSame(property, property.scale(0));
335: assertTrue(property.hasScale());
336: assertEquals(0, property.getScale());
337:
338: assertSame(property, property.scale(10));
339: assertTrue(property.hasScale());
340: assertEquals(10, property.getScale());
341:
342: assertSame(property, property.scale(-1));
343: assertFalse(property.hasScale());
344: assertEquals(-1, property.getScale());
345: }
346:
347: public void testRegexp() {
348: ConstrainedProperty property = new ConstrainedProperty(
349: "the_name");
350: assertSame(property, property.regexp("/l/k/"));
351: assertTrue(property.matchesRegexp());
352: assertEquals("/l/k/", property.getRegexp());
353:
354: assertSame(property, property.regexp(null));
355: assertFalse(property.matchesRegexp());
356: assertNull(property.getRegexp());
357: }
358:
359: public void testEmail() {
360: ConstrainedProperty property = new ConstrainedProperty(
361: "the_name");
362: assertSame(property, property.email(true));
363: assertTrue(property.isEmail());
364:
365: assertSame(property, property.email(false));
366: assertFalse(property.isEmail());
367: }
368:
369: public void testUrl() {
370: ConstrainedProperty property = new ConstrainedProperty(
371: "the_name");
372: assertSame(property, property.url(true));
373: assertTrue(property.isUrl());
374:
375: assertSame(property, property.url(false));
376: assertFalse(property.isUrl());
377: }
378:
379: public void testLimitedDate() {
380: Date date1 = new Date();
381: Date date2 = new Date();
382:
383: ConstrainedProperty property = new ConstrainedProperty(
384: "the_name");
385:
386: assertSame(property, property.minDate(date1));
387: assertTrue(property.isLimitedDate());
388: assertSame(date1, property.getMinDate());
389:
390: assertSame(property, property.minDate(null));
391: assertFalse(property.isLimitedDate());
392: assertNull(property.getMinDate());
393:
394: assertSame(property, property.maxDate(date2));
395: assertTrue(property.isLimitedDate());
396: assertSame(date2, property.getMaxDate());
397:
398: assertSame(property, property.maxDate(null));
399: assertFalse(property.isLimitedDate());
400: assertNull(property.getMaxDate());
401:
402: assertSame(property, property.minDate(date2));
403: assertSame(property, property.maxDate(date1));
404: assertTrue(property.isLimitedDate());
405: assertSame(date2, property.getMinDate());
406: assertSame(date1, property.getMaxDate());
407: }
408:
409: public void testFormat() {
410: SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy");
411:
412: ConstrainedProperty property = new ConstrainedProperty(
413: "the_name");
414: assertSame(property, property.format(format));
415: assertTrue(property.isFormatted());
416: assertSame(format, property.getFormat());
417:
418: assertSame(property, property.format(null));
419: assertFalse(property.isFormatted());
420: assertNull(property.getFormat());
421: }
422:
423: public void testInList() {
424: String[] list = new String[] { "one", "two" };
425:
426: ConstrainedProperty property = new ConstrainedProperty(
427: "the_name");
428: assertSame(property, property.inList(list));
429: assertTrue(property.isInList());
430: assertSame(list, property.getInList());
431:
432: assertSame(property, property.inList((String[]) null));
433: assertFalse(property.isInList());
434: assertNull(property.getInList());
435:
436: list = new String[0];
437: assertSame(property, property.inList(list));
438: assertFalse(property.isInList());
439: assertSame(list, property.getInList());
440: }
441:
442: public void testRangeByte() {
443: ConstrainedProperty property = new ConstrainedProperty(
444: "the_name");
445:
446: assertSame(property, property.rangeBegin((byte) 5));
447: assertTrue(property.isRange());
448: assertEquals((byte) 5, property.getRangeBegin());
449:
450: assertSame(property, property.rangeBegin(null));
451: assertFalse(property.isRange());
452: assertNull(property.getRangeBegin());
453:
454: assertSame(property, property.rangeEnd((byte) 78));
455: assertTrue(property.isRange());
456: assertEquals((byte) 78, property.getRangeEnd());
457:
458: assertSame(property, property.rangeEnd(null));
459: assertFalse(property.isRange());
460: assertNull(property.getRangeEnd());
461:
462: assertSame(property, property.rangeBegin((byte) 7));
463: assertSame(property, property.rangeEnd((byte) 27));
464: assertTrue(property.isRange());
465: assertEquals((byte) 7, property.getRangeBegin());
466: assertEquals((byte) 27, property.getRangeEnd());
467: }
468:
469: public void testRangeChar() {
470: ConstrainedProperty property = new ConstrainedProperty(
471: "the_name");
472:
473: assertSame(property, property.rangeBegin('b'));
474: assertTrue(property.isRange());
475: assertEquals('b', property.getRangeBegin());
476:
477: assertSame(property, property.rangeBegin(null));
478: assertFalse(property.isRange());
479: assertNull(property.getRangeBegin());
480:
481: assertSame(property, property.rangeEnd('z'));
482: assertTrue(property.isRange());
483: assertEquals('z', property.getRangeEnd());
484:
485: assertSame(property, property.rangeEnd(null));
486: assertFalse(property.isRange());
487: assertNull(property.getRangeEnd());
488:
489: assertSame(property, property.rangeBegin('d'));
490: assertSame(property, property.rangeEnd('g'));
491: assertTrue(property.isRange());
492: assertEquals('d', property.getRangeBegin());
493: assertEquals('g', property.getRangeEnd());
494: }
495:
496: public void testRangeShort() {
497: ConstrainedProperty property = new ConstrainedProperty(
498: "the_name");
499:
500: assertSame(property, property.rangeBegin((short) 23));
501: assertTrue(property.isRange());
502: assertEquals((short) 23, property.getRangeBegin());
503:
504: assertSame(property, property.rangeBegin(null));
505: assertFalse(property.isRange());
506: assertNull(property.getRangeBegin());
507:
508: assertSame(property, property.rangeEnd((short) 534));
509: assertTrue(property.isRange());
510: assertEquals((short) 534, property.getRangeEnd());
511:
512: assertSame(property, property.rangeEnd(null));
513: assertFalse(property.isRange());
514: assertNull(property.getRangeEnd());
515:
516: assertSame(property, property.rangeBegin((short) 39));
517: assertSame(property, property.rangeEnd((short) 3534));
518: assertTrue(property.isRange());
519: assertEquals((short) 39, property.getRangeBegin());
520: assertEquals((short) 3534, property.getRangeEnd());
521: }
522:
523: public void testRangeInt() {
524: ConstrainedProperty property = new ConstrainedProperty(
525: "the_name");
526:
527: assertSame(property, property.rangeBegin(534));
528: assertTrue(property.isRange());
529: assertEquals(534, property.getRangeBegin());
530:
531: assertSame(property, property.rangeBegin(null));
532: assertFalse(property.isRange());
533: assertNull(property.getRangeBegin());
534:
535: assertSame(property, property.rangeEnd(6344));
536: assertTrue(property.isRange());
537: assertEquals(6344, property.getRangeEnd());
538:
539: assertSame(property, property.rangeEnd(null));
540: assertFalse(property.isRange());
541: assertNull(property.getRangeEnd());
542:
543: assertSame(property, property.rangeBegin(423));
544: assertSame(property, property.rangeEnd(89724));
545: assertTrue(property.isRange());
546: assertEquals(423, property.getRangeBegin());
547: assertEquals(89724, property.getRangeEnd());
548: }
549:
550: public void testRangeLong() {
551: ConstrainedProperty property = new ConstrainedProperty(
552: "the_name");
553:
554: assertSame(property, property.rangeBegin(242L));
555: assertTrue(property.isRange());
556: assertEquals(242L, property.getRangeBegin());
557:
558: assertSame(property, property.rangeBegin(null));
559: assertFalse(property.isRange());
560: assertNull(property.getRangeBegin());
561:
562: assertSame(property, property.rangeEnd(783658L));
563: assertTrue(property.isRange());
564: assertEquals(783658L, property.getRangeEnd());
565:
566: assertSame(property, property.rangeEnd(null));
567: assertFalse(property.isRange());
568: assertNull(property.getRangeEnd());
569:
570: assertSame(property, property.rangeBegin(2432L));
571: assertSame(property, property.rangeEnd(9872949L));
572: assertTrue(property.isRange());
573: assertEquals(2432L, property.getRangeBegin());
574: assertEquals(9872949L, property.getRangeEnd());
575: }
576:
577: public void testRangeFloat() {
578: ConstrainedProperty property = new ConstrainedProperty(
579: "the_name");
580:
581: assertSame(property, property.rangeBegin(234.32f));
582: assertTrue(property.isRange());
583: assertEquals(234.32f, property.getRangeBegin());
584:
585: assertSame(property, property.rangeBegin(null));
586: assertFalse(property.isRange());
587: assertNull(property.getRangeBegin());
588:
589: assertSame(property, property.rangeEnd(9887.23f));
590: assertTrue(property.isRange());
591: assertEquals(9887.23f, property.getRangeEnd());
592:
593: assertSame(property, property.rangeEnd(null));
594: assertFalse(property.isRange());
595: assertNull(property.getRangeEnd());
596:
597: assertSame(property, property.rangeBegin(12.8f));
598: assertSame(property, property.rangeEnd(89736.25f));
599: assertTrue(property.isRange());
600: assertEquals(12.8f, property.getRangeBegin());
601: assertEquals(89736.25f, property.getRangeEnd());
602: }
603:
604: public void testRangeDouble() {
605: ConstrainedProperty property = new ConstrainedProperty(
606: "the_name");
607:
608: assertSame(property, property.rangeBegin(290.523d));
609: assertTrue(property.isRange());
610: assertEquals(290.523d, property.getRangeBegin());
611:
612: assertSame(property, property.rangeBegin(null));
613: assertFalse(property.isRange());
614: assertNull(property.getRangeBegin());
615:
616: assertSame(property, property.rangeEnd(7623847.3453d));
617: assertTrue(property.isRange());
618: assertEquals(7623847.3453d, property.getRangeEnd());
619:
620: assertSame(property, property.rangeEnd(null));
621: assertFalse(property.isRange());
622: assertNull(property.getRangeEnd());
623:
624: assertSame(property, property.rangeBegin(24.2348d));
625: assertSame(property, property.rangeEnd(423987.2345d));
626: assertTrue(property.isRange());
627: assertEquals(24.2348d, property.getRangeBegin());
628: assertEquals(423987.2345d, property.getRangeEnd());
629: }
630:
631: public void testRange() {
632: ConstrainedProperty property = new ConstrainedProperty(
633: "the_name");
634:
635: assertSame(property, property.rangeBegin(new Integer(5)));
636: assertTrue(property.isRange());
637: assertEquals(5, property.getRangeBegin());
638:
639: assertSame(property, property.rangeBegin(null));
640: assertFalse(property.isRange());
641: assertNull(property.getRangeBegin());
642:
643: assertSame(property, property.rangeEnd(new Integer(78)));
644: assertTrue(property.isRange());
645: assertEquals(78, property.getRangeEnd());
646:
647: assertSame(property, property.rangeEnd(null));
648: assertFalse(property.isRange());
649: assertNull(property.getRangeEnd());
650:
651: assertSame(property, property.rangeBegin(new Integer(7)));
652: assertSame(property, property.rangeEnd(new Integer(27)));
653: assertTrue(property.isRange());
654: assertEquals(7, property.getRangeBegin());
655: assertEquals(27, property.getRangeEnd());
656: }
657:
658: public void testDefaultValueChar() {
659: ConstrainedProperty property = new ConstrainedProperty(
660: "the_name");
661: assertSame(property, property.defaultValue('C'));
662: assertTrue(property.hasDefaultValue());
663: assertEquals('C', property.getDefaultValue());
664:
665: assertSame(property, property.defaultValue(null));
666: assertFalse(property.hasDefaultValue());
667: assertNull(property.getDefaultValue());
668: }
669:
670: public void testDefaultValueBoolean() {
671: ConstrainedProperty property = new ConstrainedProperty(
672: "the_name");
673: assertSame(property, property.defaultValue(false));
674: assertTrue(property.hasDefaultValue());
675: assertEquals(false, property.getDefaultValue());
676:
677: assertSame(property, property.defaultValue(null));
678: assertFalse(property.hasDefaultValue());
679: assertNull(property.getDefaultValue());
680: }
681:
682: public void testDefaultValueByte() {
683: ConstrainedProperty property = new ConstrainedProperty(
684: "the_name");
685: assertSame(property, property.defaultValue((byte) 89));
686: assertTrue(property.hasDefaultValue());
687: assertEquals((byte) 89, property.getDefaultValue());
688:
689: assertSame(property, property.defaultValue(null));
690: assertFalse(property.hasDefaultValue());
691: assertNull(property.getDefaultValue());
692: }
693:
694: public void testDefaultValueDouble() {
695: ConstrainedProperty property = new ConstrainedProperty(
696: "the_name");
697: assertSame(property, property.defaultValue(87923.878d));
698: assertTrue(property.hasDefaultValue());
699: assertEquals(87923.878d, property.getDefaultValue());
700:
701: assertSame(property, property.defaultValue(null));
702: assertFalse(property.hasDefaultValue());
703: assertNull(property.getDefaultValue());
704: }
705:
706: public void testDefaultValueFloat() {
707: ConstrainedProperty property = new ConstrainedProperty(
708: "the_name");
709: assertSame(property, property.defaultValue(61.9f));
710: assertTrue(property.hasDefaultValue());
711: assertEquals(61.9f, property.getDefaultValue());
712:
713: assertSame(property, property.defaultValue(null));
714: assertFalse(property.hasDefaultValue());
715: assertNull(property.getDefaultValue());
716: }
717:
718: public void testDefaultValueInt() {
719: ConstrainedProperty property = new ConstrainedProperty(
720: "the_name");
721: assertSame(property, property.defaultValue(9824));
722: assertTrue(property.hasDefaultValue());
723: assertEquals(9824, property.getDefaultValue());
724:
725: assertSame(property, property.defaultValue(null));
726: assertFalse(property.hasDefaultValue());
727: assertNull(property.getDefaultValue());
728: }
729:
730: public void testDefaultValueLong() {
731: ConstrainedProperty property = new ConstrainedProperty(
732: "the_name");
733: assertSame(property, property.defaultValue(2332979L));
734: assertTrue(property.hasDefaultValue());
735: assertEquals(2332979L, property.getDefaultValue());
736:
737: assertSame(property, property.defaultValue(null));
738: assertFalse(property.hasDefaultValue());
739: assertNull(property.getDefaultValue());
740: }
741:
742: public void testDefaultValueShort() {
743: ConstrainedProperty property = new ConstrainedProperty(
744: "the_name");
745: assertSame(property, property.defaultValue((short) 221));
746: assertTrue(property.hasDefaultValue());
747: assertEquals((short) 221, property.getDefaultValue());
748:
749: assertSame(property, property.defaultValue(null));
750: assertFalse(property.hasDefaultValue());
751: assertNull(property.getDefaultValue());
752: }
753:
754: public void testDefaultValueObject() {
755: ConstrainedProperty property = new ConstrainedProperty(
756: "the_name");
757: assertSame(property, property.defaultValue("the default"));
758: assertTrue(property.hasDefaultValue());
759: assertEquals("the default", property.getDefaultValue());
760:
761: assertSame(property, property.defaultValue(null));
762: assertFalse(property.hasDefaultValue());
763: assertNull(property.getDefaultValue());
764: }
765:
766: public void testManyToOne() {
767: ConstrainedProperty property = new ConstrainedProperty(
768: "the_name");
769: assertSame(property, property.manyToOne(BeanImpl.class,
770: "column"));
771: assertTrue(property.hasManyToOne());
772: assertEquals("column", property.getManyToOne().getColumn());
773: assertNull(property.getManyToOne().getTable());
774: assertEquals("beanimpl", property.getManyToOne()
775: .getDerivedTable());
776:
777: property.manyToOne("tablename", "column");
778: assertTrue(property.hasManyToOne());
779: assertEquals("column", property.getManyToOne().getColumn());
780: assertEquals("tablename", property.getManyToOne().getTable());
781: assertEquals("tablename", property.getManyToOne()
782: .getDerivedTable());
783: }
784:
785: public void testFile() {
786: ConstrainedProperty property = new ConstrainedProperty(
787: "the_name");
788: assertSame(property, property.file(true));
789: assertTrue(property.isFile());
790:
791: assertSame(property, property.file(false));
792: assertFalse(property.isFile());
793: }
794: }
|