Service Virtualization

 View Only
  • 1.  Help me in Beanshell Scripting

    Posted Jun 08, 2022 01:15 PM
    Hi ,
    How can I use java inbuilt methods in Beanshell?
    what are the statements/ packages I need to import?
    How to spilit a string in Beanshell?

    Can anyone help me on this.


  • 2.  RE: Help me in Beanshell Scripting

    Broadcom Employee
    Posted Jun 08, 2022 02:04 PM
    Hi,

    Java JRE classes are available in beanshell and you can just write down
    your java statements.

    Generic example:

    String[] parts = "004-034556".split("-");

    String part1 = parts[0]; // 004String part2 = parts[1]; // 034556

    Example for splitting a previous created property within your workflow
    (.vsm or .tst) and storing the parts in new properties (The assumption here
    is that the property value will be split in 2 parts)

    String[] parts = testExec.getStateValue("myExistingProperty").split("-");
    testExec.setStateValue("myNewProperty1") = parts[0];
    testExec.setStateValue("myNewProperty2") = parts[1];

    Hope this helps,

    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: Help me in Beanshell Scripting

    Posted Jun 10, 2022 10:00 AM
    Thanks Danny.


  • 4.  RE: Help me in Beanshell Scripting

    Broadcom Employee
    Posted Jun 09, 2022 12:47 AM
    Hi Murali
    You can simply import Java classes into your Beanshell script and
    use them. Please see this example below.

    import com.itko.lisa.vse.stateful.model.TransientResponse;
    import com.itko.lisa.vse.stateful.model.Response;
    import com.itko.util.ParameterList;
    import com.itko.lisa.asset.AssetUtils;
    import javax.net.ssl.SSLContext;
    import java.security.SecureRandom;
    import javax.net.ssl.HttpsURLConnection;

    Response response1 = new Response();

    SSLContext sc = SSLContext.getInstance("TLSv1.2");
    sc.init(null, null, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

    response1.setBody(CheckJVMVendor.getJVMVersion());

    ParameterList metadata = response1.getMetaData();
    metadata.setParameterValue("HTTP-Response-Code","200");
    TransientResponse transRsp = response1.createTransientCopy();
    testExec.setStateObject("lisa.vse.response", transRsp);

    return;

    --
    regards
    Sankar Natarajan

    --
    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: Help me in Beanshell Scripting

    Posted Jun 10, 2022 10:02 AM
    Thanks Sankar.


  • 6.  RE: Help me in Beanshell Scripting

    Posted Jun 10, 2022 01:23 AM
    Hi Murali,

    I hope the responses from Sankar & Danny helped you. Please let us know in case you have any challenges.

    Thanks

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 7.  RE: Help me in Beanshell Scripting

    Posted Jun 10, 2022 10:08 AM
    Hi Vaibhav,
    Yes, It helped me. I will let you know, if I got any other challenges.Thanks.


  • 8.  RE: Help me in Beanshell Scripting

    Posted Jun 12, 2022 02:09 PM
    Thanks for the update.

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------