GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / commons / org / codehaus / groovy / grails / validation / BlankConstraintTests.java
blob3aaa51e77e5ed79b57f765695d7b5469676a3625
1 package org.codehaus.groovy.grails.validation;
3 /**
4 * Tests for 'blank' constraint.
6 * @author Sergey Nebolsin (<a href="mailto:nebolsin@gmail.com"/>)
7 */
8 public class BlankConstraintTests extends AbstractConstraintTests {
9 protected Class getConstraintClass() {
10 return BlankConstraint.class;
13 public void testValidate() {
14 testConstraintMessageCodes(
15 getConstraint( "testString", Boolean.FALSE ),
16 "",
17 new String[] {"testClass.testString.blank.error","testClass.testString.blank"},
18 new Object[] {"testString", TestClass.class }
21 testConstraintPassed(
22 getConstraint( "testString", Boolean.FALSE ),
23 "someData"
26 testConstraintPassed(
27 getConstraint( "testString", Boolean.TRUE ),
28 "someData"
31 testConstraintFailedAndVetoed(
32 getConstraint( "testString", Boolean.FALSE ),
36 testConstraintFailed(
37 getConstraint( "testString", Boolean.FALSE ),
38 " "
41 testConstraintDefaultMessage(
42 getConstraint( "testString", Boolean.FALSE ),
43 "",
44 "Property [{0}] of class [{1}] cannot be blank"
48 public void testConstraintCreation() {
49 BlankConstraint constraint = new BlankConstraint();
50 assertEquals( ConstrainedProperty.BLANK_CONSTRAINT, constraint.getName());
51 assertTrue( constraint.supports( String.class ));
52 assertFalse( constraint.supports( null ));
53 assertFalse( constraint.supports( Long.class ));
54 constraint = (BlankConstraint) getConstraint( "testString", Boolean.TRUE );
55 assertEquals( Boolean.TRUE, constraint.getParameter() );
57 try {
58 getConstraint( "testString", "wrong");
59 fail("BlankConstraint must throw an exception for non-boolean parameters.");
60 } catch( IllegalArgumentException iae ) {
61 // Great