Grails ...模仿返回PagedResultList的条件 [英] Grails...Mocking criteria that returns PagedResultList

查看:146
本文介绍了Grails ...模仿返回PagedResultList的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

  params.max =数学公式中的数学公式.min(params.max?params.int('max'):20,100)
def c = DomainObj.createCriteria()
def result = []
result = c.list (params){
'eq'(employerid,id)
}

我在我的测试用例中这样调用了这个调用:

$ p $ def result = [DomainObj1]
def mycriteria = [
list:{Object params = null,Closure cls - >结果}
]

DomainObj.metaClass.static.createCriteria = {mycriteria}

到目前为止工作良好。

但是在控制器中,有一行代码表示result.totalCount,其中result是标准查询的输出并且是PagedResultList类型。
但在测试用例中,iam将结果嘲笑为arrayList,而不是PagedResultList。因此,如果从测试用例运行,代码会在result.totalCount中断。



有关如何将标准响应模拟为PagedResultList而非arraylist的任何想法,以便它具有totalCount orm / PagedResultList.htmlrel =nofollow>其界面。你可以把它写成像

  result = new PagedResultList(列表:inctanceList,totalCount:inctanceList.size())


In my controller, i have an action which uses criteria to hit db and fetch results.

params.max = Math.min(params.max ? params.int('max') : 20, 100)    
def c = DomainObj.createCriteria()
    def result =[]
    result = c.list(params) {
        'eq'("employerid", id)
        }

I have mocked this call in my testcase this way:

def result=[DomainObj1]         
            def mycriteria =[
                list: {Object params=null,Closure cls -> result}                    
                ]

DomainObj.metaClass.static.createCriteria = {mycriteria}

Works fine so far.

But in the controller, there is a line where the code says result.totalCount where result is the output of criteria query and is of PagedResultList type. But in the test case, iam mocking the result as an arrayList, but not as PagedResultList. So, code breaks at result.totalCount if run from the test case.

Any idea of how can I mock the criteria response to PagedResultList instead of arraylist so that it has totalCount

解决方案

Take a look at its interface. You can just compose it like

result = new PagedResultList(list: inctanceList, totalCount: inctanceList.size())

这篇关于Grails ...模仿返回PagedResultList的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆