HP Service Virtualization

Install HPE _SV Designer 3.82 CE

  • Windows 2012R2
  • SQL 2012 Express SP1

RestApi

We will use the API from ft-demo-website project => API. We will explore HPE SV and We will virtualize 2 methods from the API:

  • Read list of books
  • Add a book

Read list of books

Original : http://../api/listBooks.php
This GET Rest Api provides a list of books

  • We need to configure HPE Sv to learn the service:
    • Go to Add a new virtual service…
    • Select I don’t have a service description & click Next
    • Select REST & click Next
    • Select agent HTTP Gateway because we want to simulate the endpoint.
    • Add in Real Service > Endpoints the original rest api as specified above & click Next
    • Start to learn by selecting Learn and create a call using the Virtual Service not the Real service
    • System is learning thanks to this unique call. You will see that you have been redirected to the real service. When it the system is learning it captures the call, redirects it, plays as proxy and records the answer.
    • Switch to Simulate now & do again the call using again Virtual Service url. As you can see, you are not redirected and it is providing the same content. Now the service is kind of cached. We can say this service is stubbed as per this definition.

Add books

Original : http//../api/insertBook.php?title=toto&author=tutu&edition=Sun%20Edition
This GET Rest Api adds a book with the content defined in the param. You create a new Virtual service as the step above. Then put the 2 services in Learning mode.
Before starting, reset the db using http//../api/createTable.php (this will not simulated), and start to alternate the call (list, add, list, add etc…) then switch to Simulate and redo the same pattern. You will see the system is redoing the same outputs.
Now lets trick the system. Call only listBooks.php, you will notice he will loop as per the pattern even we don’t use insertBook.php! We you could face some issue for complex Business Process. How you could solve it? By using script or data driven set.

Beyond a simple stub

After recording you can more data scenarios. You have 2 options that could be used even together:

Script (C# or Javascript) to add business logic.
Data driven set managed with an Excel file and you define all the possible request and response required for your test.
Data test strategy

If you are stuck with some poor data or it is hard to use test data. It could be a good tool to put in place and have a new data test set. Based on your test scenarios, you create all the set of data you want to have in requests and answers and you will have fairly quick your data test set. This should be consider when you are doing your test strategy.

Conclusion

It works perfect if you are doing automated test but if you are doing manual explanatory tests it will be wired.
If you need to put more business logic it is still possible. For each service virtualized, you can add scripts with business logic. But how far you want to replicate the business logic? This could be complicated if you need a perfect replication, that means you will have 2 technologies to maintain with the same business logic. You should avoid creating scripts and answer as much as possible with Data driven set. This will be more easy to maintain.

Samy Kacem

Leave a Reply