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

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Jun 16 15:59:10 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-16 15:59:10 -0400 (Tue, 16 Jun 2009)
New Revision: 16807

Added:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
   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/Boy.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Customer.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/First.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Last.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/Person.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Second.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/messageinterpolation/
Removed:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/CachedTraversableResolverTest.java
Modified:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/TraversableResolverTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
Log:
Added basic validation tests

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,89 @@
+// $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 java.util.ArrayList;
+import java.util.List;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Actor implements Person {
+
+	private String firstName;
+	private String middleName;
+	private String lastName;
+
+	@Valid
+	private List<Actor> playedWith = new ArrayList<Actor>();
+
+	public Actor() {
+
+	}
+
+	public Actor(String firstName, String lastName) {
+		this.firstName = firstName;
+		this.lastName = lastName;
+	}
+
+	public List<Actor> getPlayedWith() {
+		return playedWith;
+	}
+
+	public void setPlayedWith(List<Actor> playedWith) {
+		this.playedWith = playedWith;
+	}
+
+	public void addPlayedWith(Actor playedWith) {
+		this.playedWith.add( playedWith );
+	}
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+	public String getMiddleName() {
+		return middleName;
+	}
+
+	public void setMiddleName(String middleName) {
+		this.middleName = middleName;
+	}
+
+	public String getLastName() {
+		return lastName;
+	}
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+
+	@Override
+	public String toString() {
+		return "Actor{" +
+				"firstName='" + firstName + '\'' +
+				", middleName='" + middleName + '\'' +
+				", lastName='" + lastName + '\'' +
+				'}';
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Actor.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: 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	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,72 @@
+// $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;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Address {
+	@NotNull
+	@Size(max = 30)
+	private String addressline1;
+
+	@NotNull
+	@Size(max = 30)
+	private String addressline2;
+
+	private String zipCode;
+
+	private String city;
+
+	public String getAddressline1() {
+		return addressline1;
+	}
+
+	public void setAddressline1(String addressline1) {
+		this.addressline1 = addressline1;
+	}
+
+	public String getAddressline2() {
+		return addressline2;
+	}
+
+	public void setAddressline2(String addressline2) {
+		this.addressline2 = addressline2;
+	}
+
+	public String getZipCode() {
+		return zipCode;
+	}
+
+	public void setZipCode(String zipCode) {
+		this.zipCode = zipCode;
+	}
+
+	@Size(max = 30)
+	@NotNull
+	public String getCity() {
+		return city;
+	}
+
+	public void setCity(String city) {
+		this.city = city;
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Boy.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Boy.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Boy.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,65 @@
+// $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 Boy implements Person {
+
+	private String firstName;
+	private String middleName;
+	private String lastName;
+	private Integer age;
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+	public String getMiddleName() {
+		return middleName;
+	}
+
+	public void setMiddleName(String middleName) {
+		this.middleName = middleName;
+	}
+
+	public String getLastName() {
+		return lastName;
+	}
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+
+	public void setAge(Integer age) {
+		this.age = age;
+	}
+
+	@NotNull
+	public Integer age() {
+		return age;
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Boy.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Customer.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Customer.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Customer.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,67 @@
+// $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 java.util.HashSet;
+import java.util.Set;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Customer implements Person {
+
+	private String firstName;
+	private String middleName;
+	private String lastName;
+
+	@Valid
+	private Set<Order> orders = new HashSet<Order>();
+
+	public void addOrder(Order order) {
+		orders.add( order );
+	}
+
+	public Set<Order> getOrders() {
+		return orders;
+	}
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+	public String getMiddleName() {
+		return middleName;
+	}
+
+	public void setMiddleName(String middleName) {
+		this.middleName = middleName;
+	}
+
+	public String getLastName() {
+		return lastName;
+	}
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Customer.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,41 @@
+// $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.Pattern;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Engine {
+	@Pattern.List({
+			@Pattern(regexp = "^[A-Z0-9-]+$",
+					message = "must contain alphabetical characters only"),
+			@Pattern(regexp = "^....-....-....$", message = "must match ....-....-....")
+	})
+	private String serialNumber;
+
+	public String getSerialNumber() {
+		return serialNumber;
+	}
+
+	public void setSerialNumber(String serialNumber) {
+		this.serialNumber = serialNumber;
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Engine.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/First.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/First.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/First.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,9 @@
+package org.hibernate.jsr303.tck.tests.validation;
+
+/**
+ * Group executed first in the validation
+ *
+ * @author Emmanuel Bernard
+ */
+public interface First {
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/First.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Last.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Last.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Last.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,9 @@
+package org.hibernate.jsr303.tck.tests.validation;
+
+/**
+ * Group executed Last in the validation
+ *
+ * @author Emmanuel Bernard
+ */
+public interface Last {
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Last.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: 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	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -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;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Order {
+	@NotNull
+	Integer orderNumber;
+
+	public Integer getOrderNumber() {
+		return orderNumber;
+	}
+
+	public void setOrderNumber(Integer orderNumber) {
+		this.orderNumber = orderNumber;
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Person.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Person.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Person.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -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.validation;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Person {
+	@NotNull
+	String getFirstName();
+
+	String getMiddleName();
+
+	@NotNull
+	String getLastName();
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Person.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Second.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Second.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Second.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,9 @@
+package org.hibernate.jsr303.tck.tests.validation;
+
+/**
+ * Group executed second during the validation
+ *
+ * @author Emmanuel Bernard
+ */
+public interface Second {
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Second.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -0,0 +1,437 @@
+// $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 java.util.Set;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.ConstraintViolation;
+import javax.validation.metadata.PropertyDescriptor;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * Tests for the implementation of <code>Validator</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ValidatorImplTest {
+
+
+	@Test
+	public void testWrongMethodName() {
+		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"
+			);
+		}
+	}
+
+	@Test(expectedExceptions = IllegalArgumentException.class)
+	public void testNullParamterToValidatorImplConstructor() {
+		TestUtil.getDefaultValidator().getConstraintsForClass( null );
+	}
+
+	@Test(expectedExceptions = IllegalArgumentException.class)
+	public void testValidateWithNull() {
+		Validator validator = TestUtil.getDefaultValidator();
+		validator.validate( null );
+	}
+
+	@Test
+	@SuppressWarnings("NullArgumentToVariableArgMethod")
+	public void testPassingNullAsGroup() {
+		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
+		}
+
+		try {
+			validator.validateValue( Customer.class, "firstName", "foobar", null );
+			fail();
+		}
+		catch ( IllegalArgumentException e ) {
+			// success
+		}
+	}
+
+	@Test
+	public void testValidateWithNullProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+		try {
+			validator.validate( null );
+			fail();
+		}
+		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
+	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();
+
+		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."
+		);
+	}
+
+	@Test
+	public void testValidateSet() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Customer customer = new Customer();
+		customer.setFirstName( "John" );
+		customer.setLastName( "Doe" );
+
+		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+
+		Order order = new Order();
+		customer.addOrder( order );
+
+		constraintViolations = validator.validate( customer );
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+		assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+		org.testng.Assert.assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
+		org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
+		assertEquals( "orders[].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+	}
+
+	@Test
+	public void testMultiValueConstraint() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		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" );
+
+		engine.setSerialNumber( "ABCDEFGH1234" );
+		constraintViolations = validator.validate( engine );
+		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+		engine.setSerialNumber( "ABCD-EFGH-1234" );
+		constraintViolations = validator.validate( engine );
+		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+	}
+
+	@Test
+	public void testGraphValidation() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Actor clint = new Actor( "Clint", "Eastwood" );
+		Actor morgan = new Actor( "Morgan", null );
+		Actor charlie = new Actor( "Charlie", "Sheen" );
+
+		clint.addPlayedWith( charlie );
+		charlie.addPlayedWith( clint );
+		charlie.addPlayedWith( morgan );
+		morgan.addPlayedWith( charlie );
+		morgan.addPlayedWith( clint );
+		clint.addPlayedWith( morgan );
+
+
+		Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
+		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+		org.testng.Assert.assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
+		org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
+		assertEquals(
+				constraintViolation.getPropertyPath(), "playedWith[0].playedWith[1].lastName", "Wrong propertyName"
+		);
+	}
+
+	@Test
+	public void testValidateValue() {
+		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( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+		assertEquals( constraintViolation.getRootBean(), null, "Wrong root entity" );
+		assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
+		assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
+		assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+		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();
+		}
+		catch ( IllegalArgumentException e ) {
+			assertEquals( "Invalid property path.", e.getMessage() );
+		}
+
+		try {
+			validator.validateValue( Customer.class, "foobar", null );
+			fail();
+		}
+		catch ( IllegalArgumentException e ) {
+			assertEquals( "Invalid property path.", e.getMessage() );
+		}
+
+		try {
+			validator.validateValue( Customer.class, "orders[0].foobar", null );
+			fail();
+		}
+		catch ( IllegalArgumentException e ) {
+			assertEquals( "Invalid property path.", e.getMessage() );
+		}
+	}
+
+	@Test
+	public void testValidateProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Customer customer = new Customer();
+		Order order = new Order();
+		customer.addOrder( order );
+
+		Set<ConstraintViolation<Customer>> constraintViolations = validator.validateProperty(
+				customer, "orders[0].orderNumber"
+		);
+		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+		assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+		org.testng.Assert.assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
+		org.testng.Assert.assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
+		assertEquals( "orders[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
+
+		order.setOrderNumber( 1234 );
+		constraintViolations = validator.validateProperty( customer, "orderList[0].orderNumber" );
+		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+	}
+
+	@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();
+
+		Customer customer = new Customer();
+		customer.setFirstName( "Foo" );
+		customer.setLastName( "Bar" );
+
+		Order order = new Order();
+		customer.addOrder( order );
+
+		Set<ConstraintViolation<Person>> constraintViolations = validator.validate( (Person) customer );
+		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+
+		TestUtil.assertConstraintViolation(
+				constraintViolations.iterator().next(),
+				Customer.class,
+				null,
+				"orders[].orderNumber"
+		);
+
+		order.setOrderNumber( 123 );
+
+		constraintViolations = validator.validate( (Person) customer );
+		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+	}
+
+	@Test
+	public void testObjectTraversion() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		Customer customer = new Customer();
+		customer.setFirstName( "John" );
+		customer.setLastName( "Doe" );
+
+		for ( int i = 0; i < 100; i++ ) {
+			Order order = new Order();
+			customer.addOrder( order );
+		}
+
+		Set<ConstraintViolation<Customer>> constraintViolations = validator.validate(
+				customer, Default.class, First.class, Second.class, Last.class
+		);
+		assertEquals( constraintViolations.size(), 100, "Wrong number of constraints" );
+	}
+
+	/**
+	 * HV-120
+	 */
+	@Test
+	public void testConstraintDescriptorWithoutExplicitGroup() {
+		Validator validator = TestUtil.getDefaultValidator();
+
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
+		PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderNumber" );
+		Set<ConstraintDescriptor<?>> descriptors = propertyDescriptor.getConstraintDescriptors();
+
+		assertEquals( descriptors.size(), 1, "There should be only one constraint descriptor" );
+		ConstraintDescriptor<?> descriptor = descriptors.iterator().next();
+		Set<Class<?>> groups = descriptor.getGroups();
+		assertTrue( groups.size() == 1, "There should be only one group" );
+		assertEquals(
+				groups.iterator().next(),
+				Default.class,
+				"The declared constraint does not explicitly define a group, hence Default is expected"
+		);
+	}
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatorImplTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/CachedTraversableResolverTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/CachedTraversableResolverTest.java	2009-06-16 19:58:17 UTC (rev 16806)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/CachedTraversableResolverTest.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -1,137 +0,0 @@
-// $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.traversableresolver;
-
-import java.lang.annotation.ElementType;
-import java.util.HashSet;
-import java.util.Set;
-import javax.validation.Configuration;
-import javax.validation.TraversableResolver;
-import javax.validation.Validation;
-import javax.validation.Validator;
-import javax.validation.ValidatorFactory;
-import javax.validation.groups.Default;
-
-import static org.testng.Assert.fail;
-import org.testng.annotations.Test;
-
-/**
- * @author Emmanuel Bernard
- */
-//this test is specific to Hibernate Validator
-public class CachedTraversableResolverTest {
-	@Test
-	public void testCache() {
-		TraversableResolver resolver = new AskOnceTR();
-		Configuration<?> config = (Configuration<?>) Validation.byDefaultProvider()
-				.configure()
-				.traversableResolver( resolver );
-		ValidatorFactory factory = config.buildValidatorFactory();
-		Suit suit = new Suit();
-		suit.setTrousers( new Trousers() );
-		suit.setJacket( new Jacket() );
-		suit.setSize( 3333 );
-		suit.getTrousers().setLength( 32321 );
-		suit.getJacket().setWidth( 432432 );
-		Validator v = factory.getValidator();
-		try {
-			v.validate( suit, Default.class, Cloth.class );
-		}
-		catch ( IllegalStateException e ) {
-			fail( "Traversable Called several times for a given object" );
-		}
-
-		v = factory.usingContext().traversableResolver( new AskOnceTR() ).getValidator();
-		try {
-			v.validateProperty( suit, "size", Default.class, Cloth.class );
-		}
-		catch ( IllegalStateException e ) {
-			fail( "Traversable Called several times for a given object" );
-		}
-
-		v = factory.usingContext().traversableResolver( new AskOnceTR() ).getValidator();
-		try {
-			v.validateValue( Suit.class, "size", 2, Default.class, Cloth.class );
-		}
-		catch ( IllegalStateException e ) {
-			fail( "Traversable Called several times for a given object" );
-		}
-	}
-
-	private static class AskOnceTR implements TraversableResolver {
-		private Set<Holder> askedReach = new HashSet<Holder>();
-		private Set<Holder> askedCascade = new HashSet<Holder>();
-
-		private boolean isTraversable(Set<Holder> asked, Object traversableObject, String traversableProperty, Class<?> rootBeanType, String pathToTraversableObject, ElementType elementType) {
-			Holder h = new Holder( traversableObject, traversableProperty );
-			if ( asked.contains( h ) ) {
-				throw new IllegalStateException( "Called twice" );
-			}
-			asked.add( h );
-			return true;
-		}
-
-		public boolean isReachable(Object traversableObject, String traversableProperty, Class<?> rootBeanType, String pathToTraversableObject, ElementType elementType) {
-			return isTraversable(
-					askedReach,
-					traversableObject,
-					traversableProperty,
-					rootBeanType,
-					pathToTraversableObject,
-					elementType
-			);
-		}
-
-		public boolean isCascadable(Object traversableObject, String traversableProperty, Class<?> rootBeanType, String pathToTraversableObject, ElementType elementType) {
-			return isTraversable(
-					askedCascade,
-					traversableObject,
-					traversableProperty,
-					rootBeanType,
-					pathToTraversableObject,
-					elementType
-			);
-		}
-
-		public static class Holder {
-			Object NULL = new Object();
-			Object to;
-			String tp;
-
-			public Holder(Object traversableObject, String traversableProperty) {
-				to = traversableObject == null ? NULL : traversableObject;
-				tp = traversableProperty;
-			}
-
-			@Override
-			public int hashCode() {
-				return to.hashCode() + tp.hashCode();
-			}
-
-			@Override
-			public boolean equals(Object obj) {
-				if ( !( obj instanceof Holder ) ) {
-					return false;
-				}
-				Holder that = ( Holder ) obj;
-
-				return to != NULL && to == that.to && tp.equals( that.tp );
-			}
-		}
-	}
-}
\ No newline at end of file

Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/TraversableResolverTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/TraversableResolverTest.java	2009-06-16 19:58:17 UTC (rev 16806)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/traversableresolver/TraversableResolverTest.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -25,11 +25,19 @@
 
 import static org.testng.Assert.assertEquals;
 import org.testng.annotations.Test;
+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 org.hibernate.jsr303.tck.util.TestUtil;
+
 /**
  * @author Emmanuel Bernard
  */
-public class TraversableResolverTest {
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes(TestUtil.class)
+public class TraversableResolverTest extends AbstractTest {
 	@Test
 	public void testCorrectPathsAreRequested() {
 		Suit suit = new Suit();

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-16 19:58:17 UTC (rev 16806)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java	2009-06-16 19:59:10 UTC (rev 16807)
@@ -93,7 +93,7 @@
 		}
 	}
 
-	public static <T> void assertConstraintViolation(ConstraintViolation<T> violation, Class<T> rootBean, Object invalidValue, String propertyPath) {
+	public static <T> void assertConstraintViolation(ConstraintViolation<T> violation, Class<?> rootBean, Object invalidValue, String propertyPath) {
 		assertEquals(
 				violation.getPropertyPath(),
 				propertyPath,




More information about the hibernate-commits mailing list