Hibernate SVN: r16724 - in validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation: util and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 10:27:55 -0400 (Tue, 09 Jun 2009)
New Revision: 16724
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java
Log:
Improved handling of array types.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-06-09 14:27:01 UTC (rev 16723)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-06-09 14:27:55 UTC (rev 16724)
@@ -19,8 +19,8 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
-import java.lang.reflect.Array;
import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -30,6 +30,8 @@
import javax.validation.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
+import com.googlecode.jtype.TypeUtils;
+
import org.hibernate.validation.util.ReflectionHelper;
/**
@@ -150,8 +152,8 @@
}
default: {
t = ReflectionHelper.typeOf( member );
- if ( t instanceof Class && ((Class) t).isArray()) {
- t = Array.class;
+ if ( t instanceof Class && ((Class) t).isPrimitive()) {
+ t = ReflectionHelper.boxedTyp( t );
}
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java 2009-06-09 14:27:01 UTC (rev 16723)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ValidatorTypeHelper.java 2009-06-09 14:27:55 UTC (rev 16724)
@@ -18,7 +18,6 @@
package org.hibernate.validation.util;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -29,7 +28,9 @@
import javax.validation.ConstraintValidator;
import javax.validation.ValidationException;
+import com.googlecode.jtype.TypeUtils;
+
/**
* Helper methods around <code>ConstraintValidator</code> types.
*
@@ -70,7 +71,7 @@
throw new ValidationException( "Null is an invalid type for a constraint validator." );
}
else if ( validatorType instanceof GenericArrayType ) {
- validatorType = Array.class;
+ validatorType = TypeUtils.getArrayType( TypeUtils.getComponentType( validatorType ) );
}
while ( resolvedTypes.containsKey( validatorType ) ) {
@@ -87,7 +88,9 @@
else if ( type instanceof Class ) {
Class clazz = ( Class ) type;
final Type returnedType = resolveTypeForClassAndHierarchy( resolvedTypes, clazz );
- if ( returnedType != null) return returnedType;
+ if ( returnedType != null ) {
+ return returnedType;
+ }
}
else if ( type instanceof ParameterizedType ) {
ParameterizedType paramType = ( ParameterizedType ) type;
@@ -109,7 +112,9 @@
}
else {
Type returnedType = resolveTypeForClassAndHierarchy( resolvedTypes, rawType );
- if ( returnedType != null) return returnedType;
+ if ( returnedType != null ) {
+ return returnedType;
+ }
}
}
//else we don't care I think
15 years, 7 months
Hibernate SVN: r16723 - in validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation: engine and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 10:27:01 -0400 (Tue, 09 Jun 2009)
New Revision: 16723
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java
Log:
Added @Size validators for primitive array types.
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -0,0 +1,48 @@
+// $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;
+
+import java.lang.reflect.Array;
+import javax.validation.constraints.Size;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfBoolean extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, boolean[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(boolean[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfBoolean.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -0,0 +1,48 @@
+// $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;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForArraysOfByte extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, byte[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(byte[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfByte.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -0,0 +1,48 @@
+// $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;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForArraysOfChar extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, char[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(char[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfChar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -0,0 +1,48 @@
+// $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;
+
+import java.lang.reflect.Array;
+import javax.validation.constraints.Size;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfDouble extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, double[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(double[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfDouble.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -0,0 +1,48 @@
+// $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;
+
+import java.lang.reflect.Array;
+import javax.validation.constraints.Size;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfFloat extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, float[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(float[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfFloat.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -0,0 +1,48 @@
+// $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;
+
+import java.lang.reflect.Array;
+import javax.validation.constraints.Size;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfInt extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, int[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(int[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfInt.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -0,0 +1,48 @@
+// $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;
+
+import java.lang.reflect.Array;
+import javax.validation.constraints.Size;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfLong extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, long[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(long[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfLong.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -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.constraints;
+
+import java.lang.reflect.Array;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ValidationException;
+import javax.validation.constraints.Size;
+
+/**
+ * Check that the length of an array is betweeb <i>min</i> and <i>max</i>
+ *
+ * @author Hardy Ferentschik
+ */
+public class SizeValidatorForArraysOfPrimitives {
+ protected int min;
+ protected int max;
+
+ public void initialize(Size parameters) {
+ min = parameters.min();
+ max = parameters.max();
+ validateParameters();
+ }
+
+ private void validateParameters() {
+ if ( min < 0 ) {
+ throw new ValidationException( "The min parameter cannot be negative." );
+ }
+ if ( max < 0 ) {
+ throw new ValidationException( "The max paramter cannot be negative." );
+ }
+ if ( max < min ) {
+ throw new ValidationException( "The length cannot be negative." );
+ }
+ }
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfPrimitives.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -0,0 +1,48 @@
+// $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;
+
+import java.lang.reflect.Array;
+import javax.validation.constraints.Size;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+*/
+public class SizeValidatorForArraysOfShort extends SizeValidatorForArraysOfPrimitives
+ implements ConstraintValidator<Size, short[]> {
+
+ /**
+ * Checks the number of entries in an array.
+ *
+ * @param array The array to validate.
+ * @param constraintValidatorContext context in which the constraint is evaluated.
+ *
+ * @return Returns <code>true</code> if the array is <code>null</code> or the number of entries in
+ * <code>array</code> is between the specified <code>min</code> and <code>max</code> values (inclusive),
+ * <code>false</code> otherwise.
+ */
+ public boolean isValid(short[] array, ConstraintValidatorContext constraintValidatorContext) {
+ if ( array == null ) {
+ return true;
+ }
+ int length = Array.getLength( array );
+ return length >= min && length <= max;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArraysOfShort.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
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-09 14:26:06 UTC (rev 16722)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintHelper.java 2009-06-09 14:27:01 UTC (rev 16723)
@@ -56,6 +56,13 @@
import org.hibernate.validation.constraints.PastValidatorForDate;
import org.hibernate.validation.constraints.PatternValidator;
import org.hibernate.validation.constraints.SizeValidatorForArray;
+import org.hibernate.validation.constraints.SizeValidatorForArraysOfBoolean;
+import org.hibernate.validation.constraints.SizeValidatorForArraysOfByte;
+import org.hibernate.validation.constraints.SizeValidatorForArraysOfChar;
+import org.hibernate.validation.constraints.SizeValidatorForArraysOfDouble;
+import org.hibernate.validation.constraints.SizeValidatorForArraysOfFloat;
+import org.hibernate.validation.constraints.SizeValidatorForArraysOfInt;
+import org.hibernate.validation.constraints.SizeValidatorForArraysOfLong;
import org.hibernate.validation.constraints.SizeValidatorForCollection;
import org.hibernate.validation.constraints.SizeValidatorForMap;
import org.hibernate.validation.constraints.SizeValidatorForString;
@@ -124,6 +131,13 @@
constraintList.add( SizeValidatorForCollection.class );
constraintList.add( SizeValidatorForArray.class );
constraintList.add( SizeValidatorForMap.class );
+ constraintList.add( SizeValidatorForArraysOfBoolean.class );
+ constraintList.add( SizeValidatorForArraysOfByte.class );
+ constraintList.add( SizeValidatorForArraysOfChar.class );
+ constraintList.add( SizeValidatorForArraysOfDouble.class );
+ constraintList.add( SizeValidatorForArraysOfFloat.class );
+ constraintList.add( SizeValidatorForArraysOfInt.class );
+ constraintList.add( SizeValidatorForArraysOfLong.class );
builtinConstraints.put( Size.class, constraintList );
constraintList = new ArrayList<Class<? extends ConstraintValidator<?, ?>>>();
15 years, 7 months
Hibernate SVN: r16722 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 10:26:06 -0400 (Tue, 09 Jun 2009)
New Revision: 16722
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
Log:
Added a new helper method to determine the autoboxed type of a primitive type.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-06-09 14:19:42 UTC (rev 16721)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/util/ReflectionHelper.java 2009-06-09 14:26:06 UTC (rev 16722)
@@ -435,6 +435,47 @@
}
/**
+ * Returns the autoboxed type of a primitive type.
+ *
+ * @param primitiveType the primitive type
+ * @return the autoboxed type of a primitive type.
+ * @throws IllegalArgumentException in case the parameter {@code primitiveType} does not represent a primitive type.
+ */
+ public static Class<?> boxedTyp(Type primitiveType) {
+ if ( !( primitiveType instanceof Class ) && !( ( Class ) primitiveType ).isPrimitive() ) {
+ throw new IllegalArgumentException( primitiveType.getClass() + "has to be a primitive type" );
+ }
+
+ if ( primitiveType == boolean.class ) {
+ return Boolean.class;
+ }
+ else if ( primitiveType == char.class ) {
+ return Character.class;
+ }
+ else if ( primitiveType == double.class ) {
+ return Double.class;
+ }
+ else if ( primitiveType == float.class ) {
+ return Float.class;
+ }
+ else if ( primitiveType == long.class ) {
+ return Long.class;
+ }
+ else if ( primitiveType == int.class ) {
+ return Integer.class;
+ }
+ else if ( primitiveType == short.class ) {
+ return Short.class;
+ }
+ else if ( primitiveType == byte.class ) {
+ return Byte.class;
+ }
+ else {
+ throw new RuntimeException( "Unhandled primitive type." );
+ }
+ }
+
+ /**
* Get all superclasses and interfaces recursively.
*
* @param clazz The class to start the search with.
15 years, 7 months
Hibernate SVN: r16721 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 10:19:42 -0400 (Tue, 09 Jun 2009)
New Revision: 16721
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java
Log:
Javadoc
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java 2009-06-09 14:17:25 UTC (rev 16720)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/SizeValidatorForArray.java 2009-06-09 14:19:42 UTC (rev 16721)
@@ -24,7 +24,7 @@
import javax.validation.constraints.Size;
/**
- * Check that a string's length is between min and max.
+ * Check that the length of an array is betweeb <i>min</i> and <i>max</i>
*
* @author Hardy Ferentschik
*/
15 years, 7 months
Hibernate SVN: r16720 - in beanvalidation/trunk/validation-tck/src/main: resources and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 10:17:25 -0400 (Tue, 09 Jun 2009)
New Revision: 16720
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
Built-in constraint tests
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-08 16:05:31 UTC (rev 16719)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-09 14:17:25 UTC (rev 16720)
@@ -19,21 +19,34 @@
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.validation.constraints.AssertFalse;
import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.Future;
+import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
+import javax.validation.constraints.Past;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecAssertions;
+import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
-import org.jboss.testharness.AbstractTest;
import static org.testng.Assert.fail;
import org.testng.annotations.Test;
@@ -43,7 +56,7 @@
import static org.hibernate.jsr303.tck.util.TestUtil.assertInvalidPropertyPaths;
/**
- * Tests for built-in constraints.
+ * Tests for built-in constraints. Basically juyst checks the availabiltiy of the build-in constraints.
*
* @author Hardy Ferentschik
*/
@@ -161,105 +174,300 @@
MinDummyEntity dummy = new MinDummyEntity();
Set<ConstraintViolation<MinDummyEntity>> constraintViolations = validator.validate( dummy );
+ // only the min constraints on the primitive values should fail. Object values re still null and should pass per spec
assertCorrectNumberOfViolations( constraintViolations, 4 );
- assertInvalidPropertyPaths(constraintViolations, new String[] {"bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive"});
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive" }
+ );
-// dummy.setPrimitiveBoolean( false );
-// dummy.setObjectBoolean( Boolean.TRUE );
-//
-// constraintViolations = validator.validate( dummy );
-// assertCorrectNumberOfViolations( constraintViolations, 1 );
-// assertConstraintViolation(
-// constraintViolations.iterator().next(), MinDummyEntity.class, Boolean.TRUE, "objectBoolean"
-// );
-//
-// dummy.setObjectBoolean( Boolean.FALSE );
-// constraintViolations = validator.validate( dummy );
-// assertCorrectNumberOfViolations( constraintViolations, 0 );
+ dummy.intPrimitive = 101;
+ dummy.longPrimitive = 1001;
+ dummy.bytePrimitive = 111;
+ dummy.shortPrimitive = 142;
+
+ dummy.intObject = Integer.valueOf( "100" );
+ dummy.longObject = Long.valueOf( "0" );
+ dummy.byteObject = Byte.parseByte( "-1" );
+ dummy.shortObject = Short.parseShort( "3" );
+ dummy.bigDecimal = BigDecimal.valueOf( 100.9 );
+ dummy.bigInteger = BigInteger.valueOf( 100 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 6 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "byteObject", "intObject", "longObject", "shortObject", "bigDecimal", "bigInteger" }
+ );
+
+ dummy.intObject = Integer.valueOf( "101" );
+ dummy.longObject = Long.valueOf( "12345" );
+ dummy.byteObject = Byte.parseByte( "102" );
+ dummy.shortObject = Short.parseShort( "111" );
+ dummy.bigDecimal = BigDecimal.valueOf( 101.1 );
+ dummy.bigInteger = BigInteger.valueOf( 101 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
-// @Test
-// @SpecAssertions({
-// @SpecAssertion(section = "6", id = "a"),
-// @SpecAssertion(section = "6", id = "h")
-// })
-// public void testMaxConstraint() {
-// Validator validator = TestUtil.getDefaultValidator();
-// fail();
-// }
-//
-// @Test
-// @SpecAssertions({
-// @SpecAssertion(section = "6", id = "a"),
-// @SpecAssertion(section = "6", id = "i")
-// })
-// public void testDecimalMinConstraint() {
-// Validator validator = TestUtil.getDefaultValidator();
-// fail();
-// }
-//
-// @Test
-// @SpecAssertions({
-// @SpecAssertion(section = "6", id = "a"),
-// @SpecAssertion(section = "6", id = "j")
-// })
-// public void testDecimalMaxConstraint() {
-// Validator validator = TestUtil.getDefaultValidator();
-// fail();
-// }
-//
-// @Test
-// @SpecAssertions({
-// @SpecAssertion(section = "6", id = "a"),
-// @SpecAssertion(section = "6", id = "k")
-// })
-// public void testSizeConstraint() {
-// Validator validator = TestUtil.getDefaultValidator();
-// fail();
-// }
-//
-// @Test
-// @SpecAssertions({
-// @SpecAssertion(section = "6", id = "a"),
-// @SpecAssertion(section = "6", id = "l")
-// })
-// public void testDigitsConstraint() {
-// Validator validator = TestUtil.getDefaultValidator();
-// fail();
-// }
-//
-// @Test
-// @SpecAssertions({
-// @SpecAssertion(section = "6", id = "a"),
-// @SpecAssertion(section = "6", id = "m")
-// })
-// public void testPastConstraint() {
-// Validator validator = TestUtil.getDefaultValidator();
-// fail();
-// }
-//
-// @Test
-// @SpecAssertions({
-// @SpecAssertion(section = "6", id = "a"),
-// @SpecAssertion(section = "6", id = "n")
-// })
-// public void testFutureConstraint() {
-// Validator validator = TestUtil.getDefaultValidator();
-// fail();
-// }
-//
-// @Test
-// @SpecAssertions({
-// @SpecAssertion(section = "6", id = "a"),
-// @SpecAssertion(section = "6", id = "o")
-// })
-// public void testPatternConstraint() {
-// Validator validator = TestUtil.getDefaultValidator();
-// fail();
-// }
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "h")
+ })
+ public void testMaxConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ MaxDummyEntity dummy = new MaxDummyEntity();
+ dummy.intPrimitive = 102;
+ dummy.longPrimitive = 1234;
+ dummy.bytePrimitive = 102;
+ dummy.shortPrimitive = 102;
+ Set<ConstraintViolation<MaxDummyEntity>> constraintViolations = validator.validate( dummy );
+ // only the max constraints on the primitive values should fail. Object values re still null and should pass per spec
+ assertCorrectNumberOfViolations( constraintViolations, 4 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive" }
+ );
+
+
+ dummy.intPrimitive = 101;
+ dummy.longPrimitive = 100;
+ dummy.bytePrimitive = 99;
+ dummy.shortPrimitive = 42;
+
+ dummy.intObject = Integer.valueOf( "102" );
+ dummy.longObject = Long.valueOf( "12345" );
+ dummy.byteObject = Byte.parseByte( "111" );
+ dummy.shortObject = Short.parseShort( "1234" );
+ dummy.bigDecimal = BigDecimal.valueOf( 102 );
+ dummy.bigInteger = BigInteger.valueOf( 102 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 6 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "byteObject", "intObject", "longObject", "shortObject", "bigDecimal", "bigInteger" }
+ );
+
+ dummy.intObject = Integer.valueOf( "101" );
+ dummy.longObject = Long.valueOf( "100" );
+ dummy.byteObject = Byte.parseByte( "100" );
+ dummy.shortObject = Short.parseShort( "101" );
+ dummy.bigDecimal = BigDecimal.valueOf( 100.9 );
+ dummy.bigInteger = BigInteger.valueOf( 100 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test(enabled = false)
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "i")
+ })
+ public void testDecimalMinConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ fail();
+ }
+
+ @Test(enabled = false)
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "j")
+ })
+ public void testDecimalMaxConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ fail();
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "k")
+ })
+ public void testSizeConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ SizeDummyEntity dummy = new SizeDummyEntity();
+
+ Set<ConstraintViolation<SizeDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ dummy.collection = new HashSet<String>();
+ dummy.collection.add( "foo" );
+ dummy.collection.add( "bar" );
+
+ dummy.string = "";
+
+ dummy.map = new HashMap<String, String>();
+ dummy.map.put( "key1", "value1" );
+ dummy.map.put( "key2", "value2" );
+
+ dummy.integerArray = new Integer[0];
+
+ dummy.intArray = new int[0];
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 5 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "collection", "map", "string", "integerArray", "intArray" }
+ );
+
+ dummy.collection.remove( "bar" );
+ dummy.string = "a";
+ dummy.integerArray = new Integer[1];
+ dummy.intArray = new int[1];
+ dummy.map.remove( "key1" );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "l")
+ })
+ public void testDigitsConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ DigitsDummyEntity dummy = new DigitsDummyEntity();
+
+ dummy.intPrimitive = 42;
+ dummy.longPrimitive = 42;
+ dummy.bytePrimitive = 42;
+ dummy.shortPrimitive = 42;
+
+ Set<ConstraintViolation<DigitsDummyEntity>> constraintViolations = validator.validate( dummy );
+ // only the max constraints on the primitive values should fail. Object values re still null and should pass per spec
+ assertCorrectNumberOfViolations( constraintViolations, 4 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive" }
+ );
+
+
+ dummy.intPrimitive = 1;
+ dummy.longPrimitive = 1;
+ dummy.bytePrimitive = 1;
+ dummy.shortPrimitive = 1;
+
+ dummy.intObject = Integer.valueOf( "102" );
+ dummy.longObject = Long.valueOf( "12345" );
+ dummy.byteObject = Byte.parseByte( "111" );
+ dummy.shortObject = Short.parseShort( "1234" );
+ dummy.bigDecimal = BigDecimal.valueOf( 102 );
+ dummy.bigInteger = BigInteger.valueOf( 102 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 6 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "byteObject", "intObject", "longObject", "shortObject", "bigDecimal", "bigInteger" }
+ );
+
+ dummy.intObject = Integer.valueOf( "1" );
+ dummy.longObject = Long.valueOf( "1" );
+ dummy.byteObject = Byte.parseByte( "1" );
+ dummy.shortObject = Short.parseShort( "1" );
+ dummy.bigDecimal = BigDecimal.valueOf( 1.93 );
+ dummy.bigInteger = BigInteger.valueOf( 5 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "m")
+ })
+ public void testPastConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ PastDummyEntity dummy = new PastDummyEntity();
+
+ Set<ConstraintViolation<PastDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ Calendar cal = GregorianCalendar.getInstance();
+ cal.add( Calendar.YEAR, 1 );
+
+ dummy.calendar = cal;
+ dummy.date = cal.getTime();
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "date", "calendar" }
+ );
+
+ cal.add( Calendar.YEAR, -2 );
+ dummy.calendar = cal;
+ dummy.date = cal.getTime();
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "n")
+ })
+ public void testFutureConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ FutureDummyEntity dummy = new FutureDummyEntity();
+
+ Set<ConstraintViolation<FutureDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ Calendar cal = GregorianCalendar.getInstance();
+ cal.add( Calendar.YEAR, -1 );
+
+ dummy.calendar = cal;
+ dummy.date = cal.getTime();
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "date", "calendar" }
+ );
+
+ cal.add( Calendar.YEAR, 2 );
+ dummy.calendar = cal;
+ dummy.date = cal.getTime();
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "o")
+ })
+ public void testPatternConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ PatternDummyEntity dummy = new PatternDummyEntity();
+
+ Set<ConstraintViolation<PatternDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ dummy.pattern = "ab cd";
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), PatternDummyEntity.class, "ab cd", "pattern"
+ );
+
+ dummy.pattern = "wc 00";
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
class NullDummyEntity {
@Null
Object property;
@@ -365,4 +573,106 @@
@Min(101)
Long longObject;
}
+
+ class MaxDummyEntity {
+ @Max(101)
+ BigDecimal bigDecimal;
+
+ @Max(101)
+ BigInteger bigInteger;
+
+ @Max(101)
+ byte bytePrimitive;
+
+ @Max(101)
+ short shortPrimitive;
+
+ @Max(101)
+ int intPrimitive;
+
+ @Max(101)
+ long longPrimitive;
+
+ @Max(101)
+ Byte byteObject;
+
+ @Max(101)
+ Short shortObject;
+
+ @Max(101)
+ Integer intObject;
+
+ @Max(101)
+ Long longObject;
+ }
+
+ class SizeDummyEntity {
+ @Size(min = 1, max = 1)
+ String string;
+
+ @Size(min = 1, max = 1)
+ Collection<String> collection;
+
+ @Size(min = 1, max = 1)
+ Map<String, String> map;
+
+ @Size(min = 1, max = 1)
+ Integer[] integerArray;
+
+ @Size(min = 1, max = 1)
+ int[] intArray;
+ }
+
+ class DigitsDummyEntity {
+ @Digits(integer = 1, fraction = 2)
+ BigDecimal bigDecimal;
+
+ @Digits(integer = 1, fraction = 0)
+ BigInteger bigInteger;
+
+ @Digits(integer = 1, fraction = 0)
+ byte bytePrimitive;
+
+ @Digits(integer = 1, fraction = 0)
+ short shortPrimitive;
+
+ @Digits(integer = 1, fraction = 0)
+ int intPrimitive;
+
+ @Digits(integer = 1, fraction = 0)
+ long longPrimitive;
+
+ @Digits(integer = 1, fraction = 0)
+ Byte byteObject;
+
+ @Digits(integer = 1, fraction = 0)
+ Short shortObject;
+
+ @Digits(integer = 1, fraction = 0)
+ Integer intObject;
+
+ @Digits(integer = 1, fraction = 0)
+ Long longObject;
+ }
+
+ class PastDummyEntity {
+ @Past
+ Calendar calendar;
+
+ @Past
+ Date date;
+ }
+
+ class FutureDummyEntity {
+ @Future
+ Calendar calendar;
+
+ @Future
+ Date date;
+ }
+
+ class PatternDummyEntity {
+ @Pattern(regexp = "[a-z][a-z] \\d\\d")
+ String pattern;
+ }
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-08 16:05:31 UTC (rev 16719)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-09 14:17:25 UTC (rev 16720)
@@ -211,22 +211,14 @@
</section>
<section id="2.5" title="The ConstraintValidatorFactory">
<assertion id="a">
- <text>Constraint validation implementation instances are created by a
- ConstraintValidatorFactory</text>
- </assertion>
- <assertion id="b">
<text>The default ConstraintValidatorFactory provided by the Bean Validation provider
- implementation uses the pub- lic constraint no-arg constructor</text>
+ implementation uses the public constraint no-arg constructor</text>
</assertion>
- <assertion id="c">
- <text>ConstraintValidatorFactory should not cache instances as the state of each
- instance can be altered in the ini- tialize method</text>
- </assertion>
- <assertion id="d">
+ <assertion id="b">
<text>If an exception occurs in the factory while retrieving the ConstraintValidator
instance, the runtime exception is wrapped in a ValidationException</text>
</assertion>
- <assertion id="e">
+ <assertion id="c">
<text>If the instance returned by the factory is null, a ValidationException is
raised</text>
</assertion>
15 years, 7 months
Hibernate SVN: r16719 - core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-08 12:05:31 -0400 (Mon, 08 Jun 2009)
New Revision: 16719
Added:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/BasicLoader.java
Log:
HHH-2980 - Error "org.hibernate.HibernateException: cannot simultaneously fetch multiple bags" not specific enough
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/BasicLoader.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/BasicLoader.java 2009-06-08 16:05:08 UTC (rev 16718)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/BasicLoader.java 2009-06-08 16:05:31 UTC (rev 16719)
@@ -24,11 +24,13 @@
*/
package org.hibernate.loader;
+import java.util.Set;
+import java.util.HashSet;
+
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.BagType;
-import org.hibernate.HibernateException;
/**
* Uses the default mapping from property to result set column
@@ -68,13 +70,16 @@
}
CollectionPersister[] collectionPersisters = getCollectionPersisters();
- int bagCount = 0;
+ Set bagRoles = null;
if ( collectionPersisters != null ) {
String[] collectionSuffixes = getCollectionSuffixes();
collectionDescriptors = new CollectionAliases[collectionPersisters.length];
for ( int i = 0; i < collectionPersisters.length; i++ ) {
if ( isBag( collectionPersisters[i] ) ) {
- bagCount++;
+ if ( bagRoles == null ) {
+ bagRoles = new HashSet();
+ }
+ bagRoles.add( collectionPersisters[i].getRole() );
}
collectionDescriptors[i] = new GeneratedCollectionAliases(
collectionPersisters[i],
@@ -85,8 +90,8 @@
else {
collectionDescriptors = null;
}
- if ( bagCount > 1 ) {
- throw new HibernateException( "cannot simultaneously fetch multiple bags" );
+ if ( bagRoles != null && bagRoles.size() > 1 ) {
+ throw new MultipleBagFetchException( bagRoles );
}
}
@@ -98,13 +103,31 @@
* Utility method that generates 0_, 1_ suffixes. Subclasses don't
* necessarily need to use this algorithm, but it is intended that
* they will in most cases.
+ * <p/>
+ * This form simply calls {@link #generateSuffixes(int, int) generateSuffixes(0,length}
+ *
+ * @param length The number of suffixes to generate
+ *
+ * @return The array of generated suffixes; the array length = length.
*/
public static String[] generateSuffixes(int length) {
return generateSuffixes( 0, length );
}
+ /**
+ * Utility method that generates alias suffixes.
+ *
+ * @param seed The number from which to begin the suffix sequencing. For example,
+ * a seed of 0 would return 0_ as the first suffix; a seed of 5 would return 5_ as
+ * the first suffix.
+ * @param length The number of suffixes to generate
+ *
+ * @return The array of generated suffixes; the array length = length.
+ */
public static String[] generateSuffixes(int seed, int length) {
- if ( length == 0 ) return NO_SUFFIX;
+ if ( length == 0 ) {
+ return NO_SUFFIX;
+ }
String[] suffixes = new String[length];
for ( int i = 0; i < length; i++ ) {
Added: core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java (rev 0)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java 2009-06-08 16:05:31 UTC (rev 16719)
@@ -0,0 +1,52 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.loader;
+
+import java.util.Set;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Exception used to indicate that a query is attempting to simultaneously fetch multiple
+ * {@link org.hibernate.type.BagType bags}
+*
+* @author Steve Ebersole
+*/
+public class MultipleBagFetchException extends HibernateException {
+ private final Set bagRoles;
+
+ public MultipleBagFetchException(Set bagRoles) {
+ super( "cannot simultaneously fetch multiple bags" );
+ this.bagRoles = bagRoles;
+ }
+
+ /**
+ * Retrieves the set of collection roles for the bags encountered.
+ *
+ * @return The bag collection roles.
+ */
+ public Set getBagRoles() {
+ return bagRoles;
+ }
+}
15 years, 7 months
Hibernate SVN: r16718 - core/branches/Branch_3_2/src/org/hibernate/loader.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-08 12:05:08 -0400 (Mon, 08 Jun 2009)
New Revision: 16718
Added:
core/branches/Branch_3_2/src/org/hibernate/loader/MultipleBagFetchException.java
Modified:
core/branches/Branch_3_2/src/org/hibernate/loader/BasicLoader.java
Log:
HHH-2980 - Error "org.hibernate.HibernateException: cannot simultaneously fetch multiple bags" not specific enough
Modified: core/branches/Branch_3_2/src/org/hibernate/loader/BasicLoader.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/loader/BasicLoader.java 2009-06-08 15:55:03 UTC (rev 16717)
+++ core/branches/Branch_3_2/src/org/hibernate/loader/BasicLoader.java 2009-06-08 16:05:08 UTC (rev 16718)
@@ -1,11 +1,13 @@
//$Id$
package org.hibernate.loader;
+import java.util.Set;
+import java.util.HashSet;
+
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.BagType;
-import org.hibernate.HibernateException;
/**
* Uses the default mapping from property to result set column
@@ -45,13 +47,16 @@
}
CollectionPersister[] collectionPersisters = getCollectionPersisters();
- int bagCount = 0;
+ Set bagRoles = null;
if ( collectionPersisters != null ) {
String[] collectionSuffixes = getCollectionSuffixes();
collectionDescriptors = new CollectionAliases[collectionPersisters.length];
for ( int i = 0; i < collectionPersisters.length; i++ ) {
if ( isBag( collectionPersisters[i] ) ) {
- bagCount++;
+ if ( bagRoles == null ) {
+ bagRoles = new HashSet();
+ }
+ bagRoles.add( collectionPersisters[i].getRole() );
}
collectionDescriptors[i] = new GeneratedCollectionAliases(
collectionPersisters[i],
@@ -62,8 +67,8 @@
else {
collectionDescriptors = null;
}
- if ( bagCount > 1 ) {
- throw new HibernateException( "cannot simultaneously fetch multiple bags" );
+ if ( bagRoles != null && bagRoles.size() > 1 ) {
+ throw new MultipleBagFetchException( bagRoles );
}
}
@@ -75,13 +80,31 @@
* Utility method that generates 0_, 1_ suffixes. Subclasses don't
* necessarily need to use this algorithm, but it is intended that
* they will in most cases.
+ * <p/>
+ * This form simply calls {@link #generateSuffixes(int, int) generateSuffixes(0,length}
+ *
+ * @param length The number of suffixes to generate
+ *
+ * @return The array of generated suffixes; the array length = length.
*/
public static String[] generateSuffixes(int length) {
return generateSuffixes( 0, length );
}
+ /**
+ * Utility method that generates alias suffixes.
+ *
+ * @param seed The number from which to begin the suffix sequencing. For example,
+ * a seed of 0 would return 0_ as the first suffix; a seed of 5 would return 5_ as
+ * the first suffix.
+ * @param length The number of suffixes to generate
+ *
+ * @return The array of generated suffixes; the array length = length.
+ */
public static String[] generateSuffixes(int seed, int length) {
- if ( length == 0 ) return NO_SUFFIX;
+ if ( length == 0 ) {
+ return NO_SUFFIX;
+ }
String[] suffixes = new String[length];
for ( int i = 0; i < length; i++ ) {
Added: core/branches/Branch_3_2/src/org/hibernate/loader/MultipleBagFetchException.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/loader/MultipleBagFetchException.java (rev 0)
+++ core/branches/Branch_3_2/src/org/hibernate/loader/MultipleBagFetchException.java 2009-06-08 16:05:08 UTC (rev 16718)
@@ -0,0 +1,52 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.loader;
+
+import java.util.Set;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Exception used to indicate that a query is attempting to simultaneously fetch multiple
+ * {@link org.hibernate.type.BagType bags}
+*
+* @author Steve Ebersole
+*/
+public class MultipleBagFetchException extends HibernateException {
+ private final Set bagRoles;
+
+ public MultipleBagFetchException(Set bagRoles) {
+ super( "cannot simultaneously fetch multiple bags" );
+ this.bagRoles = bagRoles;
+ }
+
+ /**
+ * Retrieves the set of collection roles for the bags encountered.
+ *
+ * @return The bag collection roles.
+ */
+ public Set getBagRoles() {
+ return bagRoles;
+ }
+}
15 years, 7 months
Hibernate SVN: r16717 - core/trunk/core/src/main/java/org/hibernate/loader.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-06-08 11:55:03 -0400 (Mon, 08 Jun 2009)
New Revision: 16717
Added:
core/trunk/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java
Modified:
core/trunk/core/src/main/java/org/hibernate/loader/BasicLoader.java
Log:
HHH-2980 - Error "org.hibernate.HibernateException: cannot simultaneously fetch multiple bags" not specific enough
Modified: core/trunk/core/src/main/java/org/hibernate/loader/BasicLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/BasicLoader.java 2009-06-08 09:41:28 UTC (rev 16716)
+++ core/trunk/core/src/main/java/org/hibernate/loader/BasicLoader.java 2009-06-08 15:55:03 UTC (rev 16717)
@@ -24,11 +24,13 @@
*/
package org.hibernate.loader;
+import java.util.Set;
+import java.util.HashSet;
+
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.BagType;
-import org.hibernate.HibernateException;
/**
* Uses the default mapping from property to result set column
@@ -68,13 +70,16 @@
}
CollectionPersister[] collectionPersisters = getCollectionPersisters();
- int bagCount = 0;
+ Set bagRoles = null;
if ( collectionPersisters != null ) {
String[] collectionSuffixes = getCollectionSuffixes();
collectionDescriptors = new CollectionAliases[collectionPersisters.length];
for ( int i = 0; i < collectionPersisters.length; i++ ) {
if ( isBag( collectionPersisters[i] ) ) {
- bagCount++;
+ if ( bagRoles == null ) {
+ bagRoles = new HashSet();
+ }
+ bagRoles.add( collectionPersisters[i].getRole() );
}
collectionDescriptors[i] = new GeneratedCollectionAliases(
collectionPersisters[i],
@@ -85,8 +90,8 @@
else {
collectionDescriptors = null;
}
- if ( bagCount > 1 ) {
- throw new HibernateException( "cannot simultaneously fetch multiple bags" );
+ if ( bagRoles != null && bagRoles.size() > 1 ) {
+ throw new MultipleBagFetchException( bagRoles );
}
}
@@ -98,6 +103,10 @@
* Utility method that generates 0_, 1_ suffixes. Subclasses don't
* necessarily need to use this algorithm, but it is intended that
* they will in most cases.
+ *
+ * @param length The number of suffixes to generate
+ *
+ * @return The array of generated suffixes (with length=length).
*/
public static String[] generateSuffixes(int length) {
return generateSuffixes( 0, length );
Added: core/trunk/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/loader/MultipleBagFetchException.java 2009-06-08 15:55:03 UTC (rev 16717)
@@ -0,0 +1,52 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.loader;
+
+import java.util.Set;
+
+import org.hibernate.HibernateException;
+
+/**
+ * Exception used to indicate that a query is attempting to simultaneously fetch multiple
+ * {@link org.hibernate.type.BagType bags}
+*
+* @author Steve Ebersole
+*/
+public class MultipleBagFetchException extends HibernateException {
+ private final Set bagRoles;
+
+ public MultipleBagFetchException(Set bagRoles) {
+ super( "cannot simultaneously fetch multiple bags" );
+ this.bagRoles = bagRoles;
+ }
+
+ /**
+ * Retrieves the set of collection roles for the bags encountered.
+ *
+ * @return The bag collection roles.
+ */
+ public Set getBagRoles() {
+ return bagRoles;
+ }
+}
15 years, 7 months
Hibernate SVN: r16716 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-08 05:41:28 -0400 (Mon, 08 Jun 2009)
New Revision: 16716
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
Modified:
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
Started adding tests for built-in constraints
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-08 09:41:28 UTC (rev 16716)
@@ -0,0 +1,368 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.constraints.builtinconstraints;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.constraints.AssertFalse;
+import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Null;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.AbstractTest;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertInvalidPropertyPaths;
+
+/**
+ * Tests for built-in constraints.
+ *
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+public class BuiltinConstraintsTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "c")
+ })
+ public void testNullConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ NullDummyEntity dummy = new NullDummyEntity();
+ Object foo = new Object();
+ dummy.setProperty( foo );
+ Set<ConstraintViolation<NullDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), NullDummyEntity.class, foo, "property"
+ );
+
+ dummy.setProperty( null );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "d")
+ })
+ public void testNotNullConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ NotNullDummyEntity dummy = new NotNullDummyEntity();
+ Set<ConstraintViolation<NotNullDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), NotNullDummyEntity.class, null, "property"
+ );
+
+ dummy.setProperty( new Object() );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "e")
+ })
+ public void testAssertTrueConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ AssertTrueDummyEntity dummy = new AssertTrueDummyEntity();
+
+ Set<ConstraintViolation<AssertTrueDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), AssertTrueDummyEntity.class, false, "primitiveBoolean"
+ );
+
+ dummy.setPrimitiveBoolean( true );
+ dummy.setObjectBoolean( Boolean.FALSE );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), AssertTrueDummyEntity.class, Boolean.FALSE, "objectBoolean"
+ );
+
+ dummy.setObjectBoolean( Boolean.TRUE );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "f")
+ })
+ public void testAssertFalseConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ AssertFalseDummyEntity dummy = new AssertFalseDummyEntity();
+ dummy.setPrimitiveBoolean( true );
+
+ Set<ConstraintViolation<AssertFalseDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), AssertFalseDummyEntity.class, true, "primitiveBoolean"
+ );
+
+ dummy.setPrimitiveBoolean( false );
+ dummy.setObjectBoolean( Boolean.TRUE );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), AssertFalseDummyEntity.class, Boolean.TRUE, "objectBoolean"
+ );
+
+ dummy.setObjectBoolean( Boolean.FALSE );
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "6", id = "a"),
+ @SpecAssertion(section = "6", id = "g")
+ })
+ public void testMinConstraint() {
+ Validator validator = TestUtil.getDefaultValidator();
+ MinDummyEntity dummy = new MinDummyEntity();
+
+ Set<ConstraintViolation<MinDummyEntity>> constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 4 );
+ assertInvalidPropertyPaths(constraintViolations, new String[] {"bytePrimitive", "intPrimitive", "longPrimitive", "shortPrimitive"});
+
+
+// dummy.setPrimitiveBoolean( false );
+// dummy.setObjectBoolean( Boolean.TRUE );
+//
+// constraintViolations = validator.validate( dummy );
+// assertCorrectNumberOfViolations( constraintViolations, 1 );
+// assertConstraintViolation(
+// constraintViolations.iterator().next(), MinDummyEntity.class, Boolean.TRUE, "objectBoolean"
+// );
+//
+// dummy.setObjectBoolean( Boolean.FALSE );
+// constraintViolations = validator.validate( dummy );
+// assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "h")
+// })
+// public void testMaxConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "i")
+// })
+// public void testDecimalMinConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "j")
+// })
+// public void testDecimalMaxConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "k")
+// })
+// public void testSizeConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "l")
+// })
+// public void testDigitsConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "m")
+// })
+// public void testPastConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "n")
+// })
+// public void testFutureConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+//
+// @Test
+// @SpecAssertions({
+// @SpecAssertion(section = "6", id = "a"),
+// @SpecAssertion(section = "6", id = "o")
+// })
+// public void testPatternConstraint() {
+// Validator validator = TestUtil.getDefaultValidator();
+// fail();
+// }
+
+
+ class NullDummyEntity {
+ @Null
+ Object property;
+
+ public Object getProperty() {
+ return property;
+ }
+
+ public void setProperty(Object property) {
+ this.property = property;
+ }
+ }
+
+ class NotNullDummyEntity {
+ @NotNull
+ Object property;
+
+ public Object getProperty() {
+ return property;
+ }
+
+ public void setProperty(Object property) {
+ this.property = property;
+ }
+ }
+
+ class AssertTrueDummyEntity {
+ @AssertTrue
+ boolean primitiveBoolean;
+
+ @AssertTrue
+ Boolean objectBoolean;
+
+ public boolean isPrimitiveBoolean() {
+ return primitiveBoolean;
+ }
+
+ public void setPrimitiveBoolean(boolean primitiveBoolean) {
+ this.primitiveBoolean = primitiveBoolean;
+ }
+
+ public Boolean isObjectBoolean() {
+ return objectBoolean;
+ }
+
+ public void setObjectBoolean(Boolean objectBoolean) {
+ this.objectBoolean = objectBoolean;
+ }
+ }
+
+ class AssertFalseDummyEntity {
+ @AssertFalse
+ boolean primitiveBoolean;
+
+ @AssertFalse
+ Boolean objectBoolean;
+
+ public boolean isPrimitiveBoolean() {
+ return primitiveBoolean;
+ }
+
+ public void setPrimitiveBoolean(boolean primitiveBoolean) {
+ this.primitiveBoolean = primitiveBoolean;
+ }
+
+ public Boolean isObjectBoolean() {
+ return objectBoolean;
+ }
+
+ public void setObjectBoolean(Boolean objectBoolean) {
+ this.objectBoolean = objectBoolean;
+ }
+ }
+
+ class MinDummyEntity {
+ @Min(101)
+ BigDecimal bigDecimal;
+
+ @Min(101)
+ BigInteger bigInteger;
+
+ @Min(101)
+ byte bytePrimitive;
+
+ @Min(101)
+ short shortPrimitive;
+
+ @Min(101)
+ int intPrimitive;
+
+ @Min(101)
+ long longPrimitive;
+
+ @Min(101)
+ Byte byteObject;
+
+ @Min(101)
+ Short shortObject;
+
+ @Min(101)
+ Integer intObject;
+
+ @Min(101)
+ Long longObject;
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-08 08:06:47 UTC (rev 16715)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-08 09:41:28 UTC (rev 16716)
@@ -982,13 +982,13 @@
<assertion id="l">
<text>@Digits constraint</text>
</assertion>
- <assertion id="i">
+ <assertion id="m">
<text>@Past constraint</text>
</assertion>
- <assertion id="j">
+ <assertion id="n">
<text>@Future constraint</text>
</assertion>
- <assertion id="l">
+ <assertion id="o">
<text>@Pattern constraint</text>
</assertion>
</section>
15 years, 7 months
Hibernate SVN: r16715 - validator/trunk.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-08 04:06:47 -0400 (Mon, 08 Jun 2009)
New Revision: 16715
Modified:
validator/trunk/pom.xml
Log:
HV-147
Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml 2009-06-05 15:41:20 UTC (rev 16714)
+++ validator/trunk/pom.xml 2009-06-08 08:06:47 UTC (rev 16715)
@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-parent</artifactId>
@@ -23,7 +25,7 @@
<id>hardy.ferentschik</id>
<name>Hardy Ferentschik</name>
<email>hferents(a)redhat.com</email>
- <organization>JBoss, a division of Red Hat</organization>
+ <organization>JBoss, a division of Red Hat</organization>
<url>http://in.relation.to/Bloggers/Hardy</url>
</developer>
</developers>
@@ -135,9 +137,14 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
+ <version>2.0-beta-9</version>
<configuration>
- <goals>package site assembly:assembly</goals>
+ <autoVersionSubmodules>true</autoVersionSubmodules>
+ <allowTimestampedSnapshots>true</allowTimestampedSnapshots>
+ <remoteTagging>true</remoteTagging>
+ <goals>package site assembly:assembly deploy</goals>
</configuration>
</plugin>
</plugins>
@@ -164,8 +171,8 @@
</licenses>
<scm>
- <connection>scm:svn:https://svn.jboss.org/repos/hibernate/validator/tags/v4_0_0_Beta1</connection>
- <url>http://fisheye.jboss.org/browse/Hibernate/validator/tags/v4_0_0_Beta1</url>
+ <connection>scm:svn:https://svn.jboss.org/repos/hibernate/validator/trunk</connection>
+ <url>http://fisheye.jboss.org/browse/Hibernate/validator/trunk</url>
</scm>
<distributionManagement>
15 years, 7 months