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: TestValidationRuleNotNull.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 TestValidationRuleNotNull extends TestCase {
13: public TestValidationRuleNotNull(String name) {
14: super (name);
15: }
16:
17: public void testInstantiation() {
18: Bean bean = new Bean("not null");
19: ValidationRuleNotNull rule = new ValidationRuleNotNull(
20: "property").setBean(bean);
21: assertNotNull(rule);
22: }
23:
24: public void testValid() {
25: Bean bean = new Bean("not null");
26: ValidationRuleNotNull rule = new ValidationRuleNotNull(
27: "property").setBean(bean);
28: assertTrue(rule.validate());
29: }
30:
31: public void testInvalid() {
32: Bean bean = new Bean(null);
33: ValidationRuleNotNull rule = new ValidationRuleNotNull(
34: "property").setBean(bean);
35: assertFalse(rule.validate());
36: }
37:
38: public void testUnknownProperty() {
39: Bean bean = new Bean("not null");
40: ValidationRuleNotNull rule = new ValidationRuleNotNull(
41: "unknown_property").setBean(bean);
42: assertTrue(rule.validate());
43: }
44:
45: public void testGetError() {
46: Bean bean = new Bean("");
47: ValidationRuleNotNull rule = new ValidationRuleNotNull(
48: "property").setBean(bean);
49: ValidationError error = rule.getError();
50: assertEquals(ValidationError.IDENTIFIER_MANDATORY, error
51: .getIdentifier());
52: assertEquals("property", error.getSubject());
53: assertEquals(rule.getSubject(), error.getSubject());
54: }
55:
56: public class Bean {
57: private String mProperty = null;
58:
59: public Bean(String property) {
60: mProperty = property;
61: }
62:
63: public void setProperty(String property) {
64: mProperty = property;
65: }
66:
67: public String getProperty() {
68: return mProperty;
69: }
70: }
71: }
|