1 package org
.codehaus
.groovy
.grails
.validation
;
4 * Test cases for 'matches' constraint.
6 * @author Sergey Nebolsin (<a href="mailto:nebolsin@gmail.com"/>)
8 public class MatchesConstraintTests
extends AbstractConstraintTests
{
9 protected Class
getConstraintClass() {
10 return MatchesConstraint
.class;
13 public void testValidation() {
14 testConstraintMessageCodes(
15 getConstraint( "testString", "[a-zA-Z]"),
17 new String
[] {"testClass.testString.matches.error","testClass.testString.matches.invalid"},
18 new Object
[] {"testString",TestClass
.class,"$","[a-zA-Z]"}
22 getConstraint( "testString", "[a-zA-Z]+"),
26 // must always pass for null values
28 getConstraint( "testString", "[a-zA-Z]+" ),
32 testConstraintDefaultMessage(
33 getConstraint( "testString", "[a-zA-Z]+" ),
35 "Property [{0}] of class [{1}] with value [{2}] does not match the required pattern [{3}]"
40 public void testCreation() {
41 MatchesConstraint constraint
= new MatchesConstraint();
42 assertEquals( ConstrainedProperty
.MATCHES_CONSTRAINT
, constraint
.getName() );
43 assertTrue( constraint
.supports( String
.class ));
44 assertFalse( constraint
.supports( null ));
45 assertFalse( constraint
.supports( Long
.class ));
47 constraint
= (MatchesConstraint
) getConstraint( "testString", "[a-z]");
48 assertEquals( "[a-z]", constraint
.getRegex());
51 getConstraint( "testString", new Long(123));
52 fail("MatchesConstraint must throw an exception for non-string parameters.");
53 } catch( IllegalArgumentException iae
) {