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

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Jun 22 07:37:30 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-22 07:37:29 -0400 (Mon, 22 Jun 2009)
New Revision: 16851

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/ValidateTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
   beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
some more tests mappings. Cleanup

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 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java	2009-06-22 11:37:29 UTC (rev 16851)
@@ -63,6 +63,8 @@
 		}
 	}
 
+
+
 	@Test
 	@SpecAssertion(section = "4.1.1", id = "e")
 	public void testIllegalArgumentExceptionIsThrownForNullValue() {

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 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java	2009-06-22 11:37:29 UTC (rev 16851)
@@ -26,11 +26,11 @@
 import javax.validation.metadata.ConstraintDescriptor;
 import javax.validation.metadata.PropertyDescriptor;
 
+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;
 import org.jboss.testharness.impl.packaging.Classes;
-import org.jboss.test.audit.annotations.SpecAssertion;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
@@ -47,23 +47,36 @@
 @Classes(TestUtil.class)
 public class ValidateTest extends AbstractTest {
 
-
 	@Test
-	public void testWrongMethodName() {
+	@SpecAssertion(section = "5.1", id = "a")
+	public void testValidatedPropertyDoesNotFollowJavaBeansConvention() {
 		try {
 			Boy boy = new Boy();
 			TestUtil.getDefaultValidator().validate( boy );
 			fail();
 		}
 		catch ( ValidationException e ) {
-			assertEquals(
-					"Annotated methods must follow the JavaBeans naming convention. age() does not.",
-					e.getMessage(),
-					"Wrong error message"
-			);
+			// success
 		}
 	}
 
+	@Test
+	@SpecAssertion(section = "5.1", id = "a")
+	public void testBasicValidation() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Customer customer = new Customer();
+		customer.setFirstName( "John" );
+
+		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+		customer.setLastName( "Doe" );
+
+		constraintViolations = validator.validate( customer );
+		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+	}
+
 	@Test(expectedExceptions = IllegalArgumentException.class)
 	public void testNullParamterToValidatorImplConstructor() {
 		TestUtil.getDefaultValidator().getConstraintsForClass( null );
@@ -86,22 +99,6 @@
 		catch ( IllegalArgumentException e ) {
 			// success
 		}
-
-		try {
-			validator.validateProperty( customer, "firstName", null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
-
-		try {
-			validator.validateValue( Customer.class, "firstName", "foobar", null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
 	}
 
 	@Test
@@ -114,42 +111,9 @@
 		catch ( IllegalArgumentException e ) {
 			// success
 		}
-
-		try {
-			validator.validateProperty( null, "firstName" );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
-
-		try {
-			validator.validateValue( null, "firstName", "foobar" );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
 	}
 
 	@Test
-	@SpecAssertion(section = "5.1", id="a")
-	public void testBasicValidation() {
-		Validator validator = TestUtil.getDefaultValidator();
-
-		Customer customer = new Customer();
-		customer.setFirstName( "John" );
-
-		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
-		customer.setLastName( "Doe" );
-
-		constraintViolations = validator.validate( customer );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
-	}
-
-	@Test
 	public void testMultipleValidationMethods() {
 		Validator validator = TestUtil.getDefaultValidator();
 
@@ -164,27 +128,6 @@
 				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."
-		);
 	}
 
 	@Test
@@ -331,50 +274,6 @@
 	}
 
 	@Test
-	public void testValidatePropertyWithInvalidPropertyPath() {
-		Validator validator = TestUtil.getDefaultValidator();
-
-		Customer customer = new Customer();
-		Order order = new Order();
-		customer.addOrder( order );
-
-		try {
-			validator.validateProperty( customer, "orders[].orderNumber" );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
-
-		try {
-			validator.validateProperty( customer, "" );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
-
-		try {
-			validator.validateProperty( customer, "foobar" );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
-
-		try {
-			validator.validateProperty( customer, "orders[].foobar" );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			// success
-		}
-	}
-
-	/**
-	 * HV-108
-	 */
-	@Test
 	public void testValidationIsPolymorphic() {
 		Validator validator = TestUtil.getDefaultValidator();
 
@@ -420,9 +319,6 @@
 		assertEquals( constraintViolations.size(), 100, "Wrong number of constraints" );
 	}
 
-	/**
-	 * HV-120
-	 */
 	@Test
 	public void testConstraintDescriptorWithoutExplicitGroup() {
 		Validator validator = TestUtil.getDefaultValidator();

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java	2009-06-22 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java	2009-06-22 11:37:29 UTC (rev 16851)
@@ -17,22 +17,21 @@
 */
 package org.hibernate.jsr303.tck.tests.validation.graphnavigation;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Set;
 import javax.validation.ConstraintViolation;
 import javax.validation.Validator;
-import javax.validation.Validation;
 
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
+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 org.jboss.testharness.AbstractTest;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
 
 import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
 
 
 /**
@@ -43,6 +42,10 @@
 public class GraphNavigationTest extends AbstractTest {
 
 	@Test
+	@SpecAssertions({
+			@SpecAssertion(section = "3.5.1", id = "a"),
+			@SpecAssertion(section = "3.5.1", id = "b")
+	})
 	public void testGraphNavigationDeterminism() {
 		// build the test object graph
 		User user = new User( "John", "Doe" );
@@ -70,22 +73,17 @@
 
 		Set<ConstraintViolation<Order>> constraintViolations = validator.validate( order );
 		assertEquals( constraintViolations.size(), 3, "Wrong number of constraints" );
-
-		List<String> expectedErrorMessages = new ArrayList<String>();
-		expectedErrorMessages.add( "shippingAddress.addressline1" );
-		expectedErrorMessages.add( "customer.addresses[0].addressline1" );
-		expectedErrorMessages.add( "billingAddress.inhabitant.addresses[0].addressline1" );
-
-		for ( ConstraintViolation<Order> violation : constraintViolations ) {
-			if ( expectedErrorMessages.contains( violation.getPropertyPath() ) ) {
-				expectedErrorMessages.remove( violation.getPropertyPath() );
-			}
-		}
-
-		assertTrue( expectedErrorMessages.size() == 0, "All error messages should have occured once" );
+		assertCorrectPropertyPaths(
+				constraintViolations, new String[] {
+						"shippingAddress.addressline1",
+						"customer.addresses[0].addressline1",
+						"billingAddress.inhabitant.addresses[0].addressline1"
+				}
+		);
 	}
 
 	@Test
+	@SpecAssertion(section = "3.5.1", id = "d")
 	public void testNoEndlessLoop() {
 		User john = new User( "John", null );
 		john.knows( john );
@@ -124,7 +122,7 @@
 	public void testFullGraphValidationBeforeNextGroupInSequence() {
 		Parent p = new Parent();
 		p.setChild( new Child() );
-		Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
+		Validator validator = TestUtil.getDefaultValidator();
 		Set<ConstraintViolation<Parent>> errors = validator.validate( p, ProperOrder.class );
 		assertEquals( 1, errors.size() );
 		assertEquals( "child.name", errors.iterator().next().getPropertyPath() );

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java	2009-06-22 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/xmlconfiguration/InvalidXmlConfigurationTest.java	2009-06-22 11:37:29 UTC (rev 16851)
@@ -48,13 +48,4 @@
 			// success
 		}
 	}
-
-//
-//	@Test
-//	public void testNoDefinedConstraints() {
-//		Validator validator = getValidatorWithCustomConfiguration( "org/hibernate/validation/engine/xmlconfiguration/validation.xmlconfiguration" );
-//		assertFalse(
-//				validator.getConstraintsForClass( Order.class ).isBeanConstrained(), "Bean should be unsonstrained"
-//		);
-//	}
 }
\ No newline at end of file

Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-06-22 11:00:33 UTC (rev 16850)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml	2009-06-22 11:37:29 UTC (rev 16851)
@@ -416,7 +416,7 @@
     <section id="3.5.1" title="Object graph validation ">
         <assertion id="a">
             <text>The @Valid annotation on a given association (i.e. object reference or collection,
-                array, Iterable of objects), dic- tates the Bean Validator implementation to apply
+                array, Iterable of objects), dictates the Bean Validator implementation to apply
                 recursively the bean validation routine on (each of) the associated object(s)</text>
         </assertion>
         <assertion id="b">
@@ -444,11 +444,11 @@
         </assertion>
         <assertion id="c">
             <text>If an exception occurs when the TraversableResolver is called, the exception is
-                wrapped into a ValidationEx- ception</text>
+                wrapped into a ValidationException</text>
         </assertion>
         <assertion id="d">
             <text>if Java Persistence is available in the runtime environment, a property is
-                considered reachable if Java Persist- ence considers the property as loaded</text>
+                considered reachable if Java Persistence considers the property as loaded</text>
         </assertion>
         <assertion id="d">
             <text>if Java Persistence is not available in the runtime environment, all properties
@@ -577,7 +577,7 @@
         </assertion>
         <assertion id="g">
             <text>the name of the association property (field name or Java Bean property name) is
-                concatenated to the prop- ertyPath.</text>
+                concatenated to the propertyPath.</text>
         </assertion>
         <assertion id="h">
             <text>if the association is a List or an array, the index value surrounded by square




More information about the hibernate-commits mailing list