How to make two posts with different contents in GrailsIntegrationTesting

谁都会走 提交于 2019-12-06 13:21:55
NachoB

Thanks, I could with reset(), removeAllParameters(), and clearAttributes(). Below is the example:

void testSomething(){

    def json1 = [number: "345678000000007", exp_month: 5, exp_year: 2012] as JSON
    def strJson1 = json1 as String

    cardController.request.contentType = "text/json"
    cardController.request.content = strJson1.getBytes()
    def post1 = cardController.post()


    cardController.response.reset()    
    cardController.request.reset()
    cardController.request.removeAllParameters()
    cardController.request.clearAttributes()

    def json2 = [number: "345678000000009", exp_month: 5, exp_year: 2013] as JSON
    def strJson2 = json2 as String

    cardController.request.contentType = "text/json"
    cardController.request.content = strJson2.getBytes()
    def post2 = cardController.post()
}
Burt Beckwith

Try calling cardController.response.reset() after def post1 = cardController.post(). It's not expected that you'll make two requests per test method, so you need to do some cleanup.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!