1 package org
.codehaus
.groovy
.grails
.validation
;
5 import java
.util
.Collection
;
6 import java
.util
.ArrayList
;
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 )),
22 new String
[] {"testClass.testString.maxSize.error","testClass.testString.maxSize.exceeded"},
23 new Object
[] {"testString",TestClass
.class,"12345678901",new Integer( 10 )}
27 getConstraint( "testArray", new Integer(2)),
28 new String
[] {"one","two","three"}
31 List list
= new ArrayList();
37 getConstraint( "testCollection", new Integer(2)),
42 getConstraint( "testCollection", new Integer(3)),
47 getConstraint( "testString", new Integer(5)),
51 // must always pass for null value
53 getConstraint( "testString", new Integer(5)),
57 testConstraintDefaultMessage(
58 getConstraint( "testString", new Integer(5) ),
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());
78 getConstraint( "testString", "wrong");
79 fail("MaxSizeConstraint must throw an exception for non-integer parameters.");
80 } catch( IllegalArgumentException iae
) {