[hibernate-commits] Hibernate SVN: r15990 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validation/engine and 4 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Feb 17 12:27:48 EST 2009


Author: hardy.ferentschik
Date: 2009-02-17 12:27:48 -0500 (Tue, 17 Feb 2009)
New Revision: 15990

Added:
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/GroupExecutionOrder.java
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/package.html
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/package.html
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/package.html
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/GroupTest.java
Removed:
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/EnglishDictonary.java
Modified:
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaData.java
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Account.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
Log:
HV-92 Some cleanup in preperation for the real grouping feature.

Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/package.html	2009-02-17 17:27:48 UTC (rev 15990)
@@ -0,0 +1,27 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<!--
+
+  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.
+
+-->
+</head>
+<body>
+This package contains the implementations of the builtin constraints as well as Hibernate Validator specific
+constraints and their implementations.
+</body>
+</html>

Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaData.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaData.java	2009-02-17 13:16:07 UTC (rev 15989)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaData.java	2009-02-17 17:27:48 UTC (rev 15990)
@@ -61,7 +61,7 @@
 	/**
 	 * @return A map mapping defined group sequences to a list of groups.
 	 */
-	Map<Class<?>, List<Class<?>>> getGroupSequences();
+	List<Class<?>> getDefaultGroupSequence();
 
 	/**
 	 * @return A list of <code>MetaConstraint</code> instances encapsulating the information of all the constraints

Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java	2009-02-17 13:16:07 UTC (rev 15989)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java	2009-02-17 17:27:48 UTC (rev 15990)
@@ -22,15 +22,16 @@
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Arrays;
 import javax.validation.BeanDescriptor;
 import javax.validation.GroupSequence;
 import javax.validation.PropertyDescriptor;
 import javax.validation.Valid;
 import javax.validation.ValidationException;
+import javax.validation.groups.Default;
 
 import org.slf4j.Logger;
 
@@ -83,7 +84,7 @@
 	/**
 	 * Maps group sequences to the list of group/sequences.
 	 */
-	private Map<Class<?>, List<Class<?>>> groupSequences = new HashMap<Class<?>, List<Class<?>>>();
+	private List<Class<?>> defaultGroupSequence = new ArrayList<Class<?>>();
 
 	private final BuiltinConstraints builtinConstraints;
 
@@ -99,6 +100,7 @@
 	 */
 	private void createMetaData() {
 		beanDescriptor = new BeanDescriptorImpl<T>( beanClass, this );
+		initDefaultGroupSequence( beanClass );
 		List<Class> classes = new ArrayList<Class>();
 		computeClassHierarchy( beanClass, classes );
 		for ( Class current : classes ) {
@@ -128,54 +130,21 @@
 	}
 
 	private void initClass(Class clazz) {
-		initGroupSequences( clazz );
 		initClassConstraints( clazz );
 		initMethodConstraints( clazz );
 		initFieldConstraints( clazz );
 	}
 
-	private void initGroupSequences(Class<?> clazz) {
+	private void initDefaultGroupSequence(Class<?> clazz) {
 		GroupSequence groupSequenceAnnotation = clazz.getAnnotation( GroupSequence.class );
-		if ( groupSequenceAnnotation != null ) {
-			addGroupSequence( groupSequenceAnnotation );
+		if ( groupSequenceAnnotation == null ) {
+			defaultGroupSequence.add( Default.class );
 		}
-
-		for ( Map.Entry<Class<?>, List<Class<?>>> mapEntry : groupSequences.entrySet() ) {
-			List<Class<?>> groups = mapEntry.getValue();
-			List<Class<?>> expandedGroups = new ArrayList<Class<?>>();
-			for ( Class<?> group : groups ) {
-				expandedGroups.addAll( expandGroupSequences( group ) );
-			}
-			groupSequences.put( mapEntry.getKey(), expandedGroups );
-		}
-		if ( log.isDebugEnabled() && !groupSequences.isEmpty() ) {
-			log.debug( "Expanded groups sequences: {}", groupSequences );
-		}
-	}
-
-	private List<Class<?>> expandGroupSequences(Class<?> group) {
-		List<Class<?>> groupList = new ArrayList<Class<?>>();
-		if ( groupSequences.containsKey( group ) ) {
-			for ( Class<?> localGroup : groupSequences.get( group ) ) {
-				groupList.addAll( expandGroupSequences( localGroup ) );
-			}
-		}
 		else {
-			groupList.add( group );
+			defaultGroupSequence.addAll( Arrays.asList( groupSequenceAnnotation.sequence() ) );
 		}
-		if ( log.isTraceEnabled() ) {
-			log.trace( "Expanded {} to {}", group, groupList.toString() );
-		}
-		return groupList;
 	}
 
-	private void addGroupSequence(GroupSequence groupSequence) {
-		if ( groupSequences.containsKey( groupSequence.name() ) ) {
-			throw new ValidationException( "Encountered duplicate sequence name: " + groupSequence.name() );
-		}
-		groupSequences.put( groupSequence.name(), Arrays.asList( groupSequence.sequence() ) );
-	}
-
 	private void initFieldConstraints(Class clazz) {
 		for ( Field field : clazz.getDeclaredFields() ) {
 			List<ConstraintDescriptorImpl> fieldMetadata = findFieldLevelConstraints( field );
@@ -244,12 +213,6 @@
 	@SuppressWarnings("unchecked")
 	private <A extends Annotation> ConstraintDescriptorImpl buildConstraintDescriptor(A annotation) {
 		Class<?>[] groups = ReflectionHelper.getAnnotationParameter( annotation, "groups", Class[].class );
-		for ( Class<?> groupName : groups ) {
-			if ( groupSequences.containsKey( groupName ) ) {
-				throw new ValidationException( groupName + " is illegally used as group and sequence name." );
-			}
-		}
-
 		return new ConstraintDescriptorImpl( annotation, groups, builtinConstraints );
 	}
 
@@ -360,8 +323,8 @@
 		return cascadedMembers;
 	}
 
-	public Map<Class<?>, List<Class<?>>> getGroupSequences() {
-		return groupSequences;
+	public List<Class<?>> getDefaultGroupSequence() {
+		return defaultGroupSequence;
 	}
 
 	public List<MetaConstraint> geMetaConstraintList() {

Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java	2009-02-17 13:16:07 UTC (rev 15989)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java	2009-02-17 17:27:48 UTC (rev 15990)
@@ -178,6 +178,7 @@
 	 * @param context the validation context.
 	 * @param type the type of the cascaded field or property.
 	 * @param value the actual value.
+	 *
 	 * @return An iterator over the value of a cascaded property.
 	 */
 	private <T> Iterator<?> createIteratorForCascadedValue(ExecutionContext<T> context, Type type, Object value) {
@@ -202,7 +203,7 @@
 			iter = list.iterator();
 		}
 		return iter;
-	}	
+	}
 
 	private <T> void validateCascadedConstraint(ExecutionContext<T> context, Iterator<?> iter) {
 		Object actualValue;
@@ -403,8 +404,8 @@
 
 		boolean isGroupSequence;
 		BeanMetaData<T> metaDataProvider = getBeanMetaData( beanType );
-		if ( metaDataProvider.getGroupSequences().containsKey( group ) ) {
-			expandedGroups.addAll( metaDataProvider.getGroupSequences().get( group ) );
+		if ( Default.class.getName().equals( group.getName() ) ) {
+			expandedGroups.addAll( metaDataProvider.getDefaultGroupSequence() );
 			isGroupSequence = true;
 		}
 		else {

Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/GroupExecutionOrder.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/GroupExecutionOrder.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/GroupExecutionOrder.java	2009-02-17 17:27:48 UTC (rev 15990)
@@ -0,0 +1,26 @@
+// $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.group;
+
+/**
+ * Used to determine the execution order if there is one or more group or group sequences are specified.
+ *
+ * @author Hardy Ferentschik
+ */
+public class GroupExecutionOrder {
+}

Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/package.html	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/group/package.html	2009-02-17 17:27:48 UTC (rev 15990)
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<!--
+
+  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.
+
+-->
+</head>
+<body>
+This package contains helper classes for the processing of groups.
+</body>
+</html>

Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/package.html	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/package.html	2009-02-17 17:27:48 UTC (rev 15990)
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<!--
+
+  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.
+
+-->
+</head>
+<body>
+This package contains the implementing classes for the core interfaces of JSR-303.
+</body>
+</html>

Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/package.html
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/package.html	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/package.html	2009-02-17 17:27:48 UTC (rev 15990)
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<!--
+
+  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.
+
+-->
+</head>
+<body>
+This package contains helper independend helper classes.
+</body>
+</html>

Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Account.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Account.java	2009-02-17 13:16:07 UTC (rev 15989)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/Account.java	2009-02-17 17:27:48 UTC (rev 15990)
@@ -1,3 +1,20 @@
+// $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.eg;
 
 import javax.validation.Valid;

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/EnglishDictonary.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/EnglishDictonary.java	2009-02-17 13:16:07 UTC (rev 15989)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/eg/EnglishDictonary.java	2009-02-17 17:27:48 UTC (rev 15990)
@@ -1,30 +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.eg;
-
-import javax.validation.GroupSequence;
-import javax.validation.groups.Default;
-
-import org.hibernate.validation.eg.groups.First;
-
-/**
- * @author Hardy Ferentschik
- */
- at GroupSequence(name = Default.class, sequence = { First.class }) // illegal - default is already defined in Book
-public class EnglishDictonary extends Dictonary {
-}
\ No newline at end of file

Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/GroupTest.java (from rev 15989, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/GroupTest.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/GroupTest.java	2009-02-17 17:27:48 UTC (rev 15990)
@@ -0,0 +1,181 @@
+// $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.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import org.hibernate.validation.eg.Animal;
+import org.hibernate.validation.eg.Author;
+import org.hibernate.validation.eg.Book;
+import org.hibernate.validation.eg.DefaultAlias;
+import org.hibernate.validation.eg.Dictonary;
+import org.hibernate.validation.eg.groups.First;
+import org.hibernate.validation.eg.groups.Last;
+import org.hibernate.validation.eg.groups.Second;
+import org.hibernate.validation.util.TestUtil;
+
+/**
+ * Tests for the implementation of <code>Validator</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+public class GroupTest {
+
+	@Test
+	public void testGroups() {
+		Validator validator = TestUtil.getValidator();
+
+		Author author = new Author();
+		author.setLastName( "" );
+		author.setFirstName( "" );
+		Book book = new Book();
+		book.setTitle( "" );
+		book.setAuthor( author );
+
+		Set<ConstraintViolation<Book>> constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+		assertEquals( "Wrong number of constraints", 3, constraintViolations.size() );
+
+		author.setFirstName( "Gavin" );
+		author.setLastName( "King" );
+
+		constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+		assertEquals( "Wrong message", "may not be empty", constraintViolation.getMessage() );
+		assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
+		assertEquals( "Wrong value", book.getTitle(), constraintViolation.getInvalidValue() );
+		assertEquals( "Wrong propertyName", "title", constraintViolation.getPropertyPath() );
+
+		book.setTitle( "Hibernate Persistence with JPA" );
+		book.setSubtitle( "Revised Edition of Hibernate in Action" );
+
+		constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+		constraintViolation = constraintViolations.iterator().next();
+		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+		assertEquals( "Wrong message", "length must be between 0 and 30", constraintViolation.getMessage() );
+		assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
+		assertEquals( "Wrong value", book.getSubtitle(), constraintViolation.getInvalidValue() );
+		assertEquals( "Wrong propertyName", "subtitle", constraintViolation.getPropertyPath() );
+
+		book.setSubtitle( "Revised Edition" );
+		author.setCompany( "JBoss a divison of RedHat" );
+
+		constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+		constraintViolation = constraintViolations.iterator().next();
+		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+		assertEquals( "Wrong message", "length must be between 0 and 20", constraintViolation.getMessage() );
+		assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
+		assertEquals( "Wrong value", author.getCompany(), constraintViolation.getInvalidValue() );
+		assertEquals( "Wrong propertyName", "author.company", constraintViolation.getPropertyPath() );
+
+		author.setCompany( "JBoss" );
+
+		constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
+		assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+	}
+
+	@Test
+	public void testDefaultGroupSequence() {
+		Validator validator = TestUtil.getValidator();
+
+		Author author = new Author();
+		author.setLastName( "" );
+		author.setFirstName( "" );
+		Book book = new Book();
+		book.setAuthor( author );
+
+		Set<ConstraintViolation<Book>> constraintViolations = validator.validate( book, Default.class );
+		assertEquals( "Wrong number of constraints", 2, constraintViolations.size() );
+
+		author.setFirstName( "Gavin" );
+		author.setLastName( "King" );
+
+		constraintViolations = validator.validate( book, Default.class );
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+		assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
+		assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
+		assertEquals( "Wrong value", book.getTitle(), constraintViolation.getInvalidValue() );
+		assertEquals( "Wrong propertyName", "title", constraintViolation.getPropertyPath() );
+
+		book.setTitle( "Hibernate Persistence with JPA" );
+		book.setSubtitle( "Revised Edition of Hibernate in Action" );
+
+		constraintViolations = validator.validate( book, Default.class );
+		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+
+		book.setSubtitle( "Revised Edition" );
+		author.setCompany( "JBoss a divison of RedHat" );
+
+		constraintViolations = validator.validate( book, Default.class );
+		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+
+		author.setCompany( "JBoss" );
+
+		constraintViolations = validator.validate( book, Default.class );
+		assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+	}
+
+	@Test
+	public void testGroupSequences() {
+		Validator validator = TestUtil.getValidator();
+
+		Dictonary dictonary = new Dictonary();
+		dictonary.setTitle( "English - German" );
+		Author author = new Author();
+		author.setLastName( "-" );
+		author.setFirstName( "-" );
+		author.setCompany( "Langenscheidt Publ." );
+		dictonary.setAuthor( author );
+
+		Set<ConstraintViolation<Dictonary>> constraintViolations = validator.validate( dictonary, DefaultAlias.class );
+		assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+	}
+
+	@Test
+	public void testValidationFailureInMultipleGroups() {
+		Validator validator = TestUtil.getValidator();
+		Animal elepfant = new Animal();
+		elepfant.setName( "" );
+		elepfant.setDomain( Animal.Domain.EUKARYOTA );
+
+		Set<ConstraintViolation<Animal>> constraintViolations = validator.validate( elepfant, First.class, Second.class );
+		assertEquals(
+				"The should be two invalid constraints since the same propertyName gets validated in both groups",
+				1,
+				constraintViolations.size()
+		);
+
+		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+		Set<Class<?>> expected = new HashSet<Class<?>>();
+		expected.add( First.class );
+		expected.add( Second.class );
+		assertEquals(
+				"The constraint should be invalid for both groups",
+				expected,
+				constraintViolation.getGroups()
+		);
+	}
+}
\ No newline at end of file


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/GroupTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:mergeinfo
   + 

Modified: 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-02-17 13:16:07 UTC (rev 15989)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java	2009-02-17 17:27:48 UTC (rev 15990)
@@ -17,12 +17,10 @@
 */
 package org.hibernate.validation.engine;
 
-import java.util.HashSet;
 import java.util.Set;
 import javax.validation.ConstraintViolation;
 import javax.validation.ValidationException;
 import javax.validation.Validator;
-import javax.validation.groups.Default;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -31,20 +29,11 @@
 
 import org.hibernate.validation.eg.Actor;
 import org.hibernate.validation.eg.Address;
-import org.hibernate.validation.eg.Animal;
-import org.hibernate.validation.eg.Author;
-import org.hibernate.validation.eg.Book;
 import org.hibernate.validation.eg.Boy;
 import org.hibernate.validation.eg.Customer;
-import org.hibernate.validation.eg.DefaultAlias;
-import org.hibernate.validation.eg.Dictonary;
 import org.hibernate.validation.eg.Engine;
-import org.hibernate.validation.eg.EnglishDictonary;
 import org.hibernate.validation.eg.Order;
 import org.hibernate.validation.eg.UnconstraintEntity;
-import org.hibernate.validation.eg.groups.First;
-import org.hibernate.validation.eg.groups.Last;
-import org.hibernate.validation.eg.groups.Second;
 import org.hibernate.validation.util.TestUtil;
 
 /**
@@ -103,101 +92,6 @@
 	}
 
 	@Test
-	public void testGroups() {
-		Validator validator = TestUtil.getValidator();
-
-		Author author = new Author();
-		author.setLastName( "" );
-		author.setFirstName( "" );
-		Book book = new Book();
-		book.setTitle( "" );
-		book.setAuthor( author );
-
-		Set<ConstraintViolation<Book>> constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
-		assertEquals( "Wrong number of constraints", 3, constraintViolations.size() );
-
-		author.setFirstName( "Gavin" );
-		author.setLastName( "King" );
-
-		constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
-		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
-		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
-		assertEquals( "Wrong message", "may not be empty", constraintViolation.getMessage() );
-		assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
-		assertEquals( "Wrong value", book.getTitle(), constraintViolation.getInvalidValue() );
-		assertEquals( "Wrong propertyName", "title", constraintViolation.getPropertyPath() );
-
-		book.setTitle( "Hibernate Persistence with JPA" );
-		book.setSubtitle( "Revised Edition of Hibernate in Action" );
-
-		constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
-		constraintViolation = constraintViolations.iterator().next();
-		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
-		assertEquals( "Wrong message", "length must be between 0 and 30", constraintViolation.getMessage() );
-		assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
-		assertEquals( "Wrong value", book.getSubtitle(), constraintViolation.getInvalidValue() );
-		assertEquals( "Wrong propertyName", "subtitle", constraintViolation.getPropertyPath() );
-
-		book.setSubtitle( "Revised Edition" );
-		author.setCompany( "JBoss a divison of RedHat" );
-
-		constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
-		constraintViolation = constraintViolations.iterator().next();
-		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
-		assertEquals( "Wrong message", "length must be between 0 and 20", constraintViolation.getMessage() );
-		assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
-		assertEquals( "Wrong value", author.getCompany(), constraintViolation.getInvalidValue() );
-		assertEquals( "Wrong propertyName", "author.company", constraintViolation.getPropertyPath() );
-
-		author.setCompany( "JBoss" );
-
-		constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
-		assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
-	}
-
-	@Test
-	public void testDefaultGroupSequence() {
-		Validator validator = TestUtil.getValidator();
-
-		Author author = new Author();
-		author.setLastName( "" );
-		author.setFirstName( "" );
-		Book book = new Book();
-		book.setAuthor( author );
-
-		Set<ConstraintViolation<Book>> constraintViolations = validator.validate( book, Default.class );
-		assertEquals( "Wrong number of constraints", 2, constraintViolations.size() );
-
-		author.setFirstName( "Gavin" );
-		author.setLastName( "King" );
-
-		constraintViolations = validator.validate( book, Default.class );
-		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
-		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
-		assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
-		assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
-		assertEquals( "Wrong value", book.getTitle(), constraintViolation.getInvalidValue() );
-		assertEquals( "Wrong propertyName", "title", constraintViolation.getPropertyPath() );
-
-		book.setTitle( "Hibernate Persistence with JPA" );
-		book.setSubtitle( "Revised Edition of Hibernate in Action" );
-
-		constraintViolations = validator.validate( book, Default.class );
-		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
-
-		book.setSubtitle( "Revised Edition" );
-		author.setCompany( "JBoss a divison of RedHat" );
-
-		constraintViolations = validator.validate( book, Default.class );
-		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
-
-		author.setCompany( "JBoss" );
-
-		constraintViolations = validator.validate( book, Default.class );
-		assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
-	}
-
-	@Test
 	public void testBasicValidation() {
 		Validator validator = TestUtil.getValidator();
 
@@ -214,53 +108,6 @@
 	}
 
 	@Test
-	public void testGroupSequences() {
-		Validator validator = TestUtil.getValidator();
-
-		Dictonary dictonary = new Dictonary();
-		dictonary.setTitle( "English - German" );
-		Author author = new Author();
-		author.setLastName( "-" );
-		author.setFirstName( "-" );
-		author.setCompany( "Langenscheidt Publ." );
-		dictonary.setAuthor( author );
-
-		Set<ConstraintViolation<Dictonary>> constraintViolations = validator.validate( dictonary, DefaultAlias.class );
-		assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
-	}
-
-	@Test
-	public void testValidationFailureInMultipleGroups() {
-		Validator validator = TestUtil.getValidator();
-		Animal elepfant = new Animal();
-		elepfant.setName( "" );
-		elepfant.setDomain( Animal.Domain.EUKARYOTA );
-
-		Set<ConstraintViolation<Animal>> constraintViolations = validator.validate( elepfant, First.class, Second.class );
-		assertEquals(
-				"The should be two invalid constraints since the same propertyName gets validated in both groups",
-				1,
-				constraintViolations.size()
-		);
-
-		ConstraintViolation constraintViolation = constraintViolations.iterator().next();
-		Set<Class<?>> expected = new HashSet<Class<?>>();
-		expected.add( First.class );
-		expected.add( Second.class );
-		assertEquals(
-				"The constraint should be invalid for both groups",
-				expected,
-				constraintViolation.getGroups()
-		);
-	}
-
-	@Test(expected = ValidationException.class)
-	public void testInvalidSequenceName() {
-		Validator validator = TestUtil.getValidator();
-		validator.getConstraintsForClass( EnglishDictonary.class ).hasConstraints();
-	}
-
-	@Test
 	public void testValidationMethod() {
 		Validator validator = TestUtil.getValidator();
 




More information about the hibernate-commits mailing list