Author: niallp
Date: Wed Nov 22 14:25:19 2006
New Revision: 478345
URL: http://svn.apache.org/viewvc?view=rev&rev=478345
Log:
Fix for VALIDATOR-19 - Validator incorrectly storing itself under the
FORM_PARAM key rather than the Form - patch supplied by Masahiro Honda
Added:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest-config.xml
(with props)
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest.java
(with props)
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTestValidator.java
(with props)
Modified:
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Validator.java
Modified:
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Validator.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Validator.java?view=diff&rev=478345&r1=478344&r2=478345
==============================================================================
---
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Validator.java
(original)
+++
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Validator.java
Wed Nov 22 14:25:19 2006
@@ -347,7 +347,7 @@
Form form = this.resources.getForm(locale, this.formName);
if (form != null) {
- this.setParameter(FORM_PARAM, this);
+ this.setParameter(FORM_PARAM, form);
return form.validate(
this.parameters,
this.resources.getValidatorActions(),
Added:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest-config.xml
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest-config.xml?view=auto&rev=478345
==============================================================================
---
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest-config.xml
(added)
+++
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest-config.xml
Wed Nov 22 14:25:19 2006
@@ -0,0 +1,37 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<form-validation>
+ <global>
+ <validator name="required"
+
classname="org.apache.commons.validator.ParameterTestValidator"
+ method="validateParameter"
+ methodParams="java.lang.Object,
+ org.apache.commons.validator.Form,
+ org.apache.commons.validator.Field,
+ org.apache.commons.validator.Validator,
+ org.apache.commons.validator.ValidatorAction,
+ org.apache.commons.validator.ValidatorResults,
+ java.util.Locale"/>
+ </global>
+
+ <formset>
+ <form name="nameForm">
+ <field property="firstName" depends="required">
+ </field>
+ </form>
+ </formset>
+</form-validation>
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest-config.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest-config.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest.java?view=auto&rev=478345
==============================================================================
---
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest.java
(added)
+++
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest.java
Wed Nov 22 14:25:19 2006
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.IOException;
+import java.util.Locale;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.xml.sax.SAXException;
+
+/**
+ * This TestCase is a confirmation of the parameter of the validator's method.
+ *
+ * @version $Revision$ $Date$
+ */
+public class ParameterTest extends TestCommon {
+
+ private static final String FORM_KEY = "nameForm";
+
+ private static final String firstNameField = "firstName";
+
+ private static final String middleNameField = "middleName";
+
+ private static final String lastNameField = "lastName";
+
+ private String firstName;
+
+ private String middleName;
+
+ private String lastName;
+
+ /**
+ * Constructor.
+ */
+ public ParameterTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Start the tests.
+ *
+ * @param theArgs the arguments. Not used
+ */
+ public static void main(String[] theArgs) {
+ junit.awtui.TestRunner.main(new String[] {
+ ParameterTest.class.getName()
+ });
+ }
+
+ /**
+ * Create a Test Suite
+ * @return a test suite (<code>TestSuite</code>) that includes all
+ * methods starting with "test"
+ */
+ public static Test suite() {
+ return new TestSuite(ParameterTest.class);
+ }
+
+ /**
+ * Load <code>ValidatorResources</code> from
+ * ValidatorResultsTest-config.xml.
+ */
+ protected void setUp() throws IOException, SAXException {
+ // Load resources
+ loadResources("ParameterTest-config.xml");
+
+ // initialize values
+ firstName = "foo";
+ middleName = "123";
+ lastName = "456";
+
+ }
+
+ protected void tearDown() {
+ }
+
+ /**
+ * Test all validations ran and passed.
+ */
+ public void testAllValid() throws ValidatorException {
+
+ // Create bean to run test on.
+ NameBean bean = createNameBean();
+
+ 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, bean);
+ validator.setParameter(Validator.LOCALE_PARAM, Locale.getDefault());
+
+ // Get results of the validation.
+ ValidatorResults results = null;
+ try {
+ results = validator.validate();
+ } catch(Exception e) {
+ fail("Validator.validate() threw " + e);
+ }
+ assertParameterValue(validator, Validator.BEAN_PARAM, Object.class);
+ assertParameterValue(validator, Validator.FIELD_PARAM, Field.class);
+ assertParameterValue(validator, Validator.FORM_PARAM, Form.class);
+ assertParameterValue(validator, Validator.LOCALE_PARAM, Locale.class);
+ assertParameterValue(validator, Validator.VALIDATOR_ACTION_PARAM,
+ ValidatorAction.class);
+ assertParameterValue(validator, Validator.VALIDATOR_PARAM,
+ Validator.class);
+ assertParameterValue(validator, Validator.VALIDATOR_RESULTS_PARAM,
+ ValidatorResults.class);
+ }
+
+ private void assertParameterValue(Validator validator, String name,
+ Class type) {
+ Object value = validator.getParameterValue(name);
+ assertNotNull("Expected '" + type.getName() + "' but was null", value);
+ assertTrue("Expected '" + type.getName() + "' but was '" +
value.getClass().getName() + "'",
+ type.isInstance(value));
+ }
+
+ /**
+ * Create a NameBean.
+ */
+ private NameBean createNameBean() {
+ NameBean name = new NameBean();
+ name.setFirstName(firstName);
+ name.setMiddleName(middleName);
+ name.setLastName(lastName);
+ return name;
+ }
+}
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTestValidator.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTestValidator.java?view=auto&rev=478345
==============================================================================
---
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTestValidator.java
(added)
+++
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTestValidator.java
Wed Nov 22 14:25:19 2006
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
+
+/**
+ * Contains validation methods for different unit tests.
+ *
+ * @version $Revision$ $Date$
+ */
+public class ParameterTestValidator {
+
+ /**
+ * ValidatorParameter is valid.
+ *
+ */
+ public static boolean validateParameter(
+ final java.lang.Object bean,
+ final org.apache.commons.validator.Form form,
+ final org.apache.commons.validator.Field field,
+ final org.apache.commons.validator.Validator validator,
+ final org.apache.commons.validator.ValidatorAction action,
+ final org.apache.commons.validator.ValidatorResults results,
+ final java.util.Locale locale)
+ throws Exception {
+
+ return true;
+ }
+}
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTestValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ParameterTestValidator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]