Forum Discussion

Scripps_Network's avatar
Scripps_Network
Occasional Contributor
13 years ago

[Reg] JDBC test step does not execute when changing the env

Hi Admin,
I have created a soap ui project in soap ui pro 4.5.1 and inside it i have around 20 test suites.
in each test suite i have jdbc test step to call the database and get the result of the query which i wrote in that jdbc test step.
in the project summary i have created JDBC connections for every environment - Dev, INT, QA, whichever i am using(double click the project, and go to environments tab, and then JDBC connections tab inside it)
so when i want to execute all the test suites in this project in Dev which is my default env, it works fine. But if i change the envs to INT or QA, JDBC test step is failing.
it is returning 0 rows. I have to manually execute this step instead.
Can you please resolve this issue?

16 Replies

  • DDS__Inc__Suppo's avatar
    DDS__Inc__Suppo
    Occasional Contributor
    Is this issue being addressed? I'm using Pro 4.6.4 and it still happens.

    I've tried several workaround and none of them do the job. This prevents me from using the environments feature and is causing a lot of rework.
  • Hi,

    There is a current issue when using the JDBC TestStep with Environments where it doesn't pickup the environment-specific connection. If that is what you are experiencing, the workaround is to open the JDBC TestStep after having applied the new environment. We do have a bug that is logged regarding this: SOAP-1210. Sorry for the inconvenience.

    Regards,

    Giscard
    SmartBear Support
  • DDS__Inc__Suppo's avatar
    DDS__Inc__Suppo
    Occasional Contributor
    Is there a workaround if it's being run from the command line? The scripts are part of a CI process and are run against multiple environments.
  • Hi,

    There is currently a workaround posted here, viewtopic.php?f=13&t=20577.

    Add this to event handler TestRunListener.beforeRun.


    // Get first databaseName.
    databaseName = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionAt(0).getName()

    // Get connectionString of active environment.
    connectionString = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getConnectionString()

    // Iterate all test steps in the test case and change connectionString for all ProJdbcRequestTestStep to the selected environment connectionString.
    for(testStep in context.testCase.getTestStepList())
    {
    // Set the connectionString for all ProJdbcRequestTestStep
    if(testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.ProJdbcRequestTestStep)
    {
    testStep.setConnectionString(connectionString)
    }
    }



    Regards,
    Marcus
    SmartBear Support
  • ibridge's avatar
    ibridge
    Occasional Contributor
    I'm still struggling with this problem. When changing the active environment, the default connect information seems to be used. The problem occurs when using a DataSource (WsdlDataSourceTestStep) that uses an environment specific JDBC connection. When manually trying "TestConnection" in the DataSource, it works, and after that it keeps working. Unfortunately that's not a workable situation as the tests are being executed on a CI (Jenkins) server...

    I've tried the following code, in the "TestRunListener.beforeRun" event, to workaround the problem:

    // Get first databaseName.
    databaseName = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionAt(0).getName()
    log.info "Found databaseName: " + databaseName

    // Get connectionString of active environment.
    connectionString = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getConnectionString()
    log.info "Found connectionString: " + connectionString

    // Iterate all test steps in the test case and change connectionString for all ProJdbcRequestTestStep to the selected environment connectionString.
    for(testStep in context.testCase.getTestStepList())
    {
    // Set the connectionString for all ProJdbcRequestTestStep and WsdlDataSourceTestStep
    if(testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.ProJdbcRequestTestStep)
    {
    // Get databaseName
    def databaseName = testStep.getJdbcRequestTestStepConfig().getDbConnectionName()
    // Get connectionString of active environment
    def connectionString = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getConnectionString()
    testStep.setConnectionString(connectionString)
    // Get connection password of active environment
    def connectionPassword = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getPassword()
    testStep.setPassword(connectionPassword)
    }
    else if(testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSourceTestStep)
    {
    if(testStep.getDataSource() instanceof com.eviware.soapui.impl.wsdl.teststeps.datasource.DBDataSource)
    {
    // Get databaseName
    def databaseName = testStep.getDataSource().getDbConnectionName()
    // Get connectionString of active environment
    def connectionString = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getConnectionString()
    testStep.getDataSource().setConnectionString(connectionString)
    // Get connection password of active environment
    def connectionPassword = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getPassword()
    testStep.getDataSource().setPassword(connectionPassword)
    }
    }
    }


    The connectionString and password values are correct, but still it uses the default connect settings. As changing the default JDBC connect settings makes it work again.
  • ibridge's avatar
    ibridge
    Occasional Contributor
    After a good night of sleep I found the solution this morning! Apparantly calling "context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getConnectionString()" twice results in a nullpointer. So removing the first call solved the problem. My now working code looks like:

    // Get first databaseName.
    def databaseName = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionAt(0).getName()
    log.info "Found databaseName: " + databaseName

    // Iterate all test steps in the test case and change connectionString for all ProJdbcRequestTestStep to the selected environment connectionString.
    for(testStep in context.testCase.getTestStepList())
    {
    // Set the connectionString for all ProJdbcRequestTestStep and WsdlDataSourceTestStep
    if(testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.ProJdbcRequestTestStep)
    {
    // Get databaseName
    def databaseName = testStep.getJdbcRequestTestStepConfig().getDbConnectionName()
    // Get connectionString of active environment
    def connectionString = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getConnectionString()
    log.info "Found connectionString: " + connectionString
    testStep.setConnectionString(connectionString)
    // Get connection password of active environment
    def connectionPassword = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getPassword()
    testStep.getDataSource().setPassword(connectionPassword)
    }
    else if(testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSourceTestStep)
    {
    if(testStep.getDataSource() instanceof com.eviware.soapui.impl.wsdl.teststeps.datasource.DBDataSource)
    {
    // Get databaseName
    def databaseName = testStep.getDataSource().getDbConnectionName()
    // Get connectionString of active environment
    def connectionString = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getConnectionString()
    log.info "Found connectionString: " + connectionString
    testStep.getDataSource().setConnectionString(connectionString)
    // Get connection password of active environment
    def connectionPassword = context.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(databaseName).getPassword()
    testStep.getDataSource().setPassword(connectionPassword)
    }
    }
    }