Skip to content

Create and Deploy Virtual Service with Parameterized VSM File

sachinmaske edited this page Oct 20, 2022 · 1 revision

Below example describe how to create and deploy virtual service by using VSM/VSI file and changing port and documentation.

Add the below virtual service annotation above each test method. This annotation should refer to the Requests/Responses pair folder and define virtual service configuration such as service name, listening port, path, type of protocol and parameters.

@DevTestVirtualServer()
public class BasicTest {
	static final Log logger = LogFactory.getLog(BasicTest.class);
	@Autowired
	private BankService bankServices;

	@Rule
	public VirtualServicesRule rules = new VirtualServicesRule();

        @DevTestVirtualServiceV3(
              serviceName = "vsV3_VSMVSI_CustomPort",
              description = "Test Case vsV3_VSMVSI_CustomPort",
              port = "24000",
              workingFolder = "v3/vsmvsi_port_parameter",
              inputFile1 = "Op8AndOp9.vsi",
              inputFile2 = "Op8AndOp9.vsm"
       )
       @Test
       public void vsV3_VSMVSI_CustomPort() {
             ResponseParser op8Response = HttpUtils.GET(HttpUtils.URL_FORMAT, "http", "localhost", "24000", "import/test/operation-8");
             ResponseParser op9Response = HttpUtils.GET(HttpUtils.URL_FORMAT, "http", "localhost", "24000", "import/test/operation-9");
             assert (op8Response != null);
             assert (op8Response.getValue("$.TCEntry[0].termsType").equals("Operation 8 terms"));
             assert (op9Response != null);
             assert (op9Response.getValue("$.TCEntry[0].termsType").equals("Operation 9 terms"));
      }
}

The port and the description values passed in the virtual service annotation will replace the value in the VSM file. The VSM file should contains ${listenPort} for port and ${documentation} for the description. Below is the example of a VSM file.

<?xml version="1.0" ?>

<VSModel name="Op8AndOp9" version="5">

<meta>
   <create version="10.6.0" buildNumber="10.6.0.23" author="admin" date="09/15/2022" host="C02CP01UPWDG" />
   <lastEdited version="10.6.0" buildNumber="10.6.0.23" author="admin" date="09/15/2022" host="C02CP01UPWDG" />
</meta>

<id>8FF615E034F311ED8AAE5C5230A69BCF</id>
<Documentation>${documentation}</Documentation>
<IsInProject>true</IsInProject>
<sig>ZWQ9NSZ0Y3Y9NSZsaXNhdj0xMC42LjAgKDEwLjYuMC4yMykmbm9kZXM9LTE2Mjc5NzUwMTQ=</sig>
<subprocess>false</subprocess>
....
....
....
</CustomFilterData>
      </Filter>

<outputAsObject>false</outputAsObject>
<onExceptionStep>abort</onExceptionStep>
<listenPort>${listenPort}</listenPort>
<basePath>/</basePath>
<bindOnly>false</bindOnly>
<useSSL>false</useSSL>
<sslClientAuthType>none</sslClientAuthType>
    </Node>
....
....
....

Getting Started

Code Library

Core Functionality

Version 1.4.0

Annotation DevTestVirtualServiceV3

Version 1.3.2

Acknowledgments

Clone this wiki locally