Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No signature of method: is applicable for argument types error in Groovy

I am quite new to groovy and getting following error when running the below method. I am trying to pass xml file name and 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()
    }

Error:

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)

After searching the issue it turned out its a common issue. Couldn't figure out though. Because all solutions are subjective.

Just curious where I am doing wrong

Thanks

like image 264
SMPH Avatar asked Jul 20 '14 04:07

SMPH


People also ask

Why is with () used instead of RestAssured in Groovy?

It is most likely because with () is also provided by Groovy, so taken instead of the static RestAssured realization.. Sorry, something went wrong. Sign up for free to join this conversation on GitHub .

What version of Groovy is currconvert?

Groovy Version: 2.1.9 JVM: 1.7.0_45 Vendor: Oracle Corporation OS: Windows 7 I tried single quote and toString () as well. But no luck currConvert is an instance method, but it's being called as if it was a static method.

Why do I get error when passing objects to a method?

You can also get this error if the objects you're passing to the method are out of order. In other words say your method takes, in order, a string, an integer, and a date. If you pass a date, then a string, then an integer you will get the same error message.


1 Answers

currConvert is an instance method, but it's being called as if it was a static method.

like image 94
Peter Niederwieser Avatar answered Sep 16 '22 11:09

Peter Niederwieser