Service Virtualization

  • 1.  Possible to calculate a property value?

    Posted Apr 17, 2017 03:40 PM

    Is it possible in DevTest Solutions (on 9.5.1.6) to set a property in a step?

     

    Specifically, I need to set a date to a long integer (milliseconds) and return that in a JSON object.  I know how to reference such a date "dueDate": {{dueDate}}, and I know how to calculate the date (somewhat cumbersome, but not terribly so) in Java, but where would I put my Java code?  And how would Java populate dueDate property?

    I'm reasonably sure I have to declare the property in the project.properties file which is fine.

    But I see nowhere in DevTest Solutions where I can execute Java code and assign a property value from Java (or any other manner) in a VSM step.

    Is it possible to do such?



  • 2.  Re: Possible to calculate a property value?

    Broadcom Employee
    Posted Apr 17, 2017 05:35 PM

    Where would you like to use {{dueDate}} ?

     

    You mention a VSM step, and there are a number of places in a virtual service where you can add your Java code to do this, depending on where you want to use it. It could be in a Router step (VSM), a scripted data set (VSM), a match script (VSI), a request or a response scriptable Data Protocol Handler (VSM), in-line in your response data (VSI) or even a custom JSR-223 step (VSM).

     

    DevTest 8.0 - Scripting Guide - V1.1.pdf includes descriptions and examples.

     

    The command:

       testExec.setStateValue("dueDate", theDateYouCreate);

    will put theDateYouCreate into a property that {{dueDate}} will retrieve, depending on where you put your Java code.



  • 3.  Re: Possible to calculate a property value?
    Best Answer

    Posted Apr 18, 2017 01:41 PM

    Thank you sir! 

     

     

    The command:

    testExec.setStateValue("dueDate", theDateYouCreate); will put theDateYouCreate into a property that {{dueDate}} will retrieve, depending on where you put your Java code.

    That is the key to what I needed.  And dueDate does not have to be declared in a properties file.  One can simply "create it in the step" and have it available for later steps.  Once the response step was executed, {{dueDate}} (in a JSON object), was correct populated.