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 static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertNull;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import java.io.IOException;
26 import java.util.Locale;
27
28 import org.junit.jupiter.api.AfterEach;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31 import org.xml.sax.SAXException;
32
33
34
35
36 public class VarTest extends AbstractCommonTest {
37
38
39
40
41 protected static String FORM_KEY = "testForm";
42
43
44
45
46 protected static String ACTION = "byte";
47
48
49
50
51 @BeforeEach
52 protected void setUp() throws IOException, SAXException {
53
54 loadResources("VarTest-config.xml");
55 }
56
57 @AfterEach
58 protected void tearDown() {
59 }
60
61
62
63
64 @Test
65 public void testVars() {
66
67 final Form form = resources.getForm(Locale.getDefault(), FORM_KEY);
68
69
70 final Field field1 = form.getField("field-1");
71 assertNotNull(field1, "field-1 is null.");
72 assertEquals(field1.getProperty(), "field-1", "field-1 property is wrong");
73
74
75 final Var var11 = field1.getVar("var-1-1");
76 assertNotNull(var11, "var-1-1 is null.");
77 assertEquals(var11.getName(), "var-1-1", "var-1-1 name is wrong");
78 assertEquals(var11.getValue(), "value-1-1", "var-1-1 value is wrong");
79 assertEquals(var11.getJsType(), "jstype-1-1", "var-1-1 jstype is wrong");
80 assertFalse(var11.isResource(), "var-1-1 resource is true");
81 assertNull(var11.getBundle(), "var-1-1 bundle is not null.");
82
83
84 final Field field2 = form.getField("field-2");
85 assertNotNull(field2, "field-2 is null.");
86 assertEquals(field2.getProperty(), "field-2", "field-2 property is wrong");
87
88
89 final Var var21 = field2.getVar("var-2-1");
90 assertNotNull(var21, "var-2-1 is null.");
91 assertEquals(var21.getName(), "var-2-1", "var-2-1 name is wrong");
92 assertEquals(var21.getValue(), "value-2-1", "var-2-1 value is wrong");
93 assertEquals("jstype-2-1", var21.getJsType(), "var-2-1 jstype is wrong");
94 assertTrue(var21.isResource(), "var-2-1 resource is false");
95 assertEquals(var21.getBundle(), "bundle-2-1", "var-2-1 bundle is wrong");
96
97
98 final Var var22 = field2.getVar("var-2-2");
99 assertNotNull(var22, "var-2-2 is null.");
100 assertEquals(var22.getName(), "var-2-2", "var-2-2 name is wrong");
101 assertEquals(var22.getValue(), "value-2-2", "var-2-2 value is wrong");
102 assertNull(var22.getJsType(), "var-2-2 jstype is not null");
103 assertFalse(var22.isResource(), "var-2-2 resource is true");
104 assertEquals(var22.getBundle(), "bundle-2-2", "var-2-2 bundle is wrong");
105
106 }
107
108 }