Service Virtualization

 View Only
  • 1.  Writing groovy script in output log message step

    Posted Jul 04, 2019 08:41 AM
    Hi,

    I need to form a for loop using groovy in "output log message step" where i can print the string value for n times and store it in a property.
    This String Value also consists of some value from property.

    E.g:-
    <name_detail>
        <name>{{property value}}</name>
        <email>xyz@gmail.com</email>
    </name_detail>

    I want to loop the above example dynamically from the "output log message" step and send the response to some rest services

    Could anyone please help me with the syntax for this?


    Thanks,
    Suvendu


  • 2.  RE: Writing groovy script in output log message step
    Best Answer

    Posted Jul 04, 2019 09:37 AM
    Apologies, I don't know Groovy, I am a one-trick java-pony.

    My understanding is your "Output Log Message" step outputs an xml-snippet:
    <name_detail>
        <name>{{property value}}</name>
        <email>xyz@gmail.com</email>
    </name_detail>

    So, this snippet is stored in property lisa.Output Log Message.rsp
    And {{property value}} is already parsed and replaced by a real value.

    For concatening the snippet x number of times and storing the result in another property, I would add a Scripted Assertion step to the "Output Log Message" step. Configure the assertion to fire when "false"
    Then add following script

    String snippet = testExec.getStateValue("lisa.Output Log Message.rsp");
    // Hardcode the value of how many loops
    int n = 10;
    // If you want to grab that value from a property (eg. loopCount) that you defined somewhere, example in your config file
    int n = Integer.parseInt(testExec.getStateValue("loopCount"));

    String result = "";
    for (int i; i < n; )
    {
       result=result + snippet + "\n";
    }

    // Store result in property, example "responseBody"
    testExec.setStateValue("responseBody", result);

    // Avoid that the assertion fires
    return true;



    ------------------------------
    Cheers,
    Danny
    ------------------------------



  • 3.  RE: Writing groovy script in output log message step

    Posted Jul 04, 2019 10:19 AM

    Sorry, small typo, forgot the iterator in the for loop, it needs to be :

     

    for (int i; i < n; i++)

     

     

    Cheers,

    Danny

     

    ::DISCLAIMER::
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------