gpt4 book ai didi

testing - Grails:使用多个/前缀参数进行集成测试,例如(参数 ["book"])

转载 作者:行者123 更新时间:2023-11-28 20:05:12 26 4
gpt4 key购买 nike

我在 nabble here 上问过完全相同的问题

我正在尝试在 Controller 集成测试中发送参数或不同的域。但是无法让它们绑定(bind)到前缀为“book”的域类

//正在测试的 Controller Action

def saveBook = {
def book = new Book()
bindData(book, params["book"], [include: ['publicPrivacy', 'description', 'title'])
}

//集成测试-

def bookController = BookContoller()
//Doesn't Bind
bookController.params.publicPrivacy = false
bookController.params.description = "Best book in the world"
bookController.params.title = "The world"

bookController.params.book.publicPrivacy = false
bookController.params.book.description = "Best book in the world"
bookController.params.book.title = "The world"

bookController.params["book"].publicPrivacy = false
bookController.params.[book.description] = "Best book in the world"

bookController.saveBook()

我如何设置带有前缀的“params”以发送到 Controller 以便它们绑定(bind)到域?

最佳答案

要使参数命名空间起作用,我必须使用 org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap对于参数对象。例如:

def p = ['book.description': "Best book in the world", ...]
def request = [getParameterMap: { -> p }] as javax.servlet.http.HttpServletRequest

controller.params = new org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap(request)
controller.saveBook()

关于testing - Grails:使用多个/前缀参数进行集成测试,例如(参数 ["book"]),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3770677/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com