View Source

{section}
{column}

h1. Introduction

To unitary test a client of the Petals Registry Client API (as Petals Registry CLI), it is needed to use a dedicated implementation not requiring a Petals Registry Overlay.

Such an implementation was created to provide a mock for Petals Registry Client API: *Petals Registry Client Mock*.

It is available as [JUnit Rule|https://github.com/junit-team/junit/wiki/Rules], and so the Petals environment is cleaned between each unit test.

{column}
{column:width=35%}
{panel:title=Table of contents}{toc:outline=true}{panel}
{panel:title=Contributors}{contributors:order=name|mode=list|showAnonymous=true|showCount=true|showLastTime=true}{panel}
{column}
{section}

h1. Using the Petals Registry Client Mock

h2. Working with topologies

Each Petals Registry Client Mock instance comes with an internal registry registry. All methods of the Petals Registry Client Mock managing topologies works with this topology registry according to the Petals Registry Client API definition.

h3. Registering a topology

A topology can be put into the topology registry at any moment of the unit test. *Caution, the topology registry is cleared at the end of the unit test.*
{code}
@Rule
public PetalsRegistryClientApi petalsRegistryClientApi = new PetalsRegistryClientApi();

@Test
public void test...() {

this.petalsRegistryClientApi.registerTopology("a-topology-id", new Topology());

... Your unit test source code ...

// The topology registry will be automatically cleared leaving the unit test
}
{code}

h1. Installation

The Petals Registry Client Mock implementation is available as a Maven artifact to add to the POM of your project:
{code}
<project>
...
<dependencies>
...
<dependency>
<groupId>org.ow2.petals</groupId>
<artifactId>petals-registry-client-mock</artifactId>
<version>...</version>
<scope>test</scope>
</dependency>
...
</dependencies>
...
</project>
{code}