KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.validator.rules;
2
3 import junit.framework.*;
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 MandatoryTest extends TestCase {
13   /**
14    * Constructor for MandatoryTest.
15    * @param arg0
16    */

17   public MandatoryTest(String JavaDoc arg0) {
18     super(arg0);
19   }
20
21   public void testExists() throws Exception JavaDoc {
22     Vlad v = new Vlad();
23     RuleSet rs = new RuleSet();
24
25     rs.setId("mandatory");
26
27     Mandatory m = new Mandatory();
28
29     rs.addValidatable(m);
30     v.addRuleSet(rs);
31
32     Status st = v.validate("mandatory", new Object JavaDoc(),
33         java.util.Locale.getDefault());
34
35     super.assertTrue("Mandatory check failed", !st.isError());
36   }
37
38   public void testNotExists()
39     throws Exception JavaDoc {
40     Vlad v = new Vlad();
41     RuleSet rs = new RuleSet();
42
43     rs.setId("mandatory");
44
45     Mandatory m = new Mandatory();
46
47     rs.addValidatable(m);
48     v.addRuleSet(rs);
49
50     Status st = v.validate("mandatory", null, java.util.Locale.getDefault());
51
52     super.assertTrue("Mandatory check failed", st.isError());
53   }
54
55   public void testExistAttribute()
56     throws Exception JavaDoc {
57     Vlad v = new Vlad();
58     RuleSet rs = new RuleSet();
59
60     rs.setId("mandatory");
61
62     Mandatory m = new Mandatory();
63
64     m.setAttribute("name");
65     rs.addValidatable(m);
66     v.addRuleSet(rs);
67
68     Status st = v.validate("mandatory", new Company("ACME"),
69         java.util.Locale.getDefault());
70
71     super.assertTrue("Mandatory check failed", !st.isError());
72   }
73
74   public void testNotExistAttribute()
75     throws Exception JavaDoc {
76     Vlad v = new Vlad();
77     RuleSet rs = new RuleSet();
78
79     rs.setId("mandatory");
80
81     Mandatory m = new Mandatory();
82
83     m.setAttribute("name");
84     rs.addValidatable(m);
85     v.addRuleSet(rs);
86
87     Status st = v.validate("mandatory", new Company(null),
88         java.util.Locale.getDefault());
89
90     super.assertTrue("Mandatory check failed", st.isError());
91   }
92 }
93
Popular Tags