01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestValidationRuleNotEqual.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.site;
09:
10: import junit.framework.TestCase;
11:
12: public class TestValidationRuleNotEqual extends TestCase {
13: public TestValidationRuleNotEqual(String name) {
14: super (name);
15: }
16:
17: public void testInstantiation() {
18: Bean bean = new Bean("value");
19: ValidationRuleNotEqual rule = new ValidationRuleNotEqual(
20: "property", "").setBean(bean);
21: assertNotNull(rule);
22: }
23:
24: public void testValid() {
25: Bean bean = new Bean("value");
26: ValidationRuleNotEqual rule = new ValidationRuleNotEqual(
27: "property", "other").setBean(bean);
28: assertTrue(rule.validate());
29: }
30:
31: public void testValidArray() {
32: Bean bean = new Bean(new String[] { "value", "something" });
33: ValidationRuleNotEqual rule = new ValidationRuleNotEqual(
34: "arrayProperty", "other").setBean(bean);
35: assertTrue(rule.validate());
36: }
37:
38: public void testInvalid() {
39: Bean bean = new Bean("value");
40: ValidationRuleNotEqual rule = new ValidationRuleNotEqual(
41: "property", "value").setBean(bean);
42: assertFalse(rule.validate());
43: }
44:
45: public void testInvalidArray() {
46: Bean bean = new Bean(new String[] { "value", "other" });
47: ValidationRuleNotEqual rule = new ValidationRuleNotEqual(
48: "arrayProperty", "other").setBean(bean);
49: assertFalse(rule.validate());
50: }
51:
52: public void testUnknownProperty() {
53: Bean bean = new Bean("value");
54: ValidationRuleNotEqual rule = new ValidationRuleNotEqual(
55: "unknown_property", "blurp").setBean(bean);
56: assertTrue(rule.validate());
57: }
58:
59: public void testGetError() {
60: Bean bean = new Bean("value");
61: ValidationRuleNotEqual rule = new ValidationRuleNotEqual(
62: "property", "value").setBean(bean);
63: ValidationError error = rule.getError();
64: assertEquals(ValidationError.IDENTIFIER_INVALID, error
65: .getIdentifier());
66: assertEquals("property", error.getSubject());
67: assertEquals(rule.getSubject(), error.getSubject());
68: }
69:
70: public class Bean {
71: private String mProperty = null;
72: private String[] mArrayProperty = null;
73:
74: public Bean(String property) {
75: mProperty = property;
76: }
77:
78: public Bean(String[] arrayProperty) {
79: mArrayProperty = arrayProperty;
80: }
81:
82: public void setArrayProperty(String[] arrayProperty) {
83: mArrayProperty = arrayProperty;
84: }
85:
86: public String[] getArrayProperty() {
87: return mArrayProperty;
88: }
89:
90: public void setProperty(String property) {
91: mProperty = property;
92: }
93:
94: public String getProperty() {
95: return mProperty;
96: }
97: }
98: }
|