Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 4de3dba

Browse files
author
Chinni Krishna
committed
Initial commit
0 parents  commit 4de3dba

File tree

248 files changed

+17577
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+17577
-0
lines changed

README.adoc

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
== CA Service Virtualization As Code
2+
3+
This project provides simple **Java annotations** that can be used in your Junit Test to deploy Virtual Services before starting your test. The scope of annotations are test methods. +
4+
This java annotation helps to embed your Virtual Services in your source code. This approach makes your application ready for Continous Integration testing by removing system and data constraints with **CA Service Virtualization**. **Your tests become more reliable, repeatable and automated**. +
5+
With this approach, using **CA Virtual Services** from your Continuous Integration plateform becomes native.
6+
7+
== Projects description
8+
- **devtest-unit-test-java** : Source code of java annotations and java API wrapped on **CA Devtest Rest API** to build and deploy virtual services
9+
- **lisabank-demo** : Demo project using SV as Code annotation to deploy virtual services in junit test
10+
11+
== Pre-requises
12+
13+
You should have **CA DevTest Server ** up and running. This server could be installed on your machine or on remote server. You will setup registry url and VSE name through Java Annotation *@DevTestVirtualServer* .
14+
This both parameters will be used to build and deploy your virtual services.
15+
This annotations will use ***CA DevTest Rest API (CA DevTest Invoke 2)*** and it's compatible **from CA DevTest 8.0 to 10.1**.
16+
17+
== Getting started
18+
19+
In the **pom file** of your maven project add a new repository to get the libraries dependencies.
20+
[source,xml]
21+
----
22+
<repositories>
23+
<repository>
24+
<id>git-devtest</id>
25+
<name>DevTest's Git based repo</name>
26+
<url>https://raw.github.com/helpingdev/maven/master/</url>
27+
</repository>
28+
</repositories>
29+
----
30+
31+
Add below dependency with scope test in your **pom file** :
32+
[source,xml]
33+
----
34+
<dependency>
35+
<groupId>com.ca.devtest.sv.devtools</groupId>
36+
<artifactId>devtest-unit-test-java</artifactId>
37+
<version>1.1.11</version>
38+
</dependency>
39+
40+
----
41+
42+
Below is a quick sample of how to use " SV as code " in your Junit classes:
43+
44+
[source,java,indent=0]
45+
----
46+
/**
47+
48+
*
49+
*/
50+
@RunWith(SpringJUnit4ClassRunner.class)
51+
@SpringApplicationConfiguration(classes = LisaBankClientApplication.class)
52+
@DevTestVirtualServer(registryHost = "localhost", deployServiceToVse = "VSE")
53+
54+
public class SimpleDemo {
55+
static final Log logger = LogFactory.getLog(SimpleDemo.class);
56+
@Autowired
57+
private BankService bankServices;
58+
@Rule
59+
public VirtualServicesRule rules = new VirtualServicesRule();
60+
61+
@DevTestVirtualService(serviceName = "UserServiceTest-EJB3UserControlBean",
62+
port = 9080, basePath = "/itkoExamples/EJB3UserControlBean",
63+
rrpairsFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
64+
requestDataProtocol = {@Protocol(ProtocolType.DPH_SOAP) })
65+
@Test
66+
public void getListUser() {
67+
User[] users = bankServices.getListUser();
68+
assertNotNull(users);
69+
assertEquals(9, users.length);
70+
}
71+
}
72+
----
73+
74+
First, flag your Junit class as a Test using CA Virtual Services. This annotation will be used to refer to the CA DevTest Server :
75+
76+
* *registryHost* :* Registry hostname _(default value localhost)_
77+
* *deployServiceToVse :* Name of VSE
78+
* *login :* CA Devtest username _(default value svpower)_
79+
* *password :* CA Devtest password _(default value svpower)_
80+
all of this parameters are optional. You could set values in local-svascode.porperties file.
81+
[source,java,indent=0]
82+
----
83+
@DevTestVirtualServer()
84+
----
85+
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
86+
[source,java,indent=0]
87+
----
88+
@Rule
89+
public VirtualServicesRule rules = new VirtualServicesRule();
90+
----
91+
92+
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
93+
[source,java,indent=0]
94+
----
95+
@DevTestVirtualService(serviceName = "UserServiceTest-EJB3UserControlBean",
96+
port = 9080, basePath = "/itkoExamples/EJB3UserControlBean",
97+
rrpairsFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
98+
requestDataProtocol = {@Protocol(ProtocolType.DPH_SOAP) })
99+
100+
----
101+
It's possible to define a set of Virtual Services with Class scope. In this case all virtual services will be deployed once at class level.
102+
First you should add Junit Class Rule as described below
103+
[source,java,indent=0]
104+
----
105+
@ClassRule
106+
public static VirtualServiceClassScopeRule ruleClass= new VirtualServiceClassScopeRule();
107+
----
108+
Then you could use DevTestVirtualService annotations on top of your class.
109+
[source,java,indent=0]
110+
----
111+
/**
112+
*
113+
*/
114+
package com.ca.devtest.lisabank.demo.sv.http;
115+
116+
import static org.junit.Assert.assertEquals;
117+
import static org.junit.Assert.assertNotNull;
118+
119+
import org.apache.commons.logging.Log;
120+
import org.apache.commons.logging.LogFactory;
121+
import org.junit.ClassRule;
122+
import org.junit.Test;
123+
import org.junit.runner.RunWith;
124+
import org.springframework.beans.factory.annotation.Autowired;
125+
import org.springframework.boot.test.context.SpringBootTest;
126+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
127+
128+
import com.ca.devtest.lisabank.demo.LisaBankClientApplication;
129+
import com.ca.devtest.lisabank.demo.business.BankService;
130+
import com.ca.devtest.lisabank.wsdl.User;
131+
import com.ca.devtest.sv.devtools.annotation.DevTestVirtualServer;
132+
import com.ca.devtest.sv.devtools.annotation.DevTestVirtualService;
133+
import com.ca.devtest.sv.devtools.annotation.Protocol;
134+
import com.ca.devtest.sv.devtools.annotation.ProtocolType;
135+
import com.ca.devtest.sv.devtools.junit.VirtualServiceClassScopeRule;
136+
137+
/**
138+
139+
*
140+
*/
141+
@RunWith(SpringJUnit4ClassRunner.class)
142+
@SpringBootTest(classes = LisaBankClientApplication.class)
143+
// Mark as Test using CA Service Virtualization
144+
@DevTestVirtualServer()
145+
// Define Virtual Service with Clazz scope => Deploy once for all methods
146+
@DevTestVirtualService(serviceName = "VSClazzScopeSimpleDemo",
147+
basePath = "/itkoExamples/EJB3UserControlBean",
148+
port = 9081,
149+
workingFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
150+
requestDataProtocol = {
151+
@Protocol(ProtocolType.DPH_SOAP) })
152+
153+
public class VSClazzScopeSimpleDemo {
154+
static final Log logger = LogFactory.getLog(VSClazzScopeSimpleDemo.class);
155+
@Autowired
156+
private BankService bankServices;
157+
158+
// handle VS with Class scope
159+
@ClassRule
160+
public static VirtualServiceClassScopeRule clazzRule = new VirtualServiceClassScopeRule();
161+
162+
@Test
163+
public void getListUser() {
164+
User[] users = bankServices.getListUser();
165+
assertNotNull(users);
166+
printUsers(users);
167+
assertEquals(9, users.length);
168+
}
169+
170+
private void printUsers(User[] users) {
171+
for (User user : users) {
172+
logger.info(user.getFname() + " " + user.getLname() + " " + user.getLogin());
173+
}
174+
175+
}
176+
}
177+
178+
----
179+
180+
== Contributors
181+
Pascal Gasp *Sr Architect Devops @ CA Technologies* +
182+
Vincent Mazot *Sr Consultant Devops @ CA Technologies* +
183+
Olivier Laplace *Sr Presales Devops @ CA Technologies* +
184+
Benoit Boulc'h *Developer* +
185+

devtest-unit-test-java/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/target/
2+
**/.DS_Store
3+
/.classpath
4+
/.project
5+
/.settings/*
6+
/.settings/

devtest-unit-test-java/eclipse.jks

5.08 KB
Binary file not shown.

devtest-unit-test-java/pom.xml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.ca.devtest.sv.devtools</groupId>
5+
<artifactId>devtest-unit-test-java</artifactId>
6+
<version>1.3.2</version>
7+
<name>devtest-unit-test-java</name>
8+
<packaging>jar</packaging>
9+
10+
<description>API to use SV as API with Junit
11+
This API will cover same scope as WirMock or MokServer</description>
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<maven.compiler.source>1.7</maven.compiler.source>
15+
<maven.compiler.target>1.7</maven.compiler.target>
16+
<javadoc.opts>-Xdoclint:none</javadoc.opts>
17+
<jarsigner.plugin.version>1.3.1</jarsigner.plugin.version>
18+
19+
</properties>
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.slf4j</groupId>
23+
<artifactId>slf4j-api</artifactId>
24+
<version>1.7.25</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.httpcomponents</groupId>
28+
<artifactId>httpcore</artifactId>
29+
<version>4.4.5</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.apache.httpcomponents</groupId>
33+
<artifactId>httpmime</artifactId>
34+
<version>4.5.3</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>commons-codec</groupId>
38+
<artifactId>commons-codec</artifactId>
39+
<version>1.10</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>commons-io</groupId>
44+
<artifactId>commons-io</artifactId>
45+
<version>2.5</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.velocity</groupId>
49+
<artifactId>velocity</artifactId>
50+
<version>1.7</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.aeonbits.owner</groupId>
54+
<artifactId>owner</artifactId>
55+
<version>1.0.6</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.jayway.jsonpath</groupId>
59+
<artifactId>json-path</artifactId>
60+
<version>2.4.0</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>junit</groupId>
64+
<artifactId>junit</artifactId>
65+
<version>4.12</version>
66+
</dependency>
67+
68+
69+
</dependencies>
70+
71+
<profiles>
72+
<profile>
73+
<id>build</id>
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-compiler-plugin</artifactId>
79+
<version>3.1</version>
80+
<configuration>
81+
<source>${maven.compiler.source}</source>
82+
<target>${maven.compiler.target}</target>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-source-plugin</artifactId>
88+
<version>3.0.1</version>
89+
<executions>
90+
<execution>
91+
<id>attach-sources</id>
92+
<phase>verify</phase>
93+
<goals>
94+
<goal>jar-no-fork</goal>
95+
</goals>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
100+
<plugin>
101+
<groupId>org.apache.maven.plugins</groupId>
102+
<artifactId>maven-javadoc-plugin</artifactId>
103+
<version>2.10.2</version>
104+
<executions>
105+
<execution>
106+
<id>attach-javadocs</id>
107+
<goals>
108+
<goal>jar</goal>
109+
</goals>
110+
<configuration>
111+
<nohelp>true</nohelp>
112+
<notree>true</notree>
113+
<quiet>true</quiet>
114+
<additionalparam>${javadoc.opts}</additionalparam>
115+
<excludePackageNames>com.ca.devtest.sv.devtools.annotation.processors</excludePackageNames>
116+
<subpackages>com.ca.devtest.sv.devtools.annotation</subpackages>
117+
<sourcepath>${project.basedir}/src/main/java</sourcepath>
118+
</configuration>
119+
</execution>
120+
</executions>
121+
</plugin>
122+
123+
</plugins>
124+
</build>
125+
</profile>
126+
<profile>
127+
<id>sign</id>
128+
<build>
129+
<plugins>
130+
<!--
131+
The property values for this plugin should be either passed in on the
132+
command line (not really secure as the passwords will be easily
133+
readable and recorded in the shell/CI invocation) or set in the maven
134+
settings.xml file for the 'sign' profile.
135+
-->
136+
<plugin>
137+
<groupId>org.apache.maven.plugins</groupId>
138+
<artifactId>maven-jarsigner-plugin</artifactId>
139+
<version>${jarsigner.plugin.version}</version>
140+
<executions>
141+
<execution>
142+
<id>sign</id>
143+
<goals>
144+
<goal>sign</goal>
145+
</goals>
146+
</execution>
147+
</executions>
148+
</plugin>
149+
</plugins>
150+
</build>
151+
</profile>
152+
</profiles>
153+
154+
155+
156+
</project>

devtest-unit-test-java/readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
How to deploy new version :
2+
mvn install:install-file -DgroupId=com.ca.devtest.sv.devtools -DartifactId=devtest-unit-test-java -Dversion=1.3.1 -Dpackaging=jar -Dfile=/Users/gaspa03/git/svascode/devtest-unit-test-java/target/devtest-unit-test-java-1.3.1.jar -DpomFile=/Users/gaspa03/git/svascode/devtest-unit-test-java/pom.xml -DlocalRepositoryPath=//Users/gaspa03/git/maven

0 commit comments

Comments
 (0)