executeUpdate查询不适用于grails spock测试 [英] executeUpdate query not working on grails spock test

查看:126
本文介绍了executeUpdate查询不适用于grails spock测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在愿意进行如下集成测试,但问题在于:

  MerchantTier.executeUpdate('更新MerchantTier .... ......'),

此处更新无效



,但是如果我使用

  def merchant = MerchantTier.get(params.id.toLong ())

merchant.setValue(merchantTierVal)

而不是执行更新它有效



是否有任何使用executeUpdate Query的prolem?

  def merchantTier 
$ b def setup(){

merchantTier = new MerchantTier(
startTier:tier,
endTier:tier,
value: 2.02).save(flush:true)
}


void对于给定的商家或更新商家(){

setup:
params = [id:merchantTier.id,tierVal:2]

当:
testData = updateIndividualSuperResellerTier(params)

then:返回n数据
merchantTier.value == params.tierVal
}

def updateIndividualSuperResellerTier(params){

def merchantTierVal = 0
if(params.tierVal){
merchantTierVal = params.tierVal.toDouble()
}
def merchantTier = MerchantTier.get(params.id.toLong())
def updateMerchantTier = MerchantTier.executeUpdate('update MerchantTier mt set mt.value =:mrValue where mt.id =:mtId',[mrValue:merchantTierVal,mtId:params.id.toLong()])
}


解决方案

executeUpdate似乎没有问题,这里的问题可能是, executeUpdate没有返回一个对象,它只是返回更新的行数,所以 updateMerchantTier不包含updatedObject



另外,您应该再次获取对象,因为它是由 void>中的executeUpdate更新的,用于给定merchantTierId update merchantTier(),则:statement

 然后:返回数据
merchantTier.value == params.tierVal

这里merchantTier仍然是一个旧对象,因此它的值不会等于params.tierVal



在另一个例子中,您明确使用setter来设置属性,因此它通过了您的Integration测试。

  def merchant = MerchantTier.get(params.id.toLong())
merchant.setValue(merchantTierVal)



希望这有助于。谢谢

Now willing to do integration test as below but problem is that

MerchantTier.executeUpdate('update MerchantTier..........'), 

here update does not working

but if I make update with

def merchant = MerchantTier.get(params.id.toLong())

merchant.setValue(merchantTierVal)

instead of execute update it works

Is there is any prolem with executeUpdate Query?

def merchantTier

def setup() {

merchantTier = new MerchantTier(
     startTier: tier,
     endTier: tier,
     value: 2.02).save(flush: true)
}


void "for given merchantTierId update merchantTier"(){

     setup:
     params = [id:merchantTier.id,tierVal:2]

     when:
     testData = updateIndividualSuperResellerTier(params)

     then:"return data"
     merchantTier.value==params.tierVal
}

def updateIndividualSuperResellerTier(params) {

     def merchantTierVal = 0
     if (params.tierVal) {
         merchantTierVal = params.tierVal.toDouble()
     }
     def merchantTier = MerchantTier.get(params.id.toLong())
     def updateMerchantTier = MerchantTier.executeUpdate('update MerchantTier mt set mt.value=:mrValue where mt.id=:mtId', [mrValue: merchantTierVal, mtId: params.id.toLong()])
}

解决方案

There seems to be no problem with executeUpdate, the problem here could be, that executeUpdate did not return an object, it just return the number of rows updated so updateMerchantTier doesnot contain updatedObject.

Also you should again fetch the object as it is updated by executeUpdate in your void "for given merchantTierId update merchantTier"() then: statement

then:"return data"
 merchantTier.value==params.tierVal

here merchantTier is still an old object hence will not be having value equal to params.tierVal

in your other case you are using setter explicitly to set the property and hence it passed your Integration test.

 def merchant = MerchantTier.get(params.id.toLong())
 merchant.setValue(merchantTierVal)

hope this helps. Thanks

这篇关于executeUpdate查询不适用于grails spock测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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