Service Virtualization

  • 1.  Validating the incoming Request

    Posted Feb 12, 2019 12:37 AM

    Hi All,

     

    There is a virtual service and the requirement is to validate the incoming request and the condition here is : the  incoming request should not contain few keywords like: Education, Training, Solutions (case in-sensitive). These keyword values can come at any field- there is no fixed xpath as such where this keywords may appear. if one of these keywords were found in incoming request (XML) then response should be put into failure queue.

     

    Could you please let us know how can this validation be incorporated in the Virtual service.

     

    Thanks



  • 2.  Re: Validating the incoming Request

    Broadcom Employee
    Posted Feb 12, 2019 01:28 AM

    Without testing the below I would add an XPATh assertion with something like:

     

    //*[lower-case(text()) = 'education' | lower-case(text()) = 'training' | lower-case(text()) = 'solutions']

    if the assertion is true then you can branch to step to put the message on the failure queue

    Cheers,

    Danny



  • 3.  Re: Validating the incoming Request

    Posted Feb 12, 2019 05:09 AM

    Hi Danny,

     

    lower-case function in the xpath query is not working in Xpath Assertion. Have checked in bothe  DevTest 9.5 and DevTest 10.3.

     

    Consider the below example request xml :
    <request>
    <a>training</a>
    <b>class</b>
    </request>

     

    to the above xml, added xpath Assertion :

    1. XPATH Query: //*[lower-case(text())='training']  ---  upon running the xpath assertion, result is False though the string 'training' is present in the xml. 

     

    2. only this case-sensitive xpath query is working: 

    //*[text()='training']-- result is True upon running the assertion

     

    But the requirement here is for case-insensitive.

    Is there any jar file to be added in lib folder to make this query work. Please suggest.

     

    Thanks.

     



  • 4.  Re: Validating the incoming Request

    Broadcom Employee
    Posted Feb 12, 2019 05:55 AM

    The lower-case() function is an XPath v2 feature, so it appears DevTest is using an v1.x version.

     

    So, with some googling it appears that a translate function could do the trick. It makes the Xpath much longer so you'll have to edit it in a text editor and copy-paste into DevTest assertion pane.

     

    //*[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='training'] 

     

    The above one obviously only for 'training', if that one works you can expand it with the | (OR) constructs

     

    //*[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='training' | translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='education' | translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='solutions']

     

    Hope this helps,

    Danny



  • 5.  Re: Validating the incoming Request

    Posted Feb 12, 2019 07:56 AM

    i will check and let you know

     

    Thanks



  • 6.  Re: Validating the incoming Request

    Posted Feb 13, 2019 01:21 AM

    Hi Danny,

     

    This is working as expected for case insensitive keywords. 

     

    Thank you for your support



  • 7.  Re: Validating the incoming Request

    Broadcom Employee
    Posted Feb 12, 2019 09:47 AM

    You can also try adding an assertion and see the request contains any of the words you are looking and change the logic to goto failure queue. May be you try "Ensure result contains Expression" assertion.

     

    Ensure Result Contains Expression Assertion - DevTest Solutions - 10.4 - CA Technologies Documentation 



  • 8.  Re: Validating the incoming Request

    Posted Feb 13, 2019 01:28 AM

    Thanks prema for the reply. 

     

    if the keyword is case sensitive then "Ensure Result Contains Expression" Assertion will work. otherwise (case insensitive) this assertion will not work as per my understanding.

     

    Anyways the raised query is fixed by using  Xpath Assertion.

     

    Thank you.



  • 9.  Re: Validating the incoming Request

    Posted Feb 13, 2019 02:26 AM

    Hi Danny/Prema,

     

    One more issue identified today is that,  if the value of any xpath is coming as 'training' or 'education' or 'solutions' [Case insensitive]. the below xpath query is working fine.

     

    //*[translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='training']

     

    but  if the xpath value is appended with some other value in the incoming requests, then this particular xpath query is not working . For example  consider the below request:

     

    request>

    <a>training vic support</a>
    <b>class</b>
    </request>

     

    our requirement now is, though those values coming along with other text also like the example above, the response should go to failure response queue.

     

    Do you have any suggestions here?

     

    Thanks



  • 10.  Re: Validating the incoming Request
    Best Answer

    Broadcom Employee
    Posted Feb 13, 2019 03:09 AM

    Try:

     

    //*[contains(translate(text(),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'training')]

     

    Cheers,

    Danny



  • 11.  Re: Validating the incoming Request

    Posted Feb 13, 2019 05:11 AM

    Thanks Danny. it is working now!