Permalink
Browse files

test command object validation

Testing command object validation which relies on an injected bean
  • Loading branch information...
1 parent 44e3308 commit 8962f37b75a41849100ce3339d0f242af8742153 @jeffbrown jeffbrown committed Apr 13, 2012
@@ -10,4 +10,8 @@ beans = {
widget(Widget) {
name = 'Good Name'
}
+
+ myValidationHelper(commandobjects.MyValidationHelper) {
+ minimumValidValue = 42
+ }
}
@@ -51,6 +51,20 @@ class CommandObjectsTestController {
def testConstraintsProperty() {
render "Matches: ${CommandObjectClassDefinedUnderSrcGroovy.constraints.name.matches}"
}
+ def commandUsingBeanForValidation(CommandUsingBeanForValidation co) {
+ render "Valid?: ${!co.hasErrors()}"
+ }
+}
+
+class CommandUsingBeanForValidation {
+ Integer value
+ def myValidationHelper
+
+ static constraints = {
+ value validator: { val, obj ->
+ val >= obj.myValidationHelper.minimumValidValue
+ }
+ }
}
class TestCommand {
@@ -0,0 +1,5 @@
+package commandobjects
+
+class MyValidationHelper {
+ def minimumValidValue
+}
@@ -114,5 +114,18 @@ class CommandObjectsFunctionalTests extends functionaltestplugin.FunctionalTestC
assertContentContains '<input type="text" name="c.name" value="ccc" id="c.name" />'
assertContentContains '<input type="text" name="d.query" value="ddd" id="d.query" />'
}
-
+
+ void testCommandObjectUsingBeanForValidation() {
+ get('/commandObjectsTest/commandUsingBeanForValidation?value=9')
+ assertStatus 200
+ assertContentContains 'Valid?: false'
+
+ get('/commandObjectsTest/commandUsingBeanForValidation?value=100')
+ assertStatus 200
+ assertContentContains 'Valid?: true'
+
+ get('/commandObjectsTest/commandUsingBeanForValidation?value=1')
+ assertStatus 200
+ assertContentContains 'Valid?: false'
+ }
}

0 comments on commit 8962f37

Please sign in to comment.