[hibernate-commits] Hibernate SVN: r16855 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/tests/xmlconfiguration and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Jun 22 10:15:57 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-22 10:15:57 -0400 (Mon, 22 Jun 2009)
New Revision: 16855

Added:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorListBased.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/PlayedWith.java
Removed:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
Modified:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java
   beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
mapped constrinat violation exceptions

Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java	2009-06-22 13:54:37 UTC (rev 16854)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -1,88 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* 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.hibernate.jsr303.tck.tests.validation;
-
-import java.util.ArrayList;
-import java.util.List;
-import javax.validation.Valid;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Actor implements Person {
-
-	private String firstName;
-	private String middleName;
-	private String lastName;
-
-	@Valid
-	private List<Actor> playedWith = new ArrayList<Actor>();
-
-	public Actor() {
-	}
-
-	public Actor(String firstName, String lastName) {
-		this.firstName = firstName;
-		this.lastName = lastName;
-	}
-
-	public List<Actor> getPlayedWith() {
-		return playedWith;
-	}
-
-	public void setPlayedWith(List<Actor> playedWith) {
-		this.playedWith = playedWith;
-	}
-
-	public void addPlayedWith(Actor playedWith) {
-		this.playedWith.add( playedWith );
-	}
-
-	public String getFirstName() {
-		return firstName;
-	}
-
-	public void setFirstName(String firstName) {
-		this.firstName = firstName;
-	}
-
-	public String getMiddleName() {
-		return middleName;
-	}
-
-	public void setMiddleName(String middleName) {
-		this.middleName = middleName;
-	}
-
-	public String getLastName() {
-		return lastName;
-	}
-
-	public void setLastName(String lastName) {
-		this.lastName = lastName;
-	}
-
-	@Override
-	public String toString() {
-		return "Actor{" +
-				"firstName='" + firstName + '\'' +
-				", middleName='" + middleName + '\'' +
-				", lastName='" + lastName + '\'' +
-				'}';
-	}
-}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -0,0 +1,67 @@
+// $Id: ActorListBased.java 16840 2009-06-19 11:38:29Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.jsr303.tck.tests.validation;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public abstract class Actor implements Person, PlayedWith {
+
+	private String firstName;
+	private String middleName;
+	private String lastName;
+
+
+	public Actor(String firstName, String lastName) {
+		this.firstName = firstName;
+		this.lastName = lastName;
+	}
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+	public String getMiddleName() {
+		return middleName;
+	}
+
+	public void setMiddleName(String middleName) {
+		this.middleName = middleName;
+	}
+
+	public String getLastName() {
+		return lastName;
+	}
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+
+	@Override
+	public String toString() {
+		return "Actor{" +
+				"firstName='" + firstName + '\'' +
+				", middleName='" + middleName + '\'' +
+				", lastName='" + lastName + '\'' +
+				'}';
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorArrayBased.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -0,0 +1,50 @@
+// $Id: ActorListBased.java 16840 2009-06-19 11:38:29Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.jsr303.tck.tests.validation;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ActorArrayBased extends Actor {
+	public static final int MAX_ACTOR_SIZE = 100;
+
+	@Valid
+	private Actor[] playedWith = new Actor[MAX_ACTOR_SIZE];
+
+	int currentPointer = 0;
+
+	public ActorArrayBased(String firstName, String lastName) {
+		super( firstName, lastName );
+	}
+
+	public List<Actor> getPlayedWith() {
+		return Arrays.asList( playedWith );
+	}
+
+	public void addPlayedWith(Actor playedWith) {
+		if ( currentPointer == MAX_ACTOR_SIZE ) {
+			throw new RuntimeException( "Exceeded allowed number of actors." );
+		}
+		this.playedWith[currentPointer] = playedWith;
+		currentPointer++;
+	}
+}
\ No newline at end of file

Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorListBased.java (from rev 16842, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorListBased.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorListBased.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -0,0 +1,50 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.jsr303.tck.tests.validation;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ActorListBased extends Actor {
+
+	@Valid
+	private List<Actor> playedWith = new ArrayList<Actor>();
+
+	public ActorListBased(String firstName, String lastName) {
+		super( firstName, lastName );
+	}
+
+	public List<Actor> getPlayedWith() {
+		return playedWith;
+	}
+
+	public void addPlayedWith(Actor playedWith) {
+		this.playedWith.add( playedWith );
+	}
+
+	@Override
+	public String toString() {
+		return "ActorListBased{" +
+				"playedWith=" + playedWith +
+				'}';
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ActorListBased.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java	2009-06-22 13:54:37 UTC (rev 16854)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -27,7 +27,7 @@
 	@Pattern.List({
 			@Pattern(regexp = "^[A-Z0-9-]+$",
 					message = "must contain alphabetical characters only"),
-			@Pattern(regexp = "^....-....-....$", message = "must match ....-....-....")
+			@Pattern(regexp = "^....-....-....$", message = "must match {regexp}")
 	})
 	private String serialNumber;
 

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/PlayedWith.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/PlayedWith.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/PlayedWith.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -0,0 +1,29 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.jsr303.tck.tests.validation;
+
+import java.util.List;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface PlayedWith {
+	List<Actor> getPlayedWith();
+
+	void addPlayedWith(Actor playedWith);
+}

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java	2009-06-22 13:54:37 UTC (rev 16854)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -155,9 +155,9 @@
 	public void testValidatePropertyWithIndexedPath() {
 		Validator validator = TestUtil.getDefaultValidator();
 
-		Actor clint = new Actor( "Clint", "Eastwood" );
-		Actor morgan = new Actor( "Morgan", null );
-		Actor charlie = new Actor( "Charlie", "Sheen" );
+		ActorListBased clint = new ActorListBased( "Clint", "Eastwood" );
+		ActorListBased morgan = new ActorListBased( "Morgan", null );
+		ActorListBased charlie = new ActorListBased( "Charlie", "Sheen" );
 
 		clint.addPlayedWith( charlie );
 		charlie.addPlayedWith( clint );
@@ -167,14 +167,14 @@
 		clint.addPlayedWith( morgan );
 
 		String property = "playedWith[0].playedWith[1].lastName";
-		Set<ConstraintViolation<Actor>> constraintViolations = validator.validateProperty(
+		Set<ConstraintViolation<ActorListBased>> constraintViolations = validator.validateProperty(
 				clint, property
 		);
 		assertCorrectNumberOfViolations( constraintViolations, 1 );
 
-		ConstraintViolation<Actor> violation = constraintViolations.iterator().next();
+		ConstraintViolation<ActorListBased> violation = constraintViolations.iterator().next();
 		assertCorrectConstraintType( violation, NotNull.class );
-		assertConstraintViolation( violation, Actor.class, null, property );
+		assertConstraintViolation( violation, ActorListBased.class, null, property );
 		assertCorrectConstraintViolationMessage( violation, "Everyone has a last name." );
 	}
 }
\ No newline at end of file

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java	2009-06-22 13:54:37 UTC (rev 16854)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -21,17 +21,20 @@
 import javax.validation.ConstraintViolation;
 import javax.validation.ValidationException;
 import javax.validation.Validator;
+import javax.validation.constraints.Pattern;
 import javax.validation.groups.Default;
 import javax.validation.metadata.BeanDescriptor;
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
 
 import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
 import org.jboss.testharness.AbstractTest;
 import org.jboss.testharness.impl.packaging.Artifact;
 import org.jboss.testharness.impl.packaging.ArtifactType;
 import org.jboss.testharness.impl.packaging.Classes;
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 import org.testng.annotations.Test;
@@ -48,7 +51,10 @@
 public class ValidateTest extends AbstractTest {
 
 	@Test
-	@SpecAssertion(section = "5.1", id = "a")
+	@SpecAssertions({
+			@SpecAssertion(section = "3.1", id = "a"),
+			@SpecAssertion(section = "5.1", id = "a")
+	})
 	public void testValidatedPropertyDoesNotFollowJavaBeansConvention() {
 		try {
 			Boy boy = new Boy();
@@ -58,65 +64,33 @@
 		catch ( ValidationException e ) {
 			// success
 		}
+
 	}
 
 	@Test
-	@SpecAssertion(section = "5.1", id = "a")
-	public void testBasicValidation() {
+	@SpecAssertion(section = "4.1.1", id = "c")
+	public void testMultipleViolationOfTheSameType() {
 		Validator validator = TestUtil.getDefaultValidator();
 
-		Customer customer = new Customer();
-		customer.setFirstName( "John" );
+		Engine engine = new Engine();
+		engine.setSerialNumber( "mail at foobar.com" );
+		Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
+		assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
 
-		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+		engine.setSerialNumber( "ABCDEFGH1234" );
+		constraintViolations = validator.validate( engine );
 		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
 
-		customer.setLastName( "Doe" );
-
-		constraintViolations = validator.validate( customer );
+		engine.setSerialNumber( "ABCD-EFGH-1234" );
+		constraintViolations = validator.validate( engine );
 		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
 	}
 
-	@Test(expectedExceptions = IllegalArgumentException.class)
-	public void testNullParamterToValidatorImplConstructor() {
-		TestUtil.getDefaultValidator().getConstraintsForClass( null );
-	}
-
-	@Test(expectedExceptions = IllegalArgumentException.class)
-	public void testValidateWithNull() {
-		Validator validator = TestUtil.getDefaultValidator();
-		validator.validate( null );
-	}
-
 	@Test
-	@SuppressWarnings("NullArgumentToVariableArgMethod")
-	public void testPassingNullAsGroup() {
+	@SpecAssertion(section = "4.1.1", id = "c")
+	public void testMultipleConstraintViolationOfDifferentTypes() {
 		Validator validator = TestUtil.getDefaultValidator();
-		Customer customer = new Customer();
-		try {
-			validator.validate( customer, null );
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
-	}
 
-	@Test
-	public void testValidateWithNullProperty() {
-		Validator validator = TestUtil.getDefaultValidator();
-		try {
-			validator.validate( null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
-	}
-
-	@Test
-	public void testMultipleValidationMethods() {
-		Validator validator = TestUtil.getDefaultValidator();
-
 		Address address = new Address();
 		address.setAddressline1( null );
 		address.setAddressline2( null );
@@ -126,58 +100,77 @@
 		assertEquals(
 				constraintViolations.size(),
 				3,
-				"we should have been 2 not null violation for addresslines and one length violation for city"
+				"We should have been 2 @NotNull violations for addresslines and one @Length violation for city."
 		);
 	}
 
 	@Test
-	public void testValidateSet() {
+	@SpecAssertions({
+			@SpecAssertion(section = "3.1", id = "a"),
+			@SpecAssertion(section = "4.2", id = "a"),
+			@SpecAssertion(section = "4.2", id = "b"),
+			@SpecAssertion(section = "4.2", id = "c"),
+			@SpecAssertion(section = "4.2", id = "d"),
+			@SpecAssertion(section = "4.2", id = "e"),
+			@SpecAssertion(section = "4.2", id = "g")
+	})
+	public void testConstraintViolation() {
 		Validator validator = TestUtil.getDefaultValidator();
 
-		Customer customer = new Customer();
-		customer.setFirstName( "John" );
-		customer.setLastName( "Doe" );
+		Engine engine = new Engine();
+		engine.setSerialNumber( "mail at foobar.com" );
+		engine.setSerialNumber( "ABCDEFGH1234" );
+		Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
+		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
 
-		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+		ConstraintViolation<Engine> violation = constraintViolations.iterator().next();
 
-		Order order = new Order();
-		customer.addOrder( order );
+		assertEquals( violation.getMessage(), "must match ^....-....-....$", "Wrong message" );
+		assertEquals( violation.getMessageTemplate(), "must match {regexp}", "Wrong message template" );
+		assertEquals( violation.getRootBean(), engine, "Wrong root entity." );
+		assertEquals( violation.getInvalidValue(), "ABCDEFGH1234", "Wrong validated value" );
+		assertNotNull( violation.getConstraintDescriptor(), "Constraint descriptor should not be null" );
+		assertEquals(
+				violation.getConstraintDescriptor().getAnnotation().annotationType(),
+				Pattern.class, "Wrong annotation type"
+		);
+		assertEquals( violation.getPropertyPath(), "serialNumber", "Wrong property path." );
 
-		constraintViolations = validator.validate( customer );
-		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-		assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
-		org.testng.Assert.assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
-		org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
-		assertEquals( "orders[].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+		engine.setSerialNumber( "ABCD-EFGH-1234" );
+		constraintViolations = validator.validate( engine );
+		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
 	}
 
 	@Test
-	public void testMultiValueConstraint() {
+	@SpecAssertions({
+			@SpecAssertion(section = "4.2", id = "f"),
+			@SpecAssertion(section = "4.2", id = "g")
+	})
+	public void testValidateAssociation() {
 		Validator validator = TestUtil.getDefaultValidator();
 
-		Engine engine = new Engine();
-		engine.setSerialNumber( "mail at foobar.com" );
-		Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
-		assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
+		Customer customer = new Customer();
+		customer.setFirstName( "John" );
+		customer.setLastName( "Doe" );
+		Order order = new Order();
+		customer.addOrder( order );
 
-		engine.setSerialNumber( "ABCDEFGH1234" );
-		constraintViolations = validator.validate( engine );
+		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
 		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
-		engine.setSerialNumber( "ABCD-EFGH-1234" );
-		constraintViolations = validator.validate( engine );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+		assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
+		assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
+		assertEquals( "orders[].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
 	}
 
 	@Test
-	public void testGraphValidation() {
+	@SpecAssertion(section = "4.2", id = "h")
+	public void testGraphValidationWithList() {
 		Validator validator = TestUtil.getDefaultValidator();
 
-		Actor clint = new Actor( "Clint", "Eastwood" );
-		Actor morgan = new Actor( "Morgan", null );
-		Actor charlie = new Actor( "Charlie", "Sheen" );
+		Actor clint = new ActorListBased( "Clint", "Eastwood" );
+		Actor morgan = new ActorListBased( "Morgan", null );
+		Actor charlie = new ActorListBased( "Charlie", "Sheen" );
 
 		clint.addPlayedWith( charlie );
 		charlie.addPlayedWith( clint );
@@ -199,81 +192,57 @@
 	}
 
 	@Test
-	public void testValidateValue() {
+	@SpecAssertion(section = "4.2", id = "h")
+	public void testGraphValidationWithArray() {
 		Validator validator = TestUtil.getDefaultValidator();
 
-		Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
-				Customer.class, "orders[0].orderNumber", null
-		);
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+		Actor clint = new ActorArrayBased( "Clint", "Eastwood" );
+		Actor morgan = new ActorArrayBased( "Morgan", null );
+		Actor charlie = new ActorArrayBased( "Charlie", "Sheen" );
 
-		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		clint.addPlayedWith( charlie );
+		charlie.addPlayedWith( clint );
+		charlie.addPlayedWith( morgan );
+		morgan.addPlayedWith( charlie );
+		morgan.addPlayedWith( clint );
+		clint.addPlayedWith( morgan );
+
+		Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
 		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-		assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
-		assertEquals( constraintViolation.getRootBean(), null, "Wrong root entity" );
-		assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
-		assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
-		assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
+		org.testng.Assert.assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
+		org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
+		assertEquals(
+				constraintViolation.getPropertyPath(), "playedWith[0].playedWith[1].lastName", "Wrong propertyName"
+		);
+	}
 
-		constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+	@Test(expectedExceptions = IllegalArgumentException.class)
+	public void testNullParamterToValidatorImplConstructor() {
+		TestUtil.getDefaultValidator().getConstraintsForClass( null );
 	}
 
-	@Test
-	public void testValidateValueWithInvalidPropertyPath() {
+	@Test(expectedExceptions = IllegalArgumentException.class)
+	public void testValidateWithNull() {
 		Validator validator = TestUtil.getDefaultValidator();
+		validator.validate( null );
+	}
 
+	@Test
+	@SuppressWarnings("NullArgumentToVariableArgMethod")
+	public void testPassingNullAsGroup() {
+		Validator validator = TestUtil.getDefaultValidator();
+		Customer customer = new Customer();
 		try {
-			validator.validateValue( Customer.class, "", null );
-			fail();
+			validator.validate( customer, null );
 		}
 		catch ( IllegalArgumentException e ) {
-			assertEquals( "Invalid property path.", e.getMessage() );
+			// success
 		}
-
-		try {
-			validator.validateValue( Customer.class, "foobar", null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			assertEquals( "Invalid property path.", e.getMessage() );
-		}
-
-		try {
-			validator.validateValue( Customer.class, "orders[0].foobar", null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			assertEquals( "Invalid property path.", e.getMessage() );
-		}
 	}
 
 	@Test
-	public void testValidateProperty() {
-		Validator validator = TestUtil.getDefaultValidator();
-
-		Customer customer = new Customer();
-		Order order = new Order();
-		customer.addOrder( order );
-
-		Set<ConstraintViolation<Customer>> constraintViolations = validator.validateProperty(
-				customer, "orders[0].orderNumber"
-		);
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
-		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-		assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
-		org.testng.Assert.assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
-		org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
-		assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
-
-		order.setOrderNumber( 1234 );
-		constraintViolations = validator.validateProperty( customer, "orderList[0].orderNumber" );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
-	}
-
-	@Test
 	public void testValidationIsPolymorphic() {
 		Validator validator = TestUtil.getDefaultValidator();
 

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java	2009-06-22 13:54:37 UTC (rev 16854)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/ConsistentUserInformation.java	2009-06-22 14:15:57 UTC (rev 16855)
@@ -48,5 +48,5 @@
 
 	public abstract Pattern[] patterns();
 
-	public abstract UserType userType() default UserType.BUYER;
+	//public abstract UserType userType() default UserType.BUYER;
 }

Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-06-22 13:54:37 UTC (rev 16854)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-06-22 14:15:57 UTC (rev 16855)
@@ -573,7 +573,7 @@
         </assertion>
         <assertion id="f">
             <text>if the association is not hosted by the root object (ie hosted on an associated
-                object) a dot (.) is concaten- ated to the propertyPath</text>
+                object) a dot (.) is concatenated to the propertyPath</text>
         </assertion>
         <assertion id="g">
             <text>the name of the association property (field name or Java Bean property name) is
@@ -581,7 +581,7 @@
         </assertion>
         <assertion id="h">
             <text>if the association is a List or an array, the index value surrounded by square
-                brackets ([index]) is concat- enated to the propertyPath (for example
+                brackets ([index]) is concatenated to the propertyPath (for example
                 order.orderLines[1])</text>
         </assertion>
         <assertion id="i">
@@ -590,18 +590,9 @@
                 the propertyPath (for example item.evaluation["quality"])</text>
         </assertion>
         <assertion id="j">
-            <text>if the property level constraint is not hosted by the root object (ie hosted on an
-                associated object) a dot (.) is concatenated to the propertyPath</text>
+            <text>If the propertyPath is empty, "" is returned (typically a class-level constraint
+                on the root object)</text>
         </assertion>
-        <assertion id="k">
-            <text>the name of the property (field name or Java Bean property name) is concatenated
-                to the propertyPath</text>
-        </assertion>
-        <assertion id="l">
-            <text>nothing is concatenated to the propertyPath, it is considered complete. If the
-                propertyPath is empty, "" is returned (typically a class-level constraint on the
-                root object)</text>
-        </assertion>
     </section>
     <section id="4.3.1" title="Default message interpolation">
         <assertion id="a">
@@ -921,7 +912,8 @@
                 returned</text>
         </assertion>
         <assertion id="f">
-            <text>The groups of a composing constraint are the groups of the composed constraint</text>
+            <text>The groups of a composing constraint are the groups of the composed
+                constraint</text>
         </assertion>
     </section>
     <section id="6" title="Built-in Constraint definitions">




More information about the hibernate-commits mailing list