Service Virtualization

 View Only
  • 1.  Scripting whole response in devtest

    Posted Nov 15, 2018 02:37 AM



    Is there any way to script whole XML response in devtest rather than mentioning response in response editor in VSI. I want to write code to generate whole response then reply it  to the request?



  • 2.  Re: Scripting whole response in devtest
    Best Answer

    Broadcom Employee
    Posted Nov 15, 2018 03:24 AM

    We do not know your exact requirements which are forcing you to create a completely dynamic response. Before starting to discuss some solution, a word of warning. Be careful that you don't fall into the trap of making the virtual service too complex:

    • if this virtual service needs to support a fixed, known set of test cases then the need for complete dynamic responses might point to the fact that the testcases are not optimized, that there is too much overtesting resulting in too many calls to your virtual service whereby each response might be different but adds little value to the testing of the SUT functionality.
    • if this virtual service is used for exploratory testing, it would appear that the back-end system you are virtualizing has a very important function in the complete end-to-end flow. So don't end up almost rewriting the complete back-end functionality, it'll be a maintenance headache. There will be a trade-off between maintaining a complex custom virtual service or providing an actual live endpoint (from one of your test environments). At some point the latter might become less effort.


    Apologies for making the word of warning longer than the actual response.


    You can just replace the whole response with one property, e.g. {{prpCustomResponse}}, and then you can put whatever sequence of steps, or loops, or branches between the Listen step and the Responder step as long as you make sure that by the time the flow reaches the Responder step the property {{prpCustomResponse}} contains the payload you want to send back.




  • 3.  Re: Scripting whole response in devtest

    Broadcom Employee
    Posted Nov 15, 2018 10:01 AM

    Add to what Danny was saying. You can use Execute Script step (for all transactions) to customize your response and store it in a property and use that in VSI response. Documentation on Execute Script step is available at Execute Script (JSR-223) Step - DevTest Solutions - 10.3 - CA Technologies Documentation.


    If you want to write code to customize your response for a specific transaction, you can do that in Match Script also. Documentation is available at Transactions Tab for Stateless Transactions - DevTest Solutions - 10.3 - CA Technologies Documentation.

  • 4.  Re: Scripting whole response in devtest

    Posted Nov 15, 2018 06:36 PM

    I typically use the match script in the VSI whenever I write code to make my responses dynamic. You can create your entire response message in the match script and then save it to a property using:


    testExec.setStateValue("MyResponse", responseMessageVar);


    Then you can simply populate your response with: {{MyResponse}}


    I recommend this approach because there's no need to modify existing assets such as VSM.