assert controller.modelAndView.model.contractList.size() > 1
My solution was to override the controller's render method and stuff in a modelAndView to the controller myself:
import org.springframework.web.servlet.ModelAndView
class IntegrationTestUtil {
void overrideRender(controller) {
def dir = controller.class.name.replaceAll(/Controller/, '')
dir = dir[0].toLowerCase() + dir.substring(1)
def originalRender =
controller.metaClass.getMetaMethod("render", [Map] as Class[])
controller.metaClass.render = { Map args ->
if(args.view && args.model) {
delegate.metaClass.getModelAndView = {->
new ModelAndView("/${dir}/${args.view}", args.model)
}
} else {
originalRender.invoke(delegate, args)
}
}
}
}
My controllers then invoke the overrideRender method in setUp and the test run fine.
Note the override only changes render invocations that pass a map with model and view entries.
No comments:
Post a Comment