-
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.
Choose from one of the setup options below to configure SV-as-Code
To add the SV-as-Code product dependency to your Maven project follow these steps:
Modify your pom.xml by adding the CA repository:
<repositories>
<repository>
<id>bintray-ca-sv</id>
<name>bintray-ca</name>
<url>http://ca.bintray.com/sv</url>
</repository>
</repositories>
Add the SV-as-Code product dependency:
<dependency>
<groupId>com.ca.devtest.sv.devtools</groupId>
<artifactId>devtest-unit-test-java</artifactId>
<version>1.3.2</version>
</dependency>
-
Access the following URL: https://github.com/CA-DevTest/SV-as-Code-UnitTest.
The SV-as-Code-UnitTest project page in GitHub opens.
-
Click
Release
. -
Download the zip file for the latest release. Click
Clone
to clone the project 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, add the following dependencies 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>
Find 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 would 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 handles SV as Code annotations during Junit life cycle. Rules allow 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, listen port, path, and type of protocols.
@DevTestVirtualService(serviceName = "UserServiceTest-EJB3UserControlBean",
port = 9080, basePath = "/itkoExamples/EJB3UserControlBean",
rrpairsFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
requestDataProtocol = {@Protocol(ProtocolType.DPH_SOAP) })
You can also define a set of Virtual Services with Class scope. In this case, all virtual services would be deployed once at the class level. First, you should add Junit Class Rule as mentioned
@ClassRule
public static VirtualServiceClassScopeRule ruleClass= new VirtualServiceClassScopeRule();
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