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: TestValidationRuleLimitedDate.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.site;
009:
010: import java.util.Date;
011: import junit.framework.TestCase;
012:
013: public class TestValidationRuleLimitedDate extends TestCase {
014: public TestValidationRuleLimitedDate(String name) {
015: super (name);
016: }
017:
018: public void testInstantiation() {
019: Bean bean = new Bean(new Date(2003, 12, 11));
020: ValidationRuleLimitedDate rule = new ValidationRuleLimitedDate(
021: "property", new Date(2003, 3, 1), new Date(2004, 3, 1))
022: .setBean(bean);
023: assertNotNull(rule);
024: }
025:
026: public void testValid() {
027: Bean bean = new Bean(new Date(2003, 12, 11));
028: ValidationRuleLimitedDate rule = new ValidationRuleLimitedDate(
029: "property", new Date(2003, 3, 1), new Date(2004, 3, 1))
030: .setBean(bean);
031: assertTrue(rule.validate());
032: }
033:
034: public void testValidArray() {
035: Bean bean = new Bean(new Date[] { new Date(2003, 12, 11),
036: new Date(2005, 3, 7) });
037: ValidationRuleLimitedDate rule = new ValidationRuleLimitedDate(
038: "arrayProperty", new Date(2003, 3, 1), new Date(2006,
039: 3, 1)).setBean(bean);
040: assertTrue(rule.validate());
041: }
042:
043: public void testInvalid() {
044: Bean bean = new Bean(new Date(2003, 12, 11));
045: ValidationRuleLimitedDate rule = new ValidationRuleLimitedDate(
046: "property", new Date(2004, 3, 1), new Date(2004, 4, 1))
047: .setBean(bean);
048: assertFalse(rule.validate());
049: }
050:
051: public void testInvalidArray() {
052: Bean bean = new Bean(new Date[] { new Date(2003, 12, 11),
053: new Date(2006, 3, 7) });
054: ValidationRuleLimitedDate rule = new ValidationRuleLimitedDate(
055: "arrayProperty", new Date(2003, 3, 1), new Date(2006,
056: 3, 1)).setBean(bean);
057: assertFalse(rule.validate());
058: }
059:
060: public void testUnknownProperty() {
061: Bean bean = new Bean(new Date(2003, 12, 11));
062: ValidationRuleLimitedDate rule = new ValidationRuleLimitedDate(
063: "unknown_property", new Date(2003, 3, 1), new Date(
064: 2004, 3, 1)).setBean(bean);
065: assertTrue(rule.validate());
066: }
067:
068: public void testGetError() {
069: Bean bean = new Bean(new Date(2003, 12, 11));
070: ValidationRuleLimitedDate rule = new ValidationRuleLimitedDate(
071: "property", new Date(2004, 3, 1), new Date(2004, 4, 1))
072: .setBean(bean);
073: ValidationError error = rule.getError();
074: assertEquals(ValidationError.IDENTIFIER_INVALID, error
075: .getIdentifier());
076: assertEquals("property", error.getSubject());
077: assertEquals(rule.getSubject(), error.getSubject());
078: }
079:
080: public class Bean {
081: private Date mProperty = null;
082: private Date[] mArrayProperty = null;
083:
084: public Bean(Date property) {
085: mProperty = property;
086: }
087:
088: public Bean(Date[] arrayProperty) {
089: mArrayProperty = arrayProperty;
090: }
091:
092: public void setProperty(Date property) {
093: mProperty = property;
094: }
095:
096: public Date getProperty() {
097: return mProperty;
098: }
099:
100: public void setArrayProperty(Date[] arrayProperty) {
101: mArrayProperty = arrayProperty;
102: }
103:
104: public Date[] getArrayProperty() {
105: return mArrayProperty;
106: }
107: }
108: }
|