001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.validator;
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021: import java.util.Locale;
022: import java.io.IOException;
023: import org.xml.sax.SAXException;
024:
025: /**
026: * Test that the new Var attributes and the
027: * digester rule changes work.
028: *
029: * @version $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $
030: */
031: public class VarTest extends TestCommon {
032:
033: /**
034: * The key used to retrieve the set of validation
035: * rules from the xml file.
036: */
037: protected static String FORM_KEY = "testForm";
038:
039: /**
040: * The key used to retrieve the validator action.
041: */
042: protected static String ACTION = "byte";
043:
044: public VarTest(String name) {
045: super (name);
046: }
047:
048: /**
049: * Start the tests.
050: *
051: * @param theArgs the arguments. Not used
052: */
053: public static void main(String[] theArgs) {
054: junit.awtui.TestRunner.main(new String[] { VarTest.class
055: .getName() });
056: }
057:
058: /**
059: * @return a test suite (<code>TestSuite</code>) that includes all methods
060: * starting with "test"
061: */
062: public static Test suite() {
063: // All methods starting with "test" will be executed in the test suite.
064: return new TestSuite(VarTest.class);
065: }
066:
067: /**
068: * Load <code>ValidatorResources</code> from
069: * validator-multipletest.xml.
070: */
071: protected void setUp() throws IOException, SAXException {
072: // Load resources
073: loadResources("VarTest-config.xml");
074: }
075:
076: protected void tearDown() {
077: }
078:
079: /**
080: * With nothing provided, we should fail both because both are required.
081: */
082: public void testVars() throws ValidatorException {
083:
084: Form form = resources.getForm(Locale.getDefault(), FORM_KEY);
085:
086: // Get field 1
087: Field field1 = form.getField("field-1");
088: assertNotNull("field-1 is null.", field1);
089: assertEquals("field-1 property is wrong", "field-1", field1
090: .getProperty());
091:
092: // Get var-1-1
093: Var var11 = field1.getVar("var-1-1");
094: assertNotNull("var-1-1 is null.", var11);
095: assertEquals("var-1-1 name is wrong", "var-1-1", var11
096: .getName());
097: assertEquals("var-1-1 value is wrong", "value-1-1", var11
098: .getValue());
099: assertEquals("var-1-1 jstype is wrong", "jstype-1-1", var11
100: .getJsType());
101: assertFalse("var-1-1 resource is true", var11.isResource());
102: assertNull("var-1-1 bundle is not null.", var11.getBundle());
103:
104: // Get field 2
105: Field field2 = form.getField("field-2");
106: assertNotNull("field-2 is null.", field2);
107: assertEquals("field-2 property is wrong", "field-2", field2
108: .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
114: .getName());
115: assertEquals("var-2-1 value is wrong", "value-2-1", var21
116: .getValue());
117: assertEquals("var-2-1 jstype is wrong", "jstype-2-1", var21
118: .getJsType());
119: assertTrue("var-2-1 resource is false", var21.isResource());
120: assertEquals("var-2-1 bundle is wrong", "bundle-2-1", var21
121: .getBundle());
122:
123: // Get var-2-2
124: Var var22 = field2.getVar("var-2-2");
125: assertNotNull("var-2-2 is null.", var22);
126: assertEquals("var-2-2 name is wrong", "var-2-2", var22
127: .getName());
128: assertEquals("var-2-2 value is wrong", "value-2-2", var22
129: .getValue());
130: assertNull("var-2-2 jstype is not null", var22.getJsType());
131: assertFalse("var-2-2 resource is true", var22.isResource());
132: assertEquals("var-2-2 bundle is wrong", "bundle-2-2", var22
133: .getBundle());
134:
135: }
136:
137: }
|