Author: hardy.ferentschik
Date: 2009-03-03 09:26:08 -0500 (Tue, 03 Mar 2009)
New Revision: 16060
Modified:
validator/trunk/hibernate-validator/pom.xml
validator/trunk/hibernate-validator/readme.txt
validator/trunk/hibernate-validator/src/main/assembly/dist.xml
validator/trunk/hibernate-validator/src/main/docbook/en-US/master.xml
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java
Log:
HV-114 Changed the implementation so that property in addError(String message, String
property) in ConstraintValidatorContext is relative to the current validation. Added test
Made sure the referenced versions of correct. Updated the NYI sections.
Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml 2009-03-03 11:29:09 UTC (rev 16059)
+++ validator/trunk/hibernate-validator/pom.xml 2009-03-03 14:26:08 UTC (rev 16060)
@@ -22,7 +22,7 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
- <version>1.0.Beta4-SNAPSHOT</version>
+ <version>1.0.Beta4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: validator/trunk/hibernate-validator/readme.txt
===================================================================
--- validator/trunk/hibernate-validator/readme.txt 2009-03-03 11:29:09 UTC (rev 16059)
+++ validator/trunk/hibernate-validator/readme.txt 2009-03-03 14:26:08 UTC (rev 16060)
@@ -22,14 +22,13 @@
This is an alpha release and not feature complete in relation to the latest version
of JSR 303. The following features are not yet fully implemented:
- - Group inheritance using interfaces and implicit grouping
+ - Implicit grouping
- Implementation of the TraversableResolver interface to allow integration with JPA
- - Polymorphism in graph validation
- XML configuration
You can find more information about the current state of the implementation on the
Bean Validation RI Roadmap -
http://www.hibernate.org/459.html and there is copy of
- JSR as of the time of this release available here -
http://in.relation.to/service/File/10678
+ JSR as of the time of this release available here -
http://in.relation.to/service/File/10774
Documentation
-------------
@@ -61,7 +60,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
- <version>x.y.z</version>
+ <version>${project.version}</version>
</dependency>
Hibernate Validator can be found in this repository:
http://repository.jboss.com/maven2/
Modified: validator/trunk/hibernate-validator/src/main/assembly/dist.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/assembly/dist.xml 2009-03-03 11:29:09 UTC
(rev 16059)
+++ validator/trunk/hibernate-validator/src/main/assembly/dist.xml 2009-03-03 14:26:08 UTC
(rev 16060)
@@ -34,6 +34,18 @@
</dependencySet>
</dependencySets>
+ <files>
+ <file>
+ <source>readme.txt</source>
+ <outputDirectory>/</outputDirectory>
+ <filtered>true</filtered>
+ </file>
+ <file>
+ <source>license.txt</source>
+ <outputDirectory>/</outputDirectory>
+ </file>
+ </files>
+
<fileSets>
<fileSet>
<directory>target</directory>
@@ -55,6 +67,7 @@
<outputDirectory></outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<excludes>
+ <exclude>*.txt</exclude>
<exclude>**/target/**</exclude>
<exclude>*.iml</exclude>
</excludes>
Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/master.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/master.xml 2009-03-03
11:29:09 UTC (rev 16059)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/master.xml 2009-03-03
14:26:08 UTC (rev 16060)
@@ -69,12 +69,12 @@
implementation nor this documenation is complete. However, implementation
should be in a state allowing first experiments with this new API. The
following list shows the missing features in relation to the <ulink
- url="http://in.relation.to/service/File/10678">1.0.Beta3 version of JSR
+ url="http://in.relation.to/service/File/10774">1.0.Beta4 version of JSR
303</ulink> :</para>
<itemizedlist>
<listitem>
- <para>Group inheritance using interfaces and implicit
grouping</para>
+ <para>Implicit grouping</para>
</listitem>
<listitem>
@@ -83,10 +83,6 @@
</listitem>
<listitem>
- <para>Polymorphism in graph validation</para>
- </listitem>
-
- <listitem>
<para>XML configuration</para>
</listitem>
</itemizedlist>
Modified:
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml
===================================================================
---
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml 2009-03-03
11:29:09 UTC (rev 16059)
+++
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml 2009-03-03
14:26:08 UTC (rev 16060)
@@ -357,7 +357,7 @@
<para>That concludes our 5 minute tour through the world of the Bean
Validation RI. We will complete this documentation in our coming releases.
For now we recommend to refer to the JSR 303 specification directly for
- more examples. The 1.0.Beta3 version of this specification is available
- <ulink
url="http://in.relation.to/service/File/10678">here</ulink>.</para>
+ more examples. The 1.0.Beta4 version of this specification is available
+ <ulink
url="http://in.relation.to/service/File/10774">here</ulink>.</para>
</section>
</chapter>
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-03-03
11:29:09 UTC (rev 16059)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java 2009-03-03
14:26:08 UTC (rev 16060)
@@ -43,6 +43,8 @@
private static final String PROPERTY_ROOT = "";
+ private static final String PROPERTY_PATH_SEPERATOR = ".";
+
/**
* The root bean of the validation.
*/
@@ -76,7 +78,7 @@
private ValidatedProperty currentValidatedProperty;
/**
- * Stack for keeping track of the currently validated bean.
+ * Stack for keeping track of the currently validated bean.
*/
private Stack<Object> beanStack = new Stack<Object>();
@@ -207,8 +209,8 @@
* @param property the new property to add to the current path.
*/
public void pushProperty(String property) {
+ currentValidatedProperty = new ValidatedProperty( peekPropertyPath(), property );
propertyPath.add( property );
- currentValidatedProperty = new ValidatedProperty( peekPropertyPath() );
}
/**
@@ -238,10 +240,12 @@
public String peekPropertyPath() {
StringBuilder builder = new StringBuilder();
- for ( String s : propertyPath ) {
- builder.append( s ).append( "." );
+ for ( int i = 0; i <= propertyPath.size() - 1; i++ ) {
+ builder.append( propertyPath.get( i ) );
+ if ( i < propertyPath.size() - 1 ) {
+ builder.append( PROPERTY_PATH_SEPERATOR );
+ }
}
- builder.delete( builder.lastIndexOf( "." ), builder.length() );
return builder.toString();
}
@@ -297,13 +301,15 @@
class ValidatedProperty {
private final List<ErrorMessage> errorMessages = new
ArrayList<ErrorMessage>( 3 );
+ private final String property;
+ private final String propertyParent;
private ConstraintDescriptor constraintDescriptor;
private boolean defaultDisabled;
- private String property;
- private ValidatedProperty(String property) {
+ private ValidatedProperty(String propertyParent, String property) {
this.property = property;
+ this.propertyParent = propertyParent;
}
public void setConstraintDescriptor(ConstraintDescriptor constraintDescriptor) {
@@ -327,20 +333,31 @@
}
public void addError(String message) {
- errorMessages.add( new ErrorMessage( message, property ) );
+ errorMessages.add( new ErrorMessage( message, buildPropertyPath( propertyParent,
property ) ) );
}
public void addError(String message, String property) {
- errorMessages.add( new ErrorMessage( message, property ) );
+ errorMessages.add( new ErrorMessage( message, buildPropertyPath( propertyParent,
property ) ) );
}
public List<ErrorMessage> getErrorMessages() {
List<ErrorMessage> returnedErrorMessages = new ArrayList<ErrorMessage>(
errorMessages );
if ( !defaultDisabled ) {
- returnedErrorMessages.add( new ErrorMessage( getDefaultErrorMessage(), property ) );
+ returnedErrorMessages.add(
+ new ErrorMessage( getDefaultErrorMessage(), buildPropertyPath( propertyParent,
property ) )
+ );
}
return returnedErrorMessages;
}
+
+ private String buildPropertyPath(String parent, String leaf) {
+ if ( PROPERTY_ROOT.equals( parent ) ) {
+ return leaf;
+ }
+ else {
+ return new StringBuilder().append( parent ).append( PROPERTY_PATH_SEPERATOR ).append(
leaf ).toString();
+ }
+ }
}
public class ErrorMessage {
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java 2009-03-03
11:29:09 UTC (rev 16059)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java 2009-03-03
14:26:08 UTC (rev 16060)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -23,6 +23,8 @@
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
@@ -37,6 +39,9 @@
public void testNoCustomization() {
Validator validator = TestUtil.getValidator();
+ DummyValidator.disableDefaultError( false );
+ DummyValidator.setErrorMessages( null );
+
DummyBean bean = new DummyBean( "foobar" );
Set<ConstraintViolation<DummyBean>> constraintViolations =
validator.validate( bean );
@@ -52,9 +57,12 @@
public void testDisableDefaultErrorWithoutCustomError() {
Validator validator = TestUtil.getValidator();
- DummyBean bean = new DummyBean( "foobar" );
DummyValidator.disableDefaultError( true );
+ Map<String, String> errors = new HashMap<String, String>();
+ DummyValidator.setErrorMessages( errors );
+ DummyBean bean = new DummyBean( "foobar" );
+
Set<ConstraintViolation<DummyBean>> constraintViolations =
validator.validate( bean );
assertEquals( "Wrong number of constraints", 0, constraintViolations.size()
);
}
@@ -63,16 +71,46 @@
public void testDisableDefaultErrorWithCustomErrors() {
Validator validator = TestUtil.getValidator();
- DummyBean bean = new DummyBean( "foobar" );
DummyValidator.disableDefaultError( true );
Map<String, String> errors = new HashMap<String, String>();
errors.put( "message1", "property1" );
DummyValidator.setErrorMessages( errors );
+ DummyBean bean = new DummyBean( "foobar" );
+
Set<ConstraintViolation<DummyBean>> constraintViolations =
validator.validate( bean );
assertEquals( "Wrong number of constraints", 1, constraintViolations.size()
);
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
assertEquals( "Wrong message", "message1",
constraintViolation.getMessage() );
assertEquals( "Wrong property", "property1",
constraintViolation.getPropertyPath() );
}
+
+ @Test
+ public void testNestedValidation() {
+ Validator validator = TestUtil.getValidator();
+
+ DummyValidator.disableDefaultError( false );
+ DummyValidator.setErrorMessages( null );
+
+ DummyBean bean = new DummyBean( "foo" );
+ bean.setNestedDummy( new DummyBean( "bar" ) );
+
+ Set<ConstraintViolation<DummyBean>> constraintViolations =
validator.validate( bean );
+ assertEquals( "Wrong number of constraints", 2, constraintViolations.size()
);
+ boolean validatedNestedBean = false;
+ for ( ConstraintViolation<DummyBean> violation : constraintViolations ) {
+
+ if ( violation.getPropertyPath().equals( "value" ) ) {
+ assertEquals( "Wrong message", "dummy message",
violation.getMessage() );
+ }
+ else if ( violation.getPropertyPath().equals( "nestedDummy.value" ) ) {
+ assertEquals( "Wrong message", "dummy message",
violation.getMessage() );
+ validatedNestedBean = true;
+ }
+ else {
+ fail( "Wrong property " + violation.getMessage() );
+ }
+ }
+ assertTrue( validatedNestedBean );
+ }
}
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java 2009-03-03
11:29:09 UTC (rev 16059)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/DummyBean.java 2009-03-03
14:26:08 UTC (rev 16060)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -17,6 +17,8 @@
*/
package org.hibernate.validation.constraints.validatorcontext;
+import javax.validation.Valid;
+
/**
* @author Hardy Ferentschik
*/
@@ -25,7 +27,14 @@
@Dummy
String value;
+ @Valid
+ DummyBean nestedDummy;
+
public DummyBean(String value) {
this.value = value;
}
+
+ public void setNestedDummy(DummyBean nestedDummy) {
+ this.nestedDummy = nestedDummy;
+ }
}