KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > validator > rules > IfDefinedTest


1 package org.sapia.validator.rules;
2
3 import junit.framework.TestCase;
4
5 import org.sapia.validator.*;
6 import org.sapia.validator.examples.Company;
7
8 /**
9  * @author Yanick Duchesne
10  * 28-Apr-2003
11  */

12 public class IfDefinedTest extends TestCase {
13   /**
14    * Constructor for IfDefinedTest.
15    * @param arg0
16    */

17   public IfDefinedTest(String JavaDoc arg0) {
18     super(arg0);
19   }
20
21   public void testDefined() throws Exception JavaDoc {
22     Vlad v = new Vlad();
23     RuleSet rs = new RuleSet();
24
25     rs.setId("ifDefined");
26
27     IfDefined ifDef = new IfDefined();
28
29     ifDef.setAttribute("name");
30
31     TestRule t1 = new TestRule(false);
32
33     ifDef.handleObject("someRule", t1);
34     rs.addValidatable(ifDef);
35     v.addRuleSet(rs);
36     v.validate("ifDefined", new Company("ACME"), java.util.Locale.getDefault());
37     super.assertTrue("TestRule 1 was not called", t1.wasCalled());
38   }
39
40   public void testNotDefined()
41     throws Exception JavaDoc {
42     Vlad v = new Vlad();
43     RuleSet rs = new RuleSet();
44
45     rs.setId("ifDefined");
46
47     IfDefined ifDef = new IfDefined();
48
49     ifDef.setAttribute("name");
50
51     TestRule t1 = new TestRule(false);
52
53     ifDef.handleObject("someRule", t1);
54     rs.addValidatable(ifDef);
55     v.addRuleSet(rs);
56     v.validate("ifDefined", new Company(null), java.util.Locale.getDefault());
57     super.assertTrue("TestRule 1 was not called", !t1.wasCalled());
58   }
59
60   public void testNotDefinedNoAttribute()
61     throws Exception JavaDoc {
62     Vlad v = new Vlad();
63     RuleSet rs = new RuleSet();
64
65     rs.setId("ifDefined");
66
67     IfDefined ifDef = new IfDefined();
68     TestRule t1 = new TestRule(false);
69
70     ifDef.handleObject("someRule", t1);
71     rs.addValidatable(ifDef);
72     v.addRuleSet(rs);
73     v.validate("ifDefined", null, java.util.Locale.getDefault());
74     super.assertTrue("TestRule 1 was called", !t1.wasCalled());
75   }
76 }
77
Popular Tags