Forum Discussion

Buschfunk's avatar
Buschfunk
Frequent Contributor
17 years ago

[SOLVED] How can I change the data source configuration with Groovy?

Hello,

one of my test steps in a test case is a data source called "DataSource". The data source is set to use a filename filter in a certain directory which works fine. However, I'd like to change the directory using a groovy script but I have no idea how to do this.

All I have achieved so far is getting the XML structure of the configuration using the following code:

testRunner.testCase.getTestStepByName("DataSource").getConfig()


Could you please tell me how to change the value for the directory?

Sincerely,
Robert

12 Replies

  • qntrix's avatar
    qntrix
    Occasional Contributor
    Hello,
    How can i change the connectionString of WsdlDataSourceTestStep?

    I've been trying a couple of solutions, still with no success


        dsTestSteps = testCase.getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSourceTestStep.class )  //only WsdlTestRequest steps
    dsTestSteps.each
    {

    log.info it.getDataSourceStepConfig().getDataSource().getType()
    if(it.getDataSourceStepConfig().getDataSource().getType().equals("JDBC"))
    {
    log.info "test step :"+it.name

    /*attempt 2: read-only - this didn't work, either"
    it.getDataSource().properties.each
    {
    if(it.getKey().indexOf("connectionString")!=-1)
    log.info it.getKey()+":"+it.getValue()

    }
    def oldbd=it.getDataSource()
    oldbd.properties["connectionString"].value= db*/

    //attempt 1 : configuration it not loaded,even if changed
    def conf=it.getDataSourceStepConfig().getDataSource()
    log.info "conf:"+ conf
    def holder = groovyUtils.getXmlHolder(conf.toString().replace("con:","").replace("-fragment",""))
    log.info holder.getPrettyXml()

    def search='//configuration/connstr'
    c = holder.getDomNode(search)

    log.info "1:"+c
    assert c != null,"node not found"
    holder.setNodeValue(search,db)
    c = holder.getDomNode(search)
    log.info "2:"+c
    conf=holder.getXmlObject()
    log.info "connection string:"+conf
    it.getDataSourceStepConfig().getDataSource().setConfiguration(conf)

    conf=it.getDataSourceStepConfig().getDataSource()
    log.info "conf final:"+ conf

    }

    }
  • qntrix's avatar
    qntrix
    Occasional Contributor
    Hello,
    How can i change the connectionString of WsdlDataSourceTestStep?

    I've been trying a couple of solutions, still with no success


        dsTestSteps = testCase.getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSourceTestStep.class )  //only WsdlTestRequest steps
    dsTestSteps.each
    {

    log.info it.getDataSourceStepConfig().getDataSource().getType()
    if(it.getDataSourceStepConfig().getDataSource().getType().equals("JDBC"))
    {
    log.info "test step :"+it.name

    /*attempt 2: read-only - this didn't work, either"
    it.getDataSource().properties.each
    {
    if(it.getKey().indexOf("connectionString")!=-1)
    log.info it.getKey()+":"+it.getValue()

    }
    def oldbd=it.getDataSource()
    oldbd.properties["connectionString"].value= db*/

    //attempt 1 : configuration it not loaded,even if changed
    def conf=it.getDataSourceStepConfig().getDataSource()
    log.info "conf:"+ conf
    def holder = groovyUtils.getXmlHolder(conf.toString().replace("con:","").replace("-fragment",""))
    log.info holder.getPrettyXml()

    def search='//configuration/connstr'
    c = holder.getDomNode(search)

    log.info "1:"+c
    assert c != null,"node not found"
    holder.setNodeValue(search,db)
    c = holder.getDomNode(search)
    log.info "2:"+c
    conf=holder.getXmlObject()
    log.info "connection string:"+conf
    it.getDataSourceStepConfig().getDataSource().setConfiguration(conf)

    conf=it.getDataSourceStepConfig().getDataSource()
    log.info "conf final:"+ conf

    }

    }