Forum Discussion

Service_Mesh-SU's avatar
Service_Mesh-SU
Occasional Contributor
10 years ago

[Resolved] Dynamically set resource path of WADL at runtime

I have the following scenario:

1) Our product supports "X" number of versions for our REST API:

v3.0, v3.5, v4.0, etc

2) Each version of our API has a unique WADL, where the resource path has the version of the API contained in it like so:

/product/api/v4.0/.....

3) We import the WADL (say from v4.0) and create our automated tests based on it.

4) To have these same tests execute against v3.0 and v3.5, we must maintain each of these tests in a separate soapUI project, which is not only difficult (can't easily copy tests between these different projects due to the resource path difference), but also maintenance intensive (having the same test in more than one place when test needs update).

5) We currently have coded soapUI with the ability to enable/disable tests (cases and suites) based on the API version. For example, v4.0 may introduce a new resource that we can restrict so it is NOT run against v3.5

6) What we would like to do is maintain only 1 project, with the latest version WADL, and "dynamically" set the resource path at test runtime:

ex: change "product/api/v4.0/foo" to "product/api/v3.5/foo", run the tests, then change to "product/api/v3.0/foo" and run the tests again

7) I've played around a bit with a RequestFilter Event, attempting to dynamically modify the version portion of the resource path like so:

request.getPath()
//modify path and then set it
request.setPath()

This does modify the path, but only for the "next" run of the test, not the current run.

8.) I'd like to know if there is a better approach/solution to the above described problem that I should be looking at.

One thought was to edit the WADL in soapUI and replace the "version" in the resource path with a variable ($foo, for example) and then set this variable based on needs.

Any pointers would be greatly appreciated!

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    You should use the SubmitListener.beforeSubmit event handler instead.


    log.info submit.request.getPath()
    submit.request.setPath("/product/api/v4.0/foo")
    log.info submit.request.getPath()



    Regards,
    Marcus
    SmartBear Support
    • venkateshAousul's avatar
      venkateshAousul
      New Contributor

      Hi Marcus,

       

      our project had a requirement, where we need to create the testsuite and test cases using groovy script.

      In that case we have created 2 interfaces one for the old API and other for the new API. each test case contains the first API and second api rest steps and followed by a groovy script to compare.

       

      Now the problem is we need set the resource path dynamically by reading it from excel.When I try with the below code which has been suggested by you,  then following error message has been thrown: "ERROR:groovy.lang.MissingPropertyException: No such property: submit for class".

       

      Please help me in setting the resource path and query parameters dynamically. Do I need to place any jars ??

       

       

      Code for reference:

       

      RestRequestStepFactory rest = new RestRequestStepFactory()
      def restServiceConfig = RestServiceConfig.Factory.newInstance()

      restServiceConfig.setType("restrequest")
      RestService restService = project.getInterfaceList()[0]

      RestResource resource = restService.getOperationAt( 0 );

      RestRequest request = resource.getRequestAt( 0 );
      submit.request.setPath(uri1)
      TestStepConfig testStepConfig = RestRequestStepFactory.createConfig(request, d[3] );
      def teststep = tc.addTestStep(testStepConfig)
      teststep.setDisabled(true)

       

      Note Here d[3] is the cell value which reads from the excel sheet, similarly uri1 is assigned by the cell value d[0]

       

      Regards,

      Venkatesh