Forum Discussion
mlenosgrande
14 years agoContributor
Ok this is how im doing. Hope it will help you:
On the top testSuite setup secript (like @beforeClass for Junit)before anything :
On the top testSuite setup secript (like @beforeClass for Junit)before anything :
import groovy.sql.Sql;
import org.apache.commons.io.FileUtils;
//get the jdbc url define as a project property
//useful to change it dynamically for a specific environnement manually or dynamically via the maven Plugin with a specifi
//profil
def datasource=context.expand('${#Project#datasource.url}');
//!!!!!!!!!WARNING!!! Mandatory to use since >=3.6.2 the 2 following lines
//to register the jdbc
//def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
//groovyUtils.registerJdbcDriver("org.postgresql.Driver");
if( datasource != null ) {
log.info "Definition of the datasource =:"+datasource;
}
def sql;
sql = Sql.newInstance(datasource, "postgres","postgres", "org.postgresql.Driver");
//we get the relative root of the soapuiProject
def projectroot = context.expand('${projectDir}');
//the file si read according to the relative root of the sopaui project
File file = new File(projectroot+"//soapui.sql");
def sqlFileContent= FileUtils.readFileToString(file);
//execute the sql file
sql.execute(sqlFileContent);