You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2007/01/30 02:28:41 UTC
svn commit: r501273 - in /tapestry/tapestry5/tapestry-core/trunk/src:
main/java/org/apache/tapestry/ main/java/org/apache/tapestry/corelib/base/
main/java/org/apache/tapestry/internal/services/
main/java/org/apache/tapestry/services/ main/java/org/apac...
Author: hlship
Date: Mon Jan 29 17:28:39 2007
New Revision: 501273
URL: http://svn.apache.org/viewvc?view=rev&rev=501273
Log:
Fill in the set of default validators.
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Max.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxLength.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxTest.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Min.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MaxLengthTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinTest.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/FieldValidator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinLengthTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/FieldValidator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/FieldValidator.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/FieldValidator.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/FieldValidator.java Mon Jan 29 17:28:39 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -32,5 +32,5 @@
* @throws ValidationException
* if the value violates the constraint
*/
- void check(T value) throws ValidationException;
+ void validate(T value) throws ValidationException;
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/Validator.java Mon Jan 29 17:28:39 2007
@@ -35,15 +35,15 @@
/**
* Returns the value type associated with this validator.
- * {@link #check(Field, Object, MessageFormatter, Object)} will only be invoked when the value
- * is assignable to the validator's value type.
+ * {@link #validate(Field, Object, MessageFormatter, Object)} will only be invoked when the
+ * value is assignable to the validator's value type.
*/
Class<T> getValueType();
/**
* Returns the message key, within the validiation messages, normally used by this validator.
* This is used to provide the {@link MessageFormatter} passed to
- * {@link #check(Field, Object, MessageFormatter, Object)} (unless overridden).
+ * {@link #validate(Field, Object, MessageFormatter, Object)} (unless overridden).
*
* @see ValidationMessagesSource
* @return a message key
@@ -66,7 +66,7 @@
* @throws ValidationException
* if the value violates the constraint
*/
- void check(Field field, C constraintValue, MessageFormatter formatter, T value)
+ void validate(Field field, C constraintValue, MessageFormatter formatter, T value)
throws ValidationException;
/**
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java Mon Jan 29 17:28:39 2007
@@ -79,7 +79,7 @@
protected static final FieldValidator NOOP_VALIDATOR = new FieldValidator()
{
- public void check(Object value) throws ValidationException
+ public void validate(Object value) throws ValidationException
{
// Do nothing
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractTextField.java Mon Jan 29 17:28:39 2007
@@ -139,7 +139,7 @@
{
Object translated = _translate.parseClient(rawValue, messages);
- _validate.check(translated);
+ _validate.validate(translated);
_value = translated;
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorImpl.java Mon Jan 29 17:28:39 2007
@@ -40,7 +40,7 @@
}
@SuppressWarnings("unchecked")
- public void check(Object value) throws ValidationException
+ public void validate(Object value) throws ValidationException
{
if (_validator.skipIfBlank() && isBlank(value))
return;
@@ -48,7 +48,7 @@
if (value != null && !_validator.getValueType().isInstance(value))
return;
- _validator.check(_field, _constraintValue, _messageFormatter, value);
+ _validator.validate(_field, _constraintValue, _messageFormatter, value);
}
private boolean isBlank(Object value)
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/FieldValidatorSourceImpl.java Mon Jan 29 17:28:39 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -118,10 +118,10 @@
return new FieldValidator()
{
@SuppressWarnings("unchecked")
- public void check(Object value) throws ValidationException
+ public void validate(Object value) throws ValidationException
{
for (FieldValidator fv : array)
- fv.check(value);
+ fv.validate(value);
}
};
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java Mon Jan 29 17:28:39 2007
@@ -158,6 +158,9 @@
import org.apache.tapestry.runtime.RenderCommand;
import org.apache.tapestry.translator.IntegerTranslator;
import org.apache.tapestry.translator.StringTranslator;
+import org.apache.tapestry.validator.Max;
+import org.apache.tapestry.validator.MaxLength;
+import org.apache.tapestry.validator.Min;
import org.apache.tapestry.validator.MinLength;
import org.apache.tapestry.validator.Required;
@@ -512,8 +515,7 @@
ResourceCache resourceCache, @InjectService("tapestry.internal.ResourceStreamer")
ResourceStreamer streamer, @InjectService("PageLinkHandler")
PageLinkHandler pageLinkHandler, @InjectService("ActionLinkHandler")
- ActionLinkHandler actionLinkHandler,
- @InjectService("tapestry.ComponentClassResolver")
+ ActionLinkHandler actionLinkHandler, @InjectService("tapestry.ComponentClassResolver")
ComponentClassResolver componentClassResolver)
{
// This goes first because an asset to be streamed may have an file extension, such as
@@ -925,6 +927,9 @@
* <ul>
* <li>required</li>
* <li>minlength</li>
+ * <li>maxlength</li>
+ * <li>min</li>
+ * <li>max</li>
* </ul>
*/
public static void contributeFieldValidatorSource(
@@ -932,6 +937,9 @@
{
configuration.add("required", new Required());
configuration.add("minlength", new MinLength());
+ configuration.add("maxlength", new MaxLength());
+ configuration.add("min", new Min());
+ configuration.add("max", new Max());
}
public static TranslatorSource buildTranslatorSource(Map<String, Translator> configuration)
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Max.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Max.java?view=auto&rev=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Max.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Max.java Mon Jan 29 17:28:39 2007
@@ -0,0 +1,51 @@
+// Copyright 2007 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.tapestry.validator;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ioc.MessageFormatter;
+
+/** Enforces a maximum integer value. */
+public class Max implements Validator<Long, Number>
+{
+ public Class<Long> getConstraintType()
+ {
+ return Long.class;
+ }
+
+ public String getMessageKey()
+ {
+ return "max-integer";
+ }
+
+ public Class<Number> getValueType()
+ {
+ return Number.class;
+ }
+
+ public boolean skipIfBlank()
+ {
+ return true;
+ }
+
+ public void validate(Field field, Long constraintValue, MessageFormatter formatter, Number value)
+ throws ValidationException
+ {
+ if (value.longValue() > constraintValue)
+ throw new ValidationException(formatter.format(constraintValue, field.getLabel()));
+ }
+}
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxLength.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxLength.java?view=auto&rev=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxLength.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxLength.java Mon Jan 29 17:28:39 2007
@@ -0,0 +1,50 @@
+// Copyright 2007 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.tapestry.validator;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ioc.MessageFormatter;
+
+public final class MaxLength implements Validator<Integer, String>
+{
+ public Class<Integer> getConstraintType()
+ {
+ return Integer.class;
+ }
+
+ public String getMessageKey()
+ {
+ return "maximum-string-length";
+ }
+
+ public Class<String> getValueType()
+ {
+ return String.class;
+ }
+
+ public boolean skipIfBlank()
+ {
+ return true;
+ }
+
+ public void validate(Field field, Integer constraintValue, MessageFormatter formatter, String value)
+ throws ValidationException
+ {
+ if (value.length() > constraintValue)
+ throw new ValidationException(formatter.format(constraintValue, field.getLabel()));
+ }
+}
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxTest.java?view=auto&rev=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MaxTest.java Mon Jan 29 17:28:39 2007
@@ -0,0 +1,70 @@
+// Copyright 2007 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.tapestry.validator;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.ioc.MessageFormatter;
+import org.testng.annotations.Test;
+
+public class MaxTest extends InternalBaseTestCase
+{
+ @Test
+ public void small_enough() throws Exception
+ {
+ Field field = newField();
+ MessageFormatter formatter = newMessageFormatter();
+ Long constraint = 50l;
+
+ replay();
+
+ Max validator = new Max();
+
+ for (int value = 48; value <= 50; value++)
+ validator.validate(field, constraint, formatter, value);
+
+ verify();
+ }
+
+ @Test
+ public void value_too_large() throws Exception
+ {
+ String label = "My Field";
+ Field field = newFieldWithLabel(label);
+ MessageFormatter formatter = newMessageFormatter();
+ String message = "{message}";
+ Long constraint = 100l;
+ Number value = 101;
+
+ train_format(formatter, message, constraint, label);
+
+ replay();
+
+ Max validator = new Max();
+
+ try
+ {
+ validator.validate(field, constraint, formatter, value);
+ unreachable();
+ }
+ catch (ValidationException ex)
+ {
+ assertEquals(ex.getMessage(), message);
+ }
+
+ verify();
+ }
+}
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Min.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Min.java?view=auto&rev=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Min.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Min.java Mon Jan 29 17:28:39 2007
@@ -0,0 +1,51 @@
+// Copyright 2007 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.tapestry.validator;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.Validator;
+import org.apache.tapestry.ioc.MessageFormatter;
+
+/* A vaidator that enforces that a number is greater than some minimum integer value. */
+public class Min implements Validator<Long, Number>
+{
+ public Class<Long> getConstraintType()
+ {
+ return Long.class;
+ }
+
+ public String getMessageKey()
+ {
+ return "min-integer";
+ }
+
+ public Class<Number> getValueType()
+ {
+ return Number.class;
+ }
+
+ public boolean skipIfBlank()
+ {
+ return true;
+ }
+
+ public void validate(Field field, Long constraintValue, MessageFormatter formatter, Number value)
+ throws ValidationException
+ {
+ if (value.longValue() < constraintValue)
+ throw new ValidationException(formatter.format(constraintValue, field.getLabel()));
+ }
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/MinLength.java Mon Jan 29 17:28:39 2007
@@ -22,15 +22,15 @@
/**
* Validates that a string value has a minimum length.
*/
-public class MinLength implements Validator<Integer, String>
+public final class MinLength implements Validator<Integer, String>
{
public String getMessageKey()
{
return "minimum-string-length";
}
- public void check(Field field, Integer constraintValue, MessageFormatter formatter, String value)
- throws ValidationException
+ public void validate(Field field, Integer constraintValue, MessageFormatter formatter,
+ String value) throws ValidationException
{
if (value.length() < constraintValue)
throw new ValidationException(formatter.format(constraintValue, field.getLabel()));
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/validator/Required.java Mon Jan 29 17:28:39 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2007 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.
@@ -23,14 +23,14 @@
* A validator that enforces that the value is not null and not the empty string. This validator is
* not configurable.
*/
-public class Required implements Validator<Void, Object>
+public final class Required implements Validator<Void, Object>
{
public String getMessageKey()
{
return "required";
}
- public void check(Field field, Void constraintValue, MessageFormatter formatter, Object value)
+ public void validate(Field field, Void constraintValue, MessageFormatter formatter, Object value)
throws ValidationException
{
if (value == null || value.toString().equals(""))
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/ValidationMessages.properties Mon Jan 29 17:28:39 2007
@@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# We try to keep these consistent, with the constraint value (if applicable)
+# as the first parameter, and the field's label as the second parameter.
+
required=You must provide a value for %s.
integer-format-exception=The input value '%s' is not parseable as an integer value.
minimum-string-length=You must provide at least %d characters for %s.
+maximum-string-length=You may provide at most %d characters for %s.
+min-integer=%2$s requires a value of at least %1$d.
\ No newline at end of file
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorImplTest.java Mon Jan 29 17:28:39 2007
@@ -40,7 +40,7 @@
FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator);
- fv.check(null);
+ fv.validate(null);
verify();
}
@@ -59,7 +59,7 @@
FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator);
- fv.check("");
+ fv.validate("");
verify();
}
@@ -80,7 +80,7 @@
FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator);
- fv.check(value);
+ fv.validate(value);
verify();
}
@@ -95,13 +95,13 @@
train_skipIfBlank(validator, false);
- validator.check(field, null, formatter, null);
+ validator.validate(field, null, formatter, null);
replay();
FieldValidator fv = new FieldValidatorImpl(field, null, formatter, validator);
- fv.check(null);
+ fv.validate(null);
verify();
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/FieldValidatorSourceImplTest.java Mon Jan 29 17:28:39 2007
@@ -109,7 +109,7 @@
train_skipIfBlank(validator, true);
train_getValueType(validator, Object.class);
- validator.check(field, null, formatter, inputValue);
+ validator.validate(field, null, formatter, inputValue);
replay();
@@ -117,7 +117,7 @@
FieldValidator fieldValidator = source.createValidator(field, "required", null);
- fieldValidator.check(inputValue);
+ fieldValidator.validate(inputValue);
verify();
}
@@ -150,7 +150,7 @@
train_skipIfBlank(validator, true);
train_getValueType(validator, Object.class);
- validator.check(field, null, formatter, inputValue);
+ validator.validate(field, null, formatter, inputValue);
replay();
@@ -158,7 +158,7 @@
FieldValidator fieldValidator = source.createValidator(field, "required", null);
- fieldValidator.check(inputValue);
+ fieldValidator.validate(inputValue);
verify();
}
@@ -197,7 +197,7 @@
train_skipIfBlank(validator, true);
train_getValueType(validator, Object.class);
- validator.check(field, null, formatter, inputValue);
+ validator.validate(field, null, formatter, inputValue);
replay();
@@ -205,7 +205,7 @@
FieldValidator fieldValidator = source.createValidators(field, "required");
- fieldValidator.check(inputValue);
+ fieldValidator.validate(inputValue);
verify();
}
@@ -258,11 +258,11 @@
train_skipIfBlank(required, false);
train_getValueType(required, Object.class);
- required.check(field, null, requiredFormatter, inputValue);
+ required.validate(field, null, requiredFormatter, inputValue);
train_skipIfBlank(minLength, true);
train_getValueType(minLength, String.class);
- minLength.check(field, fifteen, minLengthFormatter, inputValue);
+ minLength.validate(field, fifteen, minLengthFormatter, inputValue);
replay();
@@ -270,7 +270,7 @@
FieldValidator fieldValidator = source.createValidators(field, "required,minLength=15");
- fieldValidator.check(inputValue);
+ fieldValidator.validate(inputValue);
verify();
}
@@ -312,7 +312,7 @@
train_skipIfBlank(validator, true);
train_getValueType(validator, Object.class);
- validator.check(field, five, formatter, inputValue);
+ validator.validate(field, five, formatter, inputValue);
replay();
@@ -320,7 +320,7 @@
FieldValidator fieldValidator = source.createValidator(field, "minLength", "5");
- fieldValidator.check(inputValue);
+ fieldValidator.validate(inputValue);
verify();
}
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MaxLengthTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MaxLengthTest.java?view=auto&rev=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MaxLengthTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MaxLengthTest.java Mon Jan 29 17:28:39 2007
@@ -0,0 +1,69 @@
+// Copyright 2007 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.tapestry.validator;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.ioc.MessageFormatter;
+import org.testng.annotations.Test;
+
+public class MaxLengthTest extends InternalBaseTestCase
+{
+ @Test
+ public void short_enough() throws Exception
+ {
+ Field field = newField();
+ MessageFormatter formatter = newMessageFormatter();
+ String value = "Now the student has become the master.";
+
+ replay();
+
+ MaxLength validator = new MaxLength();
+
+ validator.validate(field, value.length(), formatter, value);
+
+ verify();
+ }
+
+ @Test
+ public void long_value() throws Exception
+ {
+ String label = "My Field";
+ Field field = newFieldWithLabel(label);
+ MessageFormatter formatter = newMessageFormatter();
+ String value = "Now the student has become the master.";
+ String message = "{message}";
+ Integer constraint = value.length() - 1;
+
+ train_format(formatter, message, constraint, label);
+
+ replay();
+
+ MaxLength validator = new MaxLength();
+
+ try
+ {
+ validator.validate(field, constraint, formatter, value);
+ unreachable();
+ }
+ catch (ValidationException ex)
+ {
+ assertEquals(ex.getMessage(), message);
+ }
+
+ verify();
+ }
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinLengthTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinLengthTest.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinLengthTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinLengthTest.java Mon Jan 29 17:28:39 2007
@@ -34,10 +34,9 @@
MinLength validator = new MinLength();
- validator.check(field, value.length(), formatter, value);
+ validator.validate(field, value.length(), formatter, value);
verify();
-
}
@Test
@@ -58,7 +57,7 @@
try
{
- validator.check(field, constraint, formatter, value);
+ validator.validate(field, constraint, formatter, value);
unreachable();
}
catch (ValidationException ex)
@@ -67,6 +66,5 @@
}
verify();
-
}
}
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinTest.java?view=auto&rev=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/MinTest.java Mon Jan 29 17:28:39 2007
@@ -0,0 +1,70 @@
+// Copyright 2007 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.tapestry.validator;
+
+import org.apache.tapestry.Field;
+import org.apache.tapestry.ValidationException;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.ioc.MessageFormatter;
+import org.testng.annotations.Test;
+
+public class MinTest extends InternalBaseTestCase
+{
+ @Test
+ public void large_enough() throws Exception
+ {
+ Field field = newField();
+ MessageFormatter formatter = newMessageFormatter();
+ Long constraint = 50l;
+
+ replay();
+
+ Min validator = new Min();
+
+ for (int value = 50; value < 52; value++)
+ validator.validate(field, constraint, formatter, value);
+
+ verify();
+ }
+
+ @Test
+ public void value_too_small() throws Exception
+ {
+ String label = "My Field";
+ Field field = newFieldWithLabel(label);
+ MessageFormatter formatter = newMessageFormatter();
+ String message = "{message}";
+ Long constraint = 100l;
+ Number value = 99;
+
+ train_format(formatter, message, constraint, label);
+
+ replay();
+
+ Min validator = new Min();
+
+ try
+ {
+ validator.validate(field, constraint, formatter, value);
+ unreachable();
+ }
+ catch (ValidationException ex)
+ {
+ assertEquals(ex.getMessage(), message);
+ }
+
+ verify();
+ }
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java?view=diff&rev=501273&r1=501272&r2=501273
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/validator/RequiredTest.java Mon Jan 29 17:28:39 2007
@@ -34,7 +34,7 @@
try
{
- new Required().check(field, null, formatter, null);
+ new Required().validate(field, null, formatter, null);
unreachable();
}
catch (ValidationException ex)
@@ -57,7 +57,7 @@
try
{
- new Required().check(field, null, formatter, "");
+ new Required().validate(field, null, formatter, "");
unreachable();
}
catch (ValidationException ex)
@@ -76,7 +76,7 @@
replay();
- new Required().check(field, null, formatter, "not null");
+ new Required().validate(field, null, formatter, "not null");
verify();
}