1   /*
2    * $Id: VarTest.java 329871 2005-10-31 17:50:55Z niallp $
3    * $Rev: 329871 $
4    * $Date: 2005-10-31 17:50:55 +0000 (Mon, 31 Oct 2005) $
5    *
6    * ====================================================================
7    * Copyright 2001-2005 The Apache Software Foundation
8    *
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   *
13   *     http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   */
21  
22  
23  package org.apache.commons.validator;
24  
25  import junit.framework.Test;
26  import junit.framework.TestSuite;
27  import java.util.Locale;
28  import java.io.IOException;
29  import org.xml.sax.SAXException;
30  
31  /***                                                       
32   * Test that the new Var attributes and the
33   * digester rule changes work.
34   */
35  public class VarTest extends TestCommon {
36  
37     /***
38      * The key used to retrieve the set of validation
39      * rules from the xml file.
40      */
41     protected static String FORM_KEY = "testForm";
42  
43     /***
44      * The key used to retrieve the validator action.
45      */
46     protected static String ACTION = "byte";
47  
48  
49  
50     public VarTest(String name) {
51         super(name);
52     }
53  
54     /***
55      * Start the tests.
56      *
57      * @param theArgs the arguments. Not used
58      */
59     public static void main(String[] theArgs) {
60         junit.awtui.TestRunner.main(new String[] {VarTest.class.getName()});
61     }
62  
63     /***
64      * @return a test suite (<code>TestSuite</code>) that includes all methods
65      *         starting with "test"
66      */
67     public static Test suite() {
68         // All methods starting with "test" will be executed in the test suite.
69         return new TestSuite(VarTest.class);
70     }
71  
72     /***
73      * Load <code>ValidatorResources</code> from
74      * validator-multipletest.xml.
75      */
76     protected void setUp() throws IOException, SAXException {
77        // Load resources
78        loadResources("VarTest-config.xml");
79     }
80  
81     protected void tearDown() {
82     }
83  
84     /***
85      * With nothing provided, we should fail both because both are required.
86      */
87     public void testVars() throws ValidatorException {
88  
89         Form form = resources.getForm(Locale.getDefault(), FORM_KEY);
90  
91         // Get field 1
92         Field field1 = form.getField("field-1");
93         assertNotNull("field-1 is null.", field1);
94         assertEquals("field-1 property is wrong", "field-1", field1.getProperty());
95  
96         // Get var-1-1
97         Var var11 = field1.getVar("var-1-1");
98         assertNotNull("var-1-1 is null.", var11);
99         assertEquals("var-1-1 name is wrong", "var-1-1", var11.getName());
100        assertEquals("var-1-1 value is wrong", "value-1-1", var11.getValue());
101        assertEquals("var-1-1 jstype is wrong", "jstype-1-1", var11.getJsType());
102        assertFalse("var-1-1 resource is true", var11.isResource());
103        assertNull("var-1-1 bundle is not null.", var11.getBundle());
104 
105        // Get field 2
106        Field field2 = form.getField("field-2");
107        assertNotNull("field-2 is null.", field2);
108        assertEquals("field-2 property is wrong", "field-2", field2.getProperty());
109 
110        // Get var-2-1
111        Var var21 = field2.getVar("var-2-1");
112        assertNotNull("var-2-1 is null.", var21);
113        assertEquals("var-2-1 name is wrong", "var-2-1", var21.getName());
114        assertEquals("var-2-1 value is wrong", "value-2-1", var21.getValue());
115        assertEquals("var-2-1 jstype is wrong", "jstype-2-1", var21.getJsType());
116        assertTrue("var-2-1 resource is false", var21.isResource());
117        assertEquals("var-2-1 bundle is wrong", "bundle-2-1", var21.getBundle());
118 
119        // Get var-2-2
120        Var var22 = field2.getVar("var-2-2");
121        assertNotNull("var-2-2 is null.", var22);
122        assertEquals("var-2-2 name is wrong", "var-2-2", var22.getName());
123        assertEquals("var-2-2 value is wrong", "value-2-2", var22.getValue());
124        assertNull("var-2-2 jstype is not null", var22.getJsType());
125        assertFalse("var-2-2 resource is true", var22.isResource());
126        assertEquals("var-2-2 bundle is wrong", "bundle-2-2", var22.getBundle());
127 
128    }
129 
130 }