Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 40624 invoked from network); 4 Apr 2004 13:53:31 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 4 Apr 2004 13:53:31 -0000 Received: (qmail 53570 invoked by uid 500); 4 Apr 2004 13:53:23 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 53335 invoked by uid 500); 4 Apr 2004 13:53:22 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 53319 invoked by uid 500); 4 Apr 2004 13:53:21 -0000 Received: (qmail 53315 invoked from network); 4 Apr 2004 13:53:21 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 4 Apr 2004 13:53:21 -0000 Received: (qmail 40600 invoked by uid 1182); 4 Apr 2004 13:53:25 -0000 Date: 4 Apr 2004 13:53:25 -0000 Message-ID: <20040404135325.40599.qmail@minotaur.apache.org> From: rleland@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator ExtensionTest.java validator-extension.xml ValidatorTestSuite.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N rleland 2004/04/04 06:53:25 Modified: validator build.properties.sample build.xml project.xml validator/src/share/org/apache/commons/validator EmailValidator.java Form.java FormSet.java ValidatorResources.java ValidatorResourcesInitializer.java validator/src/test/org/apache/commons/validator ValidatorTestSuite.java Added: validator/conf/share validator_1_2_0.dtd validator/src/test/org/apache/commons/validator ExtensionTest.java validator-extension.xml Log: Bug 27870 Patch For Form inheritance provided by Nacho G. Mac Dowell Since this is a major functionality change though amount of code was small Validator version rev changed to 1.2.0-dev Revision Changes Path 1.12 +7 -7 jakarta-commons/validator/build.properties.sample Index: build.properties.sample =================================================================== RCS file: /home/cvs/jakarta-commons/validator/build.properties.sample,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- build.properties.sample 29 Feb 2004 09:48:28 -0000 1.11 +++ build.properties.sample 4 Apr 2004 13:53:25 -0000 1.12 @@ -37,16 +37,16 @@ # from the Jakarta Commons project. commons-logging.jar=../logging/dist/commons-logging.jar -# The JAR file containing version 2.07 (or later) of +# The JAR file containing version 2.08 (or later) of # the the Jakarta ORO project. -oro.jar=${apache.dir}/jakarta-oro-2.0.7/jakarta-oro-2.0.7.jar +oro.jar=${apache.dir}/jakarta-oro-2.0.8/jakarta-oro-2.0.8.jar # The JAR file containing version 3.8.1 (or later) of # JUnit Unit Testing (http://www.junit.org) junit.jar=D:/java/Lib/junit3.8.1/junit.jar -# Needed for building the Javadocs -xerces.jar=${apache.dir}/xerces-1_4_2/xerces.jar +# Needed for building the version Javadocs +xerces.jar=${apache.dir}/xerces-2_5_0/xercesImpl.jar # jsdoc 1.5.2 or Newer is needed for building the Javascript Javadocs jsdoc.home=/cygdrive/d/Projects/Sourceforge/JsDoc/JSDoc-1.5.2 1.34 +4 -2 jakarta-commons/validator/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-commons/validator/build.xml,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- build.xml 30 Mar 2004 06:22:54 -0000 1.33 +++ build.xml 4 Apr 2004 13:53:25 -0000 1.34 @@ -67,7 +67,7 @@ - + @@ -211,6 +211,8 @@ file="${conf.home}/validator_1_0_1.dtd"/> + 1.42 +7 -1 jakarta-commons/validator/project.xml Index: project.xml =================================================================== RCS file: /home/cvs/jakarta-commons/validator/project.xml,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- project.xml 4 Apr 2004 07:33:52 -0000 1.41 +++ project.xml 4 Apr 2004 13:53:25 -0000 1.42 @@ -19,7 +19,7 @@ ../commons-build/project.xml Validator commons-validator - 1.1.3-dev + 1.2.0-dev 2002 org.apache.commons.validator @@ -184,6 +184,12 @@ lmagee@biziworks.com.au + + Nacho G. Mac Dowell + + + + 1.1 jakarta-commons/validator/conf/share/validator_1_2_0.dtd Index: validator_1_2_0.dtd =================================================================== 1.13 +24 -3 jakarta-commons/validator/src/share/org/apache/commons/validator/EmailValidator.java Index: EmailValidator.java =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/EmailValidator.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- EmailValidator.java 21 Feb 2004 17:10:29 -0000 1.12 +++ EmailValidator.java 4 Apr 2004 13:53:25 -0000 1.13 @@ -88,6 +88,8 @@ return false; } + email = stripComments(email); + // Check the whole email address structure Perl5Util emailMatcher = new Perl5Util(); if (!emailMatcher.match(EMAIL_PATTERN, email)) { @@ -212,5 +214,24 @@ return true; } + /** + * Recursively remove comments, and replace with a single space. The simpler + * regexps in the Email Addressing FAQ are imperfect - they will miss escaped + * chars in atoms, for example. + * Derived From Mail::RFC822::Address + */ + protected String stripComments(String emailStr) { + String input = emailStr; + String result = emailStr; + String commentPat = "s/^((?:[^\"\\\\]|\\\\.)*(?:\"(?:[^\"\\\\]|\\\\.)*\"(?:[^\"\\\\]|\111111\\\\.)*)*)\\((?:[^()\\\\]|\\\\.)*\\)/$1 /osx"; + Perl5Util commentMatcher = new Perl5Util(); + result = commentMatcher.substitute(commentPat,input); + // This really needs to be =~ or Perl5Matcher comparison + while (!result.equals(input)) { + input = result; + result = commentMatcher.substitute(commentPat,input); + } + return result; + } } 1.15 +82 -4 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Form.java 21 Feb 2004 17:10:29 -0000 1.14 +++ Form.java 4 Apr 2004 13:53:25 -0000 1.15 @@ -59,6 +59,17 @@ */ protected FastHashMap hFields = new FastHashMap(); + /** + * The name/key of the form which this form extends from. + */ + protected String inherit = null; + + /** + * Whether or not the this Form was processed + * for replacing variables in strings with their values. + */ + private boolean processed = false; + /** * Gets the name/key of the set of validation rules. */ @@ -126,8 +137,47 @@ Field f = (Field) i.next(); f.process(globalConstants, constants); } + + processed = true; } + /** + * Processes all of the Form's Fields. + */ + protected void process(Map globalConstants, Map constants, Map forms) { + + if (isProcessed()) { + return; + } + int n = 0; //we want the fields from its parent first + if (isExtending()) { + Form parent = (Form) forms.get(inherit); + if (parent != null) { + if (!parent.isProcessed()) { + //we want to go all the way up the tree + parent.process(constants, globalConstants, forms); + } + for (Iterator i = parent.getFields().iterator(); i.hasNext();) { + Field f = (Field) i.next(); + //we want to be able to override any fields we like + if (hFields.get(f.getKey()) == null) { + lFields.add(n, f); + hFields.put(f.getKey(), f); + n++; + } + } + } + } + hFields.setFast(true); + //no need to reprocess parent's fields, we iterate from 'n' + for (Iterator i = lFields.listIterator(n); i.hasNext();) { + Field f = (Field) i.next(); + f.process(globalConstants, constants); + } + + processed = true; + } + /** * Returns a string representation of the object. */ @@ -146,7 +196,7 @@ return results.toString(); } - + /** * Validate all Fields in this Form on the given page and below. * @param params A Map of parameter class names to parameter values to pass @@ -175,4 +225,32 @@ return results; } + /** + * Whether or not the this Form was processed + * for replacing variables in strings with their values. + */ + public boolean isProcessed() { + return processed; + } + + /** + * Gets the name/key of the parent set of validation rules. + */ + public String getExtends() { + return inherit; + } + + /** + * Sets the name/key of the parent set of validation rules. + */ + public void setExtends(String string) { + inherit = string; + } + + /** + * Get extends flag. + */ + public boolean isExtending() { + return inherit != null; + } } 1.16 +4 -4 jakarta-commons/validator/src/share/org/apache/commons/validator/FormSet.java Index: FormSet.java =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/FormSet.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- FormSet.java 21 Feb 2004 17:10:29 -0000 1.15 +++ FormSet.java 4 Apr 2004 13:53:25 -0000 1.16 @@ -186,7 +186,7 @@ public synchronized void process(Map globalConstants) { for (Iterator i = forms.values().iterator(); i.hasNext();) { Form f = (Form) i.next(); - f.process(globalConstants, constants); + f.process(globalConstants, constants, forms); } processed = true; 1.31 +6 -4 jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java Index: ValidatorResources.java =================================================================== RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- ValidatorResources.java 21 Feb 2004 17:10:29 -0000 1.30 +++ ValidatorResources.java 4 Apr 2004 13:53:25 -0000 1.31 @@ -64,7 +64,9 @@ "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0.1//EN", "/org/apache/commons/validator/resources/validator_1_0_1.dtd", "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN", - "/org/apache/commons/validator/resources/validator_1_1.dtd" + "/org/apache/commons/validator/resources/validator_1_1.dtd", + "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.2.0//EN", + "/org/apache/commons/validator/resources/validator_1_2_0.dtd" }; /** 1.23 +6 -4 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.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- ValidatorResourcesInitializer.java 21 Feb 2004 17:10:29 -0000 1.22 +++ ValidatorResourcesInitializer.java 4 Apr 2004 13:53:25 -0000 1.23 @@ -59,7 +59,9 @@ "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0.1//EN", "/org/apache/commons/validator/resources/validator_1_0_1.dtd", "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN", - "/org/apache/commons/validator/resources/validator_1_1.dtd" + "/org/apache/commons/validator/resources/validator_1_1.dtd", + "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.2.0//EN", + "/org/apache/commons/validator/resources/validator_1_2_0.dtd" }; 1.16 +4 -3 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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ValidatorTestSuite.java 21 Feb 2004 17:10:30 -0000 1.15 +++ ValidatorTestSuite.java 4 Apr 2004 13:53:25 -0000 1.16 @@ -51,6 +51,7 @@ suite.addTest(FloatTest.suite()); suite.addTest(DoubleTest.suite()); suite.addTest(TypeTest.suite()); + suite.addTest(ExtensionTest.suite()); suite.addTest(EmailTest.suite()); suite.addTestSuite(CreditCardValidatorTest.class); suite.addTest(ValidatorTest.suite()); 1.1 jakarta-commons/validator/src/test/org/apache/commons/validator/ExtensionTest.java Index: ExtensionTest.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/ExtensionTest.java,v 1.1 2004/04/04 13:53:25 rleland Exp $ * $Revision: 1.1 $ * $Date: 2004/04/04 13:53:25 $ * * ==================================================================== * Copyright 2001-2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.validator; import java.io.InputStream; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** *

Performs tests for extension in form definitions. Performs the same tests * RequiredNameTest does but with an equivalent validation definition with extension * definitions (validator-extension.xml), plus an extra check on overriding rules and * another one checking it mantains correct order when extending.

*/ public class ExtensionTest extends TestCase { /** * The key used to retrieve the set of validation * rules from the xml file. */ protected static String FORM_KEY = "nameForm"; /** * The key used to retrieve the set of validation * rules from the xml file. */ protected static String FORM_KEY2 = "nameForm2"; /** * The key used to retrieve the set of validation * rules from the xml file. */ protected static String CHECK_MSG_KEY = "nameForm.lastname.displayname"; /** * The key used to retrieve the validator action. */ protected static String ACTION = "required"; /** * Commons Logging instance. */ private Log log = LogFactory.getLog(this.getClass()); /** * Resources used for validation tests. */ private ValidatorResources resources = null; /** * Constructor de ExtensionTest. * @param arg0 */ public ExtensionTest(String arg0) { super(arg0); } /** * Start the tests. * * @param theArgs the arguments. Not used */ public static void main(String[] theArgs) { junit.awtui.TestRunner.main(new String[] {RequiredNameTest.class.getName()}); } /** * @return a test suite (TestSuite) that includes all methods * starting with "test" */ public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(ExtensionTest.class); } /** * Load ValidatorResources from * validator-extension.xml. */ protected void setUp() throws Exception { // Load resources InputStream in = null; try { in = this.getClass().getResourceAsStream("validator-extension.xml"); resources = new ValidatorResources(in); } catch (Exception e) { log.error(e.getMessage(), e); throw e; } finally { if (in != null) { try { in.close(); } catch (Exception e) {} } } } protected void tearDown() { } /** * Tests the required validation failure. */ public void testRequired() throws ValidatorException { // Create bean to run test on. NameBean name = new NameBean(); // Construct validator based on the loaded resources // and the form key Validator validator = new Validator(resources, FORM_KEY); // add the name bean to the validator as a resource // for the validations to be performed on. validator.setParameter(Validator.BEAN_PARAM, name); // Get results of the validation. ValidatorResults results = null; // throws ValidatorException, // but we aren't catching for testing // since no validation methods we use // throw this results = validator.validate(); 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)); } /** * Tests the required validation for first name if it is blank. */ public void testRequiredFirstNameBlank() throws ValidatorException { // Create bean to run test on. NameBean name = new NameBean(); name.setFirstName(""); // Construct validator based on the loaded resources // and the form key Validator validator = new Validator(resources, FORM_KEY); // add the name bean to the validator as a resource // for the validations to be performed on. validator.setParameter(Validator.BEAN_PARAM, name); // Get results of the validation. ValidatorResults results = null; results = validator.validate(); 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)); } /** * Tests the required validation for first name. */ public void testRequiredFirstName() throws ValidatorException { // Create bean to run test on. NameBean name = new NameBean(); name.setFirstName("Joe"); // Construct validator based on the loaded resources // and the form key Validator validator = new Validator(resources, FORM_KEY); // add the name bean to the validator as a resource // for the validations to be performed on. validator.setParameter(Validator.BEAN_PARAM, name); // Get results of the validation. ValidatorResults results = null; results = validator.validate(); 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 passed.", 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)); } /** * Tests the required validation for last name if it is blank. */ public void testRequiredLastNameBlank() throws ValidatorException { // Create bean to run test on. NameBean name = new NameBean(); name.setLastName(""); // Construct validator based on the loaded resources // and the form key Validator validator = new Validator(resources, FORM_KEY); // add the name bean to the validator as a resource // for the validations to be performed on. validator.setParameter(Validator.BEAN_PARAM, name); // Get results of the validation. ValidatorResults results = null; results = validator.validate(); 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)); } /** * Tests the required validation for last name. */ public void testRequiredLastName() throws ValidatorException { // Create bean to run test on. NameBean name = new NameBean(); name.setLastName("Smith"); // Construct validator based on the loaded resources // and the form key Validator validator = new Validator(resources, FORM_KEY); // add the name bean to the validator as a resource // for the validations to be performed on. validator.setParameter(Validator.BEAN_PARAM, name); // Get results of the validation. ValidatorResults results = null; results = validator.validate(); 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 passed.", lastNameResult.isValid(ACTION)); } /** * Tests the required validation for first and last name. */ public void testRequiredName() throws ValidatorException { // Create bean to run test on. NameBean name = new NameBean(); name.setFirstName("Joe"); name.setLastName("Smith"); // Construct validator based on the loaded resources // and the form key Validator validator = new Validator(resources, FORM_KEY); // add the name bean to the validator as a resource // for the validations to be performed on. validator.setParameter(Validator.BEAN_PARAM, name); // Get results of the validation. ValidatorResults results = null; results = validator.validate(); 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 passed.", firstNameResult.isValid(ACTION)); assertNotNull("Last 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 passed.", lastNameResult.isValid(ACTION)); } /** * Tests if we can override a rule. We "can" override a rule if the message shown * when the firstName required test fails and the lastName test is null. */ public void testOverrideRule() throws ValidatorException { // Create bean to run test on. NameBean name = new NameBean(); name.setLastName("Smith"); // Construct validator based on the loaded resources // and the form key Validator validator = new Validator(resources, FORM_KEY2); // add the name bean to the validator as a resource // for the validations to be performed on. validator.setParameter(Validator.BEAN_PARAM, name); // Get results of the validation. ValidatorResults results = null; results = validator.validate(); 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 for the '" + ACTION +"' action should have '" + CHECK_MSG_KEY + " as a key.", firstNameResult.field.getArg(0).getKey().equals(CHECK_MSG_KEY)); assertNull("Last Name ValidatorResult should be null.", lastNameResult); } /** * Tests if the order is mantained when extending a form. Parent form fields should * preceed self form fields, except if we override the rules. */ public void testOrder() throws ValidatorException { Form form = resources.getForm(ValidatorResources.defaultLocale, FORM_KEY); Form form2 = resources.getForm(ValidatorResources.defaultLocale, FORM_KEY2); assertNotNull(FORM_KEY + " is null.", form); assertTrue("There should only be 2 fields in " + FORM_KEY, form.getFields().size() == 2); assertNotNull(FORM_KEY2 + " is null.", form2); assertTrue("There should only be 2 fields in " + FORM_KEY2, form2.getFields().size() == 2); //get the first field Field fieldFirstName = (Field)form.getFields().get(0); //get the second field Field fieldLastName = (Field)form.getFields().get(1); assertTrue("firstName in " + FORM_KEY + " should be the first in the list", fieldFirstName.getKey().equals("firstName")); assertTrue("lastName in " + FORM_KEY + " should be the first in the list", fieldLastName.getKey().equals("lastName")); // get the second field fieldLastName = (Field)form2.getFields().get(0); //get the first field fieldFirstName = (Field)form2.getFields().get(1); assertTrue("firstName in " + FORM_KEY2 + " should be the first in the list", fieldFirstName.getKey().equals("firstName")); assertTrue("lastName in " + FORM_KEY2 + " should be the first in the list", fieldLastName.getKey().equals("lastName")); } } 1.1 jakarta-commons/validator/src/test/org/apache/commons/validator/validator-extension.xml Index: validator-extension.xml ===================================================================
--------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org