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 12 public class MandatoryTest extends TestCase { 13 17 public MandatoryTest(String arg0) { 18 super(arg0); 19 } 20 21 public void testExists() throws Exception { 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 (), 33 java.util.Locale.getDefault()); 34 35 super.assertTrue("Mandatory check failed", !st.isError()); 36 } 37 38 public void testNotExists() 39 throws Exception { 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 { 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 { 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 |