1 21 22 package org.apache.commons.validator; 23 24 import java.io.IOException ; 25 26 import org.xml.sax.SAXException ; 27 28 31 abstract public class TestNumber extends TestCommon { 32 33 37 protected String FORM_KEY; 38 39 42 protected String ACTION; 43 44 45 public TestNumber(String name) { 46 super(name); 47 } 48 49 53 protected void setUp() throws IOException , SAXException { 54 loadResources("validator-numeric.xml"); 56 } 57 58 protected void tearDown() { 59 } 60 61 64 public void testNumber() throws ValidatorException { 65 ValueBean info = new ValueBean(); 67 info.setValue("0"); 68 valueTest(info, true); 69 } 70 71 74 public void testNumberFailure() throws ValidatorException { 75 ValueBean info = new ValueBean(); 77 valueTest(info, false); 78 } 79 80 86 protected void valueTest(Object info, boolean passed) throws ValidatorException { 87 Validator validator = new Validator(resources, FORM_KEY); 90 validator.setParameter(Validator.BEAN_PARAM, info); 93 94 ValidatorResults results = null; 96 97 results = validator.validate(); 102 103 assertNotNull("Results are null.", results); 104 105 ValidatorResult result = results.getValidatorResult("value"); 106 107 assertNotNull(ACTION + " value ValidatorResult should not be null.", result); 108 assertTrue(ACTION + " value ValidatorResult should contain the '" + ACTION + "' action.", result.containsAction(ACTION)); 109 assertTrue(ACTION + " value ValidatorResult for the '" + ACTION + "' action should have " + (passed ? "passed" : "failed") + ".", (passed ? result.isValid(ACTION) : !result.isValid(ACTION))); 110 } 111 112 113 } 114 | Popular Tags |