1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.nuiton.validator.xwork2.field;
23
24 import com.opensymphony.xwork2.ActionContext;
25 import org.junit.Test;
26
27 import java.util.Locale;
28
29
30
31
32 public class FieldExpressionWithParamsValidatorTest extends AbstractFieldValidatorTest<FieldExpressionBean> {
33
34 public static final String MESSAGE = "expression.too.big##100";
35
36 public static final String MESSAGE2 = "expression.too.big##100##2000";
37
38 public FieldExpressionWithParamsValidatorTest() {
39 super(FieldExpressionBean.class);
40 }
41
42 @Test
43 @Override
44 public void testValidator() throws Exception {
45
46 ActionContext.getContext().setLocale(Locale.ENGLISH);
47
48 testBooleanType();
49 testShortType();
50 testIntType();
51 testLongType();
52 testDoubleType();
53 testStringType();
54
55
56 }
57
58 protected void testBooleanType() {
59
60 assertEquals(false, bean.isBooleanValue());
61 assertFieldInError("booleanValue", "expression.boolean.not.equals##true", true);
62 assertFieldInError("booleanValue", "expression.boolean.not.equals##false", false);
63
64 bean.setBooleanValue(true);
65 assertFieldInError("booleanValue", "expression.boolean.not.equals##true", false);
66 assertFieldInError("booleanValue", "expression.boolean.not.equals##false", true);
67 }
68
69 protected void testShortType() {
70 assertEquals(0, bean.getShortValue());
71 assertFieldInError("shortValue", MESSAGE, false);
72 assertFieldInError("shortValue", MESSAGE2, false);
73 bean.setShortValue((short) 10);
74 assertFieldInError("shortValue", MESSAGE, false);
75 assertFieldInError("shortValue", MESSAGE2, false);
76 bean.setShortValue((short) 1000);
77 assertFieldInError("shortValue", MESSAGE, true);
78 assertFieldInError("shortValue", MESSAGE2, false);
79 bean.setShortValue((short) 3000);
80 assertFieldInError("shortValue", MESSAGE, true);
81 assertFieldInError("shortValue", MESSAGE2, true);
82 }
83
84 protected void testIntType() {
85 assertEquals(0, bean.getIntValue());
86 assertFieldInError("intValue", MESSAGE, false);
87 assertFieldInError("intValue", MESSAGE2, false);
88 bean.setIntValue(10);
89 assertFieldInError("intValue", MESSAGE, false);
90 assertFieldInError("intValue", MESSAGE2, false);
91 bean.setIntValue(1000);
92 assertFieldInError("intValue", MESSAGE, true);
93 assertFieldInError("intValue", MESSAGE2, false);
94 bean.setIntValue(3000);
95 assertFieldInError("intValue", MESSAGE, true);
96 assertFieldInError("intValue", MESSAGE2, true);
97 }
98
99 protected void testLongType() {
100 assertEquals(0, bean.getLongValue());
101 assertFieldInError("longValue", MESSAGE, false);
102 assertFieldInError("longValue", MESSAGE2, false);
103 bean.setLongValue(10);
104 assertFieldInError("longValue", MESSAGE, false);
105 assertFieldInError("longValue", MESSAGE2, false);
106 bean.setLongValue(1000);
107 assertFieldInError("longValue", MESSAGE, true);
108 assertFieldInError("longValue", MESSAGE2, false);
109 bean.setLongValue(3000);
110 assertFieldInError("longValue", MESSAGE, true);
111 assertFieldInError("longValue", MESSAGE2, true);
112 }
113
114 protected void testDoubleType() {
115 assertEquals(0.0, bean.getDoubleValue(), 0);
116 assertFieldInError("doubleValue", MESSAGE, false);
117 assertFieldInError("doubleValue", "expression.too.big##100##2000", false);
118 bean.setDoubleValue(10);
119 assertFieldInError("doubleValue", MESSAGE, false);
120 assertFieldInError("doubleValue", "expression.too.big##100##2000", false);
121 bean.setDoubleValue(1000);
122 assertFieldInError("doubleValue", MESSAGE, true);
123 assertFieldInError("doubleValue", "expression.too.big##100##2000", false);
124 bean.setDoubleValue(3000);
125 assertFieldInError("doubleValue", MESSAGE, true);
126 assertFieldInError("doubleValue", "expression.too.big##100##2000", true);
127 }
128
129 protected void testStringType() {
130 assertEquals(null, bean.getStringValue());
131
132 assertFieldInError("stringValue", "expression.stringNotValue##1000", true);
133 assertFieldInError("stringValue", "expression.stringNotValue##1000##3000", true);
134 bean.setStringValue("100");
135
136 assertFieldInError("stringValue", "expression.stringNotValue##1000", true);
137 assertFieldInError("stringValue", "expression.stringNotValue##1000##3000", true);
138
139 bean.setStringValue("1000");
140 assertFieldInError("stringValue", "expression.stringNotValue##1000", false);
141 assertFieldInError("stringValue", "expression.stringNotValue##1000##3000", false);
142
143 bean.setStringValue("3000");
144 assertFieldInError("stringValue", "expression.stringNotValue##1000", true);
145 assertFieldInError("stringValue", "expression.stringNotValue##1000##3000", false);
146 }
147 }