2012-04-12 186 views
2

我工作的集成测试和我得到每次缺少方法例外, 这里是集成测试缺少方法例外

package supasonic 

import grails.plugin.spock.IntegrationSpec 

class DownloadRequestServiceSpec extends IntegrationSpec { 
    def downloadRequestService  

    def 'downloadrequest can be added to the database'(){ 
     when:'the createDownloadRequest method is called' 
      downloadRequestService.createDownloadRequest(123,23,'127.0.0.0') 

     then:'download request is added to the database' 
      DownloadRequest request = DownloadRequest.read(1) 
     and:'contain the correct userId and trackId' 
      request.userId == userId 
      request.trackId == trackId 

     and:'uniqueIdentifer is not blank' 
      request.uniqueIdentifier != '' 
     and:'ip address is present' 
      request.ipAddress == ipAddress 
    } 
} 

代码及其相关的服务是遵循

package supasonic 
import com.supajam.net.NetworkUtils 
import org.apache.commons.lang.RandomStringUtils 

class DownloadRequestService { 

    static transactional = true 

    def createDownloadRequest(Long trackId,Long userId,String ipAddress) { 
     String uniqueCode = RandomStringUtils.random(20, true, true) 
     DownloadRequest request = new DownloadRequest(trackId: trackId, userId: userId, ipAddress: ipAddress, uniqueIdentifier: uniqueCode) 
     if(request.save(failOnError: true)) { 
      return request 
     } 
     return null 
    } 
} 

我得到这个错误:

groovy.lang.MissingMethodException: No signature of method: supasonic.DownloadRequest.save() is applicable for argument types:() values: [] 
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), any(), wait(long) 
    at supasonic.DownloadRequestService.createDownloadRequest(DownloadRequestService.groovy:12) 
    at supasonic.DownloadRequestServiceSpec.downloadrequest can be added to the database(DownloadRequestServiceSpec.groovy:12) 

任何人都可以帮助

+0

你的'setup'块在哪里? – 2012-04-12 17:44:43

+0

抱歉忘了提及它,我添加了我的设置块。但是仍然没有运气 – vivek 2012-04-13 08:52:14

+0

你是否在你的'''''''''''''spock测试的'setup'块中加入了'yourcontroller = yourcontroller.yourService'? – 2012-04-13 09:42:19

回答