Skip to content

pgasp/helpingDev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CA Service Virtualization As Code

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.
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.
With this approach, using CA Virtual Services from your Continuous Integration plateform becomes native.

Projects description

  • devtest-unit-test-java : Source code of java annotations and java API wrapped on CA Devtest Rest API to build and deploy virtual services

  • lisabank-demo : Demo project using SV as Code annotation to deploy virtual services in junit test

Pre-requises

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 . This both parameters will be used to build and deploy your virtual services. This annotations will use CA DevTest Rest API (CA DevTest Invoke 2) and it’s compatible from CA DevTest 8.0 to 10.1.

Getting started

In the pom file of your maven project add a new repository to get the libraries dependencies.

	<repositories>
		<repository>
			<id>git-devtest</id>
			<name>DevTest's Git based repo</name>
			<url>https://raw.github.com/pgasp/devtest-mvn-repo/master/</url>
		</repository>
	</repositories>

Add below dependency with scope test in your pom file :

	<dependency>
		<groupId>com.ca.devtest.sv.devtools</groupId>
		<artifactId>devtest-unit-test-java</artifactId>
		<version>1.1.6</version>
	</dependency>

Below is a quick sample of how to use " SV as code " in your Junit classes:

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.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
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.VirtualServicesRule;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = LisaBankClientApplication.class)

@DevTestVirtualServer(registryHost = "localhost", deployServiceToVse = "VSE")
public class UserServiceIntegrationTest {
	static final Log logger = LogFactory.getLog(UserServiceIntegrationTest.class);
	@Autowired
	private BankService bankServices;
	@Rule
	public VirtualServicesRule rules = new VirtualServicesRule();

	@DevTestVirtualService(serviceName = "UserServiceTest-EJB3UserControlBean",
	port = 9081, basePath = "/itkoExamples/EJB3UserControlBean",
	workingFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
	requestDataProtocol = {@Protocol(ProtocolType.DPH_SOAP) })

	@Test
	public void getListUser() {
		// Given

		// When
		User[] users = bankServices.getListUser();
		// Then
		printUsers(users);
		assertNotNull(users);
		assertEquals(9, users.length);

		User user = getUser("Admin", users);
		assertNotNull(user);

		assertEquals("Admin", user.getLname());

	}

	private void printUsers(User[] users) {
		for (User user : users) {
			logger.info(user.getFname() + " " + user.getLname() + " " + user.getLogin());
		}

	}

	/**
	 * @param name
	 * @param users
	 * @return
	 */
	private User getUser(String name, User[] users) {

		User result = null;
		for (User user : users) {
			if (name.equals(user.getLname())) {
				result = user;
			}

		}
		return result;
	}
}

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)

@DevTestVirtualServer(registryHost = "localhost", deployServiceToVse = "VSE")

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 = 9081, basePath = "/itkoExamples/EJB3UserControlBean",
	workingFolder = "UserServiceTest/getListUser/EJB3UserControlBean",
	requestDataProtocol = {@Protocol(ProtocolType.DPH_SOAP) })

Contributors

Pascal Gasp Sr Architect Devops @ CA Technologies
Vincent Mazot Sr Consultant Devops @ CA Technologies
Olivier Laplace Sr Presales Devops @ CA Technologies

About

Service Virtualization As Code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published