View Source

{section}
{column}

h1. Introduction

To unitary test a client of the Petals Administration API, it is needed to use a dedicated implementation not requiring a Petals ESB container.

Such a implementation was created to provide a mock for Petals Administration API: *Petals Administration 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 Administration Mock

h2. Working with JBI artifacts

Each Petals Administration Mock instance comes with an internal JBI artifact registry. All methods of the Petals Administration Mock managing JBI artifact works with this artifact registry according to the Petals Administration API definition.

h3. Creating a JBI artifact

A JBI artifact can be created using one of following classes:
|| JBI artifact || Class || Life-cycle supported ||
| Shared library | {{org.ow2.petals.admin.api.artifact.SharedLibrary}} | no |
| Component | {{org.ow2.petals.admin.api.artifact.Component}} | yes |
| Service assembly | {{org.ow2.petals.admin.api.artifact.ServiceAssembly}} | yes |
| Service unit | {{org.ow2.petals.admin.api.artifact.ServiceUnit}} | no |

You can initialize the state of JBI artifacts supporting a life-cycle:
{code}
final Component component = new Component("component-name", ComponentType.BC);
component.setState(State.STARTED);
{code}

h3. Registering a JBI artifact

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

@Test
public void test...() {

final Component component = new Component("component-name", ComponentType.BC);
component.setState(State.STARTED);
this.petalsAdminApi.registerArtifact(component);

... Your unit test source code ...

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

h1. Installation

The Petals Administration 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-admin-mock</artifactId>
<version>...</version>
<scope>test</scope>
</dependency>
...
</dependencies>
...
</project>
{code}