groovy - SoapUI Pro Groovy!源代码中 'semantic analysis' 阶段中的 ERROR :BUG! 异常查找类名导致编译失败

标签 groovy soapui ready-api

ReadyAPI“语义分析”错误。我已经将我的脚本库存储在 bin 文件夹中,我正在调用 getBuildingInfo ReadyAPI 的常规测试脚本中的方法。大多数情况下,此方法工作正常,但偶尔我会收到此错误。我想找出确切的问题并解决根本原因。
我在 eclipse 中测试了代码,它工作得很好。

ERROR:BUG! exception in phase 'semantic analysis' in source unit 'Script15.groovy' The lookup for PropertiesQuery caused a failed compilaton. There should not have been any compilation from this call. BUG! exception in phase 'semantic analysis' in source unit 'Script15.groovy' The lookup for PropertiesQuery caused a failed compilaton. There should not have been any compilation from this call.

14: Apparent variable 'Database' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes: You attempted to reference a variable in the binding or an instance variable from a static context. You misspelled a classname or statically imported field. Please check the spelling. You attempted to use a method 'Database' but left out brackets in a place not allowed by the grammar. @ line 14, column 17. def dbConn = Database.getDbConnection(env);


public class Database {

public static Connection getDbConnection (String env){

    Connection conn = null;
    Class.forName("com.mysql.jdbc.Driver")

    switch (env){
        case "TEST":
            conn = DriverManager.getConnection("a","b","c")
            break;
        case "DEV":
            conn = DriverManager.getConnection("a","b","d")
            break;
    }

    return conn;
}

public static void closeDbConnection(Connection conn) {

    conn.close();
}
}  


class PropertiesQuery {
    public static String getBuildingInfo(String env, String id, int row ){
        String result = "111";


        def query = "SELECT col1, col2 FROM tabl1 WHERE id = 1"

        def dbConn =  Database.getDbConnection(env);
        def stmt = dbConn.createStatement()
        def rs = stmt.executeQuery(query);

        while(rs.absolute(row)){
            rs.getString("col1")
            rs.getString("col2")

            result = rs.getString("col1") +"/"+rs.getString("col2")
            return result;
        }
    }   
}

最佳答案

我有自己的 Groovy 脚本用于返回 SQL 连接。我没有命名驱动程序,而是使用 Groovy SQL 包....

哦,我在我的机器上注意到了连接数据库的问题。不确定这是否是一个更广泛的问题,但我有它并在这里的其他地方提到过。当我启动 SoapUI 时,我无法运行使用数据库连接的测试,因为它失败了。我要做的是进入环境屏幕,选择我的连接之一,然后单击“测试连接”按钮。之后,我可以运行任何测试。这很奇怪,但在我的机器上似乎单击测试连接只会将空气吹出管道......

导入 groovy.sql.Sql

类 jdbcConnections {

jdbcConnections() {

}

def getJdbcConnection(conDetails, log) {

    def connString = conDetails.getConnectionString()
    def url = 'jdbc:oracle:thin:' + connString.substring(connString.indexOf('@'),connString.size());
    def userName = connString.replace('jdbc:oracle:thin:', '');
    userName = userName.substring(0,userName.indexOf('/'));
    def password = connString.substring(connString.indexOf('/') + 1,connString.indexOf('@'));

    log.info('      Connecting to database ' + conDetails.getName() + '.  Using account ' + userName + ' at URL ' + url );

    return Sql.newInstance(url, userName, password, conDetails.getDriver());

}

def getJdbcConnection(conDetails)
{
    def connString = conDetails.getConnectionString()
    def url = 'jdbc:oracle:thin:' + connString.substring(connString.indexOf('@'),connString.size());
    def userName = connString.replace('jdbc:oracle:thin:', '');
    userName = userName.substring(0,userName.indexOf('/'));
    def password = connString.substring(connString.indexOf('/') + 1,connString.indexOf('@'));

    return Sql.newInstance(url, userName, password, conDetails.getDriver());
}

}

我传入的连接详细信息来自 Environments/JDBC 连接屏幕。

关于groovy - SoapUI Pro Groovy!源代码中 'semantic analysis' 阶段中的 ERROR :BUG! 异常查找类名导致编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46206685/

相关文章:

java - 将 JDBC 获取的 Date 数据作为 XML 转换为 Date 对象

security - 在 Groovy 动态 SQL 中检测 SQL 注入(inject)

SoapUI 5.4.0 在 macOS High 上运行速度极慢

gradle - 如何将模块中的排除项聚合到根排除项中?

java - Axis2 接收 MTOM 附件未发现数据处理程序错误

.net - 如何让 SoapUI 使用 ws-security 模式 'TransportWithMessageCredential'

json - 如何为整数数组编写正则表达式?

java.io.File.plus() 适用于参数类型 : (java. lang.String) value: [\] in Ready API

java - 如何将字符串列表从 JMeter 传递到 Java 代码

spring - 如何在 Grails 应用程序中选择服务实现?