cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy datasource looping

Highlighted
Contributor

Groovy datasource looping

Take a look at this Groovy datasource code:

 

import fwa.soapui.*
import groovy.sql.*

// Execute a query and return a list of results
JdbcUtilities j = new JdbcUtilities(driver: context.expand('${#Project#driver}'), connectionStr: context.expand('${#Project#connectionStr}'))
List results = j.getData()
Collections.shuffle(results)

for (row in results) {
	result["TAB"] = row.getAt("TAB").toString()
	result["SPCT"] = row.getAt("SPCT").toString()
	result["TYPE"] = row.getAt("TYPE").toString()
	result["ID"] = row.getAt("ID").toString()
}

j.closeConnection()
log.info "Hello"

I understand that there are JDBC steps in SoapUI that can execute queries, but for reasons I won't get into, I need to execute this from an external Groovy library. Anyways, when I run this for say, 10 maximum rows, "Hello" is printed out to the log 10 separate times.

 

Is this entire block of Groovy code executed for each loop? If that is the case then this SQL connection is opened and closed repeatedly -- I was hoping this would simply open my connection once, loop over each row in my results, then close the connection, but that does not seem to be the case.

 

Can anyone shed some light on how these Groovy datasource loops actually work? It's also very possible that I might be misusing them.

API Summer News

Congratulate last week's winners here:
1. @sanj - $50
2. @Sehuang and @aaronpliu - $35
3. @jhanzeb1 - $15

To do this week:
- Ask product-related questions
- Reply to any questions

Win $50, $35 or $15 gift card!
Winners will be decided next Monday (Aug 27)

Top Kudoed Authors
Are You In?