IntroductionTo 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, and so the Petals environment is cleaned between each unit test. |
Table of contents Contributors
No contributors found for: authors on selected page(s)
|
Using the Petals Administration Mock
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.
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:
final Component component = new Component("component-name", ComponentType.BC); component.setState(State.STARTED);
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.
@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. }
Installation
The Petals Administration Mock implementation is available as a Maven artifact to add to the POM of your project:
<project> ... <dependencies> ... <dependency> <groupId>org.ow2.petals</groupId> <artifactId>petals-admin-mock</artifactId> <version>...</version> <scope>test</scope> </dependency> ... </dependencies> ... </project>