-
Notifications
You must be signed in to change notification settings - Fork 5
Quick Start Guide
CA Service Virtualization As Code (CA SV-as-Code) is available for installation from GitHub. You can clone the example project or download the product directly from the Sv-as-Code GitHub page.
-
Access the following URL: https://github.com/CA-DevTest/SV-as-Code.
This opens the SV-as-Code project page in GitHub.
-
Click
Release
. -
Download the zip file for the latest release. You can also clone the project by clicking
Clone
or download on the main page. -
Extract the downloaded
devtest-unit-test-java-<version>.zip
file. -
Add the
devtest-unit-test-java-<version>.jar
file in the lib directory as a dependency to your project classpath.
While creating a new project like lisa demo application. Following dependencies needs to be added along with devtest-unit-test-java in pom.xml
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.aeonbits.owner</groupId>
<artifactId>owner</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
Below is a quick sample of how to use "SV as code" in your Junit classes:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = LisaBankClientApplication.class)
@DevTestVirtualServer(registryHost = "localhost", deployServiceToVse = "VSE")
public class SimpleDemo {
static final Log logger = LogFactory.getLog(SimpleDemo.class);
@Autowired
private BankService bankServices;
@Rule
public VirtualServicesRule rules = new VirtualServicesRule();
@DevTestVirtualService(serviceName = "UserServiceTest-EJB3UserControlBean",
port = 9080, basePath = "/itkoExamples/EJB3UserControlBean",
rrpairsFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
requestDataProtocol = {@Protocol(ProtocolType.DPH_SOAP) })
@Test
public void getListUser() {
User[] users = bankServices.getListUser();
assertNotNull(users);
assertEquals(9, users.length);
}
}
First, flag your Junit class as a Test using CA Virtual Services. This annotation will be used to refer to the CA DevTest Server :
- registryHost : Registry hostname (default value localhost)
- deployServiceToVse : Name of VSE
- login : CA Devtest username (default value svpower)
- password : CA Devtest password (default value svpower)
All of these parameters are optional. You could set values in local-svascode.properties file.
@DevTestVirtualServer()
Add VirtualServices rule as a field member of Junit class. This rule will handle SV as Code annotations during Junit life cycle. Rules allow very flexible addition or redefinition of the behavior of each test method in a test class
@Rule
public VirtualServicesRule rules = new VirtualServicesRule();
Above of each test method, add virtual service annotations. This annotation should refer to the Requests/Responses folder and define virtual service configuration such as service name, listnen port, path, type of protocole
@DevTestVirtualService(serviceName = "UserServiceTest-EJB3UserControlBean",
port = 9080, basePath = "/itkoExamples/EJB3UserControlBean",
rrpairsFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
requestDataProtocol = {@Protocol(ProtocolType.DPH_SOAP) })
It's possible to define a set of Virtual Services with Class scope. In this case, all virtual services will be deployed once at the class level. First, you should add Junit Class Rule as described below
@ClassRule
public static VirtualServiceClassScopeRule ruleClass= new VirtualServiceClassScopeRule();
Then you could use DevTestVirtualService annotations on top of your class.
package com.ca.devtest.lisabank.demo.sv.http;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.ca.devtest.lisabank.demo.LisaBankClientApplication;
import com.ca.devtest.lisabank.demo.business.BankService;
import com.ca.devtest.lisabank.wsdl.User;
import com.ca.devtest.sv.devtools.annotation.DevTestVirtualServer;
import com.ca.devtest.sv.devtools.annotation.DevTestVirtualService;
import com.ca.devtest.sv.devtools.annotation.Protocol;
import com.ca.devtest.sv.devtools.annotation.ProtocolType;
import com.ca.devtest.sv.devtools.junit.VirtualServiceClassScopeRule;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = LisaBankClientApplication.class)
// Mark as Test using CA Service Virtualization
@DevTestVirtualServer()
// Define Virtual Service with Clazz scope => Deploy once for all methods
@DevTestVirtualService(serviceName = "VSClazzScopeSimpleDemo",
basePath = "/itkoExamples/EJB3UserControlBean",
port = 9081,
workingFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
requestDataProtocol = {
@Protocol(ProtocolType.DPH_SOAP) })
public class VSClazzScopeSimpleDemo {
static final Log logger = LogFactory.getLog(VSClazzScopeSimpleDemo.class);
@Autowired
private BankService bankServices;
// handle VS with Class scope
@ClassRule
public static VirtualServiceClassScopeRule clazzRule = new VirtualServiceClassScopeRule();
@Test
public void getListUser() {
User[] users = bankServices.getListUser();
assertNotNull(users);
printUsers(users);
assertEquals(9, users.length);
}
private void printUsers(User[] users) {
for (User user : users) {
logger.info(user.getFname() + " " + user.getLname() + " " + user.getLogin());
}
}
}
For more code examples, see Code Library
For more information, to share ideas, or to raise issues, see the CA Service Virtualization/DevTest community page at the following URL: https://communities.ca.com/community/ca-devtest-community
Annotation DevTestVirtualServiceV3
- Create and Deploy a Virtual Service Before a Test
- Create and Deploy a Virtual Service Before Any Test from the Class
- Create and Deploy Multiple Virtual Services Before a Test
- Create Update and Deploy Virtual Service Before a Test
- Create, Update and Deploy Virtual Service Before any Test from the Class
- Create and Deploy Virtual Service with RR Pair
- Create and Deploy Virtual Service with RR Pair Zip File
- Create and Deploy Virtual Service with Swagger File
- Create and Deploy Virtual Service with Swagger Url
- Create and Deploy Virtual Service with RAML File
- Create and Deploy Virtual Service with RAML Url
- Create and Deploy Virtual Service with WADL File
- Create and Deploy Virtual Service with WADL Url
- Create and Deploy Virtual Service with VSM/VSI File
- Create and Deploy Virtual Service and Update Data and Config File
- Create and Deploy Virtual Service with Parameterized VSM File
- Create and Deploy Virtual Service with Parameterized Input File
- Create and Deploy Virtual Service with SSL End-Point
- Create and Deploy a Virtual Service before a Test
- Create and Deploy a Virtual Service before Any Test from the Class
- Create and Deploy Multiple Virtual Services before a Test
- Create and Deploy with VRS
- Create and Deploy with RR Pair
- Create and Deploy with VSM
- Parameterized DevTest Virtual Service Annotation
- Generate RR Pairs Utility