[hibernate-commits] Hibernate SVN: r16678 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validation/constraints/invalidvalidators and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jun 3 11:03:43 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-03 11:03:43 -0400 (Wed, 03 Jun 2009)
New Revision: 16678

Removed:
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroups.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessage.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/ValidProperty.java
Modified:
   validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java
Log:
Started moving tests into the TCK

Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java	2009-06-03 15:03:24 UTC (rev 16677)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java	2009-06-03 15:03:43 UTC (rev 16678)
@@ -25,6 +25,7 @@
 import java.util.List;
 import java.util.Map;
 import javax.validation.Constraint;
+import javax.validation.ConstraintDefinitionException;
 import javax.validation.ConstraintValidator;
 import javax.validation.ValidationException;
 import javax.validation.constraints.AssertFalse;
@@ -39,8 +40,6 @@
 import javax.validation.constraints.Pattern;
 import javax.validation.constraints.Size;
 
-import org.slf4j.Logger;
-
 import org.hibernate.validation.constraints.AssertFalseValidator;
 import org.hibernate.validation.constraints.AssertTrueValidator;
 import org.hibernate.validation.constraints.DigitsValidatorForNumber;
@@ -60,7 +59,6 @@
 import org.hibernate.validation.constraints.SizeValidatorForCollection;
 import org.hibernate.validation.constraints.SizeValidatorForMap;
 import org.hibernate.validation.constraints.SizeValidatorForString;
-import org.hibernate.validation.util.LoggerFactory;
 import org.hibernate.validation.util.ReflectionHelper;
 
 /**
@@ -71,8 +69,6 @@
  */
 public class ConstraintHelper {
 
-	private static final Logger log = LoggerFactory.make();
-
 	private final Map<Class<? extends Annotation>, List<Class<? extends ConstraintValidator<?, ?>>>> builtinConstraints =
 			new HashMap<Class<? extends Annotation>, List<Class<? extends ConstraintValidator<?, ?>>>>();
 
@@ -263,8 +259,7 @@
 		catch ( Exception e ) {
 			String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
 					"not contain a message parameter. Annotation is getting ignored.";
-			log.warn( msg );
-			return false;
+			throw new ConstraintDefinitionException( msg );
 		}
 
 		try {
@@ -273,16 +268,14 @@
 		catch ( Exception e ) {
 			String msg = annotation.annotationType().getName() + " contains Constraint annotation, but does " +
 					"not contain a groups parameter. Annotation is getting ignored.";
-			log.warn( msg );
-			return false;
+			throw new ConstraintDefinitionException( msg );
 		}
 
 		Method[] methods = annotation.getClass().getMethods();
 		for ( Method m : methods ) {
 			if ( m.getName().startsWith( "valid" ) ) {
 				String msg = "Parameters starting with 'valid' are not allowed in a constraint.";
-				log.warn( msg );
-				return false;
+				throw new ConstraintDefinitionException( msg );
 			}
 		}
 		return true;

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroups.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroups.java	2009-06-03 15:03:24 UTC (rev 16677)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroups.java	2009-06-03 15:03:43 UTC (rev 16678)
@@ -1,37 +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.constraints.invalidvalidators;
-
-import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Target;
-import javax.validation.Constraint;
-
-/**
- * @author Hardy Ferentschik
- */
- at Documented
- at Constraint(validatedBy = NoGroupsValidator.class)
- at Target({ METHOD, FIELD })
- at Retention(RUNTIME)
-public @interface NoGroups {
-	String message() default "default message";
-}
\ No newline at end of file

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java	2009-06-03 15:03:24 UTC (rev 16677)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoGroupsValidator.java	2009-06-03 15:03:43 UTC (rev 16678)
@@ -1,34 +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.constraints.invalidvalidators;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
- */
-public class NoGroupsValidator implements ConstraintValidator<NoGroups, Object> {
-
-	public void initialize(NoGroups parameters) {
-	}
-
-	public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
-		return false;
-	}
-}
\ No newline at end of file

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessage.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessage.java	2009-06-03 15:03:24 UTC (rev 16677)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessage.java	2009-06-03 15:03:43 UTC (rev 16678)
@@ -1,37 +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.constraints.invalidvalidators;
-
-import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Target;
-import javax.validation.Constraint;
-
-/**
- * @author Hardy Ferentschik
- */
- at Documented
- at Constraint(validatedBy = NoMessageValidator.class)
- at Target({ METHOD, FIELD })
- at Retention(RUNTIME)
-public @interface NoMessage {
-	Class<?>[] groups() default { };
-}
\ No newline at end of file

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java	2009-06-03 15:03:24 UTC (rev 16677)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/NoMessageValidator.java	2009-06-03 15:03:43 UTC (rev 16678)
@@ -1,34 +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.constraints.invalidvalidators;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
- */
-public class NoMessageValidator implements ConstraintValidator<NoMessage, Object> {
-
-	public void initialize(NoMessage parameters) {
-	}
-
-	public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
-		return false;
-	}
-}
\ No newline at end of file

Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/ValidProperty.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/ValidProperty.java	2009-06-03 15:03:24 UTC (rev 16677)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/invalidvalidators/ValidProperty.java	2009-06-03 15:03:43 UTC (rev 16678)
@@ -1,41 +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.constraints.invalidvalidators;
-
-import java.lang.annotation.Documented;
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Target;
-import javax.validation.Constraint;
-
-/**
- * @author Hardy Ferentschik
- */
- at Documented
- at Constraint(validatedBy = NoGroupsValidator.class)
- at Target({ METHOD, FIELD })
- at Retention(RUNTIME)
-public @interface ValidProperty {
-	String message() default "default message";
-
-	Class<?>[] groups() default { };
-
-	int validLength() default 0;
-}
\ No newline at end of file

Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java	2009-06-03 15:03:24 UTC (rev 16677)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java	2009-06-03 15:03:43 UTC (rev 16678)
@@ -23,15 +23,11 @@
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
 
-import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import org.hibernate.validation.constraints.invalidvalidators.NoGroups;
-import org.hibernate.validation.constraints.invalidvalidators.NoMessage;
-import org.hibernate.validation.constraints.invalidvalidators.ValidProperty;
 import org.hibernate.validation.util.ReflectionHelper;
 
 /**
@@ -47,62 +43,6 @@
 	}
 
 	@Test
-	public void testConstraintWithNoMessage() {
-		Annotation annotation = new NoGroups() {
-			public String message() {
-				return "";
-			}
-
-			public Class<? extends Annotation> annotationType() {
-				return this.getClass();
-			}
-		};
-		assertFalse(
-				constraintHelper.isConstraintAnnotation( annotation ), "The constraint annotation should not be valid"
-		);
-	}
-
-	@Test
-	public void testConstraintWithNoGroups() {
-		Annotation annotation = new NoMessage() {
-			public Class<?>[] groups() {
-				return null;
-			}
-
-			public Class<? extends Annotation> annotationType() {
-				return this.getClass();
-			}
-		};
-		assertFalse(
-				constraintHelper.isConstraintAnnotation( annotation ), "The constraint annotation should not be valid"
-		);
-	}
-
-	@Test
-	public void testConstraintWithValidInPropertyName() {
-		Annotation annotation = new ValidProperty() {
-			public String message() {
-				return null;
-			}
-
-			public Class<?>[] groups() {
-				return null;
-			}
-
-			public int validLength() {
-				return 0;
-			}
-
-			public Class<? extends Annotation> annotationType() {
-				return this.getClass();
-			}
-		};
-		assertFalse(
-				constraintHelper.isConstraintAnnotation( annotation ), "The constraint annotation should not be valid"
-		);
-	}
-
-	@Test
 	public void testGetMultiValueConstraints() throws Exception {
 		Engine engine = new Engine();
 		Field[] fields = engine.getClass().getDeclaredFields();




More information about the hibernate-commits mailing list