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