Grails单元测试用例

时间:2014-06-10 10:27:47

标签: grails

我的控制器包含以下操作

def addNumber ={CountryNumberCmd  cmd ->
   def countrySelected = params?.countrySelected
   if(cmd.validate()) {
     println "Success Page"
   }else{
     flash.cmd=cmd
     render(view:'hello')
   }
}

我的hello.gsp页面包含以下代码

<html>
<head>
<title>hello</title>
</head>
<body>
<div class="width460" id="formErrorJavascriptTable">
                                <g:hasErrors bean="${flash.cmd}">
                                        <g:renderErrors bean="${flash.cmd}" as="list" />
                                </g:hasErrors>
</div>
</body>
</html>

message.properties

countryNumberCmd.countrySelected.nullable = Country value should not be null.  

命令对象验证类

class CountryNumberCmd {
   String countrySelected
   static constraints = {
    countrySelected(nullable:false)
   }
}

现在有人可以建议我如何在失败的单元测试案例中断言Country value should not be null吗?

请找到目前为止的努力!..

testAddNumber_countrySelected_NULL(){ 
params.countrySelected = null 
controller.addNumber() 
controller.response.reset() 
assertEquals controller.modelAndView.viewName,"/pCountry/hello" 
} 

但是我也想比较验证消息的断言集(我已经通过&#34; countrySelected = null&#34;)和message(code:"countryNumberCmd.countrySelected.nullable"),所以你可以应用这样的断言来比较i18验证信息 ?提前谢谢,我可以像assertEquals flash.cmd.errors['countrySelected'].getCode(),"nullable"

那样做

0 个答案:

没有答案