Forum Discussion

harry21's avatar
harry21
Occasional Contributor
8 years ago

Getting MissingMethodException while calling Groovy class in a script

Below is the groovy script which I would like to convert into reusable Groovy class

 

def resp = context.testCase.getTestStepByName(retrieveSequenceNumberAfter).getPropertyValue("ResponseAsXml")
	def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
	def holder = groovyUtils.getXmlHolder(resp)
	def transid = holder.getNodeValue("Results/ResultSet/Row/transaction_id")
	log.info transid

I've created a Groovy class library with the method validatetransid as in following code in it:

 

package com.Linos.readyapi.util.trans.transaction

class TransactionID
{
def context
def log

	def validatetransid(String stepName)
	{
	def resp = context.testCase.getTestStepByName(stepName).getPropertyValue("ResponseAsXml")
	def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
	def holder = groovyUtils.getXmlHolder(resp)
	def transid = holder.getNodeValue("Results/ResultSet/Row/transaction_id")
	log.info transid
	}
}


 

I'm trying to create the object of class and use the methods anywhere in the SoapUI projects as below:

define transid = new TransactionID(context:context, log:log)
transid.validatetransid('retrieveSequenceNumberAfter')

 

With the above code, I'm getting the following exception.. Please advise where my code goes wrong?

 

groovy.lang.MissingMethodException: No signature of method: Script17.define() is applicable for argument types: (com.Linos.readyapi.util.trans.transaction.TransactionID) values: [com.Linos.readyapi.util.trans.transaction.TransactionID@228bb11d] Possible solutions: find(), find(groovy.lang.Closure), print(java.lang.Object), main([Ljava.lang.String;), print(java.lang.Object), print(java.io.PrintWriter)
  • Below is the class for Script Library:

     

     

    package com.linos.readyapi.util.transaction
    
    class Utility {
    
        static def getData(response, element) {
          assert response, 'response is empty'
          def pXml = new XmlSlurper().parseText(response)
          pXml.'**'.findAll {it.name() == element}
        }
        
    }

     

    In the Script Assertion, use below statements:

     

    import static com.linos.readyapi.util.transaction.Utility.getData
    log.info "Details from response: ${getData(context.response, 'transaction_id')}"

     

  • nmrao's avatar
    nmrao
    Champion Level 3

    Below is the class for Script Library:

     

     

    package com.linos.readyapi.util.transaction
    
    class Utility {
    
        static def getData(response, element) {
          assert response, 'response is empty'
          def pXml = new XmlSlurper().parseText(response)
          pXml.'**'.findAll {it.name() == element}
        }
        
    }

     

    In the Script Assertion, use below statements:

     

    import static com.linos.readyapi.util.transaction.Utility.getData
    log.info "Details from response: ${getData(context.response, 'transaction_id')}"

     

    • nmrao's avatar
      nmrao
      Champion Level 3
      harry21, does it resolve the issue? If so, can it be marked as accept as solution?

      If you are still looking for resolution, please provide the response.
  • nmrao's avatar
    nmrao
    Champion Level 3
    Script and error not match. Would you mind providing full script & stack trace please?
    • harry21's avatar
      harry21
      Occasional Contributor

      The script mentioned above is the one which I'm using to print TransactionID.. wanted to convert that into reusable Groovy class.. Guessing that there would be error in creating the object to call the Groovy class

      • nmrao's avatar
        nmrao
        Champion Level 3
        harry21,
        Was it the complete stacktrace? Otherwise provide complete stacktrace.

        By the way, would you mind providing the sample response that you intended to retrieve the data?