View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.validator;
18  
19  import java.io.IOException;
20  import java.util.Locale;
21  
22  import org.xml.sax.SAXException;
23  
24  /**                                                       
25   * Test that the new Var attributes and the
26   * digester rule changes work.
27   *
28   * @version $Revision$
29   */
30  public class VarTest extends AbstractCommonTest {
31  
32     /**
33      * The key used to retrieve the set of validation
34      * rules from the xml file.
35      */
36     protected static String FORM_KEY = "testForm";
37  
38     /**
39      * The key used to retrieve the validator action.
40      */
41     protected static String ACTION = "byte";
42  
43  
44  
45     public VarTest(String name) {
46         super(name);
47     }
48  
49     /**
50      * Load <code>ValidatorResources</code> from
51      * validator-multipletest.xml.
52      */
53     @Override
54  protected void setUp() throws IOException, SAXException {
55        // Load resources
56        loadResources("VarTest-config.xml");
57     }
58  
59     @Override
60  protected void tearDown() {
61     }
62  
63     /**
64      * With nothing provided, we should fail both because both are required.
65      */
66     public void testVars() {
67  
68         Form form = resources.getForm(Locale.getDefault(), FORM_KEY);
69  
70         // Get field 1
71         Field field1 = form.getField("field-1");
72         assertNotNull("field-1 is null.", field1);
73         assertEquals("field-1 property is wrong", "field-1", field1.getProperty());
74  
75         // Get var-1-1
76         Var var11 = field1.getVar("var-1-1");
77         assertNotNull("var-1-1 is null.", var11);
78         assertEquals("var-1-1 name is wrong", "var-1-1", var11.getName());
79         assertEquals("var-1-1 value is wrong", "value-1-1", var11.getValue());
80         assertEquals("var-1-1 jstype is wrong", "jstype-1-1", var11.getJsType());
81         assertFalse("var-1-1 resource is true", var11.isResource());
82         assertNull("var-1-1 bundle is not null.", var11.getBundle());
83  
84         // Get field 2
85         Field field2 = form.getField("field-2");
86         assertNotNull("field-2 is null.", field2);
87         assertEquals("field-2 property is wrong", "field-2", field2.getProperty());
88  
89         // Get var-2-1
90         Var var21 = field2.getVar("var-2-1");
91         assertNotNull("var-2-1 is null.", var21);
92         assertEquals("var-2-1 name is wrong", "var-2-1", var21.getName());
93         assertEquals("var-2-1 value is wrong", "value-2-1", var21.getValue());
94         assertEquals("var-2-1 jstype is wrong", "jstype-2-1", var21.getJsType());
95         assertTrue("var-2-1 resource is false", var21.isResource());
96         assertEquals("var-2-1 bundle is wrong", "bundle-2-1", var21.getBundle());
97  
98         // Get var-2-2
99         Var var22 = field2.getVar("var-2-2");
100        assertNotNull("var-2-2 is null.", var22);
101        assertEquals("var-2-2 name is wrong", "var-2-2", var22.getName());
102        assertEquals("var-2-2 value is wrong", "value-2-2", var22.getValue());
103        assertNull("var-2-2 jstype is not null", var22.getJsType());
104        assertFalse("var-2-2 resource is true", var22.isResource());
105        assertEquals("var-2-2 bundle is wrong", "bundle-2-2", var22.getBundle());
106 
107    }
108 
109 }