GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / commons / org / codehaus / groovy / grails / validation / EmailConstraintTests.java
blob11dbda2a3d927c163af7b3c00bfbf151a94abfcc
1 package org.codehaus.groovy.grails.validation;
3 /**
4 * Test cases for 'email' constraint.
6 * @author Sergey Nebolsin (<a href="mailto:nebolsin@gmail.com"/>)
7 */
8 public class EmailConstraintTests extends AbstractConstraintTests {
10 protected Class getConstraintClass() {
11 return EmailConstraint.class;
14 public void testValidation() {
15 testConstraintMessageCodes(
16 getConstraint( "testString", Boolean.TRUE ),
17 "wrong_email",
18 new String[] {"testClass.testString.email.error","testClass.testString.email.invalid"},
19 new Object[] {"testString",TestClass.class,"wrong_email"}
22 testConstraintPassed(
23 getConstraint( "testString", Boolean.TRUE),
24 "test@example.com"
28 testConstraintDefaultMessage(
29 getConstraint( "testString", Boolean.TRUE ),
30 "wrong_email",
31 "Property [{0}] of class [{1}] with value [{2}] is not a valid e-mail address"
36 public void testNullValue() {
37 // must always pass for null value
38 testConstraintPassed(
39 getConstraint( "testString", Boolean.TRUE),
40 null
44 public void testBlankString() {
45 // must always pass for blank value
46 testConstraintPassed(
47 getConstraint( "testString", Boolean.TRUE),
53 public void testCreation() {
54 EmailConstraint constraint = new EmailConstraint();
55 assertEquals( ConstrainedProperty.EMAIL_CONSTRAINT, constraint.getName() );
56 assertTrue( constraint.supports( String.class ));
57 assertFalse( constraint.supports( null ));
58 assertFalse( constraint.supports( Long.class ));
60 try {
61 getConstraint( "testString", "wrong");
62 fail("EmailConstraint must throw an exception for non-boolean parameters.");
63 } catch( IllegalArgumentException iae ) {
64 // Great