Creating First Parasoft Virtual Asset

Now we know Parasoft Virtualize concepts. Today we will experience the magic of virtualization by creating our first virtual asset and testing it.

First of all create an empty project as follows:

  1. Open the pull-down menu for the New toolbar button (top left) then choose Project.
  2. Choose Virtualize –> Empty Project, and then click Next.
  3. Enter a name for the project, change the destination if needed and then click Finish.

Adding a New .pva File to an Existing Project

To add a new .pva file to an existing project.

  1. Do one of the following:
  • Right click the project node, and select Add New> .pva File from the shortcut menu.
  • Choose File > New > .pva File.
  1. In the New .pva File wizard that opens, select the project that you want to contain the .pva file, enter a name for the .pva file, and then click Next.

This will create a new Virtual Asset (referred as VA as well) in the workspace with a Responder Suite. Responder suite is the container where we are going to create one or more virtual responses to be returned to the client application.  In order to add a response we need to create a ‘Responder’.

Adding a Responder Suite

To create a new Responder suite:

  1. Do one of the following:
  • Select the Virtual Asset Explorer node where you want to add the new Responder suite, then click the Add Responder suite button:
  • Right-click the Virtual Asset Explorer node where you want to add the new Responder suite, then choose Add New > Responder suite from the shortcut menu.

For help selecting and completing the available project, .pva file, and Responder suite creation wizards, refer to the descriptions and links in the following table.

Wizard Options

Wizard

Description

Record Traffic Records live HTTP, JMS, and MQ traffic that passes through multiple endpoints.
Generate From Traffic (Generate Fixed Messages, Generate  Parameterized Messages) Creates virtual assets for the transactions represented in the traffic files.
Recorded Database Queries Creates virtual assets for the database behavior represented in the database recording.
RAML Creates virtual assets by analyzing a RAML definition.
Swagger Creates virtual assets by analyzing a Swagger definition.
WSDL Creates virtual assets by analyzing the WSDL.
XML Schema Creates virtual assets by analyzing the XML Schema.
Import .pva file | Project Imports a project that was previously exported through the Virtualize export feature.
Empty .pva file | Project Creates an empty project or .pva “skeleton” to which you can add the desired assets.
Virtualize Java Project Creates a new Eclipse Java project that has access to Virtualize’s Extensibility API. You can later configure Virtualize scripts and Extension tools to invoke classes from the new Java project.
Project from Existing Responder suites Creates a new Virtualize project based on pre-existing Responder suites.
Change Template Creates a change template for refactoring your tools/messages in response to service changes.

There are many type of Responders can be created from Parafost Virtualize. Some of the common examples are XML or JSON responders, Literal responders etc.  It is possible to add more than once responder to Virtual Asset, and correlate it with an incoming http header, url parameter, request body element etc (We will discuss correlation in detail in upcoming chapters). As the first steps let’s add a XML responder. An XML responder will return an xml message when it is called. For this follow Responder Suite -> New tool -> Plain XML Responder. Then add a XML message to response body.

Rename the responder and add value. In responder tab, select form xml or literal and update values.

Now let’s correlate this XML responder to a URL parameter, so when the Virtual Asset is called client needs to pass that specific url parameter in the address if it needs to have XML responder in return. For that go to HTTP URL Parameters and select ‘enable correlation’. Then give a parameter name to correlate.

By default URL would be like http://localhost:9080/Training where “http://localhost:9080/ is URL for virtualize server and “Training” is name of virtual or .pva file. We can modify it. To modify you need to deploy the VA on server. To deploy on server just drag the VA to Virtual Asset node in Server view.

Now double click the VA in server view to open it in editor view. Check the HTTP End Point. It is the actual URL. It can be modified if needed.

Let’s add two more responders with text and JSON response.

To test these open the browser and hit VA end point url with correlation URL Parameter defined.

http://localhost:9080/Training?response=xml

Now change the URL to http://localhost:9080/Training?response=text

Now change the URL to http://localhost:9080/Training?response=json

Leave a Reply

Your email address will not be published. Required fields are marked *