Author: hardy.ferentschik
Date: 2009-08-05 12:13:53 -0400 (Wed, 05 Aug 2009)
New Revision: 17231
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/messageinterpolation/MessageInterpolationTest.java
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
message interpolation tests
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/messageinterpolation/MessageInterpolationTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/messageinterpolation/MessageInterpolationTest.java 2009-08-04
22:04:27 UTC (rev 17230)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/messageinterpolation/MessageInterpolationTest.java 2009-08-05
16:13:53 UTC (rev 17231)
@@ -17,6 +17,7 @@
*/
package org.hibernate.jsr303.tck.tests.messageinterpolation;
+import java.util.Date;
import java.util.Locale;
import java.util.Set;
import javax.validation.ConstraintViolation;
@@ -24,6 +25,7 @@
import javax.validation.Validator;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import javax.validation.metadata.ConstraintDescriptor;
@@ -37,6 +39,7 @@
import org.jboss.testharness.impl.packaging.Resource;
import org.jboss.testharness.impl.packaging.Resources;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import org.testng.annotations.Test;
@@ -75,7 +78,7 @@
public void testSuccessfullInterpolationOfValidationMessagesValue() {
MessageInterpolator interpolator = getDefaultMessageInterpolator();
- ConstraintDescriptor<?> descriptor = getDescriptorFor( "foo" );
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class,
"foo" );
MessageInterpolator.Context context = new TestContext( descriptor );
String expected = "replacement worked";
@@ -99,7 +102,7 @@
@SpecAssertion(section = "4.3.1.1", id = "b")
public void testRecursiveMessageInterpoliation() {
MessageInterpolator interpolator = getDefaultMessageInterpolator();
- ConstraintDescriptor<?> descriptor = getDescriptorFor( "fubar" );
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class,
"fubar" );
MessageInterpolator.Context context = new TestContext( descriptor );
String expected = "recursion worked";
@@ -132,7 +135,7 @@
public void testLiteralCurlyBraces() {
MessageInterpolator interpolator = getDefaultMessageInterpolator();
- ConstraintDescriptor<?> descriptor = getDescriptorFor( "foo" );
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class,
"foo" );
MessageInterpolator.Context context = new TestContext( descriptor );
String expected = "{";
@@ -152,7 +155,7 @@
@SpecAssertion(section = "4.3.1.1", id = "a")
public void testUnSuccessfulInterpolation() {
MessageInterpolator interpolator = getDefaultMessageInterpolator();
- ConstraintDescriptor<?> descriptor = getDescriptorFor( "foo" );
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class,
"foo" );
MessageInterpolator.Context context = new TestContext( descriptor );
String expected = "foo"; // missing {}
@@ -168,7 +171,7 @@
@SpecAssertion(section = "4.3.1.1", id = "a")
public void testUnkownTokenInterpolation() {
MessageInterpolator interpolator = getDefaultMessageInterpolator();
- ConstraintDescriptor<?> descriptor = getDescriptorFor( "foo" );
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class,
"foo" );
MessageInterpolator.Context context = new TestContext( descriptor );
String expected = "{bar}"; // unkown token {}
@@ -177,10 +180,25 @@
}
@Test
+ @SpecAssertion(section = "4.3.1.1", id = "c")
+ public void testParametersAreExtractedFromBeanValidationProviderBundle() {
+ MessageInterpolator interpolator = getDefaultMessageInterpolator();
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( Person.class,
"birthday" );
+ MessageInterpolator.Context context = new TestContext( descriptor );
+
+ String key = "{javax.validation.constraints.Past.message}"; // Past is a
builtin constraint so the provider must provide a default message
+ String actual = interpolator.interpolate( key, context );
+ assertFalse(
+ key.equals( actual ),
+ "There should have been a message interpolation from the bean validator provider
bundle."
+ );
+ }
+
+ @Test
@SpecAssertion(section = "4.3.1.1", id = "g")
- public void testDefaultInterpolation() {
+ public void testConstraintAttributeValuesAreInterpolated() {
MessageInterpolator interpolator = getDefaultMessageInterpolator();
- ConstraintDescriptor<?> descriptor = getDescriptorFor( "bar" );
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class,
"bar" );
MessageInterpolator.Context context = new TestContext( descriptor );
String expected = "size must be between 5 and 10";
@@ -192,7 +210,7 @@
@SpecAssertion(section = "4.3.1.1", id = "h")
public void testMessageInterpolationWithLocale() {
MessageInterpolator interpolator = getDefaultMessageInterpolator();
- ConstraintDescriptor<?> descriptor = getDescriptorFor( "foo" );
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class,
"foo" );
MessageInterpolator.Context context = new TestContext( descriptor );
String expected = "kann nicht null sein";
@@ -206,7 +224,7 @@
@SpecAssertion(section = "4.3.1.1", id = "i")
public void testFallbackToDefaultLocale() {
MessageInterpolator interpolator = getDefaultMessageInterpolator();
- ConstraintDescriptor<?> descriptor = getDescriptorFor( "foo" );
+ ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class,
"foo" );
MessageInterpolator.Context context = new TestContext( descriptor );
String expected = "may not be null";
@@ -220,9 +238,9 @@
assertEquals( actual, expected, "Wrong substitution" );
}
- private ConstraintDescriptor<?> getDescriptorFor(String propertyName) {
+ private ConstraintDescriptor<?> getDescriptorFor(Class<?> clazz, String
propertyName) {
Validator validator = getValidatorUnderTest();
- return validator.getConstraintsForClass( DummyEntity.class )
+ return validator.getConstraintsForClass( clazz )
.getConstraintsForProperty( propertyName )
.getConstraintDescriptors()
.iterator()
@@ -258,4 +276,12 @@
@NotNull(message = "messages can also be overridden at constraint
declaration.")
String snafu;
}
+
+ public class Person {
+
+ String name;
+
+ @Past
+ Date birthday;
+ }
}
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-08-04
22:04:27 UTC (rev 17230)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-08-05
16:13:53 UTC (rev 17231)
@@ -281,22 +281,26 @@
are used</text>
</assertion>
<assertion id="c">
- <text>Array of objects is supported by @Valid. The content of the array
is validated.</text>
+ <text>Array of objects is supported by @Valid. The content of the array
is
+ validated.</text>
</assertion>
<assertion id="d">
- <text>java.util.Collection is supported by @Valid. The content of the
collection is validated.</text>
+ <text>java.util.Collection is supported by @Valid. The content of the
collection is
+ validated.</text>
</assertion>
<assertion id="e">
<text>java.util.Set is supported by @Valid. The content of the Set is
validated.</text>
</assertion>
<assertion id="f">
- <text>java.util.List is supported by @Valid. The content of the list is
validated.</text>
+ <text>java.util.List is supported by @Valid. The content of the list
is
+ validated.</text>
</assertion>
<assertion id="g">
<text>java.util.Map is supported by @Valid</text>
</assertion>
<assertion id="h">
- <text>java.lang.Iterable is supported by @Valid. The elements of the
iterable are validated</text>
+ <text>java.lang.Iterable is supported by @Valid. The elements of the
iterable are
+ validated</text>
</assertion>
<assertion id="i">
<text>For Map, the value of each entry is validated (the key is not
validated)</text>
@@ -374,8 +378,9 @@
is raised.</text>
</assertion>
<assertion id="g" testable="false">
- <text>Groups defining a sequence should not directly inherit other
groups. In other words, the interface hosting the group
- sequence should not have any super interface.</text>
+ <text>Groups defining a sequence should not directly inherit other
groups. In other
+ words, the interface hosting the group sequence should not have any
super
+ interface.</text>
</assertion>
<assertion id="h" testable="false">
<text>Groups defining a sequence should not be used directly in
constraint
@@ -452,16 +457,18 @@
</section>
<section id="3.5.2" title="Traversable property">
<assertion id="a">
- <text>isReachable is called for every property about to be accessed
either for validation or for cascading</text>
+ <text>isReachable is called for every property about to be accessed
either for
+ validation or for cascading</text>
</assertion>
<assertion id="b">
- <text>isCascadable is called for every property about to be cascaded
(ie. marked as @Valid)</text>
+ <text>isCascadable is called for every property about to be cascaded
(ie. marked as
+ @Valid)</text>
</assertion>
<assertion id="c">
<text>isCascadable for a given property is only called if isReachable
returns true. In
other words, isReachable is always called before isCascadable for a
given
property</text>
- </assertion>
+ </assertion>
<assertion id="d">
<text>The Bean Validation provider must not access the state of a
property, nor validate
its constraints if the property is not traversable. A property is
traversable if
@@ -480,7 +487,8 @@
are considered reachable</text>
</assertion>
<assertion id="h" testable="false">
- <text>If Java Persistence is not available in the runtime environment,
all properties are considered cascadable</text>
+ <text>If Java Persistence is not available in the runtime environment,
all properties
+ are considered cascadable</text>
</assertion>
</section>
<section id="3.5.3" title="ConstraintValidator resolution
algorithm">
@@ -524,7 +532,8 @@
<text>validate(T object, Class... groups) is used to validate a given
object</text>
</assertion>
<assertion id="b">
- <text>An IllegalArgumentException is thrown when validateProperty is
called and object is null or null is passed to the varargs groups.</text>
+ <text>An IllegalArgumentException is thrown when validateProperty is
called and object
+ is null or null is passed to the varargs groups.</text>
</assertion>
<assertion id="c">
<text>A Set containing all ConstraintViolation objects representing the
failing
@@ -535,12 +544,13 @@
field or property of an object</text>
</assertion>
<assertion id="e">
- <text>An IllegalArgumentException is thrown when validateProperty is
called and object is null or propertyName is null
- empty or invalid or null is passed to the varargs groups.</text>
+ <text>An IllegalArgumentException is thrown when validateProperty is
called and object
+ is null or propertyName is null empty or invalid or null is passed to the
varargs
+ groups.</text>
</assertion>
<assertion id="f">
- <text>The property name in validateProperty is the JavaBeans property
name (as defined by the JavaBeans
- Introspector class)</text>
+ <text>The property name in validateProperty is the JavaBeans property
name (as defined
+ by the JavaBeans Introspector class)</text>
</assertion>
<assertion id="g">
<text>@Valid is not honored by a call to
validateProperty.</text>
@@ -551,8 +561,9 @@
superclasses, if the property value were value.</text>
</assertion>
<assertion id="i">
- <text>An IllegalArgumentException is thrown when validateValue is
called and object is null or propertyName is null
- empty or invalid or null is passed to the varargs groups.</text>
+ <text>An IllegalArgumentException is thrown when validateValue is
called and object is
+ null or propertyName is null empty or invalid or null is passed to the
varargs
+ groups.</text>
</assertion>
<assertion id="j">
<text>@Valid is not honored by validateValue.</text>
@@ -564,7 +575,8 @@
</section>
<section id="4.1.2" title="groups">
<assertion id="a">
- <text>All constraints belonging to the targeted group are applied
during the validation routine.</text>
+ <text>All constraints belonging to the targeted group are applied
during the validation
+ routine.</text>
</assertion>
<assertion id="b">
<text>If no group is passed, the Default group is assumed</text>
@@ -594,37 +606,38 @@
<text>getConstraintDescriptor provides access to the failing constraint
metadata</text>
</assertion>
<assertion id="f">
- <text>getPropertyPath returns the Path object representing the
navigation path from the root object to the failing
- object</text>
- </assertion>
+ <text>getPropertyPath returns the Path object representing the
navigation path from the
+ root object to the failing object</text>
+ </assertion>
<assertion id="g">
- <text>If the failing object is the root object, the property path
consists of a single Node with name set to null.</text>
- </assertion>
+ <text>If the failing object is the root object, the property path
consists of a single
+ Node with name set to null.</text>
+ </assertion>
<assertion id="h">
- <text>If failing object is traversed, a Node object whose name equals
the name of the association property (field name or Java Bean property
- name) is added to Path.
+ <text>If failing object is traversed, a Node object whose name equals
the name of the
+ association property (field name or Java Bean property name) is added to
Path.
</text>
- </assertion>
+ </assertion>
<assertion id="i">
- <text>If the traversed association is a List or an array, the added
Node object contains the index value in getIndex.
- </text>
- </assertion>
+ <text>If the traversed association is a List or an array, the added
Node object contains
+ the index value in getIndex. </text>
+ </assertion>
<assertion id="j">
- <text>If the association is a Map, the added Node object (representing
a given map entry) contains the key value in getKey
- </text>
- </assertion>
+ <text>If the association is a Map, the added Node object (representing
a given map
+ entry) contains the key value in getKey </text>
+ </assertion>
<assertion id="k">
- <text>For all Iterable or Map, the added Node object added is marked as
inIterable (isInIterable)
- </text>
+ <text>For all Iterable or Map, the added Node object added is marked as
inIterable
+ (isInIterable) </text>
</assertion>
<assertion id="l">
- <text>For a property level constraint (field and getter) a Node object
is added to Path whose name equals the name of the property.
- </text>
- </assertion>
+ <text>For a property level constraint (field and getter) a Node object
is added to Path
+ whose name equals the name of the property. </text>
+ </assertion>
<assertion id="m">
- <text>For a class level constraint a Node object is added to Path whose
name is null
+ <text>For a class level constraint a Node object is added to Path whose
name is null
</text>
- </assertion>
+ </assertion>
</section>
<section id="4.3.1" title="Default message interpolation">
<assertion id="a">
@@ -672,10 +685,12 @@
locale. If a property is found, the message parameter is replaced with
the property
value in the message string (step 2)</text>
</assertion>
- <assertion id="e">
+ <assertion id="e" testable="false">
+ <!-- in order to test one would have to make assumptions about the
provider specific resource bundle -->
<text>Contrary to step 1, step 2 is not processed
recursively</text>
</assertion>
- <assertion id="f">
+ <assertion id="f" testable="false">
+ <!-- in order to test one would have to make assumptions about the
provider specific resource bundle -->
<text>If step 2 triggers a replacement, then step 1 is applied
again</text>
</assertion>
<assertion id="g">
@@ -684,11 +699,12 @@
value of that attribute.</text>
</assertion>
<assertion id="h">
- <text>if the locale is passed to the interpolator method
interpolate(String,
+ <text>If the locale is passed to the interpolator method
interpolate(String,
CosntraintDescriptor, Object, Locale), this Locale instance is
used</text>
</assertion>
<assertion id="i">
- <text>otherwise, the default Locale as provided by Locale.getDefault()
is used.</text>
+ <text>If the locale is not specified, the default Locale as provided
by
+ Locale.getDefault() is used.</text>
</assertion>
</section>
<section id="4.3.2" title="Custom message interpolation">
@@ -807,9 +823,8 @@
providers</text>
</assertion>
<assertion id="c">
- <text>When building the Configuration object, if the
ValidationProviderResolver
- fais or if the expected provider is not found, a ValidationException is
- raised</text>
+ <text>When building the Configuration object, if the
ValidationProviderResolver fais or
+ if the expected provider is not found, a ValidationException is
raised</text>
</assertion>
</section>
<section id="4.4.6" title="XML Configuration">
@@ -893,12 +908,14 @@
invalid, a ValidationException is raised</text>
</assertion>
<assertion id="b">
- <text>Validator.getConstraintsForClass returns a BeanDescriptor object
describing the bean level constraints
- and providing access to the property level constraints metadata.
</text>
- </assertion>
+ <text>Validator.getConstraintsForClass returns a BeanDescriptor object
describing the
+ bean level constraints and providing access to the property level
constraints
+ metadata. </text>
+ </assertion>
<assertion id="c">
- <text>Validator.getConstraintsForClass throws an
IllegalArgumentException if the clazz parameter is null</text>
- </assertion>
+ <text>Validator.getConstraintsForClass throws an
IllegalArgumentException if the clazz
+ parameter is null</text>
+ </assertion>
</section>
<section id="5.3" title="BeanDescriptor">
<assertion id="a">