Writing code
This chapter is intended for developers. There are no special prerequisites. Each part describes what a developer has to look at in specific for the OpenEngSB.
Maven POM files in the OpenEngSB
Following the guidelines of Maven Central, how a pom should be designed it is required to add the following tags into every and each pom file:
*) modelVersion
*) groupId
*) artifactId
*) version
*) packaging
*) name
*) description
*) url
*) licenses
*) scm/url
*) scm/connection
*) scm/developerConnection
The following listings shows an example of these params for a typical OpenEngSB pom.
<modelVersion>4.0.0</modelVersion>
<groupId>org.openengsb.framework</groupId>
<artifactId>openengsb-framework-root</artifactId>
<packaging>pom</packaging>
<version>3.0.0-SNAPSHOT</version>
<name>OpenEngSB :: Framework :: Root</name>
<packaging>pom</packaging>
<description>
Parent project of all OpenEngSB subprojects. The OpenEngSB could be seen as an extension to an
Enterprise Service Bus and is based on JBI (Service Mix). With this project it is tried to provide as many as
possible SE domains and to allow to combine the tools as easily as possible.
</description>
<url>http://www.openengsb.org</url>
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/openengsb/openengsb-framework.git</connection>
<developerConnection>scm:git:git@github.com:openengsb/openengsb-framework.git</developerConnection>
<url>http://github.com/openengsb/openengsb-framework</url>
</scm>
Making UI Tests Localizable
If you want to test if specific text is shown in the UI extend LocalisedTest in your UI Test. The constructor automatically loads the correct ResourceBundle and via localization(String resourcename) you can load a localized version of a specific resource string. The default locale is used as to match the locale used by WicketTester.
How to write tests
Naming of tests
The name of the test method has to describe what is going to be tested. After the "_" is described what are the expected results.
@Test
public void testBehaviorX_shouldReturnY() {
//CODE
}
In addition to the normal behaviour the coder should also provide a test for the failure behavior.
@Test(expected = BehaviorException.class)
public void testBehaviorX_shouldThrowException() {
//CODE
}
Technologies for writing test, and how to use them
The OpenEngSB developers decided to use following testing tools:
Instead of using Assert.assertThat(....) or Mockito.mock(...) we use the static import variant: assertThat(...) and mock(...)
Asserting
We use Hamcrest instead of JUnit. A simple example how to use Hamcrest:
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.MatcherAssert.is;
[...]
assertThat(realValue, is(expectedValue));
Mocking
We use Mockito as mocking tool. A simple example how to use Mockito:
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;
[...]
//mocking code
ExampleMock exampleMock = mock(ExampleMock.class);
when(exampleMock.methodX()).thenReturn(y);
[...] //testing code
//verification
verify(manager, times(1).methodX(Y);