[hibernate-commits] Hibernate SVN: r17104 - in beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck: util and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Wed Jul 15 12:07:05 EDT 2009
Author: hardy.ferentschik
Date: 2009-07-15 12:07:05 -0400 (Wed, 15 Jul 2009)
New Revision: 17104
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GameReserve.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Herd.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/MultiCage.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/SingleCage.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Zebra.java
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/util/TestUtil.java
Log:
more tests for graph validation
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GameReserve.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GameReserve.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GameReserve.java 2009-07-15 16:07:05 UTC (rev 17104)
@@ -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.graphnavigation;
+
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class GameReserve<T extends Animal> {
+ @Valid
+ Herd<T> herd;
+
+ public void setHerd(Herd<T> herd) {
+ this.herd = herd;
+ }
+}
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-07-15 15:34:58 UTC (rev 17103)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/GraphNavigationTest.java 2009-07-15 16:07:05 UTC (rev 17104)
@@ -125,11 +125,53 @@
}
@Test
+ @SpecAssertion(section = "3.1.3", id = "b")
+ public void testTypeOfContainedValueIsDeterminedAtRuntime() {
+ SingleCage cage = new SingleCage();
+ Elephant elephant = new Elephant();
+ elephant.setWeight( 500 );
+ cage.setContainAnimal( elephant );
+
+ Validator validator = TestUtil.getDefaultValidator();
+ Set<ConstraintViolation<SingleCage>> constraintViolations = validator.validate( cage );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintViolationMessages( constraintViolations, "An elephant weighs at least 1000 kg" );
+ }
+
+ @Test
+ @SpecAssertion(section = "3.1.3", id = "e")
+ public void testContainedSet() {
+ MultiCage cage = new MultiCage();
+ cage.addAnimal( new Zebra( null ) );
+ cage.addAnimal( new Zebra( null ) );
+
+ Validator validator = TestUtil.getDefaultValidator();
+ Set<ConstraintViolation<MultiCage>> constraintViolations = validator.validate( cage );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages( constraintViolations, "may not be null", "may not be null" );
+ }
+
+ @Test
+ @SpecAssertion(section = "3.1.3", id = "h")
+ public void testContainedIterable() {
+ GameReserve<Zebra> reserve = new GameReserve<Zebra>();
+ Herd<Zebra> zebraHerd = new Herd<Zebra>();
+ zebraHerd.addAnimal( new Zebra( null ) );
+ zebraHerd.addAnimal( new Zebra( null ) );
+ reserve.setHerd( zebraHerd );
+
+ Validator validator = TestUtil.getDefaultValidator();
+ Set<ConstraintViolation<GameReserve<Zebra>>> constraintViolations = validator.validate( reserve );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintViolationMessages( constraintViolations, "may not be null", "may not be null" );
+ }
+
+ @Test
@SpecAssertions({
@SpecAssertion(section = "3.1.3", id = "d"),
@SpecAssertion(section = "3.1.3", id = "j")
})
- public void testTypeOfContainedValueIsDeterminedAtRuntime() {
+ public void testTypeOfContainedValuesIsDeterminedAtRuntime() {
Zoo zoo = new Zoo();
Elephant elephant = new Elephant();
elephant.setWeight( 500 );
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Herd.java (from rev 17102, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Animal.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Herd.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Herd.java 2009-07-15 16:07:05 UTC (rev 17104)
@@ -0,0 +1,37 @@
+// $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.graphnavigation;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Herd<T extends Animal> implements Iterable<T> {
+ List<T> animals = new ArrayList<T>();
+
+ public void addAnimal(T animal) {
+ animals.add( animal );
+ }
+
+ public Iterator<T> iterator() {
+ return animals.iterator();
+ }
+}
\ No newline at end of file
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/MultiCage.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/MultiCage.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/MultiCage.java 2009-07-15 16:07:05 UTC (rev 17104)
@@ -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.validation.graphnavigation;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class MultiCage {
+ @Valid
+ private Set<Animal> animalsInCage = new HashSet<Animal>();
+
+ public void addAnimal(Animal animal) {
+ animalsInCage.add( animal );
+ }
+}
\ No newline at end of file
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/SingleCage.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/SingleCage.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/SingleCage.java 2009-07-15 16:07:05 UTC (rev 17104)
@@ -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.validation.graphnavigation;
+
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SingleCage {
+ @Valid
+ private Animal containAnimal;
+
+ public Animal getContainAnimal() {
+ return containAnimal;
+ }
+
+ public void setContainAnimal(Animal containAnimal) {
+ this.containAnimal = containAnimal;
+ }
+}
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Zebra.java (from rev 17102, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Elephant.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Zebra.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/graphnavigation/Zebra.java 2009-07-15 16:07:05 UTC (rev 17104)
@@ -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.validation.graphnavigation;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Zebra extends Animal {
+ private String name;
+
+ public Zebra(String name) {
+ this.name = name;
+ }
+
+ @NotNull
+ public String getName() {
+ return name;
+ }
+}
\ 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-15 15:34:58 UTC (rev 17103)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-07-15 16:07:05 UTC (rev 17104)
@@ -57,7 +57,11 @@
}
public static <T> void assertCorrectNumberOfViolations(Set<ConstraintViolation<T>> violations, int expectedViolations) {
- assertEquals( violations.size(), expectedViolations, "Wrong number of constraint violations" );
+ assertEquals(
+ violations.size(),
+ expectedViolations,
+ "Wrong number of constraint violations. Expected: " + expectedViolations + " Actual: " + violations.size()
+ );
}
public static <T> void assertCorrectConstraintViolationMessages(Set<ConstraintViolation<T>> violations, String... messages) {
@@ -66,7 +70,10 @@
actualMessages.add( violation.getMessage() );
}
- assertTrue( actualMessages.size() == messages.length, "Wrong number or error messages" );
+ assertTrue(
+ actualMessages.size() == messages.length,
+ "Wrong number or error messages. Expected: " + messages.length + " Actual: " + actualMessages.size()
+ );
for ( String expectedMessage : messages ) {
assertTrue(
More information about the hibernate-commits
mailing list