2012-04-12 149 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

回答