GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / commons / org / codehaus / groovy / grails / validation / RangeConstraintTests.java
blob87a99e8685e9375d955606313b1ea27ac21a89b3
1 package org.codehaus.groovy.grails.validation;
3 import groovy.lang.IntRange;
4 import groovy.lang.ObjectRange;
6 /**
7 * Test cases for 'range' constraint.
9 * @author Sergey Nebolsin (<a href="mailto:nebolsin@gmail.com"/>)
11 public class RangeConstraintTests extends AbstractConstraintTests {
12 protected Class getConstraintClass() {
13 return RangeConstraint.class;
16 public void testValidation() {
17 testConstraintMessageCodes(
18 getConstraint( "testInteger", new IntRange( 1, 5 )),
19 new Integer(7),
20 new String[] {"testClass.testInteger.range.error","testClass.testInteger.size.toobig"},
21 new Object[] {"testInteger",TestClass.class,new Integer(7),new Integer(1),new Integer(5)}
24 testConstraintMessageCodes(
25 getConstraint( "testInteger", new IntRange( 1, 5 )),
26 new Integer(0),
27 new String[] {"testClass.testInteger.range.error","testClass.testInteger.size.toosmall"},
28 new Object[] {"testInteger",TestClass.class,new Integer(0),new Integer(1),new Integer(5)}
31 testConstraintPassed(
32 getConstraint( "testString", new ObjectRange("abca","abcf")),
33 "abcd"
36 testConstraintPassed(
37 getConstraint( "testInteger", new IntRange( 1, 7 )),
38 new Integer( 5 )
41 // must always pass for null value
42 testConstraintPassed(
43 getConstraint( "testInteger", new IntRange( 1, 7 )),
44 null
47 testConstraintDefaultMessage(
48 getConstraint( "testInteger", new IntRange( 1, 5 ) ),
49 new Integer( 7 ),
50 "Property [{0}] of class [{1}] with value [{2}] does not fall within the valid range from [{3}] to [{4}]"
55 public void testCreation() {
56 RangeConstraint constraint = (RangeConstraint) getConstraint( "testInteger", new IntRange(1,5) );
57 assertEquals( ConstrainedProperty.RANGE_CONSTRAINT, constraint.getName() );
58 assertTrue( constraint.supports( Integer.class ));
59 assertTrue( constraint.supports( Long.class ));
60 assertTrue( constraint.supports( Double.class ));
61 assertFalse( constraint.supports( Object.class ));
62 assertFalse( constraint.supports( null ));
63 assertEquals( new IntRange(1,5), constraint.getRange() );
65 try {
66 getConstraint( "testInteger", "wrong");
67 fail("RangeConstraint must throw an exception for non-range parameters.");
68 } catch( IllegalArgumentException iae ) {
69 // Great