cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator IntegerTest.java LongTest.java NameBean.java ShortTest.java TestTypeValidator.java TypeBean.java TypeTest.java validator-numeric.xml validator-type.xml
dwinterfeldt02/03/29 20:21:03 Added: validator/src/test/org/apache/commons/validator IntegerTest.java LongTest.java NameBean.java ShortTest.java TestTypeValidator.java TypeBean.java TypeTest.java validator-numeric.xml validator-type.xml Log: Adding new unit tests. Revision ChangesPath 1.1 jakarta-commons/validator/src/test/org/apache/commons/validator/IntegerTest.java Index: IntegerTest.java === /* * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/IntegerTest.java,v 1.1 2002/03/30 04:21:03 dwinterfeldt Exp $ * $Revision: 1.1 $ * $Date: 2002/03/30 04:21:03 $ * * * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in *the documentation and/or other materials provided with the *distribution. * * 3. The end-user documentation included with the redistribution, if *any, must include the following acknowlegement: * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names The Jakarta Project, Commons, and Apache Software *Foundation must not be used to endorse or promote products derived *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache *nor may Apache appear in their names without prior written *permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. * */ package org.apache.commons.validator; import java.io.IOException; import java.io.InputStream; import java.util.Map; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.framework.AssertionFailedError; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogSource; /** * pPerforms Validation Test for codeint/code validations./p * * @author David Winterfeldt * @version $Revision: 1.1 $ $Date: 2002/03/30 04:21:03 $ */ public class IntegerTest extends TestCase { /** * The key used to retrieve the set of validation * rules from the xml file. */ protected static String FORM_KEY = intForm; /** * The key used to retrieve the validator action. */ protected static String ACTION = int; /** * Commons Logging instance. */ private Log log = LogSource.getInstance(this.getClass().getName()); /** * Resources used for validation tests
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator GenericTypeValidator.java GenericValidator.java
dwinterfeldt02/03/29 20:25:59 Modified:validator/src/share/org/apache/commons/validator GenericValidator.java Added: validator/src/share/org/apache/commons/validator GenericTypeValidator.java Log: Modified GenericValidtor to use GenericTypeValidator. GenericValidator returns boolean from validation methods and GenericTypeValidator returns a correctly typed object if the validation was successful and null if it wasn't. Revision ChangesPath 1.4 +12 -42 jakarta-commons/validator/src/share/org/apache/commons/validator/GenericValidator.java Index: GenericValidator.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/GenericValidator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- GenericValidator.java 13 Mar 2002 05:39:32 - 1.3 +++ GenericValidator.java 30 Mar 2002 04:25:59 - 1.4 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/GenericValidator.java,v 1.4 2002/03/30 04:25:59 dwinterfeldt Exp $ + * $Revision: 1.4 $ + * $Date: 2002/03/30 04:25:59 $ + * + * * * The Apache Software License, Version 1.1 * @@ -72,6 +77,7 @@ * performing validations./p * * @author David Winterfeldt + * @version $Revision: 1.4 $ $Date: 2002/03/30 04:25:59 $ */ public class GenericValidator implements Serializable { @@ -107,13 +113,7 @@ * @paramvalue The value validation is being performed on. */ public static boolean isByte(String value) { - try { - Byte.parseByte(value); - } catch (Exception e) { - return false; - } - - return true; + return (GenericTypeValidator.formatByte(value) != null); } /** @@ -122,13 +122,7 @@ * @paramvalue The value validation is being performed on. */ public static boolean isShort(String value) { - try { - Short.parseShort(value); - } catch (Exception e) { - return false; - } - - return true; + return (GenericTypeValidator.formatShort(value) != null); } /** @@ -137,13 +131,7 @@ * @paramvalue The value validation is being performed on. */ public static boolean isInt(String value) { - try { - Integer.parseInt(value); - } catch (Exception e) { - return false; - } - - return true; + return (GenericTypeValidator.formatInt(value) != null); } /** @@ -152,13 +140,7 @@ * @paramvalue The value validation is being performed on. */ public static boolean isLong(String value) { - try { - Long.parseLong(value); - } catch (Exception e) { - return false; - } - - return true; + return (GenericTypeValidator.formatLong(value) != null); } /** @@ -167,13 +149,7 @@ * @paramvalue The value validation is being performed on. */ public static boolean isFloat(String value) { - try { - Float.parseFloat(value); - } catch (Exception e) { - return false; - } - - return true; + return (GenericTypeValidator.formatFloat(value) != null); } /** @@ -182,13 +158,7 @@ * @paramvalue The value validation is being performed on. */ public static boolean isDouble(String value) { - try { - Double.parseDouble(value); - } catch (Exception e) { - return false; - } - - return true; + return (GenericTypeValidator.formatDouble(value) != null); } /** 1.1 jakarta-commons/validator/src/share/org/apache/commons/validator/GenericTypeValidator.java Index: GenericTypeValidator.java === /* * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/GenericTypeValidator.java,v 1.1 2002/03/30 04:25:59 dwinterfeldt Exp $ * $Revision: 1.1 $ * $Date: 2002/03/30 04:25:59 $ * * * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator ByteTest.java DoubleTest.java FloatTest.java ValueBean.java
dwinterfeldt02/03/29 20:26:51 Added: validator/src/test/org/apache/commons/validator ByteTest.java DoubleTest.java FloatTest.java ValueBean.java Log: New unit tests. Revision ChangesPath 1.1 jakarta-commons/validator/src/test/org/apache/commons/validator/ByteTest.java Index: ByteTest.java === /* * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/ByteTest.java,v 1.1 2002/03/30 04:26:51 dwinterfeldt Exp $ * $Revision: 1.1 $ * $Date: 2002/03/30 04:26:51 $ * * * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in *the documentation and/or other materials provided with the *distribution. * * 3. The end-user documentation included with the redistribution, if *any, must include the following acknowlegement: * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names The Jakarta Project, Commons, and Apache Software *Foundation must not be used to endorse or promote products derived *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache *nor may Apache appear in their names without prior written *permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. * */ package org.apache.commons.validator; import java.io.IOException; import java.io.InputStream; import java.util.Map; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.framework.AssertionFailedError; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogSource; /** * pPerforms Validation Test for codebyte/code validations./p * * @author David Winterfeldt * @version $Revision: 1.1 $ $Date: 2002/03/30 04:26:51 $ */ public class ByteTest extends TestCase { /** * The key used to retrieve the set of validation * rules from the xml file. */ protected static String FORM_KEY = byteForm; /** * The key used to retrieve the validator action. */ protected static String ACTION = byte; /** * Commons Logging instance. */ private Log log = LogSource.getInstance(this.getClass().getName()); /** * Resources used for validation tests. */ private ValidatorResources resources = null; public ByteTest(String name) { super(name
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Validator.java ValidatorResult.java ValidatorResults.java
dwinterfeldt02/03/29 20:28:36 Modified:validator/src/share/org/apache/commons/validator Validator.java ValidatorResult.java ValidatorResults.java Log: Added the ability for ValidatorResults and ValidatorResult to have an object returned from a validation method be associated with the result status. Revision ChangesPath 1.7 +7 -1 jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java Index: Validator.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Validator.java17 Mar 2002 18:30:55 - 1.6 +++ Validator.java30 Mar 2002 04:28:35 - 1.7 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java,v 1.7 2002/03/30 04:28:35 dwinterfeldt Exp $ + * $Revision: 1.7 $ + * $Date: 2002/03/30 04:28:35 $ + * + * * * The Apache Software License, Version 1.1 * @@ -82,6 +87,7 @@ * and the validation rules for a JavaBean./p * * @author David Winterfeldt + * @version $Revision: 1.7 $ $Date: 2002/03/30 04:28:35 $ */ public class Validator implements Serializable { @@ -474,7 +480,7 @@ iErrorCount++; } -results.add(field, va.getName(), isValid(result)); +results.add(field, va.getName(), isValid(result), result); } catch (Exception e) { bErrors = true; log.error(reflection: + e.getMessage(), e); 1.2 +66 -2 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResult.java Index: ValidatorResult.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResult.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ValidatorResult.java 17 Mar 2002 00:15:53 - 1.1 +++ ValidatorResult.java 30 Mar 2002 04:28:35 - 1.2 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResult.java,v 1.2 2002/03/30 04:28:35 dwinterfeldt Exp $ + * $Revision: 1.2 $ + * $Date: 2002/03/30 04:28:35 $ + * + * * * The Apache Software License, Version 1.1 * @@ -58,6 +63,7 @@ package org.apache.commons.validator; import java.io.Serializable; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -67,6 +73,7 @@ * validation rules processed on JavaBean./p * * @author David Winterfeldt + * @version $Revision: 1.2 $ $Date: 2002/03/30 04:28:35 $ */ public class ValidatorResult implements Serializable { @@ -95,7 +102,14 @@ * Add the result of a validator action. */ public void add(String validatorName, boolean result) { - hAction.put(validatorName, new Boolean(result)); + add(validatorName, result, null); + } + + /** +* Add the result of a validator action. + */ + public void add(String validatorName, boolean result, Object value) { + hAction.put(validatorName, new ResultStatus(result, value)); } public boolean containsAction(String validatorName) { @@ -105,7 +119,57 @@ public boolean isValid(String validatorName) { Object o = hAction.get(validatorName); - return ((o != null) ? ((Boolean)o).booleanValue() : false); + return ((o != null) ? ((ResultStatus)o).getValid() : false); + } + + public Map getActionMap() { + return Collections.unmodifiableMap(hAction); + } + + /** +* Contains the status of the validation. + */ + protected class ResultStatus { + private boolean valid = false; + private Object result = null; + + public ResultStatus(boolean valid, Object result) { + this.valid = valid; + this.result = result; + } + + /** + * Gets whether or not the validation passed. + */ + public boolean getValid() { + return valid; + } + + /** + * Sets whether or not the validation passed. + */ + public void setValid(boolean valid) { + this.valid = valid
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator Name.java
dwinterfeldt02/03/29 20:29:43 Removed: validator/src/test/org/apache/commons/validator Name.java Log: Renamed to NameBean to clarify which test classes are just JavaBeans used for holding test data. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator RequiredNameTest.java
dwinterfeldt02/03/29 20:30:56 Modified:validator/src/test/org/apache/commons/validator RequiredNameTest.java Log: The class Name was renamed to NameBean. Revision ChangesPath 1.3 +12 -6 jakarta-commons/validator/src/test/org/apache/commons/validator/RequiredNameTest.java Index: RequiredNameTest.java === RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/RequiredNameTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RequiredNameTest.java 17 Mar 2002 00:27:35 - 1.2 +++ RequiredNameTest.java 30 Mar 2002 04:30:56 - 1.3 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/RequiredNameTest.java,v 1.3 2002/03/30 04:30:56 dwinterfeldt Exp $ + * $Revision: 1.3 $ + * $Date: 2002/03/30 04:30:56 $ + * + * * * The Apache Software License, Version 1.1 * @@ -72,6 +77,7 @@ * pPerforms Validation Test./p * * @author David Winterfeldt + * @version $Revision: 1.3 $ $Date: 2002/03/30 04:30:56 $ */ public class RequiredNameTest extends TestCase { @@ -149,7 +155,7 @@ */ public void testRequired() throws ValidatorException { // Create bean to run test on. - Name name = new Name(); + NameBean name = new NameBean(); // Construct validator based on the loaded resources // and the form key @@ -186,7 +192,7 @@ */ public void testRequiredFirstNameBlank() throws ValidatorException { // Create bean to run test on. - Name name = new Name(); + NameBean name = new NameBean(); name.setFirstName(); // Construct validator based on the loaded resources @@ -220,7 +226,7 @@ */ public void testRequiredFirstName() throws ValidatorException { // Create bean to run test on. - Name name = new Name(); + NameBean name = new NameBean(); name.setFirstName(Joe); // Construct validator based on the loaded resources @@ -254,7 +260,7 @@ */ public void testRequiredLastNameBlank() throws ValidatorException { // Create bean to run test on. - Name name = new Name(); + NameBean name = new NameBean(); name.setLastName(); // Construct validator based on the loaded resources @@ -288,7 +294,7 @@ */ public void testRequiredLastName() throws ValidatorException { // Create bean to run test on. - Name name = new Name(); + NameBean name = new NameBean(); name.setLastName(Smith); // Construct validator based on the loaded resources @@ -323,7 +329,7 @@ */ public void testRequiredName() throws ValidatorException { // Create bean to run test on. - Name name = new Name(); + NameBean name = new NameBean(); name.setFirstName(Joe); name.setLastName(Smith); -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator ValidatorTestSuite.java
dwinterfeldt02/03/29 20:31:30 Modified:validator/src/test/org/apache/commons/validator ValidatorTestSuite.java Log: Added all the new unit test to the suite. Revision ChangesPath 1.2 +14 -1 jakarta-commons/validator/src/test/org/apache/commons/validator/ValidatorTestSuite.java Index: ValidatorTestSuite.java === RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/ValidatorTestSuite.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ValidatorTestSuite.java 11 Mar 2002 05:12:02 - 1.1 +++ ValidatorTestSuite.java 30 Mar 2002 04:31:29 - 1.2 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/ValidatorTestSuite.java,v 1.2 2002/03/30 04:31:29 dwinterfeldt Exp $ + * $Revision: 1.2 $ + * $Date: 2002/03/30 04:31:29 $ + * + * * * The Apache Software License, Version 1.1 * @@ -67,6 +72,7 @@ * package. * * @author David Winterfeldt + * @version $Revision: 1.2 $ $Date: 2002/03/30 04:31:29 $ */ public class ValidatorTestSuite extends TestCase { @@ -78,6 +84,13 @@ TestSuite suite = new TestSuite(); suite.addTest(RequiredNameTest.suite()); + suite.addTest(ByteTest.suite()); + suite.addTest(ShortTest.suite()); + suite.addTest(IntegerTest.suite()); + suite.addTest(LongTest.suite()); + suite.addTest(FloatTest.suite()); + suite.addTest(DoubleTest.suite()); + suite.addTest(TypeTest.suite()); suite.addTest(ValidatorTest.suite()); return suite; @@ -87,4 +100,4 @@ junit.textui.TestRunner.run(suite()); } -} \ No newline at end of file +} -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator TestValidator.java
dwinterfeldt02/03/29 20:32:14 Modified:validator/src/test/org/apache/commons/validator TestValidator.java Log: Added new validation methods for the new unit tests. Revision ChangesPath 1.3 +90 -0 jakarta-commons/validator/src/test/org/apache/commons/validator/TestValidator.java Index: TestValidator.java === RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TestValidator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestValidator.java17 Mar 2002 00:27:35 - 1.2 +++ TestValidator.java30 Mar 2002 04:32:14 - 1.3 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TestValidator.java,v 1.3 2002/03/30 04:32:14 dwinterfeldt Exp $ + * $Revision: 1.3 $ + * $Date: 2002/03/30 04:32:14 $ + * + * * * The Apache Software License, Version 1.1 * @@ -62,6 +67,7 @@ * unit tests./p * * @author David Winterfeldt + * @version $Revision: 1.3 $ $Date: 2002/03/30 04:32:14 $ */ public class TestValidator { @@ -79,5 +85,89 @@ return !GenericValidator.isBlankOrNull(value); } + + /** +* Checks if the field can be successfully converted to a codebyte/code. +* +* @param value The value validation is being performed on. +* @returnboolean If the field can be successfully converted +* to a codebyte/code codetrue/code is returned. +* Otherwise codefalse/code. + */ + public static boolean validateByte(Object bean, Field field) { + String value = ValidatorUtil.getValueAsString(bean, field.getProperty()); + + return GenericValidator.isByte(value); + } + + /** +* Checks if the field can be successfully converted to a codeshort/code. +* +* @param value The value validation is being performed on. +* @returnboolean If the field can be successfully converted +* to a codeshort/code codetrue/code is returned. +* Otherwise codefalse/code. + */ + public static boolean validateShort(Object bean, Field field) { + String value = ValidatorUtil.getValueAsString(bean, field.getProperty()); + + return GenericValidator.isShort(value); + } + + /** +* Checks if the field can be successfully converted to a codeint/code. +* +* @param value The value validation is being performed on. +* @returnboolean If the field can be successfully converted +* to a codeint/code codetrue/code is returned. +* Otherwise codefalse/code. + */ + public static boolean validateInt(Object bean, Field field) { + String value = ValidatorUtil.getValueAsString(bean, field.getProperty()); + + return GenericValidator.isInt(value); + } + + /** +* Checks if the field can be successfully converted to a codelong/code. +* +* @param value The value validation is being performed on. +* @returnboolean If the field can be successfully converted +* to a codelong/code codetrue/code is returned. +* Otherwise codefalse/code. + */ + public static boolean validateLong(Object bean, Field field) { + String value = ValidatorUtil.getValueAsString(bean, field.getProperty()); + + return GenericValidator.isLong(value); + } + + /** +* Checks if the field can be successfully converted to a codefloat/code. +* +* @param value The value validation is being performed on. +* @returnboolean If the field can be successfully converted +* to a codefloat/code codetrue/code is returned. +* Otherwise codefalse/code. + */ + public static boolean validateFloat(Object bean, Field field) { + String value = ValidatorUtil.getValueAsString(bean, field.getProperty()); + + return GenericValidator.isFloat(value); + } + /** +* Checks if the field can be successfully converted to a codedouble/code. +* +* @param value The value validation is being performed
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator ValidatorTest.java
dwinterfeldt02/03/29 20:33:18 Modified:validator/src/share/org/apache/commons/validator Arg.java Constant.java Field.java Form.java FormSet.java Msg.java ValidatorAction.java ValidatorException.java ValidatorResources.java ValidatorResourcesInitializer.java ValidatorUtil.java Var.java validator/src/test/org/apache/commons/validator ValidatorTest.java Log: Added header info above the license and a javadoc version tag. Revision ChangesPath 1.4 +6 -0 jakarta-commons/validator/src/share/org/apache/commons/validator/Arg.java Index: Arg.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Arg.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Arg.java 13 Mar 2002 05:39:32 - 1.3 +++ Arg.java 30 Mar 2002 04:33:17 - 1.4 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Arg.java,v 1.4 2002/03/30 04:33:17 dwinterfeldt Exp $ + * $Revision: 1.4 $ + * $Date: 2002/03/30 04:33:17 $ + * + * * * The Apache Software License, Version 1.1 * @@ -74,6 +79,7 @@ * The resource field defaults to 'true'./p * * @author David Winterfeldt + * @version $Revision: 1.4 $ $Date: 2002/03/30 04:33:17 $ */ public class Arg implements Cloneable, Serializable { 1.3 +6 -0 jakarta-commons/validator/src/share/org/apache/commons/validator/Constant.java Index: Constant.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Constant.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Constant.java 13 Mar 2002 05:39:32 - 1.2 +++ Constant.java 30 Mar 2002 04:33:17 - 1.3 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Constant.java,v 1.3 2002/03/30 04:33:17 dwinterfeldt Exp $ + * $Revision: 1.3 $ + * $Date: 2002/03/30 04:33:17 $ + * + * * * The Apache Software License, Version 1.1 * @@ -72,6 +77,7 @@ * nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;mask=${zip} /p * * @author David Winterfeldt + * @version $Revision: 1.3 $ $Date: 2002/03/30 04:33:17 $ */ public class Constant implements Serializable { 1.5 +6 -0 jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java Index: Field.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Field.java19 Mar 2002 06:18:43 - 1.4 +++ Field.java30 Mar 2002 04:33:17 - 1.5 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java,v 1.5 2002/03/30 04:33:17 dwinterfeldt Exp $ + * $Revision: 1.5 $ + * $Date: 2002/03/30 04:33:17 $ + * + * * * The Apache Software License, Version 1.1 * @@ -72,6 +77,7 @@ * to perform the validations and generate error messages./p * * @author David Winterfeldt + * @version $Revision: 1.5 $ $Date: 2002/03/30 04:33:17 $ * @see org.apache.commons.validator.Form */ public class Field implements Cloneable, Serializable { 1.3 +6 -0 jakarta-commons/validator/src/share/org/apache/commons/validator/Form.java Index: Form.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Form.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Form.java 13 Mar 2002 05:39:32 - 1.2 +++ Form.java 30 Mar 2002 04:33:17 - 1.3 @@ -1,4 +1,9 @@ /* + * $Header: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Form.java,v 1.3 2002/03/30 04:33:17 dwinterfeldt Exp $ + * $Revision: 1.3 $ + * $Date: 2002/03/30 04:33:17 $ + * + * * * The Apache Software License, Version 1.1 * @@ -72,6 +77,7 @@ * list of codeField/code objects./p * * @author David Winterfeldt + * @version $Revision: 1.3 $ $Date: 2002/03/30 04:33:17
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator TypeTest.java validator-type.xml
dwinterfeldt02/03/29 21:13:13 Modified:validator/src/test/org/apache/commons/validator TypeTest.java validator-type.xml Log: Had a typo for the integer check and added a check that the results are the correct class for each numeric validation. Revision ChangesPath 1.2 +11 -4 jakarta-commons/validator/src/test/org/apache/commons/validator/TypeTest.java Index: TypeTest.java === RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TypeTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TypeTest.java 30 Mar 2002 04:21:03 - 1.1 +++ TypeTest.java 30 Mar 2002 05:13:12 - 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TypeTest.java,v 1.1 2002/03/30 04:21:03 dwinterfeldt Exp $ - * $Revision: 1.1 $ - * $Date: 2002/03/30 04:21:03 $ + * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/TypeTest.java,v 1.2 2002/03/30 05:13:12 dwinterfeldt Exp $ + * $Revision: 1.2 $ + * $Date: 2002/03/30 05:13:12 $ * * * @@ -78,7 +78,7 @@ * pPerforms Validation Test for type validations./p * * @author David Winterfeldt - * @version $Revision: 1.1 $ $Date: 2002/03/30 04:21:03 $ + * @version $Revision: 1.2 $ $Date: 2002/03/30 05:13:12 $ */ public class TypeTest extends TestCase { @@ -183,6 +183,13 @@ assertNotNull(Results are null., results); Map hResultValues = results.getResultValueMap(); + + assertTrue(Expecting byte result to be an instance of Byte., (hResultValues.get(byte) instanceof Byte)); + assertTrue(Expecting short result to be an instance of Short., (hResultValues.get(short) instanceof Short)); + assertTrue(Expecting integer result to be an instance of Integer., (hResultValues.get(integer) instanceof Integer)); + assertTrue(Expecting long result to be an instance of Long., (hResultValues.get(long) instanceof Long)); + assertTrue(Expecting float result to be an instance of Float., (hResultValues.get(float) instanceof Float)); + assertTrue(Expecting double result to be an instance of Double., (hResultValues.get(double) instanceof Double)); for (Iterator i = hResultValues.keySet().iterator(); i.hasNext(); ) { String key = (String)i.next(); 1.2 +1 -1 jakarta-commons/validator/src/test/org/apache/commons/validator/validator-type.xml Index: validator-type.xml === RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/validator-type.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- validator-type.xml30 Mar 2002 04:21:03 - 1.1 +++ validator-type.xml30 Mar 2002 05:13:12 - 1.2 @@ -39,7 +39,7 @@ fieldproperty=short depends=short /field - fieldproperty=int + fieldproperty=integer depends=int /field fieldproperty=long -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Field.java
dwinterfeldt02/03/18 22:18:43 Modified:validator/src/share/org/apache/commons/validator Field.java Log: The isIndexed only checks if indexedListProperty is set and indexedListProperty is used instead of indexedProperty when generating the key. PropertyUtils works with just getting back a List so indexProperty may be unnecessary as a reference to getXXX(int pos) and setXXX(int pos, Object value). Revision ChangesPath 1.4 +2 -3 jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java Index: Field.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Field.java13 Mar 2002 05:39:32 - 1.3 +++ Field.java19 Mar 2002 06:18:43 - 1.4 @@ -414,8 +414,7 @@ * codetrue/code will be returned. Otherwise it will be codefalse/code. */ public boolean isIndexed() { - return ((indexedProperty != null indexedProperty.length() 0) - (indexedListProperty != null indexedListProperty.length() 0)); + return ((indexedListProperty != null indexedListProperty.length() 0)); } /** @@ -423,7 +422,7 @@ */ public void generateKey() { if (isIndexed()) { - key = indexedProperty + TOKEN_INDEXED + . + property; + key = indexedListProperty + TOKEN_INDEXED + . + property; } else { key = property; } -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResult.java ValidatorResults.java
dwinterfeldt02/03/16 16:15:53 Added: validator/src/share/org/apache/commons/validator ValidatorResult.java ValidatorResults.java Log: Beginning of ValidatorResults that will be returned when validate is performed so results can be analyzed. Revision ChangesPath 1.1 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResult.java Index: ValidatorResult.java === /* * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in *the documentation and/or other materials provided with the *distribution. * * 3. The end-user documentation included with the redistribution, if *any, must include the following acknowlegement: * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names The Jakarta Project, Commons, and Apache Software *Foundation must not be used to endorse or promote products derived *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache *nor may Apache appear in their names without prior written *permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. * */ package org.apache.commons.validator; import java.io.Serializable; import java.util.HashMap; import java.util.Map; /** * pThis contains the results of a set of * validation rules processed on JavaBean./p * * @author David Winterfeldt */ public class ValidatorResult implements Serializable { /** * Map of results. The key is the name * of the codeValidatorAction/code * and the value is whether or not * this field passed or not. */ protected Map hAction = new HashMap(); /** * codeField/code being validated. */ protected Field field = null; /** * Constructs a codeValidatorResult/code * with the associated field being validated. */ public ValidatorResult(Field field) { this.field = field; } /** * Add the result of a validator action. */ public void add(String validatorName, boolean result) { hAction.put(validatorName, new Boolean(result)); } public boolean containsAction(String validatorName) { return hAction.containsKey(validatorName); } public boolean isValid(String validatorName) { Object o = hAction.get(validatorName); return ((o != null) ? ((Boolean)o).booleanValue() : false); } } 1.1 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResults.java Index: ValidatorResults.java === /* * * The Apache Software License, Version 1.1 * * Copyright (c) 1999
cvs commit: jakarta-commons/validator build.properties.sample
dwinterfeldt02/03/16 16:16:37 Modified:validator build.properties.sample Log: Changed to specify v3.7 of JUnit. Revision ChangesPath 1.4 +2 -1 jakarta-commons/validator/build.properties.sample Index: build.properties.sample === RCS file: /home/cvs/jakarta-commons/validator/build.properties.sample,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- build.properties.sample 17 Jan 2002 04:15:46 - 1.3 +++ build.properties.sample 17 Mar 2002 00:16:37 - 1.4 @@ -22,7 +22,8 @@ regexp.jar=e:/software/regexp/jakarta-regexp-1.2.jar -# Unit Testing +# The JAR file containing version 3.7 (or later) of +# JUnit Unit Testing (http://www.junit.org) junit.jar=e:/software/junit3.5/junit.jar # Just needed for building the Javadocs -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorAction.java
dwinterfeldt02/03/16 16:22:53 Modified:validator/src/share/org/apache/commons/validator ValidatorAction.java Log: Changed default methodParams signature to be generic (bean, ValidatorAction, Field) and the old Struts default signature. Revision ChangesPath 1.4 +4 -6 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorAction.java Index: ValidatorAction.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ValidatorAction.java 13 Mar 2002 05:39:32 - 1.3 +++ ValidatorAction.java 17 Mar 2002 00:22:53 - 1.4 @@ -102,7 +102,8 @@ /** * pThe method signature of the validation method. This * should be a comma delimited list of the full -* class names of each parameter that the method takes./p +* class names of each parameter in the correct order +* that the method takes./p * * pNote: codejava.lang.Object/code is reserved for the * JavaBean that is being validated. The codeValidatorAction/code @@ -111,11 +112,8 @@ * specified in the method signature./p */ private String methodParams = Validator.BEAN_KEY + , + - Validator.VALIDATOR_ACTION_KEY + , + - Validator.FIELD_KEY + , + - Validator.ACTION_ERRORS_KEY + , + - Validator.HTTP_SERVLET_REQUEST_KEY + , + - Validator.SERVLET_CONTEXT_KEY; + Validator.VALIDATOR_ACTION_KEY + , + + Validator.FIELD_KEY; /** * The other codeValidatorAction/codes that this -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorUtil.java
dwinterfeldt02/03/16 16:23:48 Modified:validator/src/share/org/apache/commons/validator ValidatorUtil.java Log: Changed log message. Revision ChangesPath 1.4 +1 -1 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorUtil.java Index: ValidatorUtil.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorUtil.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ValidatorUtil.java13 Mar 2002 05:39:32 - 1.3 +++ ValidatorUtil.java17 Mar 2002 00:23:48 - 1.4 @@ -114,7 +114,7 @@ try { value = PropertyUtils.getProperty(bean, property); } catch (Exception e) { - log.error(ValidatorUtil::getValueAsString - + e.getMessage(), e); + log.error(e.getMessage(), e); } return (value != null ? value.toString() : null); -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator Validator.java
dwinterfeldt02/03/16 16:26:16 Modified:validator/src/share/org/apache/commons/validator Validator.java Log: Removed Struts related contant references, validate method returns ValidatorResults instead of a Map, and the getErrorCount method now is a boolean method called isValid. Revision ChangesPath 1.5 +54 -53 jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java Index: Validator.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Validator.java13 Mar 2002 05:39:32 - 1.4 +++ Validator.java17 Mar 2002 00:26:16 - 1.5 @@ -90,14 +90,34 @@ */ protected static Log log = LogSource.getInstance(Validator.class.getName()); - public static String SERVLET_CONTEXT_KEY = javax.servlet.ServletContext; - public static String HTTP_SERVLET_REQUEST_KEY = javax.servlet.http.HttpServletRequest; - public static String MESSAGE_RESOURCES_KEY = org.apache.struts.util.MessageResources; - public static String LOCALE_KEY = java.util.Locale; + /** +* Resources key the JavaBean is stored to perform validation on. + */ public static String BEAN_KEY = java.lang.Object; - public static String ACTION_ERRORS_KEY = org.apache.struts.action.ActionErrors; + + /** +* Resources key the codeValidatorAction/code is stored under. +* This will be automatically passed into a validation method +* with the current codeValidatorAction/code if it is +* specified in the method signature. + */ public static String VALIDATOR_ACTION_KEY = org.apache.commons.validator.ValidatorAction; + + /** +* Resources key the codeField/code is stored under. +* This will be automatically passed into a validation method +* with the current codeField/code if it is +* specified in the method signature. + */ public static String FIELD_KEY = org.apache.commons.validator.Field; + + /** +* Resources key the codeLocale/code is stored. +* This will be used to retrieve the appropriate +* codeFormSet/code and codeForm/code to be +* processed. + */ + public static String LOCALE_KEY = java.util.Locale; protected ValidatorResources resources = null; protected String formName = null; @@ -210,8 +230,8 @@ *of the codeField/code for the key and the value *is the number of error the field had. */ - public Map validate() throws ValidatorException { - Map hResults = new HashMap(); + public ValidatorResults validate() throws ValidatorException { + ValidatorResults results = new ValidatorResults(); Locale locale = null; if (hResources.containsKey(LOCALE_KEY)) { @@ -254,7 +274,7 @@ Object o = hActionsRun.get(depend); if (log.isDebugEnabled()) { - log.debug(Validator::validate - ValidatorAction name= + va.getName() + depends= + va.getDepends()); + log.debug(ValidatorAction name= + va.getName() + depends= + va.getDepends()); } if (o == null) { @@ -266,7 +286,7 @@ boolean bContinue = ((Boolean)o).booleanValue(); if (log.isDebugEnabled()) { - log.debug(Validator::validate - ValidatorAction name= + va.getName() + depend= + depend + bContinue= + bContinue); + log.debug(ValidatorAction name= + va.getName() + depend= + depend + bContinue= + bContinue); } if (!bContinue) { @@ -283,7 +303,7 @@ if (log.isDebugEnabled()) { StringBuffer sbLog = new StringBuffer(); -sbLog.append(Validator::validate - Order \n); +sbLog.append(Order \n); for (Iterator actions = lActions.iterator(); actions.hasNext(); ) { ValidatorAction tmp = (ValidatorAction)actions.next(); @@ -339,7 +359,7 @@ va.setClassnameInstance(c.newInstance()); } } catch (Exception ex) { - log.error(Validator::validate - Couldn't load instance + + log.error(Couldn't load instance + of class + va.getClassname() + . + ex.getMessage
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator RequiredNameTest.java TestValidator.java ValidatorTest.java
dwinterfeldt02/03/16 16:27:35 Modified:validator/src/test/org/apache/commons/validator RequiredNameTest.java TestValidator.java ValidatorTest.java Log: Switched to use ValidatorResults and tests weren't correct because the required test method was returning the wrong value. Revision ChangesPath 1.2 +91 -40 jakarta-commons/validator/src/test/org/apache/commons/validator/RequiredNameTest.java Index: RequiredNameTest.java === RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/RequiredNameTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RequiredNameTest.java 11 Mar 2002 05:12:02 - 1.1 +++ RequiredNameTest.java 17 Mar 2002 00:27:35 - 1.2 @@ -80,6 +80,12 @@ * rules from the xml file. */ protected static String FORM_KEY = nameForm; + + /** +* The key used to retrieve the validator action. + */ + protected static String ACTION = required; + /** * Commons Logging instance. @@ -144,7 +150,7 @@ public void testRequired() throws ValidatorException { // Create bean to run test on. Name name = new Name(); - + // Construct validator based on the loaded resources // and the form key Validator validator = new Validator(resources, FORM_KEY); @@ -153,18 +159,26 @@ validator.addResource(Validator.BEAN_KEY, name); // Get results of the validation. - Map hResults = null; + ValidatorResults results = null; // throws ValidatorException, // but we aren't catching for testing // since no validation methods we use // throw this - hResults = validator.validate(); + results = validator.validate(); - assertNotNull(Results are null., hResults); - assertNull(First Name should have passed no validations., hResults.get(firstName)); - assertNull(Last Name should have passed no validations., hResults.get(lastName)); - + assertNotNull(Results are null., results); + + ValidatorResult firstNameResult = results.getValidatorResult(firstName); + ValidatorResult lastNameResult = results.getValidatorResult(lastName); + + assertNotNull(First Name ValidatorResult should not be null., firstNameResult); + assertTrue(First Name ValidatorResult should contain the ' + ACTION +' action., firstNameResult.containsAction(ACTION)); + assertTrue(First Name ValidatorResult for the ' + ACTION +' action should have failed., !firstNameResult.isValid(ACTION)); + + assertNotNull(First Name ValidatorResult should not be null., lastNameResult); + assertTrue(Last Name ValidatorResult should contain the ' + ACTION +' action., lastNameResult.containsAction(ACTION)); + assertTrue(Last Name ValidatorResult for the ' + ACTION +' action should have failed., !lastNameResult.isValid(ACTION)); } /** @@ -183,14 +197,22 @@ validator.addResource(Validator.BEAN_KEY, name); // Get results of the validation. - Map hResults = null; + ValidatorResults results = null; - hResults = validator.validate(); + results = validator.validate(); - assertNotNull(Results are null., hResults); - assertNull(First Name should have passed no validations., hResults.get(firstName)); - assertNull(Last Name should have passed no validations., hResults.get(lastName)); - + assertNotNull(Results are null., results); + + ValidatorResult firstNameResult = results.getValidatorResult(firstName); + ValidatorResult lastNameResult = results.getValidatorResult(lastName); + + assertNotNull(First Name ValidatorResult should not be null., firstNameResult); + assertTrue(First Name ValidatorResult should contain the ' + ACTION +' action., firstNameResult.containsAction(ACTION)); + assertTrue(First Name ValidatorResult for the ' + ACTION +' action should have failed., !firstNameResult.isValid(ACTION)); + + assertNotNull(First Name ValidatorResult should not be null., lastNameResult); + assertTrue(Last Name ValidatorResult should contain the ' + ACTION +' action., lastNameResult.containsAction(ACTION)); + assertTrue(Last Name ValidatorResult for the ' + ACTION +' action should have failed., !lastNameResult.isValid(ACTION)); } /** @@ -209,15 +231,22 @@ validator.addResource(Validator.BEAN_KEY, name); // Get results of the validation. - Map hResults = null; + ValidatorResults
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorResourcesInitializer.java
dwinterfeldt02/03/11 20:07:39 Modified:validator/src/share/org/apache/commons/validator ValidatorResourcesInitializer.java Log: Commons Digester was having it's debug level set to '1'. This line has been removed so the logging level can be controlled properly through Commons Logging. Reported by [EMAIL PROTECTED] (Bazza) in Bugzilla (Bug 6685). Revision ChangesPath 1.4 +0 -1 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResourcesInitializer.java Index: ValidatorResourcesInitializer.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResourcesInitializer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ValidatorResourcesInitializer.java17 Jan 2002 04:14:22 - 1.3 +++ ValidatorResourcesInitializer.java12 Mar 2002 04:07:39 - 1.4 @@ -133,7 +133,6 @@ Digester digester = new Digester(); digester.push(resources); - digester.setDebug(1); digester.setNamespaceAware(true); digester.setValidating(false); -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator build.xml
dwinterfeldt02/03/10 21:12:02 Modified:validator build.xml Added: validator/src/test/org/apache/commons/validator Name.java RequiredNameTest.java TestValidator.java validator-name-required.xml ValidatorTestSuite.java Log: Started adding a suite of unit tests. The required test is completed. Revision ChangesPath 1.1 jakarta-commons/validator/src/test/org/apache/commons/validator/Name.java Index: Name.java === /* * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in *the documentation and/or other materials provided with the *distribution. * * 3. The end-user documentation included with the redistribution, if *any, must include the following acknowlegement: * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names The Jakarta Project, Commons, and Apache Software *Foundation must not be used to endorse or promote products derived *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache *nor may Apache appear in their names without prior written *permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. * */ package org.apache.commons.validator; /** * pValue object that contains a * first name and last name./p * * @author David Winterfeldt */ public class Name { protected String firstName = null; protected String lastName = null; /** * Gets the first name. */ public String getFirstName() { return firstName; } /** * Sets the first name. */ public void setFirstName(String firstName) { this.firstName = firstName; } /** * Gets the last name. */ public String getLastName() { return lastName; } /** * Sets the last name. */ public void setLastName(String lastName) { this.lastName = lastName; } } 1.1 jakarta-commons/validator/src/test/org/apache/commons/validator/RequiredNameTest.java Index: RequiredNameTest.java === /* * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator ValidatorTest.java
dwinterfeldt02/01/14 22:06:24 Modified:validator/src/share/org/apache/commons/validator Field.java FormSet.java Validator.java ValidatorResources.java ValidatorResourcesInitializer.java Var.java validator/src/test/org/apache/commons/validator ValidatorTest.java Log: Worked on adding braces to if statments and other sun standard coding. Removed logger reference in ValidatorResourcesInitializer and made it so you can pass in the ValidatorResources to be processed. Revision ChangesPath 1.2 +47 -45 jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java Index: Field.java === RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Field.java6 Jan 2002 05:08:43 - 1.1 +++ Field.java15 Jan 2002 06:06:24 - 1.2 @@ -206,8 +206,9 @@ */ public void addMsg(Msg msg) { if (msg != null msg.getKey() != null msg.getKey().length() 0 - msg.getName() != null msg.getName().length() 0) + msg.getName() != null msg.getName().length() 0) { hMsgs.put(msg.getName(), msg.getKey()); + } } /** @@ -222,10 +223,11 @@ */ public void addArg0(Arg arg) { if (arg != null arg.getKey() != null arg.getKey().length() 0) { - if (arg.getName() != null arg.getName().length() 0) + if (arg.getName() != null arg.getName().length() 0) { hArg0.put(arg.getName(), arg); - else + } else { hArg0.put(ARG_DEFAULT, arg); + } } } @@ -243,10 +245,7 @@ public Arg getArg0(String key) { Object o = hArg0.get(key); - if (o != null) - return (Arg)o; - else - return getArg0(); + return ((o != null) ? (Arg)o : getArg0()); } /** @@ -254,10 +253,11 @@ */ public void addArg1(Arg arg) { if (arg != null arg.getKey() != null arg.getKey().length() 0) { - if (arg.getName() != null arg.getName().length() 0) + if (arg.getName() != null arg.getName().length() 0) { hArg1.put(arg.getName(), arg); - else + } else { hArg1.put(ARG_DEFAULT, arg); + } } } @@ -275,10 +275,7 @@ public Arg getArg1(String key) { Object o = hArg1.get(key); - if (o != null) - return (Arg)o; - else - return getArg1(); + return ((o != null) ? (Arg)o : getArg1()); } /** @@ -286,10 +283,11 @@ */ public void addArg2(Arg arg) { if (arg != null arg.getKey() != null arg.getKey().length() 0) { - if (arg.getName() != null arg.getName().length() 0) + if (arg.getName() != null arg.getName().length() 0) { hArg2.put(arg.getName(), arg); - else + } else { hArg2.put(ARG_DEFAULT, arg); + } } } @@ -307,10 +305,7 @@ public Arg getArg2(String key) { Object o = hArg2.get(key); - if (o != null) - return (Arg)o; - else - return getArg2(); + return ((o != null) ? (Arg)o : getArg2()); } /** @@ -318,10 +313,11 @@ */ public void addArg3(Arg arg) { if (arg != null arg.getKey() != null arg.getKey().length() 0) { - if (arg.getName() != null arg.getName().length() 0) + if (arg.getName() != null arg.getName().length() 0) { hArg3.put(arg.getName(), arg); - else + } else { hArg3.put(ARG_DEFAULT, arg); + } } } @@ -339,33 +335,32 @@ public Arg getArg3(String key) { Object o = hArg3.get(key); - if (o != null) - return (Arg)o; - else - return getArg3(); + return ((o != null) ? (Arg)o : getArg3()); } /** * Add a codeVar/code to the codeField/code. */ public void addVar(Var v) { - if (v != null v.getName() != null v.getName().length() 0 v.getValue() != null) + if (v != null v.getName() != null v.getName().length() 0 v.getValue() != null) { hVars.put(v.getName(), v); + } } /** * Add a codeVar/code, based on the values passed in, to the codeField/code. */ public void addVarParam(String name, String value, String jsType
cvs commit: jakarta-commons/validator build.xml build.properties.sample
dwinterfeldt02/01/08 03:30:40 Modified:validator build.xml build.properties.sample Log: Added comments and removed unecessary properties (jar/path references). Revision ChangesPath 1.2 +6 -4 jakarta-commons/validator/build.xml Index: build.xml === RCS file: /home/cvs/jakarta-commons/validator/build.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- build.xml 6 Jan 2002 05:03:47 - 1.1 +++ build.xml 8 Jan 2002 11:30:39 - 1.2 @@ -1,7 +1,6 @@ !-- - You will need Ant setup properly and have the commons-cactus-ant.jar in the classpath. The build.properties file - will need to be edited to point to some jar files, java.home, and the application servers you want to - run the tests on. + You will need Ant setup properly to run this script. The build.properties.sample file + will need to be edited to point to some jar files and renamed to build.properties. -- project name=Commons Validator default=jar basedir=. !-- set global properties for this build -- @@ -46,7 +45,8 @@ !-- Create the build directory structure used by compile -- mkdir dir=${build}/${share}/ /target - + + !-- Compile shared source -- target name=compile depends=prepare !-- Compile the java code from ${src}/${share} into ${build}/${share} -- javac srcdir=${src}/${share} @@ -55,6 +55,7 @@ /javac /target + !-- Create distribution jar of shared source -- target name=jar depends=compile !-- Create the ${dist}/lib directory -- mkdir dir=${dist} / @@ -65,6 +66,7 @@ includes=${package.root}/**/ /target + !-- Create Javadocs -- target name=javadocs depends=jar description=Creates the API documentation mkdir dir=${build.javadocs}/ javadoc packagenames=org.apache.commons.validator.* 1.2 +7 -28 jakarta-commons/validator/build.properties.sample Index: build.properties.sample === RCS file: /home/cvs/jakarta-commons/validator/build.properties.sample,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- build.properties.sample 6 Jan 2002 05:03:47 - 1.1 +++ build.properties.sample 8 Jan 2002 11:30:39 - 1.2 @@ -1,37 +1,16 @@ -# Properties related to the user's environment. This file should be provided -# for building the Cactus Sample or the properties need to be specified on -# the command line when starting Ant with the -D switch +# - +# This is an example build.properties file. Make any changes you need, +# and rename this file to build.properties in the same directory that +# contains the build.xml file. +# - -java.home=d:/jdk1.3 commons-beanutils.jar=d:/java/lib/commons-beanutils.jar commons-collections.jar=d:/java/lib/commons-collections.jar commons-digester.jar=d:/java/lib/commons-digester.jar regexp.jar=e:/software/regexp/jakarta-regexp-1.2.jar -xerces.jar=e:/software/xerces/xerces.jar - -# For compile_struts task (Struts interface for Validator) -struts.jar=../../target/library/struts.jar -struts.tlds=../../target/library -servlet.jar=e:/tomcat3/lib/servlet.jar -jdbc20ext.jar=d:/java/lib/jdbc2_0-stdext.jar # Unit Testing junit.jar=e:/software/junit3.5/junit.jar -# Unit Testing For Struts Interface to Validator -cactus.jar=e:/software/cactus/lib/commons-cactus.jar -cactus.ant.jar=e:/software/cactus/lib/commons-cactus-ant.jar - -# Shouldn't be necessary, there is a problem with my ant setup -#ant.jar=c:/software/ant/lib/ant.jar -#ant.optional.jar=c:/software/ant/lib/optional.jar - -# Servlet engine locations for the tests - -# Note: If you don't want to run the test on a given servlet engine, just -# comment it's home property. For example, if you don't want to run the -# tests on the Resin 1.3, comment the resin.home.13 property. -#resin.home.13=f:/applis/resin-1.3.s010125 -tomcat.home.32=e:/tomcat3 -tomcat.home.40=e:/tomcat4 - +# Just needed for building the Javadocs +xerces.jar=e:/software/xerces/xerces.jar \ No newline at end of file -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator - New directory
dwinterfeldt02/01/05 16:24:49 jakarta-commons/validator - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src - New directory
dwinterfeldt02/01/05 16:44:41 jakarta-commons/validator/src - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator README
dwinterfeldt02/01/05 16:47:39 Added: validator README Log: Testing my cvs karma. Revision ChangesPath 1.1 jakarta-commons/validator/README Index: README === Struts Validator == You must do the following to have the build script work. 1. Edit the build.properties file. 2. Add the follwing to the lib directory. Struts - struts.jar (http://jakarta.apache.org/struts/) Jakarata Regexp - jakarta-regexp.jar (http://jakarta.apache.org/regexp/) JDBC 2.0 Optonal Package - jdbc2_0-stdext.jar (http://java.sun.com/products/jdbc/download.html#spec) 3. Place the following Struts tlds from the Struts download in 'struts/WEB-INF/tlds'. (struts-bean.tld struts-html.tld struts-logic.tld struts-template.tld) Overview - The Validation Framework was made to work with Struts. It can perform basic validations to check if a field is required, matches a regular expression, email, credit card, and server side type checking and date validation. Different validation rules can be defined for different locales. The framework has basic support for user defined constants which can be used in some field attributes. The validation routines are modifiable in the validation.xml file so custom validation routines can be created and added to the framework. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/test - New directory
dwinterfeldt02/01/05 21:04:40 jakarta-commons/validator/src/test - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/test/org - New directory
dwinterfeldt02/01/05 21:04:49 jakarta-commons/validator/src/test/org - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/test/org/apache/commons - New directory
dwinterfeldt02/01/05 21:05:07 jakarta-commons/validator/src/test/org/apache/commons - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator - New directory
dwinterfeldt02/01/05 21:05:13 jakarta-commons/validator/src/test/org/apache/commons/validator - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share - New directory
dwinterfeldt02/01/05 21:06:42 jakarta-commons/validator/src/share - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org - New directory
dwinterfeldt02/01/05 21:06:48 jakarta-commons/validator/src/share/org - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache - New directory
dwinterfeldt02/01/05 21:06:56 jakarta-commons/validator/src/share/org/apache - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons - New directory
dwinterfeldt02/01/05 21:07:06 jakarta-commons/validator/src/share/org/apache/commons - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator - New directory
dwinterfeldt02/01/05 21:07:20 jakarta-commons/validator/src/share/org/apache/commons/validator - New directory -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]