Hibernate SVN: r15852 - validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-02 10:41:31 -0500 (Mon, 02 Feb 2009)
New Revision: 15852
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
Log:
Added proper tag for keyword substitution
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java 2009-02-02 15:40:50 UTC (rev 15851)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java 2009-02-02 15:41:31 UTC (rev 15852)
@@ -28,7 +28,7 @@
@Test
public void testIsValid() {
- NotNullConstraintValidator constraint = new NotNullConstraintValidator();
+ NotNullValidator constraint = new NotNullValidator();
assertFalse( constraint.isValid( null, null ) );
assertTrue( constraint.isValid( new Object(), null ) );
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java 2009-02-02 15:40:50 UTC (rev 15851)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java 2009-02-02 15:41:31 UTC (rev 15852)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -27,11 +27,11 @@
*/
public class NullValidatorTest {
- private static NullConstraintValidator constraint;
+ private static NullValidator constraint;
@BeforeClass
public static void init() {
- constraint = new NullConstraintValidator();
+ constraint = new NullValidator();
}
@Test
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java 2009-02-02 15:40:50 UTC (rev 15851)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java 2009-02-02 15:41:31 UTC (rev 15852)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -26,11 +26,11 @@
public class PastValidatorForCalendarTest {
- private static PastConstraintCalendarValidator constraint;
+ private static PastValidatorForCalendar constraint;
@BeforeClass
public static void init() {
- constraint = new PastConstraintCalendarValidator();
+ constraint = new PastValidatorForCalendar();
}
@Test
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java 2009-02-02 15:40:50 UTC (rev 15851)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java 2009-02-02 15:41:31 UTC (rev 15852)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -26,11 +26,11 @@
public class PastValidatorForDateTest {
- private static PastConstraintDateValidator constraint;
+ private static PastValidatorForDate constraint;
@BeforeClass
public static void init() {
- constraint = new PastConstraintDateValidator();
+ constraint = new PastValidatorForDate();
}
@Test
16 years
Hibernate SVN: r15851 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validation/constraints and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-02 10:40:50 -0500 (Mon, 02 Feb 2009)
New Revision: 15851
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
Log:
Added proper tag for keyword substitution
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java 2009-02-02 15:39:44 UTC (rev 15850)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java 2009-02-02 15:40:50 UTC (rev 15851)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java 2009-02-02 15:39:44 UTC (rev 15850)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java 2009-02-02 15:40:50 UTC (rev 15851)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java 2009-02-02 15:39:44 UTC (rev 15850)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java 2009-02-02 15:40:50 UTC (rev 15851)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java 2009-02-02 15:39:44 UTC (rev 15850)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java 2009-02-02 15:40:50 UTC (rev 15851)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java 2009-02-02 15:39:44 UTC (rev 15850)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java 2009-02-02 15:40:50 UTC (rev 15851)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java 2009-02-02 15:39:44 UTC (rev 15850)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java 2009-02-02 15:40:50 UTC (rev 15851)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java 2009-02-02 15:39:44 UTC (rev 15850)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java 2009-02-02 15:40:50 UTC (rev 15851)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java 2009-02-02 15:39:44 UTC (rev 15850)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java 2009-02-02 15:40:50 UTC (rev 15851)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
16 years
Hibernate SVN: r15850 - in validator/trunk/hibernate-validator/src: test/java/org/hibernate/validation/constraints and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-02 10:39:44 -0500 (Mon, 02 Feb 2009)
New Revision: 15850
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
Log:
Added proper tag for keyword substitution
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java 2009-02-02 15:37:19 UTC (rev 15849)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java 2009-02-02 15:39:44 UTC (rev 15850)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java 2009-02-02 15:37:19 UTC (rev 15849)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java 2009-02-02 15:39:44 UTC (rev 15850)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java 2009-02-02 15:37:19 UTC (rev 15849)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java 2009-02-02 15:39:44 UTC (rev 15850)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java 2009-02-02 15:37:19 UTC (rev 15849)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java 2009-02-02 15:39:44 UTC (rev 15850)
@@ -1,4 +1,4 @@
-// $Id
+// $Id:$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
16 years
Hibernate SVN: r15849 - validator/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-02-02 10:37:19 -0500 (Mon, 02 Feb 2009)
New Revision: 15849
Modified:
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
Log:
BVAL-106 Constraintdescriptor.getConstraintValidatorClasses() should return a List, not an array
Modified: validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2009-02-02 13:54:29 UTC (rev 15848)
+++ validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2009-02-02 15:37:19 UTC (rev 15849)
@@ -22,60 +22,59 @@
import java.util.Set;
import java.util.List;
-/**
- * Describes a single constraint and its composing constraints.
- *
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-public interface ConstraintDescriptor {
/**
- * Returns the annotation describing the constraint declaration.
- * If a composing constraint, parameter values are reflecting
- * the overridden parameters from the main constraint
+ * Describes a single constraint and its composing constraints.
*
- * @return The annotation for this constraint.
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
- Annotation getAnnotation();
+ public interface ConstraintDescriptor {
+ /**
+ * Returns the annotation describing the constraint declaration.
+ * If a composing constraint, parameter values are reflecting
+ * the overridden parameters from the main constraint
+ *
+ * @return The annotation for this constraint.
+ */
+ Annotation getAnnotation();
- /**
- * @return The groups the constraint is applied on.
- */
- Set<Class<?>> getGroups();
+ /**
+ * @return The groups the constraint is applied on.
+ */
+ Set<Class<?>> getGroups();
- /**
- * list of the constraint validation implementation classes
- * The lsit is immutable
- *
- * @return list of the constraint validation implementation classes
- */
- List<Class<? extends ConstraintValidator<?,?>>>
- getConstraintValidatorClasses();
+ /**
+ * list of the constraint validation implementation classes
+ *
+ * @return list of the constraint validation implementation classes
+ */
+ List<Class<? extends ConstraintValidator<?,?>>>
+ getConstraintValidatorClasses();
- /**
- * Returns a map containing the annotation parameter names as keys and the
- * annotation parameter values as value.
- * If this constraint is used as part of a composed constraint, parameter
- * values are reflecting the overridden parameters from the main constraint.
- *
- * @return Returns a map containing the annotation paramter names as keys
- * and the annotation parameter values as value.
- */
- Map<String, Object> getParameters();
+ /**
+ * Returns a map containing the annotation parameter names as keys and the
+ * annotation parameter values as value.
+ * If this constraint is used as part of a composed constraint, parameter
+ * values are reflecting the overridden parameters from the main constraint.
+ *
+ * @return Returns a map containing the annotation paramter names as keys
+ * and the annotation parameter values as value.
+ */
+ Map<String, Object> getParameters();
- /**
- * Return a set of composing <code>ConstraintDescriptor</code>s where each
- * descriptor describes a composing constraint. <code>ConstraintDescriptor</code>
- * instances of composing constraints reflect overridden parameter values in
- * {@link #getParameters()} and {@link #getAnnotation()}.
- *
- * @return a set of <code>ConstraintDescriptor<code> objects or an empty set
- * in case there are no composing constraints.
- */
- Set<ConstraintDescriptor> getComposingConstraints();
+ /**
+ * Return a set of composing <code>ConstraintDescriptor</code>s where each
+ * descriptor describes a composing constraint. <code>ConstraintDescriptor</code>
+ * instances of composing constraints reflect overridden parameter values in
+ * {@link #getParameters()} and {@link #getAnnotation()}.
+ *
+ * @return a set of <code>ConstraintDescriptor<code> objects or an empty set
+ * in case there are no composing constraints.
+ */
+ Set<ConstraintDescriptor> getComposingConstraints();
- /**
- * @return true if the constraint is annotated with @ReportAsViolationFromCompositeConstraint
- */
- boolean isReportAsViolationFromCompositeConstraint();
-}
\ No newline at end of file
+ /**
+ * @return true if the constraint is annotated with @ReportAsViolationFromCompositeConstraint
+ */
+ boolean isReportAsViolationFromCompositeConstraint();
+ }
\ No newline at end of file
16 years
Hibernate SVN: r15848 - in validator/trunk: hibernate-validator/src/test/java/org/hibernate/validation/util and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-02-02 08:54:29 -0500 (Mon, 02 Feb 2009)
New Revision: 15848
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
Log:
BVAL-106 Constraintdescriptor.getConstraintValidatorClasses() should return a List, not an array
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-02-02 12:04:31 UTC (rev 15847)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintDescriptorImpl.java 2009-02-02 13:54:29 UTC (rev 15848)
@@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.ArrayList;
import javax.validation.Constraint;
import javax.validation.ConstraintDescriptor;
import javax.validation.ConstraintValidator;
@@ -55,6 +56,7 @@
private static final int OVERRIDES_PARAMETER_DEFAULT_INDEX = -1;
private final U annotation;
+ //TODO make it a list
private final Class<? extends ConstraintValidator<U,?>>[] constraintClasses;
private final Set<Class<?>> groups;
private final Map<String, Object> parameters;
@@ -112,9 +114,11 @@
/**
* {@inheritDoc}
*/
- public Class<? extends ConstraintValidator<U,?>>[]
+ public List<Class<? extends ConstraintValidator<?,?>>>
getConstraintValidatorClasses() {
- return constraintClasses;
+ return Collections.unmodifiableList(
+ Arrays.asList((Class<? extends ConstraintValidator<?,?>>[]) constraintClasses)
+ );
}
/**
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-02-02 12:04:31 UTC (rev 15847)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-02-02 13:54:29 UTC (rev 15848)
@@ -131,12 +131,12 @@
ConstraintValidator constraintValidator;
try {
//FIXME do choose the right validator depending on the object validated
- constraintValidator = validationContext.getConstraintValidatorFactory().getInstance( descriptor.getConstraintValidatorClasses()[0] );
+ constraintValidator = validationContext.getConstraintValidatorFactory().getInstance( descriptor.getConstraintValidatorClasses().get(0) );
}
catch ( RuntimeException e ) {
//FIXME do choose the right validator depending on the object validated
throw new ValidationException(
- "Unable to instantiate " + descriptor.getConstraintValidatorClasses()[0], e
+ "Unable to instantiate " + descriptor.getConstraintValidatorClasses().get(0), e
);
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-02-02 12:04:31 UTC (rev 15847)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-02-02 13:54:29 UTC (rev 15848)
@@ -88,7 +88,7 @@
assertEquals(
"Wrong constraint error Type",
constraintType,
- violation.getConstraintDescriptor().getConstraintValidatorClasses()[0]
+ violation.getConstraintDescriptor().getConstraintValidatorClasses().get(0)
);
assertConstraintViolation( violation, errorMessage );
}
Modified: validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2009-02-02 12:04:31 UTC (rev 15847)
+++ validator/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2009-02-02 13:54:29 UTC (rev 15848)
@@ -20,6 +20,7 @@
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Set;
+import java.util.List;
/**
* Describes a single constraint and its composing constraints.
@@ -43,9 +44,12 @@
Set<Class<?>> getGroups();
/**
- * @return the constraint validation implementation class
+ * list of the constraint validation implementation classes
+ * The lsit is immutable
+ *
+ * @return list of the constraint validation implementation classes
*/
- Class<? extends ConstraintValidator<?,?>>[]
+ List<Class<? extends ConstraintValidator<?,?>>>
getConstraintValidatorClasses();
/**
16 years
Hibernate SVN: r15847 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-02 07:04:31 -0500 (Mon, 02 Feb 2009)
New Revision: 15847
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
Log:
BVAL-104 Applied patches and changed class names to be consistent.
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java 2009-02-02 12:04:31 UTC (rev 15847)
@@ -19,16 +19,16 @@
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.AssertFalse;
/**
* Validates that the value passed is false
*
* @author Alaa Nassef
*/
-public class AssertFalseValidator implements ConstraintValidator<AssertTrue, Boolean> {
+public class AssertFalseValidator implements ConstraintValidator<AssertFalse, Boolean> {
- public void initialize(AssertTrue constraintAnnotation) {
+ public void initialize(AssertFalse constraintAnnotation) {
}
public boolean isValid(Boolean bool, ConstraintValidatorContext constraintValidatorContext) {
16 years
Hibernate SVN: r15846 - in validator/trunk/hibernate-validator/src: main/resources/org/hibernate/validation and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-02-02 06:56:15 -0500 (Mon, 02 Feb 2009)
New Revision: 15846
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullConstraintValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintCalendarValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintDateValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthConstraintValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyConstraintValidator.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternConstraintValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthConstraintTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyConstraintTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullConstraintTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternConstraintTest.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Length.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmpty.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Pattern.java
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validation/ValidationMessages.properties
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/composition/FrenchZipcode.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroups.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroupsConstraintValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintCompositionTest.java
Log:
BVAL-104 Applied patches and changed class names to be consistent.
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,42 @@
+// $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 javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.AssertTrue;
+
+/**
+ * Validates that the value passed is false
+ *
+ * @author Alaa Nassef
+ */
+public class AssertFalseValidator implements ConstraintValidator<AssertTrue, Boolean> {
+
+ public void initialize(AssertTrue constraintAnnotation) {
+ }
+
+ public boolean isValid(Boolean bool, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( bool == null ) {
+ return true;
+ }
+ return !bool;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertFalseValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,42 @@
+// $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 javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.AssertTrue;
+
+/**
+ * Validates that the value passed is true
+ *
+ * @author Alaa Nassef
+ */
+public class AssertTrueValidator implements ConstraintValidator<AssertTrue, Boolean> {
+
+ public void initialize(AssertTrue constraintAnnotation) {
+ }
+
+ public boolean isValid(Boolean bool, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( bool == null ) {
+ return true;
+ }
+ return bool;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/AssertTrueValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,43 @@
+// $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.util.Calendar;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Past;
+
+/**
+ * Check that the <code>java.util.Calendar</code> passed to be validated is in
+ * the future.
+ *
+ * @author Alaa Nassef
+ */
+public class FutureValidatorForCalendar implements ConstraintValidator<Past, Calendar> {
+
+ public void initialize(Past constraintAnnotation) {
+ }
+
+ public boolean isValid(Calendar cal, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( cal == null ) {
+ return true;
+ }
+ return cal.after( Calendar.getInstance() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForCalendar.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,43 @@
+// $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.util.Date;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Past;
+
+/**
+ * Check that the <code>java.util.Date</code> passed to be validated is in the
+ * future.
+ *
+ * @author Alaa Nassef
+ */
+public class FutureValidatorForDate implements ConstraintValidator<Past, Date> {
+
+ public void initialize(Past constraintAnnotation) {
+ }
+
+ public boolean isValid(Date date, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( date == null ) {
+ return true;
+ }
+ return date.after( new Date() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/FutureValidatorForDate.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Length.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Length.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Length.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -32,7 +32,7 @@
* @author Emmanuel Bernard
*/
@Documented
-@Constraint(validatedBy = LengthConstraintValidator.class)
+@Constraint(validatedBy = LengthValidator.class)
@Target({ METHOD, FIELD, TYPE })
@Retention(RUNTIME)
public @interface Length {
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthConstraintValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthConstraintValidator.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthConstraintValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -1,46 +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;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * Check that a string's length is between min and max.
- *
- * @author Emmanuel Bernard
- * @author Gavin King
- */
-public class LengthConstraintValidator implements ConstraintValidator<Length, String> {
- private int min;
- private int max;
-
- public void initialize(Length parameters) {
- min = parameters.min();
- max = parameters.max();
- }
-
- public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
- if ( value == null ) {
- return true;
- }
- int length = value.length();
- return length >= min && length <= max;
- }
-
-}
\ No newline at end of file
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java (from rev 15845, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthConstraintValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,46 @@
+// $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 javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * Check that a string's length is between min and max.
+ *
+ * @author Emmanuel Bernard
+ * @author Gavin King
+ */
+public class LengthValidator implements ConstraintValidator<Length, String> {
+ private int min;
+ private int max;
+
+ public void initialize(Length parameters) {
+ min = parameters.min();
+ max = parameters.max();
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ if ( value == null ) {
+ return true;
+ }
+ int length = value.length();
+ return length >= min && length <= max;
+ }
+
+}
\ No newline at end of file
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/LengthValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,59 @@
+// $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.math.BigDecimal;
+import java.math.BigInteger;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Max;
+
+/**
+ * Check that the number being validated is less than or equal to the maximum
+ * value specified.
+ *
+ * @author Alaa Nassef
+ */
+public class MaxValidatorForNumber implements ConstraintValidator<Max, Number> {
+
+ private long maxValue;
+
+ public void initialize(Max maxValue) {
+ this.maxValue = maxValue.value();
+ }
+
+ public boolean isValid(Number value, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( value == null ) {
+ return true;
+ }
+ if ( value instanceof BigDecimal ) {
+ return ( ( BigDecimal ) value ).compareTo( BigDecimal.valueOf( maxValue ) ) != 1;
+ }
+ else if ( value instanceof BigInteger ) {
+ return ( ( BigInteger ) value ).compareTo( BigInteger.valueOf( maxValue ) ) != 1;
+ }
+ else if ( value instanceof Number ) {
+ double doubleValue = value.doubleValue();
+ return doubleValue <= maxValue;
+ }
+ else {
+ return false;
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForNumber.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,51 @@
+// $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.math.BigDecimal;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Max;
+
+/**
+ * Check that the String being validated represents a number, and has a value
+ * less than or equal to the maximum value specified.
+ *
+ * @author Alaa Nassef
+ */
+public class MaxValidatorForString implements ConstraintValidator<Max, String> {
+
+ private long maxValue;
+
+ public void initialize(Max maxValue) {
+ this.maxValue = maxValue.value();
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( value == null ) {
+ return true;
+ }
+ try {
+ return new BigDecimal( value ).compareTo( BigDecimal.valueOf( maxValue ) ) != 1;
+ }
+ catch ( NumberFormatException nfe ) {
+ return false;
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MaxValidatorForString.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,59 @@
+// $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.math.BigDecimal;
+import java.math.BigInteger;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Min;
+
+/**
+ * Check that the number being validated is greater than or equal to the minimum
+ * value specified.
+ *
+ * @author Alaa Nassef
+ */
+public class MinValidatorForNumber implements ConstraintValidator<Min, Number> {
+
+ private long minValue;
+
+ public void initialize(Min minValue) {
+ this.minValue = minValue.value();
+ }
+
+ public boolean isValid(Number value, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( value == null ) {
+ return true;
+ }
+ if ( value instanceof BigDecimal ) {
+ return ( ( BigDecimal ) value ).compareTo( BigDecimal.valueOf( minValue ) ) != -1;
+ }
+ else if ( value instanceof BigInteger ) {
+ return ( ( BigInteger ) value ).compareTo( BigInteger.valueOf( minValue ) ) != -1;
+ }
+ else if ( value instanceof Number ) {
+ double doubleValue = value.doubleValue();
+ return doubleValue >= minValue;
+ }
+ else {
+ return false;
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForNumber.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,51 @@
+// $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.math.BigDecimal;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Min;
+
+/**
+ * Check that the String being validated represents a number, and has a value
+ * more than or equal to the minimum value specified.
+ *
+ * @author Alaa Nassef
+ */
+public class MinValidatorForString implements ConstraintValidator<Min, String> {
+
+ private long minValue;
+
+ public void initialize(Min minValue) {
+ this.minValue = minValue.value();
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( value == null ) {
+ return true;
+ }
+ try {
+ return new BigDecimal( ( String ) value ).compareTo( BigDecimal.valueOf( minValue ) ) != -1;
+ }
+ catch ( NumberFormatException nfe ) {
+ return false;
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/MinValidatorForString.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmpty.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmpty.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmpty.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -29,7 +29,7 @@
* @author Emmanuel Bernard
*/
@Documented
-@Constraint(validatedBy = NotEmptyConstraintValidator.class)
+@Constraint(validatedBy = NotEmptyValidator.class)
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
public @interface NotEmpty {
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyConstraintValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyConstraintValidator.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyConstraintValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -1,39 +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;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
- * @todo Extend to not only support strings, but also collections and maps. Needs to be specified first though.
- */
-public class NotEmptyConstraintValidator implements ConstraintValidator<NotEmpty, String> {
-
- public void initialize(NotEmpty parameters) {
- }
-
- public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
- if ( object == null ) {
- return true;
- }
- int length = object.length();
- return length > 0;
- }
-}
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java (from rev 15845, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyConstraintValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,39 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ * @todo Extend to not only support strings, but also collections and maps. Needs to be specified first though.
+ */
+public class NotEmptyValidator implements ConstraintValidator<NotEmpty, String> {
+
+ public void initialize(NotEmpty parameters) {
+ }
+
+ public boolean isValid(String object, ConstraintValidatorContext constraintValidatorContext) {
+ if ( object == null ) {
+ return true;
+ }
+ int length = object.length();
+ return length > 0;
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NotEmptyValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullConstraintValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullConstraintValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullConstraintValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,38 @@
+// $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 javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Null;
+
+/**
+ * Validate that the object is <code>null</code>
+ *
+ * @author Alaa Nassef
+ */
+public class NullConstraintValidator implements ConstraintValidator<Null, Object> {
+
+ public void initialize(Null constraintAnnotation) {
+ }
+
+ public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
+ return object == null;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/NullConstraintValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintCalendarValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintCalendarValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintCalendarValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,43 @@
+// $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.util.Calendar;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Past;
+
+/**
+ * Check that the <code>java.util.Calendar</code> passed to be validated is in the
+ * past.
+ *
+ * @author Alaa Nassef
+ */
+public class PastConstraintCalendarValidator implements ConstraintValidator<Past, Calendar> {
+
+ public void initialize(Past constraintAnnotation) {
+ }
+
+ public boolean isValid(Calendar cal, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( cal == null ) {
+ return true;
+ }
+ return cal.before( Calendar.getInstance() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintCalendarValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintDateValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintDateValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintDateValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,43 @@
+// $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.util.Date;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.constraints.Past;
+
+/**
+ * Check that the <code>java.util.Date</code> passed to be validated is in the
+ * past.
+ *
+ * @author Alaa Nassef
+ */
+public class PastConstraintDateValidator implements ConstraintValidator<Past, Date> {
+
+ public void initialize(Past constraintAnnotation) {
+ }
+
+ public boolean isValid(Date date, ConstraintValidatorContext constraintValidatorContext) {
+ //null values are valid
+ if ( date == null ) {
+ return true;
+ }
+ return date.before( new Date() );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PastConstraintDateValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Pattern.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Pattern.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/Pattern.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -29,7 +29,7 @@
* @author Hardy Ferentschik
*/
@Documented
-@Constraint(validatedBy = PatternConstraintValidator.class)
+@Constraint(validatedBy = PatternValidator.class)
@Target({ METHOD, FIELD })
@Retention(RUNTIME)
public @interface Pattern {
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternConstraintValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternConstraintValidator.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternConstraintValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -1,45 +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;
-
-import java.util.regex.Matcher;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Hardy Ferentschik
- */
-public class PatternConstraintValidator implements ConstraintValidator<Pattern, String> {
-
- private java.util.regex.Pattern pattern;
-
- public void initialize(Pattern parameters) {
- pattern = java.util.regex.Pattern.compile(
- parameters.regex(),
- parameters.flags()
- );
- }
-
- public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
- if ( value == null ) {
- return true;
- }
- Matcher m = pattern.matcher( value );
- return m.matches();
- }
-}
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java (from rev 15845, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternConstraintValidator.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,45 @@
+// $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.util.regex.Matcher;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class PatternValidator implements ConstraintValidator<Pattern, String> {
+
+ private java.util.regex.Pattern pattern;
+
+ public void initialize(Pattern parameters) {
+ pattern = java.util.regex.Pattern.compile(
+ parameters.regex(),
+ parameters.flags()
+ );
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ if ( value == null ) {
+ return true;
+ }
+ Matcher m = pattern.matcher( value );
+ return m.matches();
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/constraints/PatternValidator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validation/ValidationMessages.properties
===================================================================
--- validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validation/ValidationMessages.properties 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validation/ValidationMessages.properties 2009-02-02 11:56:15 UTC (rev 15846)
@@ -3,4 +3,9 @@
validator.size=size must be between {min} and {max}
validator.length=length must be between {min} and {max}
validator.notEmpty=may not be empty
-\validator.pattern=must match "{regex}"
\ No newline at end of file
+validator.pattern=must match "{regex}"
+validator.min=must be greater than {value}
+validator.max=must be less than {value}
+validator.null=must be null
+validator.past=must be in the past
+validator.future=must be in the future
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,45 @@
+// $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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author Alaa Nassef
+ */
+public class AssertFalseValidatorTest {
+
+ private static AssertFalseValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new AssertFalseValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( false, null ) );
+ assertTrue( constraint.isValid( Boolean.FALSE, null ) );
+ assertFalse( constraint.isValid( true, null ) );
+ assertFalse( constraint.isValid( Boolean.TRUE, null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,45 @@
+// $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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author Alaa Nassef
+ */
+public class AssertTrueValidatorTest {
+
+ private static AssertTrueValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new AssertTrueValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( true, null ) );
+ assertTrue( constraint.isValid( Boolean.TRUE, null ) );
+ assertFalse( constraint.isValid( false, null ) );
+ assertFalse( constraint.isValid( Boolean.FALSE, null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,60 @@
+// $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.util.Calendar;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class FutureValidatorForCalendarTest {
+
+ private static FutureValidatorForCalendar constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new FutureValidatorForCalendar();
+ }
+
+ @Test
+ public void testIsValid() {
+ Calendar futureDate = getFutureDate();
+ Calendar pastDate = getPastDate();
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( futureDate, null ) );
+ assertFalse( constraint.isValid( Calendar.getInstance(), null ) );
+ assertFalse( constraint.isValid( pastDate, null ) );
+ }
+
+ private Calendar getFutureDate() {
+ Calendar cal = Calendar.getInstance();
+ int year = cal.get( Calendar.YEAR );
+ cal.set( Calendar.YEAR, year + 1 );
+ return cal;
+ }
+
+ private Calendar getPastDate() {
+ Calendar cal = Calendar.getInstance();
+ int year = cal.get( Calendar.YEAR );
+ cal.set( Calendar.YEAR, year - 1 );
+ return cal;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,60 @@
+// $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.util.Date;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class FutureValidatorForDateTest {
+
+ private static FutureValidatorForDate constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new FutureValidatorForDate();
+ }
+
+ @Test
+ public void testIsValid() {
+ Date futureDate = getFutureDate();
+ Date pastDate = getPastDate();
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( futureDate, null ) );
+ assertFalse( constraint.isValid( new Date(), null ) );
+ assertFalse( constraint.isValid( pastDate, null ) );
+ }
+
+ private Date getFutureDate() {
+ Date date = new Date();
+ long timeStamp = date.getTime();
+ date.setTime( timeStamp + 31557600000l );
+ return date;
+ }
+
+ private Date getPastDate() {
+ Date date = new Date();
+ long timeStamp = date.getTime();
+ date.setTime( timeStamp - 31557600000l );
+ return date;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthConstraintTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthConstraintTest.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthConstraintTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -1,80 +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;
-
-import java.lang.annotation.Annotation;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.Test;
-import org.junit.Before;
-
-import org.hibernate.tck.annotations.SpecAssertion;
-
-/**
- * Tests the <code>LengthConstraint</code>.
- *
- * @author Hardy Ferentschik
- */
-public class LengthConstraintTest {
-
- LengthConstraintValidator constraint;
-
- @Before
- public void init() {
- constraint = new LengthConstraintValidator();
- constraint.initialize(
- new Length() {
-
- public int min() {
- return 1;
- }
-
- public int max() {
- return 3;
- }
-
- public String message() {
- return "{validator.length}";
- }
-
- public Class<?>[] groups() {
- return new Class<?>[0];
- }
-
- public Class<? extends Annotation> annotationType() {
- return this.getClass();
- }
- }
- );
- }
-
- @Test
- public void testIsValid() {
-
- assertTrue( constraint.isValid( null, null ) );
- assertFalse( constraint.isValid( "", null ) );
- assertTrue( constraint.isValid( "f", null ) );
- assertTrue( constraint.isValid( "fo", null ) );
- assertTrue( constraint.isValid( "foo", null ) );
- assertFalse( constraint.isValid( "foobar", null ) );
-
- }
-
-}
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java (from rev 15845, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthConstraintTest.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,58 @@
+// $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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+
+/**
+ * Tests the <code>LengthConstraint</code>.
+ *
+ * @author Hardy Ferentschik
+ */
+public class LengthValidatorTest {
+
+ private static LengthValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ AnnotationDescriptor descriptor = new AnnotationDescriptor( Length.class );
+ descriptor.setValue( "min", 1 );
+ descriptor.setValue( "max", 3 );
+ descriptor.setValue( "message", "{validator.length}" );
+ Length l = AnnotationFactory.create( descriptor );
+ constraint = new LengthValidator();
+ constraint.initialize( l );
+ }
+
+ @Test
+ public void testIsValid() {
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertFalse( constraint.isValid( "", null ) );
+ assertTrue( constraint.isValid( "f", null ) );
+ assertTrue( constraint.isValid( "fo", null ) );
+ assertTrue( constraint.isValid( "foo", null ) );
+ assertFalse( constraint.isValid( "foobar", null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,66 @@
+// $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.math.BigDecimal;
+import java.math.BigInteger;
+import javax.validation.constraints.Max;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class MaxValidatorForNumberTest {
+
+ private static MaxValidatorForNumber constraint;
+
+ @BeforeClass
+ public static void init() {
+ AnnotationDescriptor descriptor = new AnnotationDescriptor( Max.class );
+ descriptor.setValue( "value", 15l );
+ descriptor.setValue( "message", "{validator.max}" );
+ Max m = AnnotationFactory.create( descriptor );
+
+ constraint = new MaxValidatorForNumber();
+ constraint.initialize( m );
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( 15l, null ) );
+ assertTrue( constraint.isValid( 15, null ) );
+ assertTrue( constraint.isValid( 15.0, null ) );
+ assertTrue( constraint.isValid( BigDecimal.valueOf( -156000000000.0 ), null ) );
+ assertTrue( constraint.isValid( BigInteger.valueOf( -10000000l ), null ) );
+ assertTrue( constraint.isValid( 10, null ) );
+ assertTrue( constraint.isValid( 14.99, null ) );
+ assertTrue( constraint.isValid( -14.99, null ) );
+ assertFalse( constraint.isValid( 20, null ) );
+ assertFalse( constraint.isValid( BigDecimal.valueOf( 156000000000.0 ), null ) );
+ assertFalse( constraint.isValid( BigInteger.valueOf( 10000000l ), null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,61 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints;
+
+import javax.validation.constraints.Max;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.BeforeClass;
+
+import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ */
+public class MaxValidatorForStringTest {
+
+ private static MaxValidatorForString constraint;
+
+ @BeforeClass
+ public static void init() {
+ AnnotationDescriptor descriptor = new AnnotationDescriptor( Max.class );
+ descriptor.setValue( "value", 15l );
+ descriptor.setValue( "message", "{validator.max}" );
+ Max m = AnnotationFactory.create( descriptor );
+
+ constraint = new MaxValidatorForString();
+ constraint.initialize( m );
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( "15", null ) );
+ assertTrue( constraint.isValid( "15.0", null ) );
+ assertTrue( constraint.isValid( "10", null ) );
+ assertTrue( constraint.isValid( "14.99", null ) );
+ assertTrue( constraint.isValid( "-14.99", null ) );
+ assertFalse( constraint.isValid( "20", null ) );
+ //number format exception
+ assertFalse( constraint.isValid( "15l", null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,66 @@
+// $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.math.BigDecimal;
+import java.math.BigInteger;
+import javax.validation.constraints.Min;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ * @author Hardy Ferentschik
+ */
+public class MinValidatorForNumberTest {
+
+ private static MinValidatorForNumber constraint;
+
+ @BeforeClass
+ public static void init() {
+ AnnotationDescriptor descriptor = new AnnotationDescriptor( Min.class );
+ descriptor.setValue( "value", 15l );
+ descriptor.setValue( "message", "{validator.min}" );
+ Min m = AnnotationFactory.create( descriptor );
+
+ constraint = new MinValidatorForNumber();
+ constraint.initialize( m );
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( 20, null ) );
+ assertTrue( constraint.isValid( 15l, null ) );
+ assertTrue( constraint.isValid( 15, null ) );
+ assertTrue( constraint.isValid( 15.0, null ) );
+ assertTrue( constraint.isValid( BigDecimal.valueOf( 156000000000.0 ), null ) );
+ assertTrue( constraint.isValid( BigInteger.valueOf( 10000000l ), null ) );
+ assertFalse( constraint.isValid( BigDecimal.valueOf( -156000000000.0 ), null ) );
+ assertFalse( constraint.isValid( BigInteger.valueOf( -10000000l ), null ) );
+ assertFalse( constraint.isValid( 10, null ) );
+ assertFalse( constraint.isValid( 14.99, null ) );
+ assertFalse( constraint.isValid( -14.99, null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,61 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.constraints;
+
+import javax.validation.constraints.Min;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Alaa Nassef
+ */
+public class MinValidatorForStringTest {
+
+ private static MinValidatorForString constraint;
+
+ @BeforeClass
+ public static void init() {
+ AnnotationDescriptor descriptor = new AnnotationDescriptor( Min.class );
+ descriptor.setValue( "value", 15l );
+ descriptor.setValue( "message", "{validator.min}" );
+ Min m = AnnotationFactory.create( descriptor );
+
+ constraint = new MinValidatorForString();
+ constraint.initialize( m );
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( "20", null ) );
+ assertTrue( constraint.isValid( "15", null ) );
+ assertTrue( constraint.isValid( "15.0", null ) );
+ assertFalse( constraint.isValid( "10", null ) );
+ assertFalse( constraint.isValid( "14.99", null ) );
+ assertFalse( constraint.isValid( "-14.99", null ) );
+ //number format exception
+ assertFalse( constraint.isValid( "15l", null ) );
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyConstraintTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyConstraintTest.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyConstraintTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -1,49 +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;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.Test;
-import org.junit.Before;
-
-import org.hibernate.tck.annotations.SpecAssertion;
-
-/**
- * @author Hardy Ferentschik
- */
-public class NotEmptyConstraintTest {
-
- NotEmptyConstraintValidator constraint;
-
- @Before
- public void init() {
- constraint = new NotEmptyConstraintValidator();
- }
-
- @Test
- public void testIsValid() {
-
- assertTrue( constraint.isValid( null, null ) );
- assertTrue( constraint.isValid( "foo", null ) );
- assertTrue( constraint.isValid( " ", null ) );
-
- assertFalse( constraint.isValid( "", null ) );
- }
-}
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java (from rev 15845, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyConstraintTest.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,46 @@
+// $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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class NotEmptyValidatorTest {
+
+ private static NotEmptyValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new NotEmptyValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( "foo", null ) );
+ assertTrue( constraint.isValid( " ", null ) );
+
+ assertFalse( constraint.isValid( "", null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullConstraintTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullConstraintTest.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullConstraintTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -1,36 +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;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-
-/**
- * @author Hardy Ferentschik
- */
-public class NotNullConstraintTest {
-
- @Test
- public void testIsValid() {
- NotNullConstraintValidator constraint = new NotNullConstraintValidator();
-
- assertFalse( constraint.isValid( null, null ) );
- assertTrue( constraint.isValid( new Object(), null ) );
- }
-}
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java (from rev 15845, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullConstraintTest.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,36 @@
+// $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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class NotNullValidatorTest {
+
+ @Test
+ public void testIsValid() {
+ NotNullConstraintValidator constraint = new NotNullConstraintValidator();
+
+ assertFalse( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( new Object(), null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,42 @@
+// $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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author Alaa Nassef
+ */
+public class NullValidatorTest {
+
+ private static NullConstraintValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new NullConstraintValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+ assertTrue( constraint.isValid( null, null ) );
+ assertFalse( constraint.isValid( new Object(), null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,60 @@
+// $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.util.Calendar;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class PastValidatorForCalendarTest {
+
+ private static PastConstraintCalendarValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new PastConstraintCalendarValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+ Calendar futureDate = getFutureDate();
+ Calendar pastDate = getPastDate();
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( pastDate, null ) );
+ assertFalse( constraint.isValid( Calendar.getInstance(), null ) );
+ assertFalse( constraint.isValid( futureDate, null ) );
+ }
+
+ private Calendar getFutureDate() {
+ Calendar cal = Calendar.getInstance();
+ int year = cal.get( Calendar.YEAR );
+ cal.set( Calendar.YEAR, year + 1 );
+ return cal;
+ }
+
+ private Calendar getPastDate() {
+ Calendar cal = Calendar.getInstance();
+ int year = cal.get( Calendar.YEAR );
+ cal.set( Calendar.YEAR, year - 1 );
+ return cal;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,60 @@
+// $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.util.Date;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class PastValidatorForDateTest {
+
+ private static PastConstraintDateValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+ constraint = new PastConstraintDateValidator();
+ }
+
+ @Test
+ public void testIsValid() {
+ Date futureDate = getFutureDate();
+ Date pastDate = getPastDate();
+ assertTrue( constraint.isValid( null, null ) );
+ assertTrue( constraint.isValid( pastDate, null ) );
+ assertFalse( constraint.isValid( new Date(), null ) );
+ assertFalse( constraint.isValid( futureDate, null ) );
+ }
+
+ private Date getFutureDate() {
+ Date date = new Date();
+ long timeStamp = date.getTime();
+ date.setTime( timeStamp + 31557600000l );
+ return date;
+ }
+
+ private Date getPastDate() {
+ Date date = new Date();
+ long timeStamp = date.getTime();
+ date.setTime( timeStamp - 31557600000l );
+ return date;
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternConstraintTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternConstraintTest.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternConstraintTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -1,75 +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;
-
-import java.lang.annotation.Annotation;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.Test;
-import org.junit.Before;
-
-import org.hibernate.tck.annotations.SpecAssertion;
-
-/**
- * @author Hardy Ferentschik
- */
-public class PatternConstraintTest {
-
- PatternConstraintValidator constraint;
-
- @Before
- public void init() {
- constraint = new PatternConstraintValidator();
- constraint.initialize(
- new Pattern() {
-
- public String message() {
- return "{validator.pattern}";
- }
-
- public Class<?>[] groups() {
- return new Class<?>[0];
- }
-
- public String regex() {
- return "foobar";
- }
-
- public int flags() {
- return 0;
- }
-
- public Class<? extends Annotation> annotationType() {
- return this.getClass();
- }
- }
- );
- }
-
- @Test
- public void testIsValid() {
-
- assertTrue( constraint.isValid( null, null ) );
- assertFalse( constraint.isValid( "", null ) );
- assertFalse( constraint.isValid( "bla bla", null ) );
- assertFalse( constraint.isValid( "This test is not foobar", null ) );
- }
-
-}
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java (from rev 15845, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternConstraintTest.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -0,0 +1,55 @@
+// $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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class PatternValidatorTest {
+
+ private static PatternValidator constraint;
+
+ @BeforeClass
+ public static void init() {
+
+ AnnotationDescriptor descriptor = new AnnotationDescriptor( Pattern.class );
+ descriptor.setValue( "regex", "foobar" );
+ descriptor.setValue( "message", "{validator.pattern}" );
+ Pattern p = AnnotationFactory.create( descriptor );
+
+ constraint = new PatternValidator();
+ constraint.initialize( p );
+ }
+
+ @Test
+ public void testIsValid() {
+
+ assertTrue( constraint.isValid( null, null ) );
+ assertFalse( constraint.isValid( "", null ) );
+ assertFalse( constraint.isValid( "bla bla", null ) );
+ assertFalse( constraint.isValid( "This test is not foobar", null ) );
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/composition/FrenchZipcode.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/composition/FrenchZipcode.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/composition/FrenchZipcode.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -52,13 +52,11 @@
@OverridesParameters({
@OverridesParameter(constraint = Size.class, parameter = "min"),
@OverridesParameter(constraint = Size.class, parameter = "max")
- })
- int size() default 5;
+ }) int size() default 5;
- @OverridesParameter(constraint = Size.class, parameter = "message")
- String sizeMessage() default "A french zip code has a length of 5";
+ @OverridesParameter(constraint = Size.class,
+ parameter = "message") String sizeMessage() default "A french zip code has a length of 5";
- @OverridesParameter(constraint = Pattern.class, parameter = "regex", index=2)
- String regex() default "\\d*";
+ @OverridesParameter(constraint = Pattern.class, parameter = "regex", index = 2) String regex() default "\\d*";
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroups.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroups.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroups.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -25,8 +25,6 @@
import java.lang.annotation.Target;
import javax.validation.Constraint;
-import org.hibernate.validation.constraints.incomplete.NoGroupsConstraintValidator;
-
/**
* @author Hardy Ferentschik
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroupsConstraintValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroupsConstraintValidator.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/incomplete/NoGroupsConstraintValidator.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -20,8 +20,6 @@
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import org.hibernate.validation.constraints.incomplete.NoGroups;
-
/**
* @author Hardy Ferentschik
*/
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintCompositionTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintCompositionTest.java 2009-02-01 23:25:06 UTC (rev 15845)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintCompositionTest.java 2009-02-02 11:56:15 UTC (rev 15846)
@@ -25,7 +25,7 @@
import org.junit.Test;
import org.hibernate.validation.constraints.NotNullConstraintValidator;
-import org.hibernate.validation.constraints.PatternConstraintValidator;
+import org.hibernate.validation.constraints.PatternValidator;
import org.hibernate.validation.constraints.SizeConstraintValidator;
import org.hibernate.validation.constraints.composition.GermanZipcodeConstraintValidator;
import org.hibernate.validation.eg.FrenchAddress;
@@ -79,7 +79,7 @@
assertConstraintViolation(
violation,
"must match \"d*\"",
- PatternConstraintValidator.class,
+ PatternValidator.class,
FrenchAddress.class,
"abc",
"zipCode"
@@ -89,7 +89,7 @@
assertConstraintViolation(
violation,
"must match \".....\"",
- PatternConstraintValidator.class,
+ PatternValidator.class,
FrenchAddress.class,
"abc",
"zipCode"
@@ -119,7 +119,7 @@
assertConstraintViolation(
violation,
"must match \".....\"",
- PatternConstraintValidator.class,
+ PatternValidator.class,
FrenchAddress.class,
"123",
"zipCode"
16 years
Hibernate SVN: r15845 - in search/trunk: src/java/org/hibernate/search/jpa and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-02-01 18:25:06 -0500 (Sun, 01 Feb 2009)
New Revision: 15845
Modified:
search/trunk/doc/reference/en/modules/getting-started.xml
search/trunk/src/java/org/hibernate/search/jpa/FullTextQuery.java
Log:
HSEARCH-332 and some other JPA/hibernate mismatch related documentation fixes
Modified: search/trunk/doc/reference/en/modules/getting-started.xml
===================================================================
--- search/trunk/doc/reference/en/modules/getting-started.xml 2009-02-01 13:27:58 UTC (rev 15844)
+++ search/trunk/doc/reference/en/modules/getting-started.xml 2009-02-01 23:25:06 UTC (rev 15845)
@@ -477,7 +477,7 @@
// create native Lucene query
String[] fields = new String[]{"title", "subtitle", "authors.name", "publicationDate"};
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
-Query query = parser.parse( "Java rocks!" );
+org.apache.lucene.search.Query query = parser.parse( "Java rocks!" );
// wrap Lucene query in a org.hibernate.Query
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Book.class);
@@ -502,18 +502,17 @@
// create native Lucene query
String[] fields = new String[]{"title", "subtitle", "authors.name", "publicationDate"};
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
-Query query = parser.parse( "Java rocks!" );
+org.apache.lucene.search.Query query = parser.parse( "Java rocks!" );
-// wrap Lucene query in a org.hibernate.Query
-org.hibernate.Query hibQuery = fullTextEntityManager.createFullTextQuery(query, Book.class);
+// wrap Lucene query in a javax.persistence.Query
+javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Book.class);
// execute search
-List result = hibQuery.list();
+List result = persistenceQuery.getResultList();
em.getTransaction().commit();
em.close();
-
</programlisting>
</example>
</section>
Modified: search/trunk/src/java/org/hibernate/search/jpa/FullTextQuery.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/jpa/FullTextQuery.java 2009-02-01 13:27:58 UTC (rev 15844)
+++ search/trunk/src/java/org/hibernate/search/jpa/FullTextQuery.java 2009-02-01 23:25:06 UTC (rev 15845)
@@ -46,8 +46,8 @@
*
* Caution:
* The number of results might be slightly different from
- * <code>list().size()</code> because list() if the index is
- * not in sync with the database at the time of query.
+ * <code>getResultList().size()</code> because getResultList()
+ * may be not in sync with the database at the time of query.
*/
int getResultSize();
16 years
Hibernate SVN: r15844 - in search/trunk/src: test/org/hibernate/search/test and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-02-01 08:27:58 -0500 (Sun, 01 Feb 2009)
New Revision: 15844
Modified:
search/trunk/src/java/org/hibernate/search/Environment.java
search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java
search/trunk/src/test/org/hibernate/search/test/query/Person.java
search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java
search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java
Log:
missing keywords, unused imports cleanup, javadoc typos.
Modified: search/trunk/src/java/org/hibernate/search/Environment.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/Environment.java 2009-02-01 13:22:19 UTC (rev 15843)
+++ search/trunk/src/java/org/hibernate/search/Environment.java 2009-02-01 13:27:58 UTC (rev 15844)
@@ -69,7 +69,7 @@
public static final String FILTER_CACHING_STRATEGY = "hibernate.search.filter.cache_strategy";
/**
- * number of docidresults cached in hard referemnce.
+ * number of docidresults cached in hard reference.
*/
public static final String CACHE_DOCIDRESULTS_SIZE = "hibernate.search.filter.cache_docidresults.size";
}
Modified: search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java 2009-02-01 13:22:19 UTC (rev 15843)
+++ search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java 2009-02-01 13:27:58 UTC (rev 15844)
@@ -14,14 +14,10 @@
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.annotations.Indexed;
-import org.hibernate.search.test.inheritance.Animal;
-import org.hibernate.search.test.inheritance.Mammal;
import org.hibernate.search.event.FullTextIndexEventListener;
import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.search.store.FSDirectoryProvider;
import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Base class for Hibernate Search unit tests.
Modified: search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java 2009-02-01 13:22:19 UTC (rev 15843)
+++ search/trunk/src/test/org/hibernate/search/test/configuration/ConfigurationReadTestCase.java 2009-02-01 13:27:58 UTC (rev 15844)
@@ -101,7 +101,7 @@
configuration.buildSessionFactory();
fail();
} catch (HibernateException e) {
- //thrown exceptions means the test is ok when cause by a SearchException
+ //thrown exceptions means the test is ok when caused by a SearchException
Throwable cause = e.getCause();
assertTrue( cause instanceof SearchException );
}
Modified: search/trunk/src/test/org/hibernate/search/test/query/Person.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/Person.java 2009-02-01 13:22:19 UTC (rev 15843)
+++ search/trunk/src/test/org/hibernate/search/test/query/Person.java 2009-02-01 13:27:58 UTC (rev 15844)
@@ -5,12 +5,6 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import org.hibernate.search.annotations.DocumentId;
-import org.hibernate.search.annotations.Field;
-import org.hibernate.search.annotations.Index;
-import org.hibernate.search.annotations.Indexed;
-import org.hibernate.search.annotations.Store;
-
/**
* @author Emmanuel Bernard
*/
Modified: search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java 2009-02-01 13:22:19 UTC (rev 15843)
+++ search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java 2009-02-01 13:27:58 UTC (rev 15844)
@@ -1,4 +1,4 @@
-//$Id
+// $Id$
package org.hibernate.search.test.query;
import org.apache.lucene.index.Term;
Modified: search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java 2009-02-01 13:22:19 UTC (rev 15843)
+++ search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java 2009-02-01 13:27:58 UTC (rev 15844)
@@ -1,4 +1,4 @@
-//$Id
+// $Id$
package org.hibernate.search.test.util;
import org.apache.lucene.analysis.StopAnalyzer;
16 years
Hibernate SVN: r15843 - in search/trunk/src: test/org/hibernate/search/test/query and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: sannegrinovero
Date: 2009-02-01 08:22:19 -0500 (Sun, 01 Feb 2009)
New Revision: 15843
Added:
search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java
search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java
Modified:
search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java
search/trunk/src/java/org/hibernate/search/query/ScrollableResultsImpl.java
search/trunk/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
Log:
HSEARCH-338, HSEARCH-339, HSEARCH-340, HSEARCH-310
Rewritten part of ScrollableResultsImpl to solve the listed issues (start at position -1, memory leaks, performance improvements in backwards and random scrolling, guarantee returned objects are attached to Session)
Modified: search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2009-01-31 06:36:02 UTC (rev 15842)
+++ search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2009-02-01 13:22:19 UTC (rev 15843)
@@ -239,7 +239,7 @@
);
Loader loader = getLoader( ( Session ) this.session, searchFactory );
return new ScrollableResultsImpl(
- searcher, first, max, fetchSize, extractor, loader, searchFactory
+ searcher, first, max, fetchSize, extractor, loader, searchFactory, this.session
);
}
catch ( IOException e ) {
@@ -334,7 +334,7 @@
}
/**
- * Execute the lucene search and return the machting hits.
+ * Execute the lucene search and return the matching hits.
*
* @param searcher The index searcher.
* @param n Numer of documents to retrieve
Modified: search/trunk/src/java/org/hibernate/search/query/ScrollableResultsImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/query/ScrollableResultsImpl.java 2009-01-31 06:36:02 UTC (rev 15842)
+++ search/trunk/src/java/org/hibernate/search/query/ScrollableResultsImpl.java 2009-02-01 13:22:19 UTC (rev 15843)
@@ -2,6 +2,8 @@
package org.hibernate.search.query;
import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Blob;
@@ -9,10 +11,8 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
-import java.util.HashMap;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.TimeZone;
import org.apache.lucene.search.IndexSearcher;
@@ -20,6 +20,7 @@
import org.hibernate.HibernateException;
import org.hibernate.ScrollableResults;
+import org.hibernate.engine.SessionImplementor;
import org.hibernate.search.SearchException;
import org.hibernate.search.SearchFactory;
import org.hibernate.search.engine.DocumentExtractor;
@@ -50,82 +51,76 @@
*
* @author Emmanuel Bernard
* @author John Griffin
+ * @author Sanne Grinovero
*/
public class ScrollableResultsImpl implements ScrollableResults {
+
private static final Logger log = LoggerFactory.make();
+
private final SearchFactory searchFactory;
private final IndexSearcher searcher;
private final int first;
private final int max;
private final int fetchSize;
- private int current;
- private final EntityInfo[] entityInfos;
private final Loader loader;
private final DocumentExtractor documentExtractor;
- private final Map<EntityInfo, Object[]> resultContext;
+ private final SessionImplementor session;
+
+ /**
+ * Caches result rows and EntityInfo from
+ * <code>first</code> to <code>max</code>
+ */
+ private final LoadedObject[] resultsContext;
+
+ private int current;
public ScrollableResultsImpl( IndexSearcher searcher, int first, int max, int fetchSize, DocumentExtractor extractor,
- Loader loader, SearchFactory searchFactory
+ Loader loader, SearchFactory searchFactory, SessionImplementor sessionImplementor
) {
this.searchFactory = searchFactory;
this.searcher = searcher;
this.first = first;
this.max = max;
- this.current = first;
this.loader = loader;
this.documentExtractor = extractor;
- int size = max - first + 1 > 0 ? max - first + 1 : 0;
- this.entityInfos = new EntityInfo[size];
- this.resultContext = new HashMap<EntityInfo, Object[]>( size );
this.fetchSize = fetchSize;
+ this.session = sessionImplementor;
+ int size = Math.max( max - first + 1, 0 );
+ this.resultsContext = new LoadedObject[size];
+ beforeFirst();
}
- // The 'cache' is a sliding window of size fetchSize that
- // moves back and forth over entityInfos as directed loading
- // values as necessary.
- private EntityInfo loadCache(int windowStart) {
- int windowStop;
-
- EntityInfo info = entityInfos[windowStart - first];
- if ( info != null ) {
- //data has already been loaded
- return info;
+ private LoadedObject ensureCurrentLoaded() {
+ LoadedObject currentCacheRef = resultsContext[current - first];
+ if ( currentCacheRef != null ) {
+ return currentCacheRef;
}
-
- if ( windowStart + fetchSize > max ) {
- windowStop = max;
- }
- else {
- windowStop = windowStart + fetchSize - 1;
- }
-
- List<EntityInfo> entityInfosLoaded = new ArrayList<EntityInfo>( windowStop - windowStart + 1 );
- for (int x = windowStart; x <= windowStop; x++) {
- try {
- if ( entityInfos[x - first] == null ) {
- //FIXME should check that clazz match classes but this complicates a lot the firstResult/maxResult
- entityInfos[x - first] = documentExtractor.extract( x );
- entityInfosLoaded.add( entityInfos[x - first] );
- }
+ // the loading window is optimized for scrolling in both directions:
+ int windowStop = Math.min( max + 1 , current + fetchSize );
+ int windowStart = Math.max( first, current - fetchSize + 1 );
+ List<EntityInfo> entityInfosToLoad = new ArrayList<EntityInfo>( fetchSize );
+ int sizeToLoad = 0;
+ for (int x = windowStart; x < windowStop; x++) {
+ int arrayIdx = x - first;
+ LoadedObject lo = resultsContext[arrayIdx];
+ if ( lo == null ) {
+ lo = new LoadedObject();
+ // makes hard references and extract EntityInfos:
+ entityInfosToLoad.add( lo.getEntityInfo( x ) );
+ resultsContext[arrayIdx] = lo;
+ sizeToLoad++;
+ if ( sizeToLoad >= fetchSize )
+ break;
}
- catch (IOException e) {
- throw new HibernateException( "Unable to read Lucene topDocs[" + x + "]", e );
- }
-
}
- //preload efficiently first
- loader.load( entityInfosLoaded.toArray( new EntityInfo[entityInfosLoaded.size()] ) );
- //load one by one to inject null results if needed
- for (EntityInfo slidingInfo : entityInfosLoaded) {
- if ( !resultContext.containsKey( slidingInfo ) ) {
- Object loaded = loader.load( slidingInfo );
- if ( !loaded.getClass().isArray() ) loaded = new Object[] { loaded };
- resultContext.put( slidingInfo, (Object[]) loaded );
- }
+ //preload efficiently by batches:
+ if ( sizeToLoad > 1 ) {
+ loader.load( entityInfosToLoad.toArray( new EntityInfo[sizeToLoad] ) );
+ //(no references stored at this point: they still need to be loaded one by one to inject null results)
}
- return entityInfos[windowStart - first];
+ return resultsContext[ current - first ];
}
-
+
/**
* {@inheritDoc}
*/
@@ -193,6 +188,7 @@
public void afterLast() {
current = max + 1;
+ //TODO help gc by clearing all structures when using forwardonly scrollmode.
}
public boolean isFirst() {
@@ -220,8 +216,8 @@
// do that since we have to make up for
// an Object[]. J.G
if ( current < first || current > max ) return null;
- loadCache( current );
- return resultContext.get( entityInfos[current - first] );
+ LoadedObject cacheEntry = ensureCurrentLoaded();
+ return cacheEntry.getManagedResult( current );
}
/**
@@ -406,4 +402,70 @@
}
return current >= first && current <= max;
}
+
+ private final class LoadedObject {
+
+ private Reference<Object[]> entity; //never==null but Reference.get can return null
+ private Reference<EntityInfo> einfo; //never==null but Reference.get can return null
+
+ /**
+ * Gets the objects from cache if it is available and attached to session,
+ * or reload them and update the cache entry.
+ * @param x absolute position in fulltext result.
+ * @return the managed objects
+ */
+ private Object[] getManagedResult(int x) {
+ EntityInfo entityInfo = getEntityInfo( x );
+ Object[] objects = entity==null ? null : entity.get();
+ if ( objects!=null && areAllEntitiesManaged( objects, entityInfo ) ) {
+ return objects;
+ }
+ else {
+ Object loaded = loader.load( entityInfo );
+ if ( ! loaded.getClass().isArray() ) loaded = new Object[] { loaded };
+ objects = (Object[]) loaded;
+ this.entity = new SoftReference<Object[]>( objects );
+ return objects;
+ }
+ }
+
+ /**
+ * Extract an entityInfo, either from cache or from the index.
+ * @param x the position in the index.
+ * @return
+ */
+ private EntityInfo getEntityInfo(int x) {
+ EntityInfo entityInfo = einfo==null ? null : einfo.get();
+ if ( entityInfo==null ) {
+ try {
+ entityInfo = documentExtractor.extract( x );
+ }
+ catch (IOException e) {
+ throw new SearchException( "Unable to read Lucene topDocs[" + x + "]", e );
+ }
+ einfo = new SoftReference<EntityInfo>( entityInfo );
+ }
+ return entityInfo;
+ }
+
+ }
+
+ private boolean areAllEntitiesManaged(Object[] objects, EntityInfo entityInfo) {
+ //check if all entities are session-managed and skip the check on projected values
+ org.hibernate.Session hibSession = (org.hibernate.Session) session;
+ if ( entityInfo.projection != null ) {
+ // using projection: test only for entities
+ for ( int idx : entityInfo.indexesOfThis ) {
+ Object o = objects[idx];
+ //TODO improve: is it useful to check for proxies and have them reassociated to persistence context?
+ if ( ! hibSession.contains( o ) )
+ return false;
+ }
+ return true;
+ }
+ else {
+ return hibSession.contains( objects[0] );
+ }
+ }
+
}
Modified: search/trunk/src/test/org/hibernate/search/test/query/LuceneQueryTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2009-01-31 06:36:02 UTC (rev 15842)
+++ search/trunk/src/test/org/hibernate/search/test/query/LuceneQueryTest.java 2009-02-01 13:22:19 UTC (rev 15843)
@@ -34,7 +34,7 @@
s.save( clock );
Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
s.save( book );
- book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
+ book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
s.save( book );
tx.commit();
s.clear();
@@ -89,7 +89,7 @@
s.save( clock );
Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
s.save( book );
- book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
+ book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
s.save( book );
tx.commit();
s.clear();
@@ -125,7 +125,7 @@
s.save( clock );
Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
s.save( book );
- book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
+ book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
s.save( book );
tx.commit();
s.clear();
@@ -171,7 +171,7 @@
s.save( clock );
Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
s.save( book );
- book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
+ book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
s.save( book );
tx.commit();//post commit events for lucene
s.clear();
@@ -217,7 +217,7 @@
s.save( clock );
Book book = new Book( 1, "La chute de la petite reine a travers les yeux de Festina", "La chute de la petite reine a travers les yeux de Festina, blahblah" );
s.save( book );
- book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
+ book = new Book( 2, "La gloire de mon p�re", "Les deboires de mon p�re en v�lo" );
s.save( book );
tx.commit();//post commit events for lucene
s.clear();
@@ -235,7 +235,7 @@
query = parser.parse( "summary:Festina Or brand:Seiko" );
hibQuery = s.createFullTextQuery( query, Clock.class, Book.class );
result = hibQuery.scroll();
- assertEquals( 0, result.getRowNumber() );
+ assertEquals( -1, result.getRowNumber() );
result.beforeFirst();
assertEquals( true, result.next() );
assertTrue( result.isFirst() );
Added: search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java 2009-02-01 13:22:19 UTC (rev 15843)
@@ -0,0 +1,218 @@
+//$Id
+package org.hibernate.search.test.query;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.lucene.search.TermQuery;
+import org.hibernate.ScrollableResults;
+import org.hibernate.Transaction;
+import org.hibernate.search.FullTextQuery;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.test.util.FullTextSessionBuilder;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for org.hibernate.search.query.ScrollableResultsImpl
+ *
+ * @see org.hibernate.search.query.ScrollableResultsImpl
+ * @author Sanne Grinovero
+ */
+public class ScrollableResultsTest extends TestCase {
+
+ private FullTextSessionBuilder builder;
+ private FullTextSession sess;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ builder = new FullTextSessionBuilder();
+ sess = builder
+ .addAnnotatedClass( AlternateBook.class )
+ .addAnnotatedClass( Employee.class )
+ .setProperty( "hibernate.default_batch_fetch_size", "10" )
+ .build();
+ Transaction tx = sess.beginTransaction();
+ //create some entities to query:
+ for ( int i = 0; i < 324; i++ ) {
+ sess.persist( new AlternateBook( i , "book about the number " + i ) );
+ }
+ for ( int i = 0; i < 133; i++ ) {
+ sess.persist( new Employee( i , "Rossi", "dept. num. " + i ) );
+ }
+ tx.commit();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ builder.close();
+ super.tearDown();
+ }
+
+ /**
+ * Test forward scrolling using pagination
+ */
+ public void testScrollingForward() {
+ Transaction tx = sess.beginTransaction();
+ TermQuery tq = new TermQuery( new Term( "summary", "number") );
+ Sort sort = new Sort( new SortField( "summary" ) );
+ ScrollableResults scrollableResults = sess
+ .createFullTextQuery( tq, AlternateBook.class )
+ .setSort( sort )
+ .setFetchSize( 10 )
+ .setFirstResult( 20 )
+ .setMaxResults( 111 )
+ .scroll();
+ assertEquals( -1, scrollableResults.getRowNumber() );
+ assertTrue( scrollableResults.last() );
+ assertEquals( 110, scrollableResults.getRowNumber() );
+ scrollableResults.beforeFirst();
+ int position = scrollableResults.getRowNumber();
+ while ( scrollableResults.next() ) {
+ position++;
+ int bookId = position + 20;
+ assertEquals( position, scrollableResults.getRowNumber() );
+ AlternateBook book = (AlternateBook) scrollableResults.get()[0];
+ assertEquals( bookId, book.getId().intValue() );
+ assertEquals( "book about the number " + bookId, book.getSummary() );
+ assertTrue( sess.contains( book ) );
+ }
+ assertEquals( 110, position );
+ scrollableResults.close();
+ tx.commit();
+ }
+
+ /**
+ * Verify inverse-order scrolling.
+ * TODO to verify correct FetchSize behavior I've been debugging
+ * the behavior; we should add a mock library to automate this kind of tests.
+ */
+ public void testScrollingBackwards() {
+ Transaction tx = sess.beginTransaction();
+ TermQuery tq = new TermQuery( new Term( "summary", "number") );
+ Sort sort = new Sort( new SortField( "summary" ) );
+ ScrollableResults scrollableResults = sess
+ .createFullTextQuery( tq, AlternateBook.class )
+ .setSort( sort )
+ .setFetchSize( 10 )
+ .scroll();
+ scrollableResults.beforeFirst();
+ // initial position should be -1 as in Hibernate Core
+ assertEquals( -1, scrollableResults.getRowNumber() );
+ assertTrue( scrollableResults.last() );
+ int position = scrollableResults.getRowNumber();
+ assertEquals( 323, position );
+ while ( scrollableResults.previous() ) {
+ AlternateBook book = (AlternateBook) scrollableResults.get()[0];
+ assertEquals( --position, book.getId().intValue() );
+ assertEquals( "book about the number " + position, book.getSummary() );
+ }
+ assertEquals( 0, position );
+ assertEquals( -1, scrollableResults.getRowNumber() );
+ scrollableResults.close();
+ tx.commit();
+ }
+
+ /**
+ * Test that all entities returned by a ScrollableResults
+ * are always attached to Session
+ */
+ public void testResultsAreManaged() {
+ Transaction tx = sess.beginTransaction();
+ TermQuery tq = new TermQuery( new Term( "summary", "number") );
+ Sort sort = new Sort( new SortField( "summary" ) );
+ ScrollableResults scrollableResults = sess
+ .createFullTextQuery( tq, AlternateBook.class )
+ .setSort( sort )
+ .setFetchSize( 10 )
+ .scroll();
+ int position = -1;
+ while ( scrollableResults.next() ) {
+ position++;
+ AlternateBook book = (AlternateBook) scrollableResults.get()[0];
+ assertTrue( sess.contains( book ) );
+ // evict some entities:
+ if ( position % 3 == 0 ) {
+ sess.evict( book );
+ assertFalse( sess.contains( book ) );
+ }
+ }
+ //verifies it did scroll to the end:
+ assertEquals( 323, position );
+ //assert the entities are re-attached after eviction:
+ while ( scrollableResults.previous() ) {
+ position--;
+ AlternateBook book = (AlternateBook) scrollableResults.get()[0];
+ assertTrue( sess.contains( book ) );
+ }
+ assertEquals( -1, position );
+ sess.clear();
+ //assert the entities are re-attached after Session.clear:
+ while ( scrollableResults.next() ) {
+ position++;
+ AlternateBook book = (AlternateBook) scrollableResults.get()[0];
+ assertTrue( sess.contains( book ) );
+ }
+ assertEquals( 323, position );
+ tx.commit();
+ }
+
+ /**
+ * Verify scrolling works correctly when combined with Projection
+ * and that the projected entities are managed, even in case
+ * of evict usage for memory management.
+ */
+ public void testScrollProjectionAndManaged() {
+ Transaction tx = sess.beginTransaction();
+ TermQuery tq = new TermQuery( new Term( "dept", "num") );
+ ScrollableResults scrollableResults = sess
+ .createFullTextQuery( tq, Employee.class )
+ .setProjection(
+ FullTextQuery.OBJECT_CLASS,
+ FullTextQuery.ID,
+ FullTextQuery.THIS,
+ "lastname",
+ FullTextQuery.THIS
+ )
+ .setFetchSize( 10 )
+ .scroll();
+ scrollableResults.last();
+ assertEquals( 132, scrollableResults.getRowNumber() );
+ scrollableResults.beforeFirst();
+ assertEquals( -1, scrollableResults.getRowNumber() );
+ int position = scrollableResults.getRowNumber();
+ while ( scrollableResults.next() ) {
+ position++;
+ Object[] objs = scrollableResults.get();
+ assertEquals( Employee.class, objs[0] );
+ assertEquals( position, objs[1] );
+ assertTrue( objs[2] instanceof Employee );
+ sess.contains( objs[2] );
+ assertEquals( "Rossi", objs[3] );
+ assertTrue( objs[4] instanceof Employee );
+ sess.contains( objs[4] );
+ assertTrue( objs[2]==objs[4] ); //projected twice the same entity
+ // detach some objects:
+ if ( position%3 == 0 ) {
+ sess.evict( objs[2] );
+ }
+ }
+ //verify we scrolled to the end:
+ assertEquals( 132, position );
+ // and now the other way around, checking entities are attached again:
+ while ( scrollableResults.previous() ) {
+ position--;
+ Object[] objs = scrollableResults.get();
+ assertTrue( objs[2] instanceof Employee );
+ sess.contains( objs[2] );
+ assertTrue( objs[4] instanceof Employee );
+ sess.contains( objs[4] );
+ assertTrue( objs[2]==objs[4] );
+ }
+ assertEquals( -1, position );
+ scrollableResults.close();
+ tx.commit();
+ }
+
+}
Property changes on: search/trunk/src/test/org/hibernate/search/test/query/ScrollableResultsTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java 2009-02-01 13:22:19 UTC (rev 15843)
@@ -0,0 +1,105 @@
+//$Id
+package org.hibernate.search.test.util;
+
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.store.RAMDirectoryProvider;
+
+/**
+ * Use the builder pattern to provide a SessionFactory.
+ * This is meant to use only ram-based index and databases, for those test
+ * which need to use several differently configured SessionFactories.
+ *
+ * @author Sanne Grinovero
+ */
+public class FullTextSessionBuilder {
+
+ private AnnotationConfiguration cfg = new AnnotationConfiguration();
+ private SessionFactory sessionFactory;
+ private Session session;
+
+ public FullTextSessionBuilder() {
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ //DB type:
+ cfg.setProperty( Environment.URL, "jdbc:hsqldb:mem:." );
+ cfg.setProperty( Environment.DRIVER,
+ org.hsqldb.jdbcDriver.class.getCanonicalName() );
+ cfg.setProperty( Environment.DIALECT,
+ org.hibernate.dialect.HSQLDialect.class.getCanonicalName() );
+ //connection:
+ cfg.setProperty( Environment.USER, "sa" );
+ cfg.setProperty( Environment.PASS, "" );
+ cfg.setProperty( Environment.ISOLATION, "2" );
+ cfg.setProperty( Environment.POOL_SIZE, "1" );
+ cfg.setProperty( Environment.ORDER_UPDATES, "true" );
+ //cache:
+ cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
+ cfg.setProperty( Environment.CACHE_PROVIDER,
+ org.hibernate.cache.HashtableCacheProvider.class.getCanonicalName() );
+ cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
+ //debugging/logging:
+ cfg.setProperty( Environment.SHOW_SQL, "false" );
+ cfg.setProperty( Environment.USE_SQL_COMMENTS, "true" );
+ cfg.setProperty( Environment.FORMAT_SQL, "true" );
+ cfg.setProperty( Environment.USE_STRUCTURED_CACHE, "true" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ //search specific:
+ cfg.setProperty( org.hibernate.search.Environment.ANALYZER_CLASS,
+ StopAnalyzer.class.getName() );
+ cfg.setProperty( "hibernate.search.default.directory_provider",
+ RAMDirectoryProvider.class.getName() );
+ }
+
+ /**
+ * Override before building any parameter, or add new ones.
+ * @param key
+ * @param value
+ * @return the same builder (this)
+ */
+ public FullTextSessionBuilder setProperty(String key, String value) {
+ cfg.setProperty( key, value );
+ return this;
+ }
+
+ /**
+ * Adds classes to the SessionFactory being built
+ * @param annotatedClass
+ * @return the same builder (this)
+ */
+ public FullTextSessionBuilder addAnnotatedClass(Class annotatedClass) {
+ cfg.addAnnotatedClass( annotatedClass );
+ return this;
+ }
+
+ /**
+ * Creates a new FullTextSession based upon the configuration built so far.
+ * @return
+ */
+ public FullTextSession build() {
+ if ( session != null || sessionFactory != null ) {
+ throw new java.lang.IllegalStateException( "session is open already" );
+ }
+ sessionFactory = cfg.buildSessionFactory();
+ session = sessionFactory.openSession();
+ return Search.getFullTextSession( session );
+ }
+
+ /**
+ * Closes the provided FullTextSession and the SessionFactory
+ */
+ public void close() {
+ if ( session == null || sessionFactory == null ) {
+ throw new java.lang.IllegalStateException( "session not yet built" );
+ }
+ session.close();
+ session = null;
+ sessionFactory.close();
+ sessionFactory = null;
+ }
+
+}
Property changes on: search/trunk/src/test/org/hibernate/search/test/util/FullTextSessionBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id
16 years