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

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Feb 26 09:18:07 EST 2009


Author: hardy.ferentschik
Date: 2009-02-26 09:18:07 -0500 (Thu, 26 Feb 2009)
New Revision: 16045

Added:
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java
Modified:
   validator/trunk/hibernate-validator/pom.xml
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChain.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainGeneratorTest.java
   validator/trunk/hibernate-validator/src/test/resources/log4j.properties
Log:
HV-83 Improved the way the object graph is traveresed in a simpel way. Now the processing of groups is breadth first and sequences are processed depth first.

Also fixed a bug regarding indexed cascaded constraints.

Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml	2009-02-26 13:52:37 UTC (rev 16044)
+++ validator/trunk/hibernate-validator/pom.xml	2009-02-26 14:18:07 UTC (rev 16045)
@@ -40,6 +40,12 @@
             <version>4.4</version>
             <scope>test</scope>
         </dependency>
+       <dependency>
+            <groupId>junitperf</groupId>
+            <artifactId>junitperf</artifactId>
+            <version>1.8</version>
+            <scope>test</scope>
+        </dependency>        
     </dependencies>
     <build>
         <resources>

Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java	2009-02-26 13:52:37 UTC (rev 16044)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ExecutionContext.java	2009-02-26 14:18:07 UTC (rev 16045)
@@ -203,7 +203,8 @@
 	}
 
 	public void replacePropertyIndex(String index) {
-		propertyPath = propertyPath.replaceAll( "\\{0\\}", index );
+		// replace the last occurance of [<oldIndex>] with [<index>] 
+		propertyPath = propertyPath.replaceAll( "\\[[0-9]*\\]$", "[" + index + "]" );
 	}
 
 	public String peekPropertyPath() {

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-26 13:52:37 UTC (rev 16044)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ValidatorImpl.java	2009-02-26 14:18:07 UTC (rev 16045)
@@ -183,16 +183,34 @@
 			return Collections.emptyList();
 		}
 
-		while ( groupChain.hasNext() ) {
-			int numberOfViolations = context.getFailingConstraints().size();
-			Group group = groupChain.next();
+		// process all groups breadth-first
+		Iterator<Group> groupIterator = groupChain.getGroupIterator();
+		while ( groupIterator.hasNext() ) {
+			Group group = groupIterator.next();
 			context.setCurrentGroup( group.getGroup() );
-
 			validateConstraints( context );
+		}
+		groupIterator = groupChain.getGroupIterator();
+		while ( groupIterator.hasNext() ) {
+			Group group = groupIterator.next();
+			context.setCurrentGroup( group.getGroup() );
 			validateCascadedConstraints( context );
+		}
 
-			if ( groupChain.inSequence() && context.getFailingConstraints().size() > numberOfViolations ) {
-				groupChain.moveToLastInCurrentSequence();
+		// process sequences depth-first to guarantee that groups following a violation within a group won't get executed. 
+		Iterator<List<Group>> sequenceIterator = groupChain.getSequenceIterator();
+		while ( sequenceIterator.hasNext() ) {
+			List<Group> sequence = sequenceIterator.next();
+			for ( Group group : sequence ) {
+				int numberOfViolations = context.getFailingConstraints().size();
+				context.setCurrentGroup( group.getGroup() );
+
+				validateConstraints( context );
+				validateCascadedConstraints( context );
+
+				if ( context.getFailingConstraints().size() > numberOfViolations ) {
+					break;
+				}
 			}
 		}
 		return context.getFailingConstraints();
@@ -209,8 +227,8 @@
 		BeanMetaData<T> beanMetaData = getBeanMetaData( ( Class<T> ) executionContext.peekValidatedObjectType() );
 		if ( executionContext.getCurrentGroup().getName().equals( Default.class.getName() ) ) {
 			List<Class<?>> defaultGroupSequence = beanMetaData.getDefaultGroupSequence();
-			if ( log.isDebugEnabled() && defaultGroupSequence.size() > 0 ) {
-				log.debug(
+			if ( log.isTraceEnabled() && defaultGroupSequence.size() > 0 && defaultGroupSequence.get( 0 ) != Default.class ) {
+				log.trace(
 						"Executing re-defined Default group for bean {} as sequence {}",
 						beanMetaData.getBeanClass().getName(),
 						defaultGroupSequence
@@ -220,12 +238,6 @@
 				executionContext.setCurrentGroup( defaultSequenceMember );
 				boolean validationSuccessful = validateConstraintsForCurrentGroup( executionContext, beanMetaData );
 				if ( !validationSuccessful ) {
-					if ( log.isDebugEnabled() ) {
-						log.debug(
-								"Aborting validation of Default group sequence for {} due to constraint violation.",
-								beanMetaData.getBeanClass().getName()
-						);
-					}
 					break;
 				}
 			}
@@ -293,12 +305,12 @@
 					( Iterable<?> ) value :
 					map.entrySet();
 			iter = elements.iterator();
-			context.appendIndexToPropertyPath( "[{0}]" );
+			context.appendIndexToPropertyPath( "[]" );
 		}
 		else if ( ReflectionHelper.isArray( type ) ) {
 			List<?> arrayList = Arrays.asList( value );
 			iter = arrayList.iterator();
-			context.appendIndexToPropertyPath( "[{0}]" );
+			context.appendIndexToPropertyPath( "[]" );
 		}
 		else {
 			List<Object> list = new ArrayList<Object>();
@@ -324,19 +336,16 @@
 				actualValue = ( ( Map.Entry ) actualValue ).getValue();
 			}
 
-			if ( context.isProcessedForCurrentGroup( actualValue ) ) {
-				i++;
-				continue;
+			if ( !context.isProcessedForCurrentGroup( actualValue ) ) {
+				context.replacePropertyIndex( propertyIndex );
+
+				context.pushValidatedObject( actualValue );
+				validateInContext(
+						context,
+						groupChainGenerator.getGroupChainFor( Arrays.asList( new Class<?>[] { context.getCurrentGroup() } ) )
+				);
+				context.popValidatedObject();
 			}
-
-			context.replacePropertyIndex( propertyIndex );
-
-			context.pushValidatedObject( actualValue );
-			validateInContext(
-					context,
-					groupChainGenerator.getGroupChainFor( Arrays.asList( new Class<?>[] { context.getCurrentGroup() } ) )
-			);
-			context.popValidatedObject();
 			i++;
 		}
 	}
@@ -357,40 +366,60 @@
 			return;
 		}
 
-		while ( groupChain.hasNext() ) {
-			Group group = groupChain.next();
+
+		Iterator<Group> groupIterator = groupChain.getGroupIterator();
+		while ( groupIterator.hasNext() ) {
+			Group group = groupIterator.next();
+			validatePropertyForGroup(
+					object, propertyIter, failingConstraintViolations, metaConstraints, hostingBeanInstance, group
+			);
+		}
+
+		Iterator<List<Group>> sequenceIterator = groupChain.getSequenceIterator();
+		while ( sequenceIterator.hasNext() ) {
+			List<Group> sequence = sequenceIterator.next();
 			int numberOfConstraintViolations = failingConstraintViolations.size();
-			BeanMetaData<T> beanMetaData = getBeanMetaData( metaConstraints.iterator().next().getBeanClass() );
+			for ( Group group : sequence ) {
+				validatePropertyForGroup(
+						object, propertyIter, failingConstraintViolations, metaConstraints, hostingBeanInstance, group
+				);
 
-			List<Class<?>> groupList;
-			if ( group.isDefaultGroup() ) {
-				groupList = beanMetaData.getDefaultGroupSequence();
-			}
-			else {
-				groupList = new ArrayList<Class<?>>();
-				groupList.add( group.getGroup() );
-			}
-
-			for ( Class<?> groupClass : groupList ) {
-				for ( MetaConstraint<T> metaConstraint : metaConstraints ) {
-					if ( metaConstraint.getGroupList().contains( groupClass ) ) {
-						ExecutionContext<T> context = new ExecutionContext<T>(
-								object, hostingBeanInstance, messageInterpolator, constraintValidatorFactory
-						);
-						context.pushProperty( propertyIter.getOriginalProperty() );
-						metaConstraint.validateConstraint( object.getClass(), context );
-						failingConstraintViolations.addAll( context.getFailingConstraints() );
-					}
-				}
-				if ( failingConstraintViolations.size() > numberOfConstraintViolations) {
+				if ( failingConstraintViolations.size() > numberOfConstraintViolations ) {
 					break;
 				}
 			}
+		}
+	}
 
-			if ( groupChain.inSequence() && failingConstraintViolations.size() > numberOfConstraintViolations ) {
-				groupChain.moveToLastInCurrentSequence();
+	private <T> int validatePropertyForGroup(T object, PropertyIterator propertyIter, List<ConstraintViolationImpl<T>> failingConstraintViolations, Set<MetaConstraint<T>> metaConstraints, Object hostingBeanInstance, Group group) {
+		int numberOfConstraintViolations = failingConstraintViolations.size();
+		BeanMetaData<T> beanMetaData = getBeanMetaData( metaConstraints.iterator().next().getBeanClass() );
+
+		List<Class<?>> groupList;
+		if ( group.isDefaultGroup() ) {
+			groupList = beanMetaData.getDefaultGroupSequence();
+		}
+		else {
+			groupList = new ArrayList<Class<?>>();
+			groupList.add( group.getGroup() );
+		}
+
+		for ( Class<?> groupClass : groupList ) {
+			for ( MetaConstraint<T> metaConstraint : metaConstraints ) {
+				if ( metaConstraint.getGroupList().contains( groupClass ) ) {
+					ExecutionContext<T> context = new ExecutionContext<T>(
+							object, hostingBeanInstance, messageInterpolator, constraintValidatorFactory
+					);
+					context.pushProperty( propertyIter.getOriginalProperty() );
+					metaConstraint.validateConstraint( object.getClass(), context );
+					failingConstraintViolations.addAll( context.getFailingConstraints() );
+				}
 			}
+			if ( failingConstraintViolations.size() > numberOfConstraintViolations ) {
+				break;
+			}
 		}
+		return numberOfConstraintViolations;
 	}
 
 	@SuppressWarnings("unchecked")
@@ -402,39 +431,69 @@
 			return;
 		}
 
-		while ( groupChain.hasNext() ) {
-			Group group = groupChain.next();
+		// process groups
+		Iterator<Group> groupIterator = groupChain.getGroupIterator();
+		while ( groupIterator.hasNext() ) {
+			Group group = groupIterator.next();
+			validateValueForGroup(
+					beanType,
+					value,
+					propertyIter,
+					failingConstraintViolations,
+					metaConstraints,
+					group
+			);
+		}
+
+		// process squences
+		Iterator<List<Group>> sequenceIterator = groupChain.getSequenceIterator();
+		while ( sequenceIterator.hasNext() ) {
+			List<Group> sequence = sequenceIterator.next();
 			int numberOfConstraintViolations = failingConstraintViolations.size();
-			BeanMetaData<T> beanMetaData = getBeanMetaData( metaConstraints.iterator().next().getBeanClass() );
+			for ( Group group : sequence ) {
+				validateValueForGroup(
+						beanType,
+						value,
+						propertyIter,
+						failingConstraintViolations,
+						metaConstraints,
+						group
+				);
 
-			List<Class<?>> groupList;
-			if ( group.isDefaultGroup() ) {
-				groupList = beanMetaData.getDefaultGroupSequence();
-			}
-			else {
-				groupList = new ArrayList<Class<?>>();
-				groupList.add( group.getGroup() );
-			}
-
-			for ( Class<?> groupClass : groupList ) {
-				for ( MetaConstraint<T> metaConstraint : metaConstraints ) {
-					if ( metaConstraint.getGroupList().contains( groupClass ) ) {
-						ExecutionContext<T> context = new ExecutionContext<T>(
-								( T ) value, messageInterpolator, constraintValidatorFactory
-						);
-						context.pushProperty( propertyIter.getOriginalProperty() );
-						metaConstraint.validateConstraint( beanType.getClass(), value, context );
-						failingConstraintViolations.addAll( context.getFailingConstraints() );
-					}
-				}
-				if ( failingConstraintViolations.size() > numberOfConstraintViolations) {
+				if ( failingConstraintViolations.size() > numberOfConstraintViolations ) {
 					break;
 				}
 			}
+		}
+	}
 
-			if ( groupChain.inSequence() && failingConstraintViolations.size() > numberOfConstraintViolations ) {
-				groupChain.moveToLastInCurrentSequence();
+	private <T> void validateValueForGroup(Class<T> beanType, Object value, PropertyIterator propertyIter, List<ConstraintViolationImpl<T>> failingConstraintViolations, Set<MetaConstraint<T>> metaConstraints, Group group) {
+		int numberOfConstraintViolations = failingConstraintViolations.size();
+		BeanMetaData<T> beanMetaData = getBeanMetaData( metaConstraints.iterator().next().getBeanClass() );
+
+		List<Class<?>> groupList;
+		if ( group.isDefaultGroup() ) {
+			groupList = beanMetaData.getDefaultGroupSequence();
+		}
+		else {
+			groupList = new ArrayList<Class<?>>();
+			groupList.add( group.getGroup() );
+		}
+
+		for ( Class<?> groupClass : groupList ) {
+			for ( MetaConstraint<T> metaConstraint : metaConstraints ) {
+				if ( metaConstraint.getGroupList().contains( groupClass ) ) {
+					ExecutionContext<T> context = new ExecutionContext<T>(
+							( T ) value, messageInterpolator, constraintValidatorFactory
+					);
+					context.pushProperty( propertyIter.getOriginalProperty() );
+					metaConstraint.validateConstraint( beanType.getClass(), value, context );
+					failingConstraintViolations.addAll( context.getFailingConstraints() );
+				}
 			}
+			if ( failingConstraintViolations.size() > numberOfConstraintViolations ) {
+				break;
+			}
 		}
 	}
 

Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChain.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChain.java	2009-02-26 13:52:37 UTC (rev 16044)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/groups/GroupChain.java	2009-02-26 14:18:07 UTC (rev 16045)
@@ -18,6 +18,7 @@
 package org.hibernate.validation.engine.groups;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -28,52 +29,27 @@
 public class GroupChain {
 
 	/**
-	 * The actual list of groups maintained by this instance.
+	 * The list of single groups.
 	 */
 	private List<Group> groupList = new ArrayList<Group>();
 
 	/**
-	 * A pointer to the next group element.
+	 * The list of sequences.
 	 */
-	private int nextGroupPointer = 0;
+	private List<List<Group>> sequenceList = new ArrayList<List<Group>>();
 
-	/**
-	 * The current group.
-	 */
-	private Class<?> currentSequence = null;
-
-	/**
-	 * @return Returns <code>true</code> if there is another group in the chain <code>false</code> otherwise.
-	 */
-	public boolean hasNext() {
-		return nextGroupPointer < groupList.size();
+	public Iterator<Group> getGroupIterator() {
+		return groupList.iterator();
 	}
 
-	/**
-	 * @return Returns the next group in the chain or <code>null</code> if there is none.
-	 */
-	public Group next() {
-		if ( !hasNext() ) {
-			return null;
-		}
-
-		Group group = groupList.get( nextGroupPointer );
-		nextGroupPointer++;
-		currentSequence = group.getSequence();
-		return group;
+	public Iterator<List<Group>> getSequenceIterator() {
+		return sequenceList.iterator();
 	}
 
-	/**
-	 * @return The number of groups in this chain.
-	 */
-	public int size() {
-		return groupList.size();
-	}
-
 	public boolean containsSequence(Class<?> groupSequence) {
 		boolean result = false;
-		for ( Group group : groupList ) {
-			if ( groupSequence.getName().equals( group.getSequence().getName() ) ) {
+		for ( List<Group> sequence : sequenceList ) {
+			if ( sequence.get( 0 ).getSequence().getName().equals( groupSequence.getName() ) ) {
 				result = true;
 				break;
 			}
@@ -81,30 +57,7 @@
 		return result;
 	}
 
-	public void moveToLastInCurrentSequence() {
-		if ( currentSequence == null ) {
-			return;
-		}
-
-		while ( hasNext() ) {
-			if ( currentSequence.getName().equals( groupList.get( nextGroupPointer ).getSequence().getName() ) ) {
-				next();
-			}
-			else {
-				break;
-			}
-		}
-	}
-
-	public boolean inSequence() {
-		return currentSequence != null;
-	}
-
 	void insertGroup(Group group) {
-		if ( nextGroupPointer != 0 ) {
-			throw new RuntimeException( "Trying to modify the GroupChain while iterating." );
-		}
-
 		if ( !groupList.contains( group ) ) {
 			groupList.add( group );
 		}
@@ -115,16 +68,8 @@
 			return;
 		}
 
-		if ( !containsSequence( groups.get( 0 ).getSequence() ) ) {
-			groupList.addAll( groups );
+		if ( !sequenceList.contains( groups ) ) {
+			sequenceList.add( groups );
 		}
 	}
-
-	@Override
-	public String toString() {
-		return "GroupChain{" +
-				"groupList=" + groupList +
-				", nextGroupPointer=" + nextGroupPointer +
-				'}';
-	}
 }
\ No newline at end of file

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-26 13:52:37 UTC (rev 16044)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java	2009-02-26 14:18:07 UTC (rev 16045)
@@ -40,6 +40,9 @@
 import org.hibernate.validation.eg.Order;
 import org.hibernate.validation.eg.Person;
 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.LoggerFactory;
 import org.hibernate.validation.util.TestUtil;
 import static org.hibernate.validation.util.TestUtil.assertConstraintViolation;
@@ -328,7 +331,7 @@
 		}
 		catch ( IllegalArgumentException e ) {
 			assertEquals( "Invalid property path.", e.getMessage() );
-		}		
+		}
 	}
 
 	@Test
@@ -451,4 +454,23 @@
 				groups.iterator().next()
 		);
 	}
+
+	@org.junit.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( "Wrong number of constraints", 100, constraintViolations.size() );
+	}
 }

Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainGeneratorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainGeneratorTest.java	2009-02-26 13:52:37 UTC (rev 16044)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainGeneratorTest.java	2009-02-26 14:18:07 UTC (rev 16045)
@@ -18,12 +18,13 @@
 package org.hibernate.validation.engine.groups;
 
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
+import java.util.List;
 import javax.validation.ValidationException;
 import javax.validation.groups.Default;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -31,8 +32,6 @@
 import org.hibernate.validation.eg.groups.Last;
 import org.hibernate.validation.eg.groups.Second;
 
-import static junit.framework.Assert.assertFalse;
-
 /**
  * @author Hardy Ferentschik
  */
@@ -83,35 +82,44 @@
 		groups.add( Second.class );
 		groups.add( Last.class );
 		GroupChain chain = generator.getGroupChainFor( groups );
-		assertEquals( "Wrong number of groups", 3, chain.size() );
+		int count = countGroups( chain );
+		assertEquals( "Wrong number of groups", 3, count );
 
 		groups.clear();
 		groups.add( First.class );
 		groups.add( First.class );
 		chain = generator.getGroupChainFor( groups );
-		assertEquals( "Wrong number of groups", 1, chain.size() );
+		count = countGroups( chain );
+		assertEquals( "Wrong number of groups", 1, count );
 
 		groups.clear();
 		groups.add( First.class );
 		groups.add( Last.class );
 		groups.add( First.class );
 		chain = generator.getGroupChainFor( groups );
-		assertEquals( "Wrong number of groups", 2, chain.size() );
+		count = countGroups( chain );
+		assertEquals( "Wrong number of groups", 2, count );
 	}
 
+	private int countGroups(GroupChain chain) {
+		Iterator<Group> groupIterator = chain.getGroupIterator();
+		int count = 0;
+		while (groupIterator.hasNext()) {
+			groupIterator.next();
+			count++;
+		}
+		return count;
+	}
+
 	@Test
 	public void testSequenceResolution() {
 		Set<Class<?>> groups = new HashSet<Class<?>>();
 		groups.add( Address.Complete.class );
 		GroupChain chain = generator.getGroupChainFor( groups );
-		assertEquals( "Wrong number of groups", 2, chain.size() );
+		Iterator<List<Group>> sequences = chain.getSequenceIterator();
+		List<Group> sequence = sequences.next();
 
-		assertTrue( "Should have more groups", chain.hasNext() );
-		assertEquals( "Wrong groups", Default.class, chain.next().getGroup() );
-
-		assertTrue( "Should have more groups", chain.hasNext() );
-		assertEquals( "Wrong groups", Address.HighLevelCoherence.class, chain.next().getGroup() );
-
-		assertFalse( "There should be no more groups", chain.hasNext() );
+		assertEquals( "Wrong group", Default.class, sequence.get(0).getGroup() );
+		assertEquals( "Wrong group", Address.HighLevelCoherence.class, sequence.get(1).getGroup() );
 	}
 }

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java	2009-02-26 14:18:07 UTC (rev 16045)
@@ -0,0 +1,52 @@
+// $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.util.performance;
+
+import java.util.List;
+
+import com.clarkware.junitperf.TestFactory;
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+class JUnit4TestFactory extends TestFactory {
+
+	static class DummyTestCase extends TestCase {
+		public void test() {
+		}
+	}
+
+	private List<Class<?>> junit4TestClass;
+
+	public JUnit4TestFactory(List<Class<?>> testClasses) {
+		super( DummyTestCase.class );
+		this.junit4TestClass = testClasses;
+	}
+
+	@Override
+	protected TestSuite makeTestSuite() {
+		TestSuite testSuite = new TestSuite( "JUnit4TestFactory" );
+		JUnit4TestAdapter unit4TestAdapter;
+		for ( Class<?> testClass : junit4TestClass ) {
+			unit4TestAdapter = new JUnit4TestAdapter( testClass );
+			testSuite.addTest( unit4TestAdapter );
+		}
+		return testSuite;
+	}
+}
+


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java	2009-02-26 14:18:07 UTC (rev 16045)
@@ -0,0 +1,50 @@
+// $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.util.performance;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.clarkware.junitperf.TimedTest;
+import junit.framework.Test;
+
+import org.hibernate.validation.engine.ValidatorImplTest;
+
+/**
+ * Work in progress. Timings have no relevance. Using this class one can verify if applied changes affect the
+ * performance of the framework.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ValidationPerformace {
+
+	public static Test suite() {
+
+		long maxTimeInMillis = 1000;
+		List<Class<?>> testClasses = new ArrayList<Class<?>>();
+		testClasses.add( ValidatorImplTest.class );
+		//testClasses.add( GroupTest.class );
+		//testClasses.add( ConstraintCompositionTest.class );
+		Test test = new JUnit4TestFactory( testClasses ).makeTestSuite();
+		return new TimedTest( test, maxTimeInMillis );
+	}
+
+	public static void main(String args[]) {
+		junit.textui.TestRunner.run( suite() );
+	}
+}


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: validator/trunk/hibernate-validator/src/test/resources/log4j.properties
===================================================================
--- validator/trunk/hibernate-validator/src/test/resources/log4j.properties	2009-02-26 13:52:37 UTC (rev 16044)
+++ validator/trunk/hibernate-validator/src/test/resources/log4j.properties	2009-02-26 14:18:07 UTC (rev 16045)
@@ -20,7 +20,7 @@
 ### set log levels - for more verbose logging change 'info' to 'debug' ###
 log4j.rootLogger=debug, stdout
 
-log4j.logger.org.hibernate.validation.engine.ValidatorImpl=debug
+log4j.logger.org.hibernate.validation.engine.ValidatorImpl=trace
 log4j.logger.org.hibernate.validation.engine.ConstraintTree=trace
 org.hibernate.validation.engine.ResourceBundleMessageInterpolator=info
 




More information about the hibernate-commits mailing list