CodeSV Blog!by CA Technologies, A Broadcom Company

Create, store and share your virtual services with others on your project!

Class Repositories in CodeSV 2.0

With our 1.3 release of CodeSV, we introduced an exciting new feature for team collaboration –  Class Repositories. (This article is updated for version 2.0)

Class repositories

These repositories offer developers the ability to create their virtual service definitions in a separated class and easily use them with our CodeSV engine. This feature brings a re-usability of definitions and also the possibility to collaborate with other members of the team. Also we introduced a new logic for more complex, logical selections of virtualized services from multiple repositories.

Let’s start

Part of the class repositories feature is the newly added annotations, which helps you to organize your definitions into repositories and virtual services with your transaction definitions.

Define your repository

You can define a repository as a Java class like this:

@VirtualServiceRepository(serviceName= "CodeSV description service")
public class MyRepo {

   * Transaction definition for {@url} which returns JSON
   * object as follow:
   * {
   *   "name" : "CodeSV",
   *   "programming language" : "JAVA"
   * }.
  @TransactionDefinition(name = "getDescription")
  public void test() {
                + "\"name\":CodeSV,"
                + "\"programming language\":\"JAVA\""
                + "}")


What we did:

  • @VirtualServiceRepository – This annotation is optional and we are using it for more specific rules about which definitions should be used. It means that you can create a groups of specific transaction definitions within one repository, logically grouped in virtual services.
  • @TransactionDefinition – Required annotation which is mapped by CodeSV for virtualization. Also it is possible to have more definitions with the same name but with different tags, more about tags can be found in our documentation here.

Virtualize anywhere

Once you have prepared your repository or more repositories, you can virtualize them anywhere in the code by adding the annotation to the virtual server variable, declaring Store object and invoking this endpoint by using the useTransaction method call or  UseTransactionRule for more complex invoking logic.

Repository configuration:

@TransactionClassRepository(repoClasses = {MyRepo.class})
public class MyTestClass {

 public VirtualServerRule vs = new VirtualServerRule();
 private TxnRepoStore store = new TxnRepoStoreBuilder().build(this);



public void simpleRepoUsageTest() throws WeatherProviderException {
  // Now you can call url to get virtualized response!

Easy, right?

Now, you can create different transaction definitions for your tests that are stored in repositories, grouped by virtual services and define them for your usage (development testing, QA testing, etc.) without code changes and also share them with other developers.

Define once, use them many times!

A repository can be created and maintained by a team in collaboration with QA or another CoE.

Repositories - Collaboration

All repositories are accessible across all units and integration tests within a project.

Share assets

What else?

If you’d like to try it, just download CodeSV as a dependency (how to start using CodeSV is described in our Quick start guide) and follow our example for defining a repository.

Comments are currently closed.