In this section:

Introduction

The Parasoft HTTP Simple Mocking Tool allows a Virtual Asset to learn and replicate the transactions between the application under test and a back-end component. It can be used to record and simulate traffic without the use of the proxy.

Prequisites

  • Parasoft Virtualize 9.10.x or later

Installation

The tool can be installed from the UI or command line.

UI Installation

  1. Go to Parasoft > Preferences and click System Properties.
  2. Click Add JARs and select the HTTPSimpleMockingTool.jar file.
  3. Click Apply.
  4. Restart Virtualize.

Command Line Installation

Add the HTTPSimpleMockingTool.jar file to the system.properties.classpath property in your settings properties file. For example:

system.properties.classpath=<PATH_TO_JAR>/HTTPSimpleMockingTool.jar

Alternatively, you could add the HTTPSimpleMockingTool.jar file to the VirtualAssets/system_jars folder. Create this folder if it does not already exist. Make the following API call to reload the .jar:

http://<VIRTUALIZE_SERVER_HOST>:<VIRTUALIZE_SERVER_PORT>/soavirt/api/<VERSION>/preferences/systemProperties/reload

Usage

The HTTP Simple Mocking Tool is used as an output to a Message Responder tool. It is attached to the payload of the outgoing response.

  1. Right-click the Virtual Assets project and choose Add New > Virtual Asset (.pva) File.
  2. Provide a name for the .pva and click Next.
  3. Choose the Empty folder and click Next.
  4. Right-click the new responder suite and choose Add New > Responder.
  5. Choose the Literal Message Responder and click Finish.
  6. In the Response tab of the newly created Literal Message Responder, add a default message for your responder in case a matching request/response pair is not found in the traffic file and the real service is not available for recording.
     
  7. Save the modified responder.
  8. Right-click the responder and choose Add Output.
  9. Choose Outgoing Response > Payload in the left panel and choose HTTP Simple Mocking Tool in the right panel. This tool must be added to the outgoing response payload; other options are not applicable.
     
  10. Configure the tool options. See Tool Configuration.

Once the tool is configured and the associated virtual asset is deployed to a Virtualize server, you can start using it for mocking. When you're ready to use the tool to record and Virtualize traffic, send requests from the client to the virtual asset's endpoint shown in the virtual asset deployment settings.

The virtual asset will process the requests sent to its endpoint and forward them to the tool. The tool will look for a correlated request/response pair in the specified traffic file.

If a match is found, the correlated request is sent to the client. If no match is found, the tool forwards the message to the actual service and attempts to record a request/response pair. If recording is not possible (for example, because the service is not responding), the message responder associated with this tool will respond to the client with the default "catch all" message that you provided. 

This behavior is illustrated in the following diagram:

If you want to exclude certain traffic patterns from the request matching process, you can use the Exclude Pattern field described in Tool Configuration. For example, assume you have the following request:

POST /parabank/services/LoanProcessor HTTP/1.1
soapaction: ""
connection: keep-alive
cache-control: no-cache
pragma: no-cache
accept: */*
user-agent: Apache CXF 2.4.2
content-type: text/xml; charset=UTF-8
content-length: 412
host: localhost:8080

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
	<soap:Body>
		<ns2:requestLoan xmlns:ns2="http://service.parabank.parasoft.com/">
			<ns2:loanRequest>
				<requestDate>2016-06-07T15:20:52.410-07:00</requestDate>
				<customerId>12212</customerId>
				<availableFunds>1510.67</availableFunds>
				<loanAmount>100</loanAmount>
				<downPayment>10</downPayment>
			</ns2:loanRequest>
		</ns2:requestLoan>
	</soap:Body>
</soap:Envelope>

If you want to ignore the requestDate and availableFunds elements when matching requests, you could enter the following: 

(<requestDate>.*</requestDate>)|(<availableFunds>.*</availableFunds>)

Tool Configuration

You can configure the following settings.

Backend Host

(Required) Specifies the host to which the request should be forwarded if a matching response cannot be found in the traffic file.

Backend Port

Specifies the port to which the request should be forwarded if a matching response cannot be found in the traffic file. The default is 80.

Traffic File Path

Specifies the location of the traffic file where request response pairs are recorded. The default is VirtualAssets/traffic_file.txt.

Exclude Pattern

Specifies a regular expression pattern that indicates what traffic patterns you want excluded from the request matching process. For example, if you wanted to exclude dates, you could use a regular expression such as <requestDate>.*</requestDate>

Debug

Specifies if processing details and error information is communicated via the Event Log. The default is false.

Third-Party Content

This tool does not contain any third-party software.


  • No labels