[hibernate-commits] Hibernate SVN: r16959 - in beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck: tests/constraints/groups and 3 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Jun 26 11:56:27 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-26 11:56:27 -0400 (Fri, 26 Jun 2009)
New Revision: 16959

Added:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/A.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B1.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B2.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B3.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/C.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/D1.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/E.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/F1.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/GroupSequenceIsolationTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/IsAdult.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/SafeEncryption.java
Modified:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.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/util/TestUtil.java
Log:
HV-164 - Add tests for default group sequence isolation


Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java	2009-06-26 12:23:06 UTC (rev 16958)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -43,7 +43,6 @@
 
 import org.hibernate.jsr303.tck.util.TestUtil;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
-import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintType;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintTypes;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessages;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
@@ -69,7 +68,7 @@
 		Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
 		assertCorrectNumberOfViolations( constraintViolations, 1 );
 		ConstraintViolation<FrenchAddress> constraintViolation = constraintViolations.iterator().next();
-		assertCorrectConstraintType( constraintViolation, NotNull.class );
+		assertCorrectConstraintTypes( constraintViolations, NotNull.class );
 		assertCorrectConstraintViolationMessages( constraintViolations, "may not be null" );
 		assertConstraintViolation(
 				constraintViolation,
@@ -179,7 +178,7 @@
 		Set<ConstraintViolation<FrenchAddress>> constraintViolations = validator.validate( address );
 		assertCorrectNumberOfViolations( constraintViolations, 1 );
 		ConstraintViolation<FrenchAddress> constraintViolation = constraintViolations.iterator().next();
-		assertCorrectConstraintType( constraintViolation, NotNull.class );
+		assertCorrectConstraintTypes( constraintViolations, NotNull.class );
 		NotNull notNull = ( NotNull ) constraintViolation.getConstraintDescriptor().getAnnotation();
 		List<Class<?>> groups = Arrays.asList( notNull.groups() );
 		assertTrue( groups.size() == 2, "There should be two groups" );

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/A.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/A.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/A.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,40 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at GroupSequence({ Minimal.class, A.class })
+public class A {
+	@Max(value = 10, groups = Minimal.class)
+	int size;
+
+	@Size(max = 20)
+	String name; //A group
+}
+
+interface Minimal {
+}
+
+interface Heavy {
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B1.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B1.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B1.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,34 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at GroupSequence({ B1.class, Heavy.class })
+public class B1 extends A {
+	@SafeEncryption(groups = Heavy.class)
+	String encryptionKey;
+
+	@Size(max = 20)
+	String nickname; //B1 group
+}
+

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B2.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B2.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B2.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,33 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at GroupSequence({ Minimal.class, B2.class, Heavy.class })
+public class B2 extends A {
+	@SafeEncryption(groups = Heavy.class)
+	String encryptionKey;
+
+	@Size(max = 20)
+	String nickname; //B1 group
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B3.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B3.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/B3.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,31 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class B3 extends A {
+	@SafeEncryption(groups = Heavy.class)
+	String encryptionKey;
+
+	@Size(max = 20)
+	String nickname; //B1 group
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/C.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/C.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/C.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,51 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import javax.validation.GroupSequence;
+import javax.validation.Valid;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Size;
+import javax.validation.groups.Default;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at GroupSequence({ Minimal.class, C.class })
+public class C {
+
+	public C() {
+		d = new D1();
+	}
+
+	@Max(value = 10, groups = Minimal.class)
+	int size;
+
+	@Size(max = 20)
+	String name;
+
+	@Valid
+	D1 d;
+}
+
+ at GroupSequence({ Default.class, Heavy.class })
+interface Complete {
+}
+
+interface Later {
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/D1.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/D1.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/D1.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,31 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class D1 {
+	@SafeEncryption(groups = Heavy.class)
+	String encryptionKey;
+
+	@Size(max = 20)
+	String nickname;
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/E.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/E.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/E.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,44 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import javax.validation.GroupSequence;
+import javax.validation.Valid;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Size;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at GroupSequence({ Minimal.class, E.class })
+public class E {
+
+	public E() {
+		f = new F1();
+	}
+
+	@Max(value = 10, groups = Minimal.class)
+	int size;
+
+	@Size(max = 20)
+	String name;
+
+	@Valid
+	F1 f;
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/F1.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/F1.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/F1.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,36 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at GroupSequence({ F1.class, Later.class })
+public class F1 {
+	@SafeEncryption(groups = Heavy.class)
+	String encryptionKey;
+
+	@Size(max = 20)
+	String nickname;
+
+	@IsAdult(groups = Later.class)
+	int age;
+}

Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/GroupSequenceIsolationTest.java (from rev 16957, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/application/ValidationRequirementTest.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/GroupSequenceIsolationTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/GroupSequenceIsolationTest.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,197 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Size;
+
+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.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintTypes;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+public class GroupSequenceIsolationTest extends AbstractTest {
+
+	@Test
+	public void testCorrectDefaultSequenceInheritance() {
+		Validator validator = TestUtil.getDefaultValidator();
+		B1 b = new B1();
+		b.name = "this name is too long";
+		b.nickname = "and this nickname as well";
+		b.size = 20;
+		b.encryptionKey = "not safe";
+
+		//	when validating Default.class on B1, the following has to be validated sequentially:
+		// - @Size on name and @Size on nickname (A is part of B1)
+		// - @SafeEncryption on encryptionKey
+		// note that @Max on size is not validated as it's not part of the sequence nor the group A
+		Set<ConstraintViolation<B1>> violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 2 );
+		assertCorrectConstraintTypes( violations, Size.class, Size.class );
+
+		b.name = "Jonathan";
+		violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 1 );
+		assertCorrectConstraintTypes( violations, Size.class );
+
+		b.nickname = "Jon";
+		violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 1 );
+		assertCorrectConstraintTypes( violations, SafeEncryption.class );
+
+		b.encryptionKey = "secret";
+		violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 0 );
+	}
+
+	@Test
+	public void testCorrectDefaultSequenceInheritance2() {
+		Validator validator = TestUtil.getDefaultValidator();
+		B2 b = new B2();
+		b.name = "this name is too long";
+		b.nickname = "and this nickname as well";
+		b.size = 20;
+		b.encryptionKey = "not safe";
+
+		// when validating Default.class on B, you need to validate sequentially:
+		//  - @Max on size (Minnimal group)
+		//  - @Size on name and @Size on nickname (A is part of B)
+		//  - @SafeEncryption on encryptionKey 
+		Set<ConstraintViolation<B2>> violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 1 );
+		assertCorrectConstraintTypes( violations, Max.class );
+
+		b.size = 10;
+		violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 2 );
+		assertCorrectConstraintTypes( violations, Size.class, Size.class );
+
+		b.name = "Jonathan";
+		violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 1 );
+		assertCorrectConstraintTypes( violations, Size.class );
+
+		b.nickname = "Jon";
+		violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 1 );
+		assertCorrectConstraintTypes( violations, SafeEncryption.class );
+
+		b.encryptionKey = "secret";
+		violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 0 );
+	}
+
+	@Test(enabled = false)
+	public void testCorrectDefaultSequenceInheritance3() {
+		Validator validator = TestUtil.getDefaultValidator();
+		B3 b = new B3();
+		b.name = "this name is too long";
+		b.nickname = "and this nickname as well";
+		b.size = 20;
+		b.encryptionKey = "not safe";
+
+		Set<ConstraintViolation<B3>> violations = validator.validate( b );
+		assertCorrectNumberOfViolations( violations, 1 );
+		assertCorrectConstraintTypes( violations, Max.class );
+	}
+
+	@Test
+	public void testCorrectDefaultSequenceContainedCaseWithoutGroupRedefinitionOnContainedEntity() {
+		Validator validator = TestUtil.getDefaultValidator();
+		C c = new C();
+		c.name = "this name is too long";
+		c.d.nickname = "and this nickname as well";
+		c.size = 20;
+		c.d.encryptionKey = "not safe";
+
+		Set<ConstraintViolation<C>> violations = validator.validate( c );
+		assertCorrectNumberOfViolations( violations, 2 );
+		assertCorrectConstraintTypes( violations, Size.class, Max.class );
+		assertCorrectPropertyPaths( violations, "size", "d.nickname" );
+
+		c.size = 10;
+		violations = validator.validate( c );
+		assertCorrectNumberOfViolations( violations, 2 );
+		assertCorrectConstraintTypes( violations, Size.class, Size.class );
+		assertCorrectPropertyPaths( violations, "name", "d.nickname" );
+
+		c.d.nickname = "Jon";
+		violations = validator.validate( c );
+		assertCorrectNumberOfViolations( violations, 1 );
+		assertCorrectConstraintTypes( violations, Size.class );
+		assertCorrectPropertyPaths( violations, "name" );
+
+		c.name = "Johnatan";
+		violations = validator.validate( c );
+		assertCorrectNumberOfViolations( violations, 0 );
+	}
+
+	@Test
+	public void testCorrectDefaultSequenceContainedCaseWithGroupRedefinitionOnContainedEntity() {
+		Validator validator = TestUtil.getDefaultValidator();
+		E e = new E();
+		e.name = "this name is too long";
+		e.f.nickname = "and this nickname as well";
+		e.size = 20;
+		e.f.encryptionKey = "not safe";
+		e.f.age = 16;
+
+
+		Set<ConstraintViolation<E>> violations = validator.validate( e );
+		assertCorrectNumberOfViolations( violations, 2 );
+		assertCorrectConstraintTypes( violations, Size.class, Max.class );
+		assertCorrectPropertyPaths( violations, "size", "f.nickname" );
+
+		e.size = 10;
+		violations = validator.validate( e );
+		assertCorrectNumberOfViolations( violations, 2 );
+		assertCorrectConstraintTypes( violations, Size.class, Size.class );
+		assertCorrectPropertyPaths( violations, "name", "f.nickname" );
+
+		e.f.nickname = "Jon";
+		violations = validator.validate( e );
+		assertCorrectNumberOfViolations( violations, 2 );
+		assertCorrectConstraintTypes( violations, Size.class, IsAdult.class );
+		assertCorrectPropertyPaths( violations, "name", "f.age" );
+
+		e.f.age = 18;
+		violations = validator.validate( e );
+		assertCorrectNumberOfViolations( violations, 1 );
+		assertCorrectConstraintTypes( violations, Size.class );
+		assertCorrectPropertyPaths( violations, "name" );
+
+		e.name = "Johnatan";
+		violations = validator.validate( e );
+		assertCorrectNumberOfViolations( violations, 0 );
+
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/IsAdult.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/IsAdult.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/IsAdult.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,55 @@
+// $Id: Positive.java 16835 2009-06-18 16:29:46Z 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.constraints.groups.groupsequenceisolation;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Constraint(validatedBy = { IsAdult.IsAdultValidator.class })
+ at Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ at Retention(RUNTIME)
+ at Documented
+public @interface IsAdult {
+	public abstract String message() default "You are too young!";
+
+	public abstract Class<?>[] groups() default { };
+
+
+	public class IsAdultValidator implements ConstraintValidator<IsAdult, Integer> {
+		public void initialize(IsAdult parameters) {
+		}
+
+		public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
+			if ( value == null ) {
+				return true;
+			}
+			return value >= 18;
+		}
+	}
+}
\ No newline at end of file

Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/SafeEncryption.java (from rev 16948, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/customconstraint/Positive.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/SafeEncryption.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/groups/groupsequenceisolation/SafeEncryption.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -0,0 +1,56 @@
+// $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.constraints.groups.groupsequenceisolation;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Constraint(validatedBy = { SafeEncryption.SafeEncryptionValidator.class })
+ at Target({ METHOD, FIELD, ANNOTATION_TYPE })
+ at Retention(RUNTIME)
+ at Documented
+public @interface SafeEncryption {
+	public abstract String message() default "encryption faild";
+
+	public abstract Class<?>[] groups() default { };
+
+
+	public class SafeEncryptionValidator implements ConstraintValidator<SafeEncryption, String> {
+		public void initialize(SafeEncryption parameters) {
+		}
+
+		public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+			if ( value == null ) {
+				return true;
+			}
+			return value.equals( "secret" );
+		}
+	}
+}
+

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-26 12:23:06 UTC (rev 16958)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -34,7 +34,7 @@
 
 import org.hibernate.jsr303.tck.util.TestUtil;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
-import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintType;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintTypes;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessages;
 import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
 
@@ -135,9 +135,8 @@
 
 		Set<ConstraintViolation<Address>> constraintViolations = validator.validateProperty( address, "city" );
 		assertCorrectNumberOfViolations( constraintViolations, 1 );
-
+		assertCorrectConstraintTypes( constraintViolations, Size.class );
 		ConstraintViolation<Address> violation = constraintViolations.iterator().next();
-		assertCorrectConstraintType( violation, Size.class );
 		assertConstraintViolation( violation, Address.class, townInNorthWales, "city" );
 		assertCorrectConstraintViolationMessages(
 				constraintViolations, "City name cannot be longer than 30 characters."
@@ -172,9 +171,9 @@
 				clint, property
 		);
 		assertCorrectNumberOfViolations( constraintViolations, 1 );
+		assertCorrectConstraintTypes( constraintViolations, NotNull.class );
 
 		ConstraintViolation<ActorListBased> violation = constraintViolations.iterator().next();
-		assertCorrectConstraintType( violation, NotNull.class );
 		assertConstraintViolation( violation, ActorListBased.class, null, property );
 		assertCorrectConstraintViolationMessages( constraintViolations, "Everyone has a last name." );
 	}

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-06-26 12:23:06 UTC (rev 16958)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java	2009-06-26 15:56:27 UTC (rev 16959)
@@ -49,12 +49,8 @@
 		return Validation.buildDefaultValidatorFactory().getValidator();
 	}
 
-	public static <T> void assertCorrectConstraintType(ConstraintViolation<T> violation, Class<?> expectedConstraintType) {
-		assertEquals(
-				( ( Annotation ) violation.getConstraintDescriptor().getAnnotation() ).annotationType().getName(),
-				expectedConstraintType.getName(),
-				"Wrong constraint type"
-		);
+	public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations, int expectedViolations) {
+		assertEquals( violations.size(), expectedViolations, "Wrong number of constraint violations" );
 	}
 
 	public static <T> void assertCorrectConstraintViolationMessages(Set<ConstraintViolation<T>> violations, String... messages) {
@@ -70,26 +66,28 @@
 					actualMessages.contains( expectedMessage ),
 					"The message " + expectedMessage + " should have been in the st of error messages"
 			);
+			actualMessages.remove( expectedMessage );
 		}
+		assertTrue(
+				actualMessages.isEmpty(), "Actual messages contained more messages as specidied expected messages"
+		);
 	}
 
-	public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations, int expectedViolations) {
-		assertEquals( violations.size(), expectedViolations, "Wrong number of constraint violations" );
-	}
-
 	public static <T> void assertCorrectConstraintTypes(Set<ConstraintViolation<T>> violations, Class<?>... expectedConsraintTypes) {
-		List<String> constraintTypes = new ArrayList<String>();
+		List<String> actualConstraintTypes = new ArrayList<String>();
 		for ( ConstraintViolation<?> violation : violations ) {
-			constraintTypes.add(
+			actualConstraintTypes.add(
 					( ( Annotation ) violation.getConstraintDescriptor().getAnnotation() ).annotationType().getName()
 			);
 		}
 
-		assertEquals( expectedConsraintTypes.length, constraintTypes.size(), "Wrong number of constraint types." );
+		assertEquals(
+				expectedConsraintTypes.length, actualConstraintTypes.size(), "Wrong number of constraint types."
+		);
 
 		for ( Class<?> expectedConstraintType : expectedConsraintTypes ) {
 			assertTrue(
-					constraintTypes.contains( expectedConstraintType.getName() ),
+					actualConstraintTypes.contains( expectedConstraintType.getName() ),
 					"The constraint type " + expectedConstraintType.getName() + " should have been violated."
 			);
 		}




More information about the hibernate-commits mailing list