Author: hardy.ferentschik
Date: 2009-06-11 11:53:57 -0400 (Thu, 11 Jun 2009)
New Revision: 16762
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
Log:
Enabled tests for DecimalMin and DecimalMax
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java
===================================================================
---
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java 2009-06-11
15:51:21 UTC (rev 16761)
+++
beanvalidation/trunk/validation-api/src/main/java/javax/validation/constraints/DecimalMax.java 2009-06-11
15:53:57 UTC (rev 16762)
@@ -38,17 +38,17 @@
* <li><code>byte</code>, <code>short</code>,
<code>int</code>, <code>long</code>,
* and their respective wrappers</li>
* </ul>
- * Note that <code>double</code> and <code>float</code> are not
supported due to rounding errors
+ * Note that <code>double</code> and <code>float</code> are not
supported due to rounding errors
* (some providers might provide some approximative support)
* <p/>
- * <code>null</code> elements are considered valid
+ * <code>null</code> elements are considered valid.
*
* @author Emmanuel Bernard
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
-@Constraint(validatedBy = {})
+@Constraint(validatedBy = { })
public @interface DecimalMax {
String message() default "{javax.validation.constraints.DecimalMax.message}";
@@ -57,20 +57,21 @@
/**
* The String representation of the max value according to the
* BigDecimal string representation
+ *
* @return value the element must be lower or equal to
*/
String value();
/**
* Defines several @DecimalMax annotations on the same element
- * @see {@link DecimalMax}
*
* @author Emmanuel Bernard
+ * @see {@link DecimalMax}
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Documented
- @interface List {
+ @interface List {
DecimalMax[] value();
}
}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-11
15:51:21 UTC (rev 16761)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/BuiltinConstraintsTest.java 2009-06-11
15:53:57 UTC (rev 16762)
@@ -31,6 +31,8 @@
import javax.validation.Validator;
import javax.validation.constraints.AssertFalse;
import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Digits;
import javax.validation.constraints.Future;
import javax.validation.constraints.Max;
@@ -47,7 +49,6 @@
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
-import static org.testng.Assert.fail;
import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
@@ -265,24 +266,105 @@
assertCorrectNumberOfViolations( constraintViolations, 0 );
}
- @Test(enabled = false)
+ @Test
@SpecAssertions({
@SpecAssertion(section = "6", id = "a"),
@SpecAssertion(section = "6", id = "i")
})
public void testDecimalMinConstraint() {
Validator validator = TestUtil.getDefaultValidator();
- fail();
+ DecimalMinDummyEntity dummy = new DecimalMinDummyEntity();
+
+ Set<ConstraintViolation<DecimalMinDummyEntity>> constraintViolations =
validator.validate( dummy );
+ // only the min constraints on the primitive values should fail. Object values re still
null and should pass per spec
+ assertCorrectNumberOfViolations( constraintViolations, 4 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "bytePrimitive", "intPrimitive",
"longPrimitive", "shortPrimitive" }
+ );
+
+
+ dummy.intPrimitive = 101;
+ dummy.longPrimitive = 1001;
+ dummy.bytePrimitive = 111;
+ dummy.shortPrimitive = 142;
+
+ dummy.intObject = Integer.valueOf( "100" );
+ dummy.longObject = Long.valueOf( "0" );
+ dummy.byteObject = Byte.parseByte( "-1" );
+ dummy.shortObject = Short.parseShort( "3" );
+ dummy.bigDecimal = BigDecimal.valueOf( 100.9 );
+ dummy.bigInteger = BigInteger.valueOf( 100 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 6 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "byteObject", "intObject", "longObject",
"shortObject", "bigDecimal", "bigInteger" }
+ );
+
+ dummy.intObject = Integer.valueOf( "101" );
+ dummy.longObject = Long.valueOf( "12345" );
+ dummy.byteObject = Byte.parseByte( "102" );
+ dummy.shortObject = Short.parseShort( "111" );
+ dummy.bigDecimal = BigDecimal.valueOf( 101.1 );
+ dummy.bigInteger = BigInteger.valueOf( 101 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
- @Test(enabled = false)
+ @Test
@SpecAssertions({
@SpecAssertion(section = "6", id = "a"),
@SpecAssertion(section = "6", id = "j")
})
public void testDecimalMaxConstraint() {
Validator validator = TestUtil.getDefaultValidator();
- fail();
+ DecimalMaxDummyEntity dummy = new DecimalMaxDummyEntity();
+
+ dummy.intPrimitive = 102;
+ dummy.longPrimitive = 1234;
+ dummy.bytePrimitive = 102;
+ dummy.shortPrimitive = 102;
+
+ Set<ConstraintViolation<DecimalMaxDummyEntity>> constraintViolations =
validator.validate( dummy );
+ // only the max constraints on the primitive values should fail. Object values re still
null and should pass per spec
+ assertCorrectNumberOfViolations( constraintViolations, 4 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "bytePrimitive", "intPrimitive",
"longPrimitive", "shortPrimitive" }
+ );
+
+
+ dummy.intPrimitive = 101;
+ dummy.longPrimitive = 100;
+ dummy.bytePrimitive = 99;
+ dummy.shortPrimitive = 42;
+
+ dummy.intObject = Integer.valueOf( "102" );
+ dummy.longObject = Long.valueOf( "12345" );
+ dummy.byteObject = Byte.parseByte( "111" );
+ dummy.shortObject = Short.parseShort( "1234" );
+ dummy.bigDecimal = BigDecimal.valueOf( 102 );
+ dummy.bigInteger = BigInteger.valueOf( 102 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 6 );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "byteObject", "intObject", "longObject",
"shortObject", "bigDecimal", "bigInteger" }
+ );
+
+ dummy.intObject = Integer.valueOf( "101" );
+ dummy.longObject = Long.valueOf( "100" );
+ dummy.byteObject = Byte.parseByte( "100" );
+ dummy.shortObject = Short.parseShort( "101" );
+ dummy.bigDecimal = BigDecimal.valueOf( 100.9 );
+ dummy.bigInteger = BigInteger.valueOf( 100 );
+
+ constraintViolations = validator.validate( dummy );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
@Test
@@ -606,6 +688,70 @@
Long longObject;
}
+ class DecimalMaxDummyEntity {
+ @DecimalMax("101.000000000")
+ BigDecimal bigDecimal;
+
+ @DecimalMax("1.01E+2")
+ BigInteger bigInteger;
+
+ @DecimalMax("101")
+ byte bytePrimitive;
+
+ @DecimalMax("101")
+ short shortPrimitive;
+
+ @DecimalMax("101")
+ int intPrimitive;
+
+ @DecimalMax("101")
+ long longPrimitive;
+
+ @DecimalMax("101")
+ Byte byteObject;
+
+ @DecimalMax("101")
+ Short shortObject;
+
+ @DecimalMax("101")
+ Integer intObject;
+
+ @DecimalMax("101")
+ Long longObject;
+ }
+
+ class DecimalMinDummyEntity {
+ @DecimalMin("101.000000000")
+ BigDecimal bigDecimal;
+
+ @DecimalMin("1.01E+2")
+ BigInteger bigInteger;
+
+ @DecimalMin("101")
+ byte bytePrimitive;
+
+ @DecimalMin("101")
+ short shortPrimitive;
+
+ @DecimalMin("101")
+ int intPrimitive;
+
+ @DecimalMin("101")
+ long longPrimitive;
+
+ @DecimalMin("101")
+ Byte byteObject;
+
+ @DecimalMin("101")
+ Short shortObject;
+
+ @DecimalMin("101")
+ Integer intObject;
+
+ @DecimalMin("101")
+ Long longObject;
+ }
+
class SizeDummyEntity {
@Size(min = 1, max = 1)
String string;