CodeSVby CA Technologies

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

CodeSV 1.3 introduces Class Repositories

With our 1.3 release of CodeSV, we introduced an exciting new feature for team collaboration –  Class Repositories.

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(virtualServiceName = "CodeSV description service")
public class MyRepo {

  /**
   * Transaction definition for {@url http://www.codesv.io/api/getDescription} which returns JSON
   * object as follow:
   * {
   *   "name" : "CodeSV",
   *   "programming language" : "JAVA"
   * }.
   */
  @TransactionDefinition(name = "getDescription")
  public void test() {
    forGet("http://www.codesv.io/api/getDescription").doReturn(
        okMessage()
            .withJsonBody("{"
                + "\"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 and invoking this endpoint by using the useTransaction method call or  UseTransactionRule for more complex invoking logic.

Repository configuration:

@Rule
@TransactionClassRepository(repoClasses = {MyRepo.class})
public VirtualServerRule vs = new VirtualServerRule(this);

Virtualizing:

@Test
public void simpleRepoUsageTest() throws WeatherProviderException {
  vs.useTransaction("getDescription");
  // 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.