Forum Discussion
dva1946
14 years agoOccasional Contributor
Solution is fairly simple, if you have the right pieces (based on what I have gathered / tested / used recently):
Below is what we are using for a DB connection to Oracle.
You can edit for your DB type.
Make sure you also have JDBC connection properly configure.
Note we define our DB connection properties at the TESTSUITE level.
Groovy Script
-------------
// Database connection:
// All these properties are defined at the TEST SUITE LEVEL
// Properties used:
// DenServer25
// Password
// sid
// Database
// DBport
// Extract global property value as local Variables
def scriptDenServer25 = context.expand( '${#TestSuite#DenServer25}' )
def scriptPassword = context.expand( '${#TestSuite#Password}' )
def scriptSid = context.expand( '${#TestSuite#sid}' )
def scriptDatabase = context.expand( '${#TestSuite#Database}' )
def scriptDBport = context.expand( '${#TestSuite#DBport}' )
//** DVA 12-28-11 Resolve db connection **//
import groovy.sql.Sql
import com.eviware.soapui.support.GroovyUtils
log.info "Connecting to DB here";
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("oracle.jdbc.driver.OracleDriver")
//***************************************//
log.info "Running Query for TestCase1 - DBConnection R&D";
sql = Sql.newInstance("jdbc:oracle:thin:@${scriptDenServer25}:${scriptDBport}:${scriptSid}", "${scriptDatabase}", "${scriptPassword}", "oracle.jdbc.pool.OracleDataSource")
// **TESTCASE** //
def scriptMOD = context.expand( '${#TestCase#MOD}' )
def scriptLIMIT = context.expand( '${#TestCase#LIMIT}' )
// **MAIN QUERY ** //
def aa = 0
def bb = 0
sql.eachRow("select my_id from mytable where type = ${scriptMOD} and deleted_flag = 0 and ROWNUM <= ${scriptLIMIT} order by my_id") { row ->
//set property to value from row selected
testRunner.testCase.setPropertyValue( "dbmyID", "$row.MY_ID" )
//log.info "Set Property dbofferingID = $row.OFFERING_ID";
// Now run desired test steps. Must send each individually.
testRunner.runTestStepByName("Property Transfer to getCatalogOffering");
testRunner.runTestStepByName("getCatalogOffering");
bb++
}
log.info "Records Processed = $bb";
sql.close()
Below is what we are using for a DB connection to Oracle.
You can edit for your DB type.
Make sure you also have JDBC connection properly configure.
Note we define our DB connection properties at the TESTSUITE level.
Groovy Script
-------------
// Database connection:
// All these properties are defined at the TEST SUITE LEVEL
// Properties used:
// DenServer25
// Password
// sid
// Database
// DBport
// Extract global property value as local Variables
def scriptDenServer25 = context.expand( '${#TestSuite#DenServer25}' )
def scriptPassword = context.expand( '${#TestSuite#Password}' )
def scriptSid = context.expand( '${#TestSuite#sid}' )
def scriptDatabase = context.expand( '${#TestSuite#Database}' )
def scriptDBport = context.expand( '${#TestSuite#DBport}' )
//** DVA 12-28-11 Resolve db connection **//
import groovy.sql.Sql
import com.eviware.soapui.support.GroovyUtils
log.info "Connecting to DB here";
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("oracle.jdbc.driver.OracleDriver")
//***************************************//
log.info "Running Query for TestCase1 - DBConnection R&D";
sql = Sql.newInstance("jdbc:oracle:thin:@${scriptDenServer25}:${scriptDBport}:${scriptSid}", "${scriptDatabase}", "${scriptPassword}", "oracle.jdbc.pool.OracleDataSource")
// **TESTCASE** //
def scriptMOD = context.expand( '${#TestCase#MOD}' )
def scriptLIMIT = context.expand( '${#TestCase#LIMIT}' )
// **MAIN QUERY ** //
def aa = 0
def bb = 0
sql.eachRow("select my_id from mytable where type = ${scriptMOD} and deleted_flag = 0 and ROWNUM <= ${scriptLIMIT} order by my_id") { row ->
//set property to value from row selected
testRunner.testCase.setPropertyValue( "dbmyID", "$row.MY_ID" )
//log.info "Set Property dbofferingID = $row.OFFERING_ID";
// Now run desired test steps. Must send each individually.
testRunner.runTestStepByName("Property Transfer to getCatalogOffering");
testRunner.runTestStepByName("getCatalogOffering");
bb++
}
log.info "Records Processed = $bb";
sql.close()