First of all you need to download DB driver, e.g. ojdbc7.jar
and place it in bin\ext
folder of SoapUI dir:
C:\Program Files (x86)\SmartBear\SoapUI-5.3.0\bin\ext
Then you can use groovy script to create connection to DB, query test values and assign it to SoapUI parameter:
import groovy.sql.Sql
import com.eviware.soapui.support.GroovyUtils
log.info("")
log.info(" init DB connection...")
def scriptServer = "db.db.test.db.db.ru"
def scriptPassword = "password"
def scriptSid = "oraSid"
def scriptUsername = "dbUser"
def scriptDBport = "1111"
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("oracle.jdbc.driver.OracleDriver")
sql = Sql.newInstance("jdbc:oracle:thin:@${scriptServer }:${scriptDBport}:${scriptSid}", "${scriptUsername}", "${scriptPassword}", "oracle.jdbc.OracleDriver")
def queryUserId= "" +
"select userId from " +
" (select userId from " +
" users_table " +
" where age between 21 and 80 and driver_licence = 1"
" order by dbms_random.value) " +
"where rownum = 1"
def res = sql.firstRow(queryUserId)
def user_id = res[0].toString()
testRunner.testCase.setPropertyValue( "user_id" , user_id)
sql.close()
And then use these variables (as SoapUI castom properties) in generation of requests & assertions of responses:
<ServiceProperties>
<UserId>${#TestCase#user_id}</UserId>
</ServiceProperties>