Service Virtualization

Expand all | Collapse all

How to check whether a specific argument is present in the argument list..?

  • 1.  How to check whether a specific argument is present in the argument list..?

    Posted 03-10-2015 04:28 AM

    In one of my scenarios, I came accross with a situation, where I need to look for a specific argument; say "CountryCode", if it is present, I need to create the responses with the values of the argument.

    I did something like this

     

     

    import com.itko.lisa.vse.stateful.model.Request;

    import com.itko.util.ParameterList;

    Request req = (Request) testExec.getStateValue("lisa.vse.request");

    String opName = req.getOperation();


    ParameterList args = req.getArguments();

    String country= args.get("CountryCode");

    IF country is USA THEN

    ELSE

    END

     

    However, It is possible that the incoming request is doesnot contain that specific tag, In that scenario, the above code snippet may throw an exception. Please let me know how can I handle this exception and check whether "args" has my specific tag without an exeception..?



  • 2.  RE: How to check whether a specific argument is present in the argument list..?

    Broadcom Employee
    Posted 12-04-2020 05:37 PM
    Just in case someone else may be looking for an answer to this question; a possible approach could be to do the following:

    ParameterList args = lisa_vse_request.getArguments();
    Parameter thisParameter;

    if(args.toString().contains("CountryCode"))
    {
        _logger.info("Great this incoming request does contain CountryCode");

         for(i=0; i<args.size(); i++)
         {
              thisParameter = args.get(i);
              if(thisParameter.getName().equals("CountryCode") && thisParameter.getValue.equals("USA"))
              {
                    _logger.info("yep, we've found it..... CountryCode is USA");
              }
         }
    else
       _logger.info("Sorry, this incoming request does NOT contain CountryCode");




  • 3.  RE: How to check whether a specific argument is present in the argument list..?

    Posted 12-07-2020 12:45 AM
    Hi Anon,

    You can also use the filter to extract the value and put an assertion around it.

    Thanks

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



  • 4.  RE: How to check whether a specific argument is present in the argument list..?

    Posted 12-08-2020 04:29 AM
    We did the same thing in one of our servcies using above script that decdies the resposne to be sent according to argumnets present .

    Used that in Script match in VSi

    ------------------------------
    Regards
    Rahul V
    ------------------------------