Service Virtualization

Expand all | Collapse all

Need suggestion on SV Approach

monika_mehta

monika_mehtaMar 28, 2017 05:04 PM

monika_mehta

monika_mehtaApr 04, 2017 11:27 AM

  • 1.  Need suggestion on SV Approach

    Posted Mar 28, 2017 04:41 AM

    Hi Team,

     

    I have a requirement to create a virtual service whose functionality is as described below:

    > For one type of request containing 10 parameters,send a synchronous response.In this synchronous response ,I need to create a random Transaction ID and send in response.

     

    > After 10 sec ,for one other type of request which will have same Transaction ID in the request as generated in the first response, send back the same values of all 10 parameters that came as part of first request in a synchronous response.

     

    I am thinking to create 2 types of request in the same VSI but i am not sure how am I going to store the values in the first request and pass the same values in the next request as a response.

     

    Can you please suggest some inputs.

     

    Thanks

    Sarthak

    Attachment(s)

    zip
    temp_appledep.zip   3 KB 1 version
    docx
    AppDepVS_error.docx   651 KB 1 version
    zip
    Enable-req.json.zip   449 B 1 version
    zip
    Enable-rsp.json.zip   319 B 1 version
    zip
    Raw files.zip   9 KB 1 version


  • 2.  Re: Need suggestion on SV Approach

    Posted Mar 28, 2017 12:24 PM

    Can we achieve this using 2 Virtual service? Below is the Idea:

     

    1. Create a VS which will take 10 params in request and send a response with random transaction id. 

    Use SharedModelMap to set your request params to property that can be used in other Virtual Service.

    2. In VSM, after sending response in step1, add a step which will send a request to other VS.

    3. VS in Step 2 will take transaction id as request and use SharedModelMap to fetch the property holding parameters value set in step 1. Create response using it and send it.

     

    I haven't tried implementing it. See if that can work for you.

     

    Thanks,

    Monika

     

     



  • 3.  Re: Need suggestion on SV Approach
    Best Answer

    Posted Mar 28, 2017 04:22 PM

    +1 ^^   

    I thought there was a later version in Communities, but check out the DevTest 8.0 - Scripting Guide - V1.1.pdf starting about page 23. Monika's reference to the Shared and Persistent Model Maps can be found here. 



  • 4.  Re: Need suggestion on SV Approach

    Posted Mar 28, 2017 05:04 PM

    norre01 Wasn't my answer correct?   



  • 5.  Re: Need suggestion on SV Approach

    Posted Mar 29, 2017 07:03 AM

    Metha,

     

    Your answer is correct. The reason I marked Joel's latest update as the correct answer was it mentioned your correct answer and also provided the reference to the DevTest 8.0 - Scripting Guide. I really appreciate all of the time and assistance in answering the questions that are posted on this DevTest Community.



  • 6.  Re: Need suggestion on SV Approach

    Posted Apr 04, 2017 11:27 AM

    Got it



  • 7.  Re: Need suggestion on SV Approach

    Posted Mar 30, 2017 05:52 AM

    Hi Monika,

     

    I am implementing the way you suggested.As of now to check the VS,I have created a request in JSON and for that I am sending the response.Thats it.

     

    However when I am trying to hit the vs after deploying it to vs,I am using a REST step and giving the VS URL and method i am using as POST and in the content I am giving the JSON that I have configured in VSI.But I am getting response that VSE could not match the request.

     

    I have used the match type as exact but still not sure why I am not getting response that I have configured .Do I need to use any other settings for this.Since I have used JSON Request reponse pairs so I am using REST Step.Shall I use something else.

     

    Thanks

    Sarthak



  • 8.  Re: Need suggestion on SV Approach

    Posted Mar 30, 2017 10:34 AM

    Did you use JSON parser data protocol?  If not, please use it while creating your Virtual Service.

     

    Thanks,

    Monika



  • 9.  Re: Need suggestion on SV Approach

    Posted Mar 30, 2017 10:44 AM

    Hi Monika,

     

    I am using JSON 2.0 as Request Data protocol while creating my virtual service.Can you suggest.

     

    Thanks

    Sarthak



  • 10.  Re: Need suggestion on SV Approach

    Posted Mar 30, 2017 11:14 AM

    Is it possible for you to share Virtual Service? 

    Which version of DevTest are you using?



  • 11.  Re: Need suggestion on SV Approach

    Posted Mar 30, 2017 11:40 AM

    HI Monika,

     

    I have attached the vsi and vsm.Can you please check.

    Thanks

    Sarthak



  • 12.  Re: Need suggestion on SV Approach

    Posted Mar 30, 2017 11:56 AM

    I am not able to access VSM SInce I am using older version. As per VSI, I don't see any operation selected when it parse JSON as XML.

    Try using Generic XML Payload Parser and select Operation Manually. 

     

    Hope that will help.



  • 13.  Re: Need suggestion on SV Approach

    Posted May 06, 2017 02:20 PM

    Hi Monika,

     

    Sorry that I could not reply to your post since long as I got held up in some other activities.I tried using Generic XML payload Parser as well as JSON 2.0 data protocol but in both the cases ,I am able to deploy the virtual service and when I am trying to hit the virtual service using REST Step ,and also POST Method ,I am getting the same error, VSE could not match the request.

     

    Please see attached screenshots.Can you please suggest what could be possibly going wrong as I am able to see transactions to VS in VSE but it says not able to match the VSI Request.

     

    For your reference ,I am attaching the Sample JSON Request response pairs also,if you can suggest further.

     

    Thanks

    Sarthak Gupta



  • 14.  Re: Need suggestion on SV Approach

    Posted May 06, 2017 08:23 PM

    Hello,

    Why don't you try running service locally(using ITR) for debugging purpose. Step by step execution will help you to understand and identify the exact problem and step which is causing issue.

     

    Problem which I can think of by looking at the document name is with Operation Name. Check the operation name in VSE or in ITR during execution and update your VSI accordingly. It should work then.

     

    thanks



  • 15.  Re: Need suggestion on SV Approach

    Posted May 08, 2017 05:07 AM

    Hi Gaurav,

    I got the issue.I have not provided the header as below in my request response pairs.Now I am able to get the response as expected for one service.

    POST /REST/SampleRequestURI2 HTTP/1.1
    Content-Type: application/json

     

    However I am still not sure to go ahead with Shared Model map approach for my requirement.Below is my requirement:

     

    1. System A send a synchronous request request to Virtual Service with 10 parameters and gets a response back with One Transaction ID.(Submit /Create Order functionality---Synchronous Request)

     

    2. Lets say after 1 minute, System A will send another synchronous request to a Virtual Service (may be same as above or different ,not sure) with Transaction ID which was generated above and then in response all the parameters that came as request in first request should be sent back as response.

     

    My Questions:

    > How are we keeping track of all requests parameters and the associated transaction ID

    > It can happen that many requests can come concurrently to virtual service,in that case we need to store the above point for all services and then when the next synchronous request comes to virtual service with a transaction id then the corresponding stored parameters should be sent.

     

    Thanks

    Sarthak Gupta



  • 16.  Re: Need suggestion on SV Approach

    Broadcom Employee
    Posted May 08, 2017 05:15 AM

    Does my blog entry help with this So you want to keep count in a virtual service?  

    Look at the end of the blog entry, as it talks about the use of multiple sharedModelMap entries for things like using your transactionID as a key.



  • 17.  Re: Need suggestion on SV Approach

    Posted May 10, 2017 05:34 AM

    Hi rick,

     

    Surely your blog information and Monika's suggested approach has helped me and I am able to call some attributes from one virtual service into other virtual service.But I have below 2 questions regarding approach:

     

    > I am not able to call the value of 1 VS request parameters into other VS image.I am calling them as below.Please suggest if it is correct approach.Only I am able to call the value of a parameter that I have defined in match script of VS1 into VS2.

    1. In VS 1 Image,I am writing below code in match script:

    com.itko.lisa.vse.SharedModelMap.put("EnableAppleDep", "Enable_DeviceID",request_orders_0_deliveries_0_devices_0_deviceId);
    return true;

    2. In VS 2 Image ,I am writing the below code to retrieve the value of above parameter:

    String fileName3 = com.itko.lisa.vse.SharedModelMap.get("EnableAppleDep", "Enable_DeviceID");
    testExec.setStateValue("DId",fileName3);
    return true;

    3. I am calling the value of DId in VS2 response as {{DId}} but I am not getting the value.

     

    > By using the shared model map approach, lets say there are 5 consecutive hits to VS1 and in this case when I will hit the VS2 ,then only the values of the paramters of most recent hit to VS1 will be called .In this case I have lost the value of other 4 hits to VS1.

    However my requirement is when a hit to VS1 is there,then the transaction id generated in response of VS1 along with request parameters are saved and when the request with this Transaction ID comes to VS2(lets say after 5 minutes) ,then transaction id is matched and then all the parameters of request to VS1 will be sent in response.

     

    Please suggest.

     

    Thanks

    Sarthak



  • 18.  Re: Need suggestion on SV Approach

    Broadcom Employee
    Posted May 10, 2017 05:58 AM

    Hi Sarthak --

     

    Your second problem first ...

    I see that your namespace and your key values are both static, which will always restrict you to having one value. Your transactionID could be your namespace. This is what my blog entry does, with "accountID"

           com.itko.lisa.vse.SharedModelMap.put(accountID, "currentBalance", currentBalance.toString());

    This will allow VS2 to query a transactionID to get the correct values.

     

    Now to your first problem ...

    I don't understand your line

       com.itko.lisa.vse.SharedModelMap.put("EnableAppleDep", "Enable_DeviceID",request_orders_0_deliveries_0_devices_0_deviceId);

    Are you actually attempting to get the value of the request argument "orders_0_deliveries_0_devices_0_deviceId", like how DevTest shows in the service image? But you're trying it without putting parentheses around it like DevTest does:

       {{=request_orders_0_deliveries_0_devices_0_deviceId)}}

    or using the facilities in DevTest to retrieve that argument (my blog entry does this)

       ParameterList args = incomingRequest.getArguments();

       String amountString = args.getParameterValue("amount");

    Surely, without doing one of those two things, it will write a blank value to that sharedModelMap, and so your line:

       String fileName3 = com.itko.lisa.vse.SharedModelMap.get("EnableAppleDep", "Enable_DeviceID");

    is correctly retrieving the blank value.

     

    So were the answers to both your questions already in my blog entry? Or do I need to update it?

     

    Rick



  • 19.  Re: Need suggestion on SV Approach

    Posted May 10, 2017 09:04 AM

    Hi Rick,

    I tried the solution for Option 1, and its pretty vague but I am able to get the value of only one request parameter in VS2 but not others.I am following below thing:

    > In VS1 match script:

    import com.itko.util.ParameterList;

    ParameterList args = incomingRequest.getArguments();
    String str_depId = args.getParameterValue("depResellerId");
    String str_delNr = args.getParameterValue("orders_0_deliveries_0_deliveryNumber");

    testExec.setStateValue("Sar1",str_depId);
    testExec.setStateValue("Sar2",str_delNr);

    return true;

    > In VS1 model ,I have added a Java Step (JSR-223) and included below code:

    com.itko.lisa.vse.SharedModelMap.put("EnableAppleDep", "Enable_DepId",Sar1);
    com.itko.lisa.vse.SharedModelMap.put("EnableAppleDep", "Enable_DeliveryNumber",Sar2);

     

    > In VS2 model,I have added a Java Step (JSR-223) and included below code:

    String fileName2 = com.itko.lisa.vse.SharedModelMap.get("EnableAppleDep", "Enable_DepId");
    testExec.setStateValue("Mapped_Enable_DepId",fileName2);
    String fileName3 = com.itko.lisa.vse.SharedModelMap.get("EnableAppleDep", "Enable_DeliveryNumber");
    testExec.setStateValue("Mapped_Enable_DeliveryNumber",fileName3);

     

    > In VS2 response ,I am calling {{Mapped_Enable_DeliveryNumber}} and {{Enable_DepId}}

     

    if I only include the above process for one parameter (depResellerId) and comment the code for other ,then it works fine else I am getting below error while executing VS1:

     

    Trapped Exception: bsh.EvalError: Sourced file: inline evaluation of: ``com.itko.lisa.vse.SharedModelMap.put("EnableAppleDep", "Enable_TransactionId",Tr . . . '' : Error in method invocation: Static method put(java.lang.String, java.lang.String, java.lang.Integer) not found in class'com.itko.lisa.vse.SharedModelMap' : at Line: 3 : in file: inline evaluation of: ``com.itko.lisa.vse.SharedModelMap.put("EnableAppleDep", "Enable_TransactionId",Tr . . . '' : com .itko .lisa .vse .SharedModelMap .put ( "EnableAppleDep" , "Enable_DeliveryNumber" , Sar2 )
    in inline evaluation of: ``com.itko.lisa.vse.SharedModelMap.put("EnableAppleDep", "Enable_TransactionId",Tr . . . '' at line number 3



  • 20.  Re: Need suggestion on SV Approach

    Broadcom Employee
    Posted May 10, 2017 09:22 AM

    What is the reason behind doing the com.itko.lisa.vse.SharedModelMap.put in a script step rather than in the match script?

     

    What is the reason behind trying to save an int into the sharedModelMap rather than a string?

     

    What is the reason behind using a static value for the sharedModelMap namespace instead of the transactionID?

     

    My blog entry does the put in the match script, it uses propertyName.toString() so I don't get the error you quote, and it uses a variable for the namespace so it can store & retrieve more than one value.

     

    The line below is from a match script from my blog entry, and it uses toString() and a namespace variable:

       com.itko.lisa.vse.SharedModelMap.put(accountID, "currentBalance", currentBalance.toString());



  • 21.  Re: Need suggestion on SV Approach

    Broadcom Employee
    Posted May 10, 2017 09:28 AM

    If you can send me (via direct message here or an email) your raw recording file, your VRS file, your extra scripts and your data model, I would be happy to take a look. I can't promise a quick response, but I'll see what I can come up with.



  • 22.  Re: Need suggestion on SV Approach

    Posted May 10, 2017 10:45 AM

    Hi rick,

    Thanks for your quick reply.Appreciate your help.

     

    >I am able to call all the parameters now after performing type conversion as below:

       com.itko.lisa.vse.SharedModelMap.put(accountID, "currentBalance", currentBalance.toString());

     

    >I have also attached the raw files (Image and model files of both the service).Can you please have a look at it.

    newimage3 is VS1

    newimage2 is VS2

     

    > Also I have changed the namespace to the name of transactionID but after that I am getting the below error 

    | Step: Execute script (JSR-223)
    ----------------------------------------------------------------------------
    | Message: bsh.EvalError: Sourced file: inline evaluation of: ``String fileName1 = com.itko.lisa.vse.SharedModelMap.get(TransactionID, "Enable_T . . . '' : Typed variable declaration : Undefined argument: TransactionID : at Line: 1 : in file: inline evaluation of: ``String fileName1 = com.itko.lisa.vse.SharedModelMap.get(TransactionID, "Enable_T . . . '' : ( TransactionID , "Enable_TransactionId" )

     

    > I have used Shared Model map inside script step during debugging.There is no specific reason for that.I will use it in Match script now.

     

    > As of now I have developed the functionality of generating a Transaction ID and storing all the request parameters of VS1 in a shared model map to be able to call in VS2.But I am not clear on the approach that when a request will come to VS2 with a transaction ID ,then how will the comparison happen or do I need to compare it with the transaction ID stored in Shared Model Map before the responder step ?Any suggestions on this.

     

    Thanks

    Sarthak



  • 23.  Re: Need suggestion on SV Approach

    Broadcom Employee
    Posted May 10, 2017 06:52 PM

    I've fixed your match scripts and removed the extra scripting steps in your VSM files. I can't see how to upload them to this thread, so send me an email and I'll respond with the files.