Grails 1.3.3:controller.redirectArgs.action 未填充

发布于 2024-09-11 13:58:44 字数 457 浏览 7 评论 0原文

有谁知道最新版本的 Grails (1.3.3) 中的controller.redirectArgs.action 发生了什么?以前可以正常使用,但现在使用时出现 NPE。

class FooController {
    def someRedirect = {
        redirect(action:"bar")
    }
}

class FooControllerTests extends grails.test.ControllerUnitTestCase {
    void testSomeRedirect() {
        controller.someRedirect()
        assertEquals "bar", controller.redirectArgs.action
    }
}

在这种情况下,controller.redirectArgs 已经为空......

Does anyone knows what happened to controller.redirectArgs.action in the latest version of Grails (1.3.3)? It used to work properly but now I get NPE when I use it.

class FooController {
    def someRedirect = {
        redirect(action:"bar")
    }
}

class FooControllerTests extends grails.test.ControllerUnitTestCase {
    void testSomeRedirect() {
        controller.someRedirect()
        assertEquals "bar", controller.redirectArgs.action
    }
}

In this case controller.redirectArgs is already null...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生不灭 2024-09-18 13:58:44

我在将操作与字符串进行比较时遇到了同样的问题。以下内容对我有用,其中

控制器看起来像:

class SomeObjectController {

  def index = { redirect(action:list,params:params) }

  def list = {
     params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)

     [ 
      someObjectInstanceList: someObject.list( params ), 
      somObjectInstanceTotal: someObject.count() 
     ]
  }
}

测试类看起来像:

class SomeObjectControllerTests extends ControllerUnitTestCase {
    void testIndexRedirectToListAction(){
        controller.index()
        assertEquals controller.list, controller.redirectArgs.action
    }
}

I was having the same problem with the comparing the action to a string. the following worked for me, where

The controller looks something like:

class SomeObjectController {

  def index = { redirect(action:list,params:params) }

  def list = {
     params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)

     [ 
      someObjectInstanceList: someObject.list( params ), 
      somObjectInstanceTotal: someObject.count() 
     ]
  }
}

and the test class would look something like:

class SomeObjectControllerTests extends ControllerUnitTestCase {
    void testIndexRedirectToListAction(){
        controller.index()
        assertEquals controller.list, controller.redirectArgs.action
    }
}
峩卟喜欢 2024-09-18 13:58:44

有趣的是,我遵循了这里的文档: http://www.grails.org/Testing+Controllers

我打电话:
assertEquals“nextAvailable”,controller.redirectArgs.action

,我得到以下信息:

junit.framework.AssertionFailedError: junit.framework.AssertionFailedError: expected:<nextAvailable> but was:<com.***.***.XxxxXxxxController$_closure1@3da2cda9>

我似乎正在返回一个闭包,我正在尝试找出如何获取操作名称。

我在这里找到了解决方案:www.ibm.com/developerworks/java/library/j-grails10209/index.html?ca=drs-

如果您快速执行 ctrl/cmd + F,您会发现此断言通过:

assertEquals controller.nextAvailable, controller.redirectArgs.action

这也通过了:

assertEquals controller.nextAvailable, controller.redirectArgs[action]

Funny, I followed the documentation here: http://www.grails.org/Testing+Controllers

I'm calling:
assertEquals "nextAvailable", controller.redirectArgs.action

and I'm getting the following:

junit.framework.AssertionFailedError: junit.framework.AssertionFailedError: expected:<nextAvailable> but was:<com.***.***.XxxxXxxxController$_closure1@3da2cda9>

I seem to be getting back a closure and I'm trying to figure out how to get the action name.

I found the solution here: www.ibm.com/developerworks/java/library/j-grails10209/index.html?ca=drs-

If you do a quick ctrl/cmd + F, you'll find that this assert passes:

assertEquals controller.nextAvailable, controller.redirectArgs.action

This passes as well:

assertEquals controller.nextAvailable, controller.redirectArgs[action]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文