[hibernate-commits] Hibernate SVN: r16806 - in validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine: traversableresolver and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Jun 16 15:58:18 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-16 15:58:17 -0400 (Tue, 16 Jun 2009)
New Revision: 16806

Added:
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/CachedTraversableResolverTest.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Cloth.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Jacket.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Suit.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Trousers.java
Removed:
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Actor.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Address.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/All.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Boy.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/DefaultAlias.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/First.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Last.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Person.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Second.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
Log:
moved basic validation tests into the TCK

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Actor.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Actor.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Actor.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,89 +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.validation.engine;
-
-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

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Address.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Address.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Address.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,74 +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.validation.engine;
-
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.Length;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Address {
-	@NotNull
-	@Length(max = 30)
-	private String addressline1;
-
-	@NotNull
-	@Length(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;
-	}
-
-	@Length(max = 30)
-	@NotNull
-	public String getCity() {
-		return city;
-	}
-
-	public void setCity(String city) {
-		this.city = city;
-	}
-}
-

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/All.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/All.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/All.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,9 +0,0 @@
-package org.hibernate.validation.engine;
-
-/**
- * Groups including all validations
- *
- * @author Emmanuel Bernard
- */
-public interface All {
-}

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Boy.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Boy.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Boy.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,65 +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.validation.engine;
-
-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

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Customer.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,67 +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.validation.engine;
-
-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

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/DefaultAlias.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/DefaultAlias.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/DefaultAlias.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,7 +0,0 @@
-package org.hibernate.validation.engine;
-
-/**
- * @author Emmanuel Bernard
- */
-public interface DefaultAlias {
-}

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/First.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/First.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/First.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,9 +0,0 @@
-package org.hibernate.validation.engine;
-
-/**
- * Group executed first in the validation
- *
- * @author Emmanuel Bernard
- */
-public interface First {
-}

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Last.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Last.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Last.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,9 +0,0 @@
-package org.hibernate.validation.engine;
-
-/**
- * Group executed Last in the validation
- *
- * @author Emmanuel Bernard
- */
-public interface Last {
-}

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Person.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Person.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Person.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,33 +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.validation.engine;
-
-import org.hibernate.validation.constraints.NotEmpty;
-
-/**
- * @author Hardy Ferentschik
- */
-public interface Person {
-	@NotEmpty
-	String getFirstName();
-
-	String getMiddleName();
-
-	@NotEmpty
-	String getLastName();
-}

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Second.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Second.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/Second.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,9 +0,0 @@
-package org.hibernate.validation.engine;
-
-/**
- * Group executed second during the validation
- *
- * @author Emmanuel Bernard
- */
-public interface Second {
-}

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java	2009-06-16 19:33:09 UTC (rev 16805)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -1,444 +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.validation.engine;
-
-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 org.slf4j.Logger;
-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.validation.util.LoggerFactory;
-import org.hibernate.validation.util.TestUtil;
-import static org.hibernate.validation.util.TestUtil.assertConstraintViolation;
-
-/**
- * Tests for the implementation of <code>Validator</code>.
- *
- * @author Hardy Ferentschik
- */
-public class ValidatorImplTest {
-
-	private static final Logger log = LoggerFactory.make();
-
-	@Test
-	public void testWrongMethodName() {
-		try {
-			Boy boy = new Boy();
-			TestUtil.getValidator().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.getValidator().getConstraintsForClass( null );
-	}
-
-	@Test(expectedExceptions = IllegalArgumentException.class)
-	public void testValidateWithNull() {
-		Validator validator = TestUtil.getValidator();
-		validator.validate( null );
-	}
-
-	@Test
-	@SuppressWarnings("NullArgumentToVariableArgMethod")
-	public void testPassingNullAsGroup() {
-		Validator validator = TestUtil.getValidator();
-		Customer customer = new Customer();
-		try {
-			validator.validate( customer, null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			log.trace( "success" );
-		}
-
-		try {
-			validator.validateProperty( customer, "firstName", null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			log.trace( "success" );
-		}
-
-		try {
-			validator.validateValue( Customer.class, "firstName", "foobar", null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			log.trace( "success" );
-		}
-	}
-
-	@Test
-	public void testValidateWithNullProperty() {
-		Validator validator = TestUtil.getValidator();
-		try {
-			validator.validate( null );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			log.trace( "success" );
-		}
-
-		try {
-			validator.validateProperty( null, "firstName" );
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			log.trace( "success" );
-		}
-
-		try {
-			validator.validateValue( null, "firstName", "foobar" );                              
-			fail();
-		}
-		catch ( IllegalArgumentException e ) {
-			log.trace( "success" );
-		}
-	}
-
-	@Test
-	public void testBasicValidation() {
-		Validator validator = TestUtil.getValidator();
-
-		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.getValidator();
-
-		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.getValidator();
-
-		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" );
-		assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
-		assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
-		assertEquals( "orders[].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
-	}
-
-	@Test
-	public void testMultiValueConstraint() {
-		Validator validator = TestUtil.getValidator();
-
-		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.getValidator();
-
-		Actor clint = new Actor( "Clint", "Eastwood" );
-		Actor morgan = new Actor( "Morgan", "" );
-		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 );
-		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-		assertEquals( "may not be empty", constraintViolation.getMessage(), "Wrong message" );
-		assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
-		assertEquals( constraintViolation.getInvalidValue(), morgan.getLastName(), "Wrong value" );
-		assertEquals(
-				constraintViolation.getPropertyPath(), "playedWith[0].playedWith[1].lastName", "Wrong propertyName"
-		);
-	}
-
-	@Test
-	public void testValidateValue() {
-		Validator validator = TestUtil.getValidator();
-
-		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.getValidator();
-
-		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.getValidator();
-
-		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" );
-		assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
-		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.getValidator();
-
-		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.getValidator();
-
-		Customer customer = new Customer();
-		customer.setFirstName( "Foo" );
-		customer.setLastName( "Bar" );
-
-		Order order = new Order();
-		customer.addOrder( order );
-
-		Person person = customer;
-
-		Set<ConstraintViolation<Person>> constraintViolations = validator.validate( person );
-		assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
-		assertConstraintViolation(
-				constraintViolations.iterator().next(),
-				"may not be null",
-				Customer.class,
-				null,
-				"orders[].orderNumber"
-		);
-
-		order.setOrderNumber( 123 );
-
-		constraintViolations = validator.validate( person );
-		assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
-	}
-
-	@Test
-	public void testObjectTraversion() {
-		Validator validator = TestUtil.getValidator();
-
-		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.getValidator();
-
-		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"
-		);
-	}
-}

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/CachedTraversableResolverTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/CachedTraversableResolverTest.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/CachedTraversableResolverTest.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -0,0 +1,137 @@
+// $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.validation.engine.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


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/CachedTraversableResolverTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Cloth.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Cloth.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Cloth.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -0,0 +1,24 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.engine.traversableresolver;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public interface Cloth {
+}
\ No newline at end of file


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Cloth.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Jacket.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Jacket.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Jacket.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -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.validation.engine.traversableresolver;
+
+import javax.validation.constraints.Max;
+
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Jacket {
+	Integer width;
+
+	@Max(30)
+	public Integer getWidth() {
+		return width;
+	}
+
+	public void setWidth(Integer width) {
+		this.width = width;
+	}
+}
\ No newline at end of file


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Jacket.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Suit.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Suit.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Suit.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -0,0 +1,61 @@
+// $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.validation.engine.traversableresolver;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.Valid;
+import javax.validation.GroupSequence;
+import javax.validation.groups.Default;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at GroupSequence( {Suit.class, Cloth.class })
+public class Suit {
+	@Max(value=50, groups = { Default.class, Cloth.class})
+	@Min(1)
+	private Integer size;
+	@Valid private Trousers trousers;
+	private Jacket jacket;
+
+	public Trousers getTrousers() {
+		return trousers;
+	}
+
+	public void setTrousers(Trousers trousers) {
+		this.trousers = trousers;
+	}
+
+	@Valid
+	public Jacket getJacket() {
+		return jacket;
+	}
+
+	public void setJacket(Jacket jacket) {
+		this.jacket = jacket;
+	}
+
+	public Integer getSize() {
+		return size;
+	}
+
+	public void setSize(Integer size) {
+		this.size = size;
+	}
+}
\ No newline at end of file


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Suit.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Trousers.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Trousers.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Trousers.java	2009-06-16 19:58:17 UTC (rev 16806)
@@ -0,0 +1,39 @@
+// $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.validation.engine.traversableresolver;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.Max;
+import javax.validation.groups.Default;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Trousers {
+	@Min(value=70, groups = {Default.class, Cloth.class})
+	@Max(value=220)
+	private Integer length;
+
+	public Integer getLength() {
+		return length;
+	}
+
+	public void setLength(Integer length) {
+		this.length = length;
+	}
+}
\ No newline at end of file


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/traversableresolver/Trousers.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native




More information about the hibernate-commits mailing list