SoapUI: 5.6.0 java.lang.ClassNotFoundException: PostgreSQL/org.postgresql.Driver when running tests using maven

Viewed 423

I'm trying to run SoapUI tests by using mvn commands, and I keep seeing this exception in every JDBC request, although the tests pass and the database is accessed."

The dependency for PostgreSQL is added in maven.

Log:

5:20:54,484 INFO  [SoapUITestCaseRunner] running step [Check db to make sure it was removed]
java.lang.ClassNotFoundException: PostgreSQL/org.postgresql.Driver
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:398)
        at com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(GroovyUtils.java:103)
        at com.eviware.soapui.support.jdbc.JdbcUtils.initConnection(JdbcUtils.java:50)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.getDatabaseConnection(JdbcSubmit.java:190)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.prepare(JdbcSubmit.java:222)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.runQuery(JdbcSubmit.java:173)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.run(JdbcSubmit.java:147)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.<init>(JdbcSubmit.java:79)
        at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcRequest.submit(JdbcRequest.java:122)
        at com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep.run(JdbcRequestTestStep.java:194)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:128)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:76)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:594)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:78)
        at com.eviware.soapui.model.testsuite.TestCase$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
        at Script1.run(Script1.groovy:7)
        at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
        at com.eviware.soapui.impl.wsdl.WsdlTestSuite.runTearDownScript(WsdlTestSuite.java:495)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestSuiteRunner.internalFinally(WsdlTestSuiteRunner.java:163)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestSuiteRunner.internalFinally(WsdlTestSuiteRunner.java:46)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:149)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
15:20:54,589 INFO  [SoapUITestCaseRunner] Assertion [JDBC Status] has status VALID
15:20:54,589 INFO  [SoapUITestCaseRunner] Assertion [JDBC Timeout] has status VALID
15:20:54,592 INFO  [SoapUITestCaseRunner] Assertion [XPath Match] has status VALID
15:20:54,595 INFO  [log] Teardown script finished.

pom.xml:

<properties>
        <soapui-maven-plugin.version>5.6.0</soapui-maven-plugin.version>
        <postgreSql.version>42.2.20</postgreSql.version>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>SmartBearPluginRepository</id>
            <url>https://rapi.tools.ops.smartbear.io/nexus/content/groups/public/</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <plugins>
            <!-- Plugin to read external properties file -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0.0</version><!-- afaik it's final, no need for parameter -->
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>project.properties</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- SoapUI plugin -->
            <plugin>
                <groupId>com.smartbear.soapui</groupId>
                <artifactId>soapui-maven-plugin</artifactId>
                <version>${soapui-maven-plugin.version}</version>
                
                <configuration>
                    <printReport>true</printReport>
                    <junitReport>true</junitReport>
                    <outputFolder>${baseDir}/target/surefire-reports</outputFolder>
                </configuration>

                <dependencies>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${postgreSql.version}</version>
                    </dependency>
                </dependencies>

Note: left groupid and executions out.

Any idea what can cause the exception, or how to suppress it? What is weird for me, it's that the JDBC requests run without an issue.

1 Answers

I Java a JDBC driver can be loaded automatically from classpath, that is why it still works.

I think there is a line in your Groovy teardown script that looks like this:

def driver = 'PostgreSQL/org.postgresql.Driver'

If you replace it with

def driver = 'org.postgresql.Driver'

it should work fine.


UPDATE: The questioner solved it by adding also this line to the script:

com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(driver)

This is kind of a hack, but it made the Exception go away.

Related