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: TestValidationRuleInList.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 TestValidationRuleInList extends TestCase {
013: public TestValidationRuleInList(String name) {
014: super (name);
015: }
016:
017: public void testInstantiation() {
018: Bean bean = new Bean("entry");
019: ValidationRuleInList rule = new ValidationRuleInList(
020: "property", new String[] { "one", "two", "entry",
021: "three" }).setBean(bean);
022: assertNotNull(rule);
023: }
024:
025: public void testValid() {
026: Bean bean = new Bean("entry");
027: ValidationRuleInList rule = new ValidationRuleInList(
028: "property", new String[] { "one", "two", "entry",
029: "three" }).setBean(bean);
030: assertTrue(rule.validate());
031: }
032:
033: public void testValidArray() {
034: Bean bean = new Bean(new String[] { "entry", "two" });
035: ValidationRuleInList rule = new ValidationRuleInList(
036: "arrayProperty", new String[] { "one", "two", "entry",
037: "three" }).setBean(bean);
038: assertTrue(rule.validate());
039: }
040:
041: public void testInvalid() {
042: Bean bean = new Bean("entrykolo");
043: ValidationRuleInList rule = new ValidationRuleInList(
044: "property", new String[] { "one", "two", "entry",
045: "three" }).setBean(bean);
046: assertFalse(rule.validate());
047: }
048:
049: public void testInvalidArray() {
050: Bean bean = new Bean(new String[] { "two", "one", "entrykolo" });
051: ValidationRuleInList rule = new ValidationRuleInList(
052: "arrayProperty", new String[] { "one", "two", "entry",
053: "three" }).setBean(bean);
054: assertFalse(rule.validate());
055: }
056:
057: public void testUnknownProperty() {
058: Bean bean = new Bean("entry");
059: ValidationRuleInList rule = new ValidationRuleInList(
060: "unknown_property", new String[] { "one", "two",
061: "entry", "three" }).setBean(bean);
062: assertTrue(rule.validate());
063: }
064:
065: public void testGetError() {
066: Bean bean = new Bean("entry");
067: ValidationRuleInList rule = new ValidationRuleInList(
068: "property", new String[] { "one", "two", "entry",
069: "three" }).setBean(bean);
070: ValidationError error = rule.getError();
071: assertEquals(ValidationError.IDENTIFIER_INVALID, error
072: .getIdentifier());
073: assertEquals("property", error.getSubject());
074: assertEquals(rule.getSubject(), error.getSubject());
075: }
076:
077: public class Bean {
078: private String mProperty = null;
079: private String[] mArrayProperty = null;
080:
081: public Bean(String property) {
082: mProperty = property;
083: }
084:
085: public Bean(String[] arrayProperty) {
086: mArrayProperty = arrayProperty;
087: }
088:
089: public void setArrayProperty(String[] arrayProperty) {
090: mArrayProperty = arrayProperty;
091: }
092:
093: public String[] getArrayProperty() {
094: return mArrayProperty;
095: }
096:
097: public void setProperty(String property) {
098: mProperty = property;
099: }
100:
101: public String getProperty() {
102: return mProperty;
103: }
104: }
105: }
|