April 30, 2010

SoapUI : JDBC Request Step example with a Sybase database

« JQuery Ajax Client and Jersey Rest Endpoint Example | Main | Caching Example with Spring Annotations and Ehcache »

I have recently played with one of the new TestSteps introduced in soapUI 3.5. Here it what came out...

In the following example, I use a Sybase database containing the following table :

 Column name          Type            Null Num
 -------------------- --------------- ---- ---
 user_id              numeric(10)     No   1
 user_name            varchar(100)    No   2

and I work with the 3.5.1 version of soapUI for Linux (2010-04-09).

1. With soapUI

  • Create a soapUI project (just give it a name, we do not need any WSDL or WADL...)
  • Add a test suite and a test case in it
  • Create a new JDBC Request TestStep : click on the "JDBC" button in the TestCase editor
  • Configure the connection : set the driver "com.sybase.jdbc2.jdbc.SybDriver" and the connection string "jdbc:sybase:Tds:<HOST>:<PORT>/<DATABASE>?user=<USER>&password=<PASSWORD>"
  • Test the connection

Here comes an error message :

com.eviware.soapui.support.SoapUIException: Failed to init connection for drvr 
[com.sybase.jdbc2.jdbc.SybDriver], connectionString 
[jdbc:sybase:Tds:<HOST>:<PORT>/<DATABASE>?user=<USER>&password;=<PASSWORD>]

For using the JDBC TestStep you need to add the JDBC driver to your soapui_home/bin/ext folder and restart the application. So save your project, close the application, add the jconn2-5.5.jar file to your soapui_home/bin/ext and start the application again...

  • Test the connection again

Here comes an information message :

The Connection Successfully Tested

There is a stacktrace to see in the soapUI log file, but it can be ignored...

2010-04-30 10:44:53,380 ERROR [SoapUI] An error occured [No suitable driver], see error log for details
2010-04-30 10:44:53,382 ERROR [errorlog] java.sql.SQLException: No suitable driver
java.sql.SQLException: No suitable driver
...
  • Enter a SQL Query, for example "select user_id, user_name from users_table"
  • Submit the request to the specified endpoint URL

If you get the following entry in the Request Log :

1970-01-01 01:00:00 - Error getting response; null

and the following stacktrace in the soapUI log file :

2010-04-30 10:56:15,531 ERROR [SoapUI] An error occured [The method com.sybase.jdbc2.tds.RowFormatToken.getTableName has not been completed and should not be called.], see error log for details
2010-04-30 10:56:15,531 ERROR [errorlog] com.sybase.jdbc2.utils.UnimplementedOperationException: The method com.sybase.jdbc2.tds.RowFormatToken.getTableName has not been completed and should not be called.
com.sybase.jdbc2.utils.UnimplementedOperationException: The method com.sybase.jdbc2.tds.RowFormatToken.getTableName has not been completed and should not be called.
...

append "&FAKE_METADATA=true" to the connection URL and submit the request to the specified endpoint URL once more

Now you should get a XML result like :

<Results>
    <ResultSet fetchSize="0">
        <Row rowNumber="1">
            <USER_ID>1</USER_ID>
            <USER_NAME>toto</USER_NAME>
        </Row>
    </ResultSet>
</Results>

Note that the test step only works with SELECT queries. I have tried with UPDATE and had to end the query manually.

2. In a maven project with the soapUI maven plugin

The soapUI maven plugin looks for external libraries to add to the classpath in the directory where you run the mvn command. All you need to do is create a directory called "ext" and put the "jconn2-5.5.jar" file in it.

If maven do not find the directory, it displays the following warning :

11:29:42,672 WARN  [DefaultSoapUICore] Missing folder [[MYPATH]./ext] for external libraries

Technorati Tags:

Posted by nadege.griesser at 8:19 AM in Testing

 

[Trackback URL for this entry]

Your comment:

(not displayed)
 
 
 

Live Comment Preview:

 
« April »
SunMonTueWedThuFriSat
    123
45678910
11121314151617
18192021222324
252627282930