2
* $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TypeTest.java,v 1.16 2004/02/21 17:10:30 rleland Exp $
4
* $Date: 2004/02/21 17:10:30 $
6
* ====================================================================
7
* Copyright 2001-2004 The Apache Software Foundation
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
13
* http://www.apache.org/licenses/LICENSE-2.0
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.
22
package org.apache.commons.validator;
24
import java.io.IOException;
25
import java.util.Iterator;
28
import junit.framework.Test;
29
import junit.framework.TestSuite;
31
import org.xml.sax.SAXException;
34
* Performs Validation Test for type validations.
36
public class TypeTest extends TestCommon {
39
* The key used to retrieve the set of validation
40
* rules from the xml file.
42
protected static String FORM_KEY = "typeForm";
45
* The key used to retrieve the validator action.
47
protected static String ACTION = "byte";
49
public TypeTest(String name) {
56
* @param theArgs the arguments. Not used
58
public static void main(String[] theArgs) {
59
junit.awtui.TestRunner.main(new String[] {TypeTest.class.getName()});
63
* @return a test suite (<code>TestSuite</code>) that includes all methods
64
* starting with "test"
66
public static Test suite() {
67
// All methods starting with "test" will be executed in the test suite.
68
return new TestSuite(TypeTest.class);
72
* Load <code>ValidatorResources</code> from
75
protected void setUp() throws IOException, SAXException {
77
loadResources("validator-type.xml");
80
protected void tearDown() {
84
* Tests the byte validation.
86
public void testType() throws ValidatorException {
87
// Create bean to run test on.
88
TypeBean info = new TypeBean();
91
info.setInteger("-144");
92
info.setLong("88000");
93
info.setFloat("12.1555f");
94
info.setDouble("129.1551511111d");
96
// Construct validator based on the loaded resources
98
Validator validator = new Validator(resources, FORM_KEY);
99
// add the name bean to the validator as a resource
100
// for the validations to be performed on.
101
validator.setParameter(Validator.BEAN_PARAM, info);
103
// Get results of the validation.
104
ValidatorResults results = null;
106
// throws ValidatorException,
107
// but we aren't catching for testing
108
// since no validation methods we use
110
results = validator.validate();
112
assertNotNull("Results are null.", results);
114
Map hResultValues = results.getResultValueMap();
116
assertTrue("Expecting byte result to be an instance of Byte.", (hResultValues.get("byte") instanceof Byte));
117
assertTrue("Expecting short result to be an instance of Short.", (hResultValues.get("short") instanceof Short));
118
assertTrue("Expecting integer result to be an instance of Integer.", (hResultValues.get("integer") instanceof Integer));
119
assertTrue("Expecting long result to be an instance of Long.", (hResultValues.get("long") instanceof Long));
120
assertTrue("Expecting float result to be an instance of Float.", (hResultValues.get("float") instanceof Float));
121
assertTrue("Expecting double result to be an instance of Double.", (hResultValues.get("double") instanceof Double));
123
for (Iterator i = hResultValues.keySet().iterator(); i.hasNext(); ) {
124
String key = (String)i.next();
125
Object value = hResultValues.get(key);
127
assertNotNull("value ValidatorResults.getResultValueMap() should not be null.", value);
130
//ValidatorResult result = results.getValidatorResult("value");
132
//assertNotNull(ACTION + " value ValidatorResult should not be null.", result);
133
//assertTrue(ACTION + " value ValidatorResult should contain the '" + ACTION +"' action.", result.containsAction(ACTION));
134
//assertTrue(ACTION + " value ValidatorResult for the '" + ACTION +"' action should have " + (passed ? "passed" : "failed") + ".", (passed ? result.isValid(ACTION) : !result.isValid(ACTION)));
b'\\ No newline at end of file'