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: TestValidationRuleRange.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 TestValidationRuleRange extends TestCase {
13: public TestValidationRuleRange(String name) {
14: super (name);
15: }
16:
17: public void testInstantiation() {
18: Bean bean = new Bean(21);
19: ValidationRuleRange rule = new ValidationRuleRange("property",
20: new Integer(12), new Integer(30)).setBean(bean);
21: assertNotNull(rule);
22: }
23:
24: public void testValid() {
25: Bean bean = new Bean(21);
26: ValidationRuleRange rule = new ValidationRuleRange("property",
27: new Integer(12), new Integer(30)).setBean(bean);
28: assertTrue(rule.validate());
29: }
30:
31: public void testValidArray() {
32: Bean bean = new Bean(new int[] { 21, 24, 30 });
33: ValidationRuleRange rule = new ValidationRuleRange(
34: "arrayproperty", 12, 30).setBean(bean);
35: assertTrue(rule.validate());
36: }
37:
38: public void testInvalid() {
39: Bean bean = new Bean(21);
40: ValidationRuleRange rule = new ValidationRuleRange("property",
41: new Integer(12), new Integer(20)).setBean(bean);
42: assertFalse(rule.validate());
43: }
44:
45: public void testInvalidArray() {
46: Bean bean = new Bean(new int[] { 21, 24, 30 });
47: ValidationRuleRange rule = new ValidationRuleRange(
48: "arrayproperty", 12, 29).setBean(bean);
49: assertFalse(rule.validate());
50: }
51:
52: public void testUnknownProperty() {
53: Bean bean = new Bean(21);
54: ValidationRuleRange rule = new ValidationRuleRange(
55: "unknown_property", new Integer(12), new Integer(30))
56: .setBean(bean);
57: assertTrue(rule.validate());
58: }
59:
60: public void testGetError() {
61: Bean bean = new Bean(21);
62: ValidationRuleRange rule = new ValidationRuleRange("property",
63: new Integer(12), new Integer(20)).setBean(bean);
64: ValidationError error = rule.getError();
65: assertEquals(ValidationError.IDENTIFIER_INVALID, error
66: .getIdentifier());
67: assertEquals("property", error.getSubject());
68: assertEquals(rule.getSubject(), error.getSubject());
69: }
70:
71: public class Bean {
72: private int mProperty;
73: private int[] mArrayproperty;
74:
75: public Bean(int property) {
76: mProperty = property;
77: }
78:
79: public Bean(int[] arrayproperty) {
80: mArrayproperty = arrayproperty;
81: }
82:
83: public void setProperty(int property) {
84: mProperty = property;
85: }
86:
87: public int getProperty() {
88: return mProperty;
89: }
90:
91: public void setArrayproperty(int[] arrayproperty) {
92: mArrayproperty = arrayproperty;
93: }
94:
95: public int[] getArrayproperty() {
96: return mArrayproperty;
97: }
98: }
99: }
|