how to access jdbc connection string set at environment level?
Hello,
currently, I am using the below to get the connection string in groovy. This obtains the connection string from database container which is static across environments. Instead of this I want to get the connection string from the JDBC Connections tab from the soapui environments. Is there a way to do that?
def ConObj = context.testCase.testSuite.project.databaseConnectionContainer.getResourceByName('testdb');
def constring = ConObj.getConnectionString();
def sql = Sql.newInstance(constring);
sql.eachRow(<select statment>)
You need to check to see if you are in the environment mode or not and if appropriate go via the Environment object, something like:
def jdbcConnectionName = 'testdb'
if (testRunner.testCase.testSuite.project.isEnvironmentMode()) { jdbcConnection = testRunner.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(jdbcConnectionName) } else { jdbcConnection = testRunner.testCase.testSuite.project.databaseConnectionContainer.getDatabaseConnectionByName(jdbcConnectionName) } log.info 'JDBC Name = ' + jdbcConnection.getName() log.info 'JDBC Connection String = ' + jdbcConnection.getConnectionString()Note, if you are just after a groovy.sql.Sql object I think you can use the following which I believe takes care of checking if you are in environment mode or not:
import com.eviware.soapui.support.GroovyUtilsPro def groovyUtilsPro = new GroovyUtilsPro(context) def sql = groovyUtilsPro.getGroovySql('testdb')