GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / commons / org / codehaus / groovy / grails / validation / MaxSizeConstraintTests.java
blobaa76f74ed34f84948b65a078c6c9cd4e02894db4
1 package org.codehaus.groovy.grails.validation;
3 import java.util.List;
4 import java.util.Set;
5 import java.util.Collection;
6 import java.util.ArrayList;
8 /**
9 * Test cases for 'maxSize' constraint.
11 * @author Sergey Nebolsin (<a href="mailto:nebolsin@gmail.com"/>)
13 public class MaxSizeConstraintTests extends AbstractConstraintTests {
14 protected Class getConstraintClass() {
15 return MaxSizeConstraint.class;
18 public void testValidation() {
19 testConstraintMessageCodes(
20 getConstraint( "testString", new Integer( 10 )),
21 "12345678901",
22 new String[] {"testClass.testString.maxSize.error","testClass.testString.maxSize.exceeded"},
23 new Object[] {"testString",TestClass.class,"12345678901",new Integer( 10 )}
26 testConstraintFailed(
27 getConstraint( "testArray", new Integer(2)),
28 new String[] {"one","two","three"}
31 List list = new ArrayList();
32 list.add("one");
33 list.add("two");
34 list.add("three");
36 testConstraintFailed(
37 getConstraint( "testCollection", new Integer(2)),
38 list
41 testConstraintPassed(
42 getConstraint( "testCollection", new Integer(3)),
43 list
46 testConstraintPassed(
47 getConstraint( "testString", new Integer(5)),
48 "12345"
51 // must always pass for null value
52 testConstraintPassed(
53 getConstraint( "testString", new Integer(5)),
54 null
57 testConstraintDefaultMessage(
58 getConstraint( "testString", new Integer(5) ),
59 "123456",
60 "Property [{0}] of class [{1}] with value [{2}] exceeds the maximum size of [{3}]"
65 public void testCreation() {
66 MaxSizeConstraint constraint = (MaxSizeConstraint) getConstraint( "testString", new Integer(10) );
67 assertEquals( ConstrainedProperty.MAX_SIZE_CONSTRAINT, constraint.getName() );
68 assertTrue( constraint.supports( String.class ));
69 assertTrue( constraint.supports( Object[].class ));
70 assertTrue( constraint.supports( List.class ));
71 assertTrue( constraint.supports( Set.class ));
72 assertTrue( constraint.supports( Collection.class ));
73 assertFalse( constraint.supports( Integer.class ));
74 assertFalse( constraint.supports( Number.class ));
75 assertEquals( 10, constraint.getMaxSize());
77 try {
78 getConstraint( "testString", "wrong");
79 fail("MaxSizeConstraint must throw an exception for non-integer parameters.");
80 } catch( IllegalArgumentException iae ) {
81 // Great