Grails controller unit tests with Joda Time

北城以北 提交于 2019-12-06 09:32:12
Sérgio Michels

Unit tests don't setup custom property editors automatically (responsible to transform the submited info in the domain class instance).

Looking at the source, it seems that JodaTimePropertyEditorRegistrar is responsible for that. So in your test you can use defineBeans to add this Spring Bean:

import grails.plugin.jodatime.binding.JodaTimePropertyEditorRegistrar

class MyTest {
  @Before
  public void setup() {
    defineBeans {
      jodaTimePropertyEditorRegistrar(JodaTimePropertyEditorRegistrar)
    }
  }
}

You can use an object to set the DateTime() or other joda-time values in the populateValidParams() method...

def populateValidParams(params) {
    assert params != null
    params["name"] = "Name"
    params["opening"] = new DateTime()
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!