Forum Discussion

Sachin_Sawe's avatar
Sachin_Sawe
Contributor
17 years ago

JDBC Connection Pooling in soapUI

Hi Ole,

I want to create a connection to the database and execute queries on it to assert some condition. I want to do this in a script assertion for a SOAP Request Test Step. I know that I can create sql connection in groovy script and do these assertions. However, I don't want to create new connection each time the soap request is fired. Instead I would like to have a sql connection common to a test case or to testrunner. So I use just one connection for entire run of my test case. How do I do that?

Thanks,
Sachin
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Sachin,

    try creating the connection in the setup script of the TestCase and save it in the context which you can access in your assertion as well.. ie in the setup script:

    context.myConnection = ..

    and in the assertion

    def connection = context.myConnection

    You can then close it in the tearDown script as well..

    regards!

    /Ole
    eviware.com
  • Hi Ole,

    Are you sure we can set anything other than text based properties on context? I have tried this in the past and had no success. I tried it again, in my setup script I do:

    //one way
    conn = Sql.newInstance(url, usr, pwd, driver)
    context.setProperty("sqlConn", conn)
    //another way
    context.sqlConn = Sql.newInstance(url, usr, pwd, driver)

    and it seems it does not work because in one of my test steps

    when I access context.sqlConn it gives me null pointer exception

    Any suggestions?

    Thanks,
    Sachin
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    this should work ok.. but it will do so only when you run the TestCase, not when running individual steps from inside their editors (which doesn't trigger the setup/tearDown scripts), maybe that is what you were doing when you got the NPE?

    regards!

    /Ole
    eviware.com
  • Yes, Ole. This does work fine now. However a feedback for you:

    1. Setup Script and Tear Down Scripts can be executed individually perfectly fine. I can also see the effect/results of running these when I run my individual test steps afterwards to test specific stuff I need to.

    2. I can also run individual test steps and access string based properties on context. I have been able to do this in the past.

    The only issue seemed to be accessing - other than string - based properties on context on individual test steps. It seems now I can access this sql connection that I set on context only when I run a complete TestCase. But, nevertheless, it works now and that is what counts.

    I appreciate your help.

    -Sachin
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    I need to check: do you mean that if you run the Setup Script from the editor and that script saves a string value to the context, then you can access that value when running (for example) a groovy script step in  the same testcase from within its editor?

    regards,

    /Ole
    eviware.com