1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.validator;
18
19 import java.io.IOException;
20
21 import org.xml.sax.SAXException;
22
23
24
25
26
27
28 abstract public class AbstractNumberTest extends AbstractCommonTest {
29
30
31
32
33
34 protected String FORM_KEY;
35
36
37
38
39 protected String ACTION;
40
41
42 public AbstractNumberTest(String name) {
43 super(name);
44 }
45
46
47
48
49
50 @Override
51 protected void setUp() throws IOException, SAXException {
52
53 loadResources("TestNumber-config.xml");
54 }
55
56 @Override
57 protected void tearDown() {
58 }
59
60
61
62
63 public void testNumber() throws ValidatorException {
64
65 ValueBeanValueBean.html#ValueBean">ValueBean info = new ValueBean();
66 info.setValue("0");
67 valueTest(info, true);
68 }
69
70
71
72
73 public void testNumberFailure() throws ValidatorException {
74
75 ValueBeanValueBean.html#ValueBean">ValueBean info = new ValueBean();
76 valueTest(info, false);
77 }
78
79
80
81
82
83
84
85 protected void valueTest(Object info, boolean passed) throws ValidatorException {
86
87
88 Validator validator = new Validator(resources, FORM_KEY);
89
90
91 validator.setParameter(Validator.BEAN_PARAM, info);
92
93
94 ValidatorResults results = null;
95
96
97
98
99
100 results = validator.validate();
101
102 assertNotNull("Results are null.", results);
103
104 ValidatorResult result = results.getValidatorResult("value");
105
106 assertNotNull(ACTION + " value ValidatorResult should not be null.", result);
107 assertTrue(ACTION + " value ValidatorResult should contain the '" + ACTION + "' action.", result.containsAction(ACTION));
108 assertTrue(ACTION + " value ValidatorResult for the '" + ACTION + "' action should have " + (passed ? "passed" : "failed") + ".", (passed ? result.isValid(ACTION) : !result.isValid(ACTION)));
109 }
110
111
112 }