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

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jul 22 08:24:20 EDT 2009


Author: hardy.ferentschik
Date: 2009-07-22 08:24:20 -0400 (Wed, 22 Jul 2009)
New Revision: 17189

Added:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/BadlyBehavedEntity.java
Modified:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.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/validation/ValidateValueTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
   beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
tests for the different validate methods

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java	2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java	2009-07-22 12:24:20 UTC (rev 17189)
@@ -61,7 +61,7 @@
 	}
 
 	@Size(max = 30, message = "City name cannot be longer than 30 characters.")
-	@NotNull
+	@NotNull(message = "You have to specify a city.")
 	public String getCity() {
 		return city;
 	}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/BadlyBehavedEntity.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/BadlyBehavedEntity.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/BadlyBehavedEntity.java	2009-07-22 12:24:20 UTC (rev 17189)
@@ -0,0 +1,32 @@
+// $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 javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class BadlyBehavedEntity {
+
+	@NotNull
+	public Object getValue() {
+		throw new RuntimeException( "BadlyBehavedEntity.getValue() always throws an exception." );
+	}
+
+}

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java	2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java	2009-07-22 12:24:20 UTC (rev 17189)
@@ -23,7 +23,7 @@
  * @author Hardy Ferentschik
  */
 public class Order {
-	@NotNull
+	@NotNull(message = "An order must have an order number.")
 	Integer orderNumber;
 
 	public Integer getOrderNumber() {

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-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java	2009-07-22 12:24:20 UTC (rev 17189)
@@ -19,6 +19,7 @@
 
 import java.util.Set;
 import javax.validation.ConstraintViolation;
+import javax.validation.ValidationException;
 import javax.validation.Validator;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
@@ -39,7 +40,7 @@
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
 
 /**
- * Tests for the implementation of <code>Validator</code>.
+ * Tests for the implementation of {@code Validator}.
  *
  * @author Hardy Ferentschik
  */
@@ -47,8 +48,8 @@
 @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
 public class ValidatePropertyTest extends AbstractTest {
 
-	//TODO Needs verification
 	@Test
+	@SpecAssertion(section = "4.1.1", id = "e")
 	@SuppressWarnings("NullArgumentToVariableArgMethod")
 	public void testPassingNullAsGroup() {
 		Validator validator = TestUtil.getDefaultValidator();
@@ -78,7 +79,10 @@
 	}
 
 	@Test
-	@SpecAssertion(section = "4.1.1", id = "e")
+	@SpecAssertions({
+			@SpecAssertion(section = "4.1.1", id = "e"),
+			@SpecAssertion(section = "4.1.1", id = "f")
+	})
 	public void testValidatePropertyWithInvalidPropertyPath() {
 		Validator validator = TestUtil.getDefaultValidator();
 
@@ -95,7 +99,7 @@
 		}
 
 		try {
-			validator.validateProperty( customer, "" );
+			validator.validateProperty( customer, "foobar" );
 			fail();
 		}
 		catch ( IllegalArgumentException e ) {
@@ -103,15 +107,16 @@
 		}
 
 		try {
-			validator.validateProperty( customer, "foobar" );
+			validator.validateProperty( customer, "orders[].foobar" );
 			fail();
 		}
 		catch ( IllegalArgumentException e ) {
 			// success
 		}
 
+		// firstname exists, but the capitalisation is wrong
 		try {
-			validator.validateProperty( customer, "orders[].foobar" );
+			validator.validateProperty( customer, "FirstName" );
 			fail();
 		}
 		catch ( IllegalArgumentException e ) {
@@ -120,9 +125,47 @@
 	}
 
 	@Test
+	@SpecAssertion(section = "4.1.1", id = "e")
+	public void testValidatePropertyWithNullProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Customer customer = new Customer();
+		Order order = new Order();
+		customer.addOrder( order );
+
+
+		try {
+			validator.validateProperty( customer, null );
+			fail();
+		}
+		catch ( IllegalArgumentException e ) {
+			// success
+		}
+	}
+
+	@Test
+	@SpecAssertion(section = "4.1.1", id = "e")
+	public void testValidatePropertyWithEmptyProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Customer customer = new Customer();
+		Order order = new Order();
+		customer.addOrder( order );
+
+		try {
+			validator.validateProperty( customer, "" );
+			fail();
+		}
+		catch ( IllegalArgumentException e ) {
+			// success
+		}
+	}
+
+	@Test
 	@SpecAssertions({
+			@SpecAssertion(section = "4.1.1", id = "c"),
 			@SpecAssertion(section = "4.1.1", id = "d"),
-			@SpecAssertion(section = "4.1.1", id = "c")
+			@SpecAssertion(section = "4.1.1", id = "f")
 	})
 	public void testValidateProperty() {
 		Validator validator = TestUtil.getDefaultValidator();
@@ -149,8 +192,9 @@
 
 	@Test
 	@SpecAssertions({
+			@SpecAssertion(section = "4.1.1", id = "c"),
 			@SpecAssertion(section = "4.1.1", id = "d"),
-			@SpecAssertion(section = "4.1.1", id = "c")
+			@SpecAssertion(section = "4.1.1", id = "f")
 	})
 	public void testValidatePropertyWithIndexedPath() {
 		Validator validator = TestUtil.getDefaultValidator();
@@ -177,4 +221,24 @@
 		assertConstraintViolation( violation, ActorListBased.class, null, property );
 		assertCorrectConstraintViolationMessages( constraintViolations, "Everyone has a last name." );
 	}
+
+	@Test
+	@SpecAssertion(section = "4.1.1", id = "g")
+	public void testValidIsNotHonoredValidateProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Customer customer = new Customer();
+		Order order = new Order();
+		customer.addOrder( order );
+
+		Set<ConstraintViolation<Customer>> constraintViolations = validator.validateProperty( customer, "orders" );
+		assertCorrectNumberOfViolations( constraintViolations, 0 );
+	}
+
+	@Test(expectedExceptions = ValidationException.class)
+	@SpecAssertion(section = "4.1.1", id = "k")
+	public void testUnexpectedExceptionsInValidatePropertyGetWrappedInValidationExceptions() {
+		Validator validator = TestUtil.getDefaultValidator();
+		validator.validateProperty( new BadlyBehavedEntity(), "value" );
+	}
 }
\ 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-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java	2009-07-22 12:24:20 UTC (rev 17189)
@@ -41,6 +41,7 @@
 import org.testng.annotations.Test;
 
 import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
 
@@ -73,11 +74,19 @@
 
 	@SpecAssertion(section = "4.1.1", id = "b")
 	@Test(expectedExceptions = IllegalArgumentException.class)
-	public void testValidateWithNull() {
+	public void testValidateWithNullValue() {
 		Validator validator = TestUtil.getDefaultValidator();
 		validator.validate( null );
 	}
 
+	@SpecAssertion(section = "4.1.1", id = "b")
+	@Test(expectedExceptions = IllegalArgumentException.class)
+	@SuppressWarnings("NullArgumentToVariableArgMethod")
+	public void testValidateWithNullGroup() {
+		Validator validator = TestUtil.getDefaultValidator();
+		validator.validate( new Boy(), null );
+	}
+
 	@Test
 	@SpecAssertions({
 			@SpecAssertion(section = "4.1.1", id = "a"),
@@ -90,15 +99,15 @@
 		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" );
+		assertCorrectNumberOfViolations( constraintViolations, 2 );
 
 		engine.setSerialNumber( "ABCDEFGH1234" );
 		constraintViolations = validator.validate( engine );
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
 
 		engine.setSerialNumber( "ABCD-EFGH-1234" );
 		constraintViolations = validator.validate( engine );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 0 );
 	}
 
 	@Test
@@ -112,11 +121,7 @@
 		address.setCity( "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch" ); //town in North Wales
 
 		Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
-		assertEquals(
-				constraintViolations.size(),
-				3,
-				"We should have been 2 @NotNull violations for addresslines and one @Length violation for city."
-		);
+		assertCorrectNumberOfViolations( constraintViolations, 3 );
 	}
 
 	@Test
@@ -136,7 +141,7 @@
 		engine.setSerialNumber( "mail at foobar.com" );
 		engine.setSerialNumber( "ABCDEFGH1234" );
 		Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
 
 		ConstraintViolation<Engine> violation = constraintViolations.iterator().next();
 
@@ -152,7 +157,7 @@
 
 		engine.setSerialNumber( "ABCD-EFGH-1234" );
 		constraintViolations = validator.validate( engine );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 0 );
 	}
 
 	@Test
@@ -170,11 +175,11 @@
 		customer.addOrder( order );
 
 		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
+		assertCorrectPropertyPaths( constraintViolations, "orders[].orderNumber" );
 		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
 		assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
 		assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
-		assertCorrectPropertyPaths( constraintViolations, "orders[].orderNumber" );
 	}
 
 	@Test
@@ -198,7 +203,8 @@
 
 
 		Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
-		assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 2 );
+
 		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
 		assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
 		assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
@@ -229,7 +235,7 @@
 		clint.addPlayedWith( morgan );
 
 		Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
-		assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 2 );
 		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
 		assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
 		assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
@@ -269,9 +275,9 @@
 		customer.addOrder( order );
 
 		Set<ConstraintViolation<Person>> constraintViolations = validator.validate( ( Person ) customer );
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
 
-		TestUtil.assertConstraintViolation(
+		assertConstraintViolation(
 				constraintViolations.iterator().next(),
 				Customer.class,
 				null,
@@ -281,7 +287,7 @@
 		order.setOrderNumber( 123 );
 
 		constraintViolations = validator.validate( ( Person ) customer );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 0 );
 	}
 
 	@Test
@@ -300,7 +306,7 @@
 		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate(
 				customer, Default.class, First.class, Second.class, Last.class
 		);
-		assertEquals( constraintViolations.size(), 100, "Wrong number of constraints" );
+		assertCorrectNumberOfViolations( constraintViolations, 100 );
 	}
 
 	@Test
@@ -340,6 +346,13 @@
 		assertCorrectNumberOfViolations( violations, 0 );
 	}
 
+	@Test(expectedExceptions = ValidationException.class)
+	@SpecAssertion(section = "4.1.1", id = "k")
+	public void testUnexpectedExceptionsInValidateGetWrappedInValidationExceptions() {
+		Validator validator = TestUtil.getDefaultValidator();
+		validator.validate( new BadlyBehavedEntity() );
+	}
+
 	class Car {
 		@Pattern(regexp = "[A-Z][A-Z][A-Z]-[0-9][0-9][0-9]", groups = { First.class, Second.class })
 		private String licensePlateNumber;

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java	2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java	2009-07-22 12:24:20 UTC (rev 17189)
@@ -21,6 +21,7 @@
 import javax.validation.ConstraintViolation;
 import javax.validation.Validator;
 
+import org.jboss.test.audit.annotations.SpecAssertion;
 import org.jboss.testharness.AbstractTest;
 import org.jboss.testharness.impl.packaging.Artifact;
 import org.jboss.testharness.impl.packaging.ArtifactType;
@@ -30,6 +31,9 @@
 import org.testng.annotations.Test;
 
 import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessages;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
 
 /**
@@ -38,44 +42,59 @@
  * @author Hardy Ferentschik
  */
 @Artifact(artifactType = ArtifactType.JSR303)
- at Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
+ at Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
 public class ValidateValueTest extends AbstractTest {
 
+	@Test
+	@SpecAssertion(section = "4.1.1", id = "h")
+	public void testValidateValueSuccess() {
+		Validator validator = TestUtil.getDefaultValidator();
 
+		Set<ConstraintViolation<Address>> constraintViolations = validator.validateValue(
+				Address.class, "city", "Paris"
+		);
+		assertCorrectNumberOfViolations( constraintViolations, 0 );
+	}
+
 	@Test
-	@SuppressWarnings("NullArgumentToVariableArgMethod")
-	public void testPassingNullAsGroup() {
+	@SpecAssertion(section = "4.1.1", id = "h")
+	public void testValidateValueFailure() {
 		Validator validator = TestUtil.getDefaultValidator();
-		Customer customer = new Customer();
-		try {
-			validator.validate( customer, null );
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
 
-		try {
-			validator.validateProperty( customer, "firstName", null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
+		Set<ConstraintViolation<Address>> constraintViolations = validator.validateValue(
+				Address.class, "city", null
+		);
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
+		assertCorrectConstraintViolationMessages( constraintViolations, "You have to specify a city." );
+	}
 
-		try {
-			validator.validateValue( Customer.class, "firstName", "foobar", null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
+	@Test
+	@SpecAssertion(section = "4.1.1", id = "h")
+	public void testValidateValue() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
+				Customer.class, "orders[0].orderNumber", null
+		);
+		assertCorrectNumberOfViolations( constraintViolations, 1 );
+		assertCorrectPropertyPaths( constraintViolations, "orders[0].orderNumber" );
+		assertCorrectConstraintViolationMessages( constraintViolations, "An order must have an order number." );
+
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		assertConstraintViolation( constraintViolation, Customer.class, null, "orders[0].orderNumber" );
+		assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
+
+		constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
+		assertCorrectNumberOfViolations( constraintViolations, 0 );
 	}
 
 	@Test
-	public void testValidateWithNullProperty() {
+	@SpecAssertion(section = "4.1.1", id = "i")
+	public void testValidateValueWithInvalidPropertyPath() {
 		Validator validator = TestUtil.getDefaultValidator();
+
 		try {
-			validator.validate( null );
+			validator.validateValue( Customer.class, "foobar", null );
 			fail();
 		}
 		catch ( IllegalArgumentException e ) {
@@ -83,15 +102,16 @@
 		}
 
 		try {
-			validator.validateProperty( null, "firstName" );
+			validator.validateValue( Customer.class, "orders[0].foobar", null );
 			fail();
 		}
 		catch ( IllegalArgumentException e ) {
 			// success
 		}
 
+		// firstname exists, but the capitalisation is wrong
 		try {
-			validator.validateValue( null, "firstName", "foobar" );
+			validator.validateValue( Customer.class, "FirstName", null );
 			fail();
 		}
 		catch ( IllegalArgumentException e ) {
@@ -100,68 +120,25 @@
 	}
 
 	@Test
-	public void testMultipleValidationMethods() {
+	@SuppressWarnings("NullArgumentToVariableArgMethod")
+	@SpecAssertion(section = "4.1.1", id = "i")
+	public void testValidateValuePassingNullAsGroup() {
 		Validator validator = TestUtil.getDefaultValidator();
 
-		Address address = new Address();
-		address.setAddressline1( null );
-		address.setAddressline2( null );
-		address.setCity( "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch" ); //town in North Wales
-
-		Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
-		assertEquals(
-				constraintViolations.size(),
-				3,
-				"we should have been 2 not null violation for addresslines and one length violation for city"
-		);
-
-		constraintViolations = validator.validateProperty( address, "city" );
-		assertEquals(
-				constraintViolations.size(),
-				1,
-				"only city should be validated"
-		);
-
-		constraintViolations = validator.validateProperty( address, "city" );
-		assertEquals(
-				constraintViolations.size(),
-				1,
-				"only city should be validated"
-		);
-
-		constraintViolations = validator.validateValue( Address.class, "city", "Paris" );
-		assertEquals(
-				constraintViolations.size(),
-				0,
-				"Paris should be a valid city name."
-		);
+		try {
+			validator.validateValue( Customer.class, "firstName", "foobar", null );
+			fail();
+		}
+		catch ( IllegalArgumentException e ) {
+			// success
+		}
 	}
 
 	@Test
-	public void testValidateValue() {
+	@SpecAssertion(section = "4.1.1", id = "i")
+	public void testValidateValueWithEmptyPropertyPath() {
 		Validator validator = TestUtil.getDefaultValidator();
 
-		Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
-				Customer.class, "orders[0].orderNumber", null
-		);
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
-		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-		assertEquals( constraintViolation.getMessage(), "may not be null", "Wrong message" );
-		assertEquals( constraintViolation.getRootBean(), null, "Wrong root entity" );
-		assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
-		assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
-		assertCorrectPropertyPaths( constraintViolations, "orders[0].orderNumber" );
-
-		constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
-	}
-
-	@Test
-	public void testValidateValueWithInvalidPropertyPath() {
-		Validator validator = TestUtil.getDefaultValidator();
-
 		try {
 			validator.validateValue( Customer.class, "", null );
 			fail();
@@ -169,21 +146,46 @@
 		catch ( IllegalArgumentException e ) {
 			// success
 		}
+	}
 
+	@Test
+	@SpecAssertion(section = "4.1.1", id = "i")
+	public void testValidateValueWithNullObject() {
+		Validator validator = TestUtil.getDefaultValidator();
 		try {
-			validator.validateValue( Customer.class, "foobar", null );
+			validator.validateValue( null, "firstName", "foobar" );
 			fail();
 		}
 		catch ( IllegalArgumentException e ) {
 			// success
 		}
+	}
 
+	@Test
+	@SpecAssertion(section = "4.1.1", id = "i")
+	public void testValidateValueWithNullPropertyName() {
+		Validator validator = TestUtil.getDefaultValidator();
 		try {
-			validator.validateValue( Customer.class, "orders[0].foobar", null );
+			validator.validateValue( Customer.class, null, "foobar" );
 			fail();
 		}
 		catch ( IllegalArgumentException e ) {
 			// success
 		}
 	}
+
+	@Test
+	@SpecAssertion(section = "4.1.1", id = "j")
+	public void testValidIsNotHonoredValidateValue() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Customer customer = new Customer();
+		Order order = new Order();
+		customer.addOrder( order );
+
+		Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
+				Customer.class, "orders", order
+		);
+		assertCorrectNumberOfViolations( constraintViolations, 0 );
+	}
 }
\ No newline at end of file

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java	2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java	2009-07-22 12:24:20 UTC (rev 17189)
@@ -134,7 +134,7 @@
 		}
 
 		assertEquals(
-				violation.getRootBean().getClass(),
+				violation.getRootBeanClass(),
 				rootBean,
 				"Wrong root bean."
 		);

Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-07-22 12:24:20 UTC (rev 17189)
@@ -524,8 +524,7 @@
             <text>validate(T object, Class... groups) is used to validate a given object</text>
         </assertion>
         <assertion id="b">
-            <text>An IllegalArgumentException is thrown if object is null when validate() is
-                called.</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
@@ -536,15 +535,15 @@
                 field or property of an object</text>
         </assertion>
         <assertion id="e">
-            <text>An IllegalArgumentException is thrown if object is null or propertyName is null
-                empty or invalid when validateProperty() is called.</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 is the JavaBeans property name (as defined by the JavaBeans
+            <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 validateProperty()</text>
+            <text>@Valid is not honored by a call to validateProperty.</text>
         </assertion>
         <assertion id="h">
             <text>validateValue(Class beanType, String propertyName, Object value, Class... groups)
@@ -552,11 +551,11 @@
                 superclasses, if the property value were value.</text>
         </assertion>
         <assertion id="i">
-            <text>An IllegalArgumentException is thrown if object is null or propertyName is null
-                empty or invalid when validateValue() is called.</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>
+            <text>@Valid is not honored by validateValue.</text>
         </assertion>
         <assertion id="k">
             <text>If some unrecoverable failure happens during validation, a ValidationException is



More information about the hibernate-commits mailing list