Forum Discussion

valentinamatera's avatar
valentinamatera
Occasional Contributor
2 years ago

ReadyAPI: How to remove table name in jdbc response

Hello, 

I need to know how it is possible to remove the table name in the jdbc response. 

 

My situation is: 

I have configured 2 environments on my project: one has Postgres database, the other one has Oracle database. 

When I run a jdbc step on postgres, an example of response is: 

 

<Results>

    <ResultSet fetchSize="0">

        <Row rowNumber="1">

            <DICTIONARY_CODE.SEQ_DICTIONARY_CODE>107</DICTIONARY_CODE.SEQ_DICTIONARY_CODE>

        </Row>

    </ResultSet>

</Results>

 

where DICTIONARY_CODE is the table name and SEQ_DICTIONARY_CODE is the column name. 

 

When I run it on the Oracle database, the response is:

<Results>

    <ResultSet fetchSize="0">

        <Row rowNumber="1">

            <SEQ_DICTIONARY_CODE>107</SEQ_DICTIONARY_CODE>

        </Row>

    </ResultSet>

</Results>

 

so, on oracle is not returned the table name. 

It is a problem for the assertions and also when I want to use this value as a property in another step. 

 

To do an example: 

After the jdbc request, I have a REST Request in which I use the jdbc response value as a property: 

 "seqAbbreviationGroup" : "${Find abbreviation_group from dictionary_code#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/DICTIONARY_CODE.SEQ_DICTIONARY_CODE[1]}"

 

So, to use it, on postgres I need to define the table name and the column name, on Oracle only the column name. 

In this way it is impossible to run the same project on 2 different environments. 

 

A solution could be to have the same jdbc response in both the environments: so, how it is possible to remove the table name in the jdbc response? 

Or, there is any particular settings to make "universal" the jdbc response? 

 

I use the 3.20.0 ReadyAPI version.

 

I hope my request is clear. If you need, I can give you further details. 

Thanks in advance.

 

 

7 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    There can multiple ways to deal with this issue.
    One of the approach is to apply filter on response and remove the unwanted table name if the environment is postgres.

    • valentinamatera's avatar
      valentinamatera
      Occasional Contributor

      Thank you for the answer but how is it possible to filter the response? 

       

       

  • nmrao's avatar
    nmrao
    Champion Level 3

    valentinamatera 

    Add Event Handler, select the "After Run TestStep" event.

    And use below script, hope it will help

    import com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep
    
    //Set the tablename to be removed
    def tableName = 'DICTIONARY_CODE'
    
    def currentStep = context.currentStep
    if (currentStep instanceof JdbcRequestTestStep) {
        // Custom logic to be executed for JDBC Request steps only
        // Add your script code here
        log.info("After Step Run Event - JDBC Request Step")
        // Get the response of the JDBC step
        def response = currentStep.testRequest.response.contentAsString
    
        // Perform processing to remove table names from the response (you can customize this as per your requirements)
        def modifiedResponse = response.replaceAll(/tableName\./, '')
    
        // Set the modified response content
        currentStep.testRequest.response.setContent(modifiedResponse)
    }