错误:groovy.lang.MissingMethodException:方法无签名

时间:2019-07-23 07:58:35

标签: groovy soapui

我有如下所示的groovy util类:

package com.hypers.test.apitest.util

import groovy.sql.Sql

class DataBaseUtil {

    static def database

    static def connectDB(def url, def username, def password, def driver){
        database = Sql.newInstance(url,username,password,driver)
    }

    static def queryData(def sqlcommand){
        database.rows(sqlcommand)
    }

    static def queryData(def sqlcommand, def offset, def pageSize){
        database.rows(sqlcommand, offset, pageSize)
    }

    static def getFirstRow(def sqlcommand){
        database.firstRow(sqlcommand)
    }

    static def updateData(def sqlcommand){
        database.executeUpdate(sqlcommand)
    }

    static def insertData(def sqlcommand){
        database.executeInsert(sqlcommand)
    }

    static def deleteData(def sqlcommand){
        database.execute(sqlcommand)
    }

    static def closeDB(){
        database.close()
    }
}

我将其复制到SoapUI以供参考,例如:

package com.hypers.test.apitest.util

def JDBC_URL = context.expand( '${#Project#JDBC_URL}' )
def DB_UserName = context.expand( '${#Project#DB_UserName}' )
def DB_Password = context.expand( '${#Project#DB_Password}' )
def DB_Driver = context.expand( '${#Project#DB_Driver}' )

def sqlcommand = "SELECT id From configs_account Where name = 'APITEST_NewAccount_ValidData_ACTIVE'"

DataBaseUtil.connectDB(JDBC_URL, DB_UserName, DB_Password, DB_Driver)
DataBaseUtil.queryData(sqlcommand)
DataBaseUtil.getFirstRow(sqlcommand)

它可以很好地与queryData方法配合使用,但是它会与getFirstRow方法引发异常,我真的无法弄清楚发生了什么并且很长时间以来一直被阻塞,请帮忙看看,谢谢。

异常如下:

Tue Jul 23 15:48:47 CST 2019:ERROR:groovy.lang.MissingMethodException: No signature of method: static com.hypers.test.apitest.util.DataBaseUtil.getFirstRow() is applicable for argument types: (java.lang.String) values: [SELECT id From configs_account Where name = 'APITEST_NewAccount_ValidData_ACTIVE']
   groovy.lang.MissingMethodException: No signature of method: static com.hypers.test.apitest.util.DataBaseUtil.getFirstRow() is applicable for argument types: (java.lang.String) values: [SELECT id From configs_account Where name = 'APITEST_NewAccount_ValidData_ACTIVE']
    at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1373)
    at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1359)
    at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
    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:116)
    at com.hypers.test.apitest.util.DBUtil.getFirstRow(Script10.groovy:38)
    at com.hypers.test.apitest.util.DBUtil$getFirstRow.call(Unknown Source)
    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:116)
    at Script18.run(Script18.groovy:10)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
    at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:79)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:138)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:0)

尝试

def database = DataBaseUtil.connectDB(JDBC_URL, DB_UserName, DB_Password, DB_Driver)
def rows = database.queryData(sqlcommand)
def row = database.getFirstRow(sqlcommand)