没有方法签名:适用于Groovy中的参数类型错误

时间:2014-07-20 04:26:20

标签: groovy gradle cucumber

在运行以下方法时,我对groovy很新并且遇到以下错误。我正在尝试传递xml文件名和Map

RD.groovy

    Given(~'^input currency "([^"]*)"$') { String baseCurr ->
     fromCurr = baseCurr
}
When(~'^insert end Currency "([^"]*)"$') { String tragetCurr ->
     toCurr = tragetCurr
}


Then(~'^get the expected end currency value "([^"]*)"$') { String result ->

    assert result == currCon(fromCurr, toCurr)


}

private currCon(fromCurr, toCurr)
{

    def binding = ["fromCurr": fromCurr, "toCurr": toCurr]
    response = Consumer.currConvert("request/CurrencyConvert.xml",binding)    --> This is line 119

    assert 200 == response.status
    return response.data.ConversionRateResult.toString()
}

ClassA.groovy

    package abc.api.member

import abc.util.Log
import abc.util.TemplateUtil
import groovyx.net.http.ContentType
import abc.api.RestClient


class ClassA extends ClassB{

    ClassA(RestClient restClient) {
        super(restClient)
    }

def currConvert(String xmlFilename, Map binding) {

        return currencyConvertRequest(TemplateUtil.xmlFromTemplate(xmlFilename, binding))

    }

def currencyConvertRequest(xmlString) {

        def params = [path : 'CurrencyConvertor.asmx',
                headers: globeHeaders(),
                body: xmlString]
        return restClient.post(params)
    }

Consumer.Groovy

package abc.api.member

import geb.Browser
import org.apache.http.client.utils.URIBuilder
import abc.api.RestClient
import abc.browser.member.Admin


class Consumer {
    Browser browser
    String token
    String userId

    @Delegate
    private ClassA classA

 Consumer(url) {
        browser = new Browser()
        browser.baseUrl = baseUrl(url)
        restClient = new RestClient(url)

        classA =  new ClassA(restClient)    
    }

private baseUrl(url) {
        URI uri = URI.create(url)
        URIBuilder builder = new URIBuilder()
        URI result =builder.setHost(uri.host). //
                setPath(uri.path). //
                setPort(uri.port). //
                setScheme(uri.scheme). 
                setUserInfo("Cons", "pbiCons").build()

        return result.toURL().toString()
    }

错误:

groovy.lang.MissingMethodException: No signature of method: abc.api.consumer.Consumer.currConvert() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, java.util.LinkedHashMap) values: [request/globe/CurrencyConvert.xml, [fromCurr:AUD, ...]]
            at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
            at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:51)
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
            at RD.currCon(RD.groovy:119)

在搜索问题后,结果证明这是一个常见问题。虽然想不出来。因为所有解决方案都是主观的。

好奇我在做错了什么

由于

2 个答案:

答案 0 :(得分:8)

currConvert是一个实例方法,但它被称为静态方法。

答案 1 :(得分:1)

我有类似的问题:

class Example {
  static void main (String [] args) {
   printMessage(obj)
  }
  def printMessage(obj) {
  }
}

我在printMessage(obj)遇到了同样的异常。 修改后将其修改为:

class Example {
  static void main (String [] args) {
    new Example().printMessage(obj)
   }
   def printMessage(obj) {
   }
 }