[hibernate-commits] Hibernate SVN: r17477 - in validator/trunk/hibernate-validator-archetype/src: test/java/org/hibernate/validator/quickstart and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Sep 3 10:29:23 EDT 2009


Author: hardy.ferentschik
Date: 2009-09-03 10:29:22 -0400 (Thu, 03 Sep 2009)
New Revision: 17477

Added:
   validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/CarChecks.java
   validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Driver.java
   validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/DriverChecks.java
   validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Person.java
   validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/BootstrapTest.java
   validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/GroupTest.java
Modified:
   validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Car.java
   validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/CarTest.java
Log:
HV-220 - some more test for the archetype and the documentation

Modified: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Car.java
===================================================================
--- validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Car.java	2009-09-03 14:28:08 UTC (rev 17476)
+++ validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Car.java	2009-09-03 14:29:22 UTC (rev 17477)
@@ -13,20 +13,23 @@
  * 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.validator.quickstart;
 
+import javax.validation.Valid;
+import javax.validation.constraints.AssertTrue;
 import javax.validation.constraints.Min;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 
 /**
- * An exemplary model class, which is enriched with constraint annotations from
+ * An example entity class enriched with constraint annotations from
  * the Bean Validation API (<a href="http://jcp.org/en/jsr/detail?id=303">JSR
- * 303</a>). Have a look at {@link CarTest} to learn, how the Bean Validation
- * API can be used to validate Car instances.
- * 
+ * 303</a>). Have a look at {@link org.hibernate.validator.quickstart.CarTest} to learn, how the Bean Validation
+ * API can be used to validate {@code Car} instances.
+ *
  * @author Gunnar Morling
+ * @author Hardy Ferentschik
  */
 public class Car {
 
@@ -34,30 +37,35 @@
 	 * By annotating the field with @NotNull we specify, that null is not a valid
 	 * value.
 	 */
-    @NotNull
-    private String manufacturer;
+	@NotNull
+	private String manufacturer;
 
-    /**
-     * This String field shall not only not allowed to be null, it shall also between
-     * 2 and 14 characters long. 
-     */
-    @NotNull
-    @Size(min = 2, max = 14)
-    private String licensePlate;
+	/**
+	 * This String field shall not only not allowed to be null, it shall also between
+	 * 2 and 14 characters long.
+	 */
+	@NotNull
+	@Size(min = 2, max = 14)
+	private String licensePlate;
 
-    /**
-     * This int field shall have a value of at least 2.
-     */
-    @Min(2)
-    private int seatCount;
-    
-    public Car(String manufacturer, String licencePlate, int seatCount) {
+	/**
+	 * This int field shall have a value of at least 2.
+	 */
+	@Min(2)
+	private int seatCount;
 
-        this.manufacturer = manufacturer;
-        this.licensePlate = licencePlate;
-        this.seatCount = seatCount;
-    }
+	@AssertTrue(message = "The car has to pass the vehicle inspection first", groups = CarChecks.class)
+	private boolean passedVehicleInspection;
 
+	@Valid
+	private Driver driver;
+
+	public Car(String manufacturer, String licencePlate, int seatCount) {
+		this.manufacturer = manufacturer;
+		this.licensePlate = licencePlate;
+		this.seatCount = seatCount;
+	}
+
 	public String getManufacturer() {
 		return manufacturer;
 	}
@@ -82,4 +90,19 @@
 		this.seatCount = seatCount;
 	}
 
+	public boolean getPassedVehicleInspection() {
+		return passedVehicleInspection;
+	}
+
+	public void setPassedVehicleInspection(boolean passed) {
+		this.passedVehicleInspection = passed;
+	}
+
+	public Driver getDriver() {
+		return driver;
+	}
+
+	public void setDriver(Driver driver) {
+		this.driver = driver;
+	}
 }
\ No newline at end of file

Added: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/CarChecks.java
===================================================================
--- validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/CarChecks.java	                        (rev 0)
+++ validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/CarChecks.java	2009-09-03 14:29:22 UTC (rev 17477)
@@ -0,0 +1,24 @@
+// $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.validator.quickstart;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface CarChecks {
+}


Property changes on: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/CarChecks.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Driver.java
===================================================================
--- validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Driver.java	                        (rev 0)
+++ validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Driver.java	2009-09-03 14:29:22 UTC (rev 17477)
@@ -0,0 +1,48 @@
+// $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.validator.quickstart;
+
+import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.Min;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Driver extends Person {
+	@Min(value = 18, message = "You have to be 18 to drive a car", groups = DriverChecks.class)
+	public int age;
+
+	@AssertTrue(message = "You first have to pass the driving test", groups = DriverChecks.class)
+	public boolean hasDrivingLicense;
+
+	public Driver(String name) {
+		super( name );
+	}
+
+	public void passedDrivingTest(boolean b) {
+		hasDrivingLicense = b;
+	}
+
+	public int getAge() {
+		return age;
+	}
+
+	public void setAge(int age) {
+		this.age = age;
+	}
+}


Property changes on: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Driver.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/DriverChecks.java
===================================================================
--- validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/DriverChecks.java	                        (rev 0)
+++ validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/DriverChecks.java	2009-09-03 14:29:22 UTC (rev 17477)
@@ -0,0 +1,24 @@
+// $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.validator.quickstart;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface DriverChecks {
+}


Property changes on: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/DriverChecks.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Person.java
===================================================================
--- validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Person.java	                        (rev 0)
+++ validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Person.java	2009-09-03 14:29:22 UTC (rev 17477)
@@ -0,0 +1,42 @@
+// $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.validator.quickstart;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Person {
+	@NotNull
+	private String name;
+
+	public Person(String name) {
+		super();
+		this.name = name;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+}
+


Property changes on: validator/trunk/hibernate-validator-archetype/src/main/java/org/hibernate/validator/quickstart/Person.java
___________________________________________________________________
Name: svn:keywords
   + Id

Copied: validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/BootstrapTest.java (from rev 17471, validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/CarTest.java)
===================================================================
--- validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/BootstrapTest.java	                        (rev 0)
+++ validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/BootstrapTest.java	2009-09-03 14:29:22 UTC (rev 17477)
@@ -0,0 +1,106 @@
+/**
+ * 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.validator.quickstart;
+
+import java.lang.annotation.ElementType;
+import java.util.Locale;
+import javax.validation.Configuration;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+
+import static org.junit.Assert.assertNotNull;
+import org.junit.Test;
+
+import org.hibernate.validator.HibernateValidator;
+import org.hibernate.validator.engine.ValidatorConfiguration;
+
+/**
+ * A module test that shows the different bootstrap possibilities of Hibernate Validator.
+ *
+ * @author Hardy Ferentschik
+ */
+public class BootstrapTest {
+
+	@Test
+	public void testBuildDefaultValidatorFactory() {
+		ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+		Validator validator = factory.getValidator();
+
+		assertNotNull( validator );
+	}
+
+	@Test
+	public void testByDefaultProvider() {
+		Configuration<?> config = Validation.byDefaultProvider().configure();
+		config.messageInterpolator( new MyMessageInterpolator() )
+				.traversableResolver( new MyTraversableResolver() )
+				.constraintValidatorFactory( new MyConstraintValidatorFactory() );
+
+		ValidatorFactory factory = config.buildValidatorFactory();
+		Validator validator = factory.getValidator();
+
+		assertNotNull( validator );
+	}
+
+	@Test
+	public void testByProvider() {
+		ValidatorConfiguration config = Validation.byProvider( HibernateValidator.class ).configure();
+		config.messageInterpolator( new MyMessageInterpolator() )
+				.traversableResolver( new MyTraversableResolver() )
+				.constraintValidatorFactory( new MyConstraintValidatorFactory() );
+
+		ValidatorFactory factory = config.buildValidatorFactory();
+		Validator validator = factory.getValidator();
+
+		assertNotNull( validator );
+	}
+
+	public class MyMessageInterpolator implements MessageInterpolator {
+
+		public String interpolate(String messageTemplate, Context context) {
+			return null;
+		}
+
+		public String interpolate(String messageTemplate, Context context, Locale locale) {
+			return null;
+		}
+	}
+
+	public class MyTraversableResolver implements TraversableResolver {
+
+		public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+			return true;
+		}
+
+		public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
+			return true;
+		}
+	}
+
+	public class MyConstraintValidatorFactory implements ConstraintValidatorFactory {
+
+		public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
+			return null;
+		}
+	}
+}
\ No newline at end of file

Modified: validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/CarTest.java
===================================================================
--- validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/CarTest.java	2009-09-03 14:28:08 UTC (rev 17476)
+++ validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/CarTest.java	2009-09-03 14:29:22 UTC (rev 17477)
@@ -13,18 +13,16 @@
  * 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.validator.quickstart;
 
-import static org.junit.Assert.*;
-
 import java.util.Set;
-
 import javax.validation.ConstraintViolation;
 import javax.validation.Validation;
 import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
 
+import static org.junit.Assert.assertEquals;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -43,8 +41,9 @@
  * In case the object in question could be validated successfully this set will
  * be empty.
  * </p>
- * 
+ *
  * @author Gunnar Morling
+ * @author Hardy Ferentschik
  */
 public class CarTest {
 
@@ -52,80 +51,69 @@
 	 * The validator to be used for object validation. Will be retrieved once
 	 * for all test methods.
 	 */
-    private static Validator validator;
+	private static Validator validator;
 
-    /**
-     * Retrieves the validator instance.
-     */
-    @BeforeClass
-    public static void setUp() {
-        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
-        validator = factory.getValidator();
-    }
+	/**
+	 * Retrieves the validator instance.
+	 */
+	@BeforeClass
+	public static void setUp() {
+		ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+		validator = factory.getValidator();
+	}
 
-    /**
+	/**
 	 * One constraint violation due to the manufacturer field being null
 	 * expected.
 	 */
-    @Test
-    public void manufacturerIsNull() {
+	@Test
+	public void manufacturerIsNull() {
+		Car car = new Car( null, "DD-AB-123", 4 );
 
-        Car car = new Car(null, "DD-AB-123", 4);
+		Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
 
-        Set<ConstraintViolation<Car>> constraintViolations =
-            validator.validate(car);
+		assertEquals( 1, constraintViolations.size() );
+		assertEquals( "may not be null", constraintViolations.iterator().next().getMessage() );
+	}
 
-        assertEquals(1, constraintViolations.size());
-        assertEquals(
-            "may not be null", constraintViolations.iterator().next().getMessage());
-    }
-
-    /**
+	/**
 	 * One constraint violation due to the licensePlate field being too short
 	 * expected.
 	 */
-    @Test
-    public void licensePlateTooShort() {
+	@Test
+	public void licensePlateTooShort() {
+		Car car = new Car( "Morris", "D", 4 );
 
-        Car car = new Car("Morris", "D", 4);
+		Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
 
-        Set<ConstraintViolation<Car>> constraintViolations = 
-            validator.validate(car);
+		assertEquals( 1, constraintViolations.size() );
+		assertEquals( "size must be between 2 and 14", constraintViolations.iterator().next().getMessage() );
+	}
 
-        assertEquals(1, constraintViolations.size());
-        assertEquals(
-            "size must be between 2 and 14", constraintViolations.iterator().next().getMessage());
-    }
-    
-    /**
+	/**
 	 * One constraint violation due to the seatCount field being too low
 	 * expected.
 	 */
-    @Test
-    public void seatCountTooLow() {
+	@Test
+	public void seatCountTooLow() {
+		Car car = new Car( "Morris", "DD-AB-123", 1 );
 
-        Car car = new Car("Morris", "DD-AB-123", 1);
+		Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
 
-        Set<ConstraintViolation<Car>> constraintViolations =
-            validator.validate(car);
+		assertEquals( 1, constraintViolations.size() );
+		assertEquals( "must be greater than or equal to 2", constraintViolations.iterator().next().getMessage() );
+	}
 
-        assertEquals(1, constraintViolations.size());
-        assertEquals(
-            "must be greater than or equal to 2", constraintViolations.iterator().next().getMessage());
-    }
-
-    /**
+	/**
 	 * No constraint violation expected, as all fields of the validated Car
 	 * instance have proper values.
 	 */
-    @Test
-    public void carIsValid() {
+	@Test
+	public void carIsValid() {
+		Car car = new Car( "Morris", "DD-AB-123", 2 );
 
-        Car car = new Car("Morris", "DD-AB-123", 2);
+		Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
 
-        Set<ConstraintViolation<Car>> constraintViolations =
-            validator.validate(car);
-
-        assertEquals(0, constraintViolations.size());
-    }
+		assertEquals( 0, constraintViolations.size() );
+	}
 }
\ No newline at end of file

Copied: validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/GroupTest.java (from rev 17471, validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/CarTest.java)
===================================================================
--- validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/GroupTest.java	                        (rev 0)
+++ validator/trunk/hibernate-validator-archetype/src/test/java/org/hibernate/validator/quickstart/GroupTest.java	2009-09-03 14:29:22 UTC (rev 17477)
@@ -0,0 +1,79 @@
+/**
+ * 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.validator.quickstart;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.groups.Default;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * A module test that shows how to use the grouping functionality of Bean Validation.
+ *
+ * @author Hardy Ferentschik
+ */
+public class GroupTest {
+
+
+	private static Validator validator;
+
+	@BeforeClass
+	public static void setUp() {
+		ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+		validator = factory.getValidator();
+	}
+
+	@Test
+	public void driveAway() {
+		// create a car and check that everything is ok with it.
+		Car car = new Car( "Morris", "DD-AB-123", 2 );
+		Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
+		assertEquals( 0, constraintViolations.size() );
+
+		// but has it passed the vehicle inspection?
+		constraintViolations = validator.validate( car, CarChecks.class );
+		assertEquals( 1, constraintViolations.size() );
+		assertEquals(
+				"The car has to pass the vehicle inspection first", constraintViolations.iterator().next().getMessage()
+		);
+
+		// let's go to the vehicle inspection
+		car.setPassedVehicleInspection( true );
+		assertEquals( 0, validator.validate( car ).size() );
+
+		// now let's add a driver. He is 18, but has not passed the driving test yet
+		Driver john = new Driver( "John Doe" );
+		john.setAge( 18 );
+		car.setDriver( john );
+		constraintViolations = validator.validate( car, DriverChecks.class );
+		assertEquals( 1, constraintViolations.size() );
+		assertEquals( "You first have to pass the driving test", constraintViolations.iterator().next().getMessage() );
+
+		// ok, John passes the test
+		john.passedDrivingTest( true );
+		assertEquals( 0, validator.validate( car, DriverChecks.class ).size() );
+
+		// just checking that everything is in order now
+		assertEquals( 0, validator.validate( car, Default.class, CarChecks.class, DriverChecks.class ).size() );
+	}
+}
\ No newline at end of file



More information about the hibernate-commits mailing list