Service Virtualization

 View Only
  • 1.  How to split the request argument value in response

    Posted Jan 03, 2023 10:37 AM
    Hi all


    We have a requirement where we have a argument in request with value '12345678'.We need to fetch some part of it in the response. like first 2 digits and the last 4 digits. Could you please help. Thanks


  • 2.  RE: How to split the request argument value in response

    Broadcom Employee
    Posted Jan 03, 2023 11:47 AM
    Hi,

    Mark the argument as a magic string
    Then, in the .vsi, in the response put something like

    {{=request_yourArgumentName.substring(0,2)+request_yourArgumentName.substring(4);}}

    The above is assuming your argument string always has the length 4, if it
    has a variable length then instead if using the fixed 4 you would have to
    calculate the index based on the length of the argument string eg.

    {{=request_yourArgumentName.substring(0,2)+request_yourArgumentName.substring(request_yourArgumentName.length()-4);}}

    Hope this helps,
    Also hope this works 😊 as I did it from the top of my head without
    verifying

    Cheers,

    Danny Saro

    Client Services Consultant

    Broadcom Software


    -------------------------------------------------

    --
    This electronic communication and the information and any files transmitted
    with it, or attached to it, are confidential and are intended solely for
    the use of the individual or entity to whom it is addressed and may contain
    information that is confidential, legally privileged, protected by privacy
    laws, or otherwise restricted from disclosure to anyone else. If you are
    not the intended recipient or the person responsible for delivering the
    e-mail to the intended recipient, you are hereby notified that any use,
    copying, distributing, dissemination, forwarding, printing, or copying of
    this e-mail is strictly prohibited. If you received this e-mail in error,
    please return the e-mail to the sender, delete it from your computer, and
    destroy any printed copy of it.




  • 3.  RE: How to split the request argument value in response

    Posted Jan 03, 2023 01:11 PM
    Hi Danny

    Thanks for your help ,it worked .Also ,could you please share ,if any , doc link to find out about the usage of such keywords/syntax to get these kind of requirements implemented.

    Many Thanks
    Akshit


  • 4.  RE: How to split the request argument value in response

    Broadcom Employee
    Posted Jan 04, 2023 03:25 AM
    Hi,

    I am not aware of any tutorial on this; understanding how it works is about
    using Beanshell in DevTest (
    https://techdocs.broadcom.com/us/en/ca-enterprise-software/devops/devtest-solutions/10-7/using/using-application-test/using-devtest-workstation-with-application-test/using-beanshell-in-devtest.html
    )

    For following:

    {{=request_yourArgumentName.substring(0,2)+request_
    yourArgumentName.substring(4);}}

    you need to understand that:

    - Everything inside the {{ and }} is beanshell functionality
    - The initial '=' and the ending ';' indicate that this is the
    right-hand side of a beanshell statement, the right-hand side of a
    statement is also called an expression. In a complete script you could find
    this expression as part of a statement like:
    var myNewValue = request_yourArgumentName.substring(0,2) + request_
    yourArgumentName.substring(4);
    - beanshell understands java so you can use java expressions; and (most
    of) java functionality in your expressions
    - if you mark an argument as a magic string then DevTest will create a
    property inside the runtime environment which is of type String and has the
    name "request_<yourargumentname>" and DevTest will give this property the
    value of the argument. The beanshell interpreter within DevTest has
    automatic access to these properties, no action needed to declare them
    and/or retrieve them
    - So, the above is just a java expression that manipulates String
    variables: in Java, you can use the substring() method to retrieve pieces
    of the original string content, and you can use '+' to concatenate strings
    together into a new value


    Hope this helps,

    Cheers,

    Danny Saro

    Client Services Consultant

    Broadcom Software


    -------------------------------------------------

    --
    This electronic communication and the information and any files transmitted
    with it, or attached to it, are confidential and are intended solely for
    the use of the individual or entity to whom it is addressed and may contain
    information that is confidential, legally privileged, protected by privacy
    laws, or otherwise restricted from disclosure to anyone else. If you are
    not the intended recipient or the person responsible for delivering the
    e-mail to the intended recipient, you are hereby notified that any use,
    copying, distributing, dissemination, forwarding, printing, or copying of
    this e-mail is strictly prohibited. If you received this e-mail in error,
    please return the e-mail to the sender, delete it from your computer, and
    destroy any printed copy of it.




  • 5.  RE: How to split the request argument value in response

    Posted Jan 04, 2023 07:36 AM
    Thanks again Danny