Skip to content

Commit 14dc714

Browse files
Merge pull request BorderTech#2 from BorderTech/unit-tests
Unit tests for model
2 parents b204b7d + ab8939b commit 14dc714

File tree

16 files changed

+344
-57
lines changed

16 files changed

+344
-57
lines changed

Diff for: model-api/pom.xml

+7-10
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,19 @@
1515

1616
<packaging>jar</packaging>
1717

18-
<properties>
19-
<spotbugs.excludeFilterFile>${basedir}/spotbugs-exclude-filter.xml</spotbugs.excludeFilterFile>
20-
</properties>
21-
2218
<dependencies>
19+
<!-- Junit -->
2320
<dependency>
24-
<groupId>commons-io</groupId>
25-
<artifactId>commons-io</artifactId>
21+
<groupId>junit</groupId>
22+
<artifactId>junit</artifactId>
23+
<scope>test</scope>
2624
</dependency>
27-
25+
<!-- POJO Tester -->
2826
<dependency>
29-
<groupId>org.junit.vintage</groupId>
30-
<artifactId>junit-vintage-engine</artifactId>
27+
<groupId>com.openpojo</groupId>
28+
<artifactId>openpojo</artifactId>
3129
<scope>test</scope>
3230
</dependency>
33-
3431
</dependencies>
3532

3633
</project>

Diff for: model-api/spotbugs-exclude-filter.xml

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.sample.app.model.client;
2+
3+
import com.openpojo.reflection.filters.FilterPackageInfo;
4+
import com.openpojo.validation.Validator;
5+
import com.openpojo.validation.ValidatorBuilder;
6+
import com.openpojo.validation.rule.impl.GetterMustExistRule;
7+
import com.openpojo.validation.rule.impl.SetterMustExistRule;
8+
import com.openpojo.validation.test.impl.GetterTester;
9+
import com.openpojo.validation.test.impl.SerializableTester;
10+
import com.openpojo.validation.test.impl.SetterTester;
11+
import org.junit.Test;
12+
13+
/**
14+
* Unit tests for model POJOs.
15+
*/
16+
public class ModelPojoTest {
17+
18+
// The package to test
19+
private static final String POJO_PACKAGE = "com.sample.app.model.client";
20+
21+
@Test
22+
public void testPojoStructureAndBehavior() {
23+
Validator validator = ValidatorBuilder.create()
24+
// Add Rules to validate structure for POJO_PACKAGE
25+
// See com.openpojo.validation.rule.impl for more ...
26+
.with(new GetterMustExistRule())
27+
.with(new SetterMustExistRule())
28+
// Add Testers to validate behaviour for POJO_PACKAGE
29+
// See com.openpojo.validation.test.impl for more ...
30+
.with(new SetterTester())
31+
.with(new GetterTester())
32+
.with(new SerializableTester())
33+
.build();
34+
35+
validator.validate(POJO_PACKAGE, new FilterPackageInfo());
36+
}
37+
}

Diff for: model-bdd/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
<artifactId>model-bdd</artifactId>
1616
<name>model-bdd</name>
17-
</project>
17+
</project>

Diff for: model-bdd/src/main/resources/api/bdd/features/RetrieveApplication.feature

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Retrieve client details
2+
User wants to retrieve a client
3+
4+
Background: Client service available
5+
Given A client retrieve service is available
6+
7+
Scenario: Retrieve a valid client
8+
When User retrieves client "ORG1"
9+
Then User gets "ORG1" client
10+
11+
Scenario: Retrieve an invalid client
12+
When User retrieves a client that does not exist
13+
Then User gets client not found exception for retrieve
14+
15+
Scenario: Retrieve a client has a system error
16+
When User retrieves client that causes a service exception
17+
Then User gets service exception for retrieve
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Feature: Update client details
2+
User wants to update a client
3+
4+
Background: Client service available
5+
Given A client update service is available
6+
7+
Scenario: Update a client
8+
When User retrieves client "ORG1"
9+
And User updates client name to "foo"
10+
And User submits client "ORG1"
11+
Then User gets updated client "ORG1"
12+
13+
Scenario: Update a client with validation error
14+
When User retrieves client "ORG1"
15+
And User updates client name to blank
16+
And User submits client "ORG1"
17+
Then User gets validation exception for "ORG1"
18+
19+
Scenario: Update an invalid client
20+
When User submits a client that does not exist
21+
Then User gets client not found exception for update
22+
23+
Scenario: Update a client has a system error
24+
When User retrieves client "ORG1"
25+
And User submits a client that receives a service exception
26+
Then User gets service exception for update

Diff for: model-mock-impl/pom.xml

+76-2
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,100 @@
1717
<description>MOCK Model API Implemention</description>
1818

1919
<properties>
20+
<enforcer.fail>false</enforcer.fail>
2021
<spotbugs.excludeFilterFile>${basedir}/spotbugs-exclude-filter.xml</spotbugs.excludeFilterFile>
2122
</properties>
2223

24+
2325
<dependencies>
26+
27+
<!-- Model API -->
2428
<dependency>
2529
<groupId>com.github.bordertech.sample.app</groupId>
2630
<artifactId>model-api</artifactId>
2731
<version>${project.version}</version>
2832
</dependency>
2933

34+
<!-- IO -->
3035
<dependency>
3136
<groupId>commons-io</groupId>
3237
<artifactId>commons-io</artifactId>
3338
</dependency>
3439

40+
<!-- Model BDD -->
41+
<dependency>
42+
<groupId>com.github.bordertech.sample.app</groupId>
43+
<artifactId>model-bdd</artifactId>
44+
<version>${project.version}</version>
45+
<scope>test</scope>
46+
</dependency>
47+
48+
<!-- Serenity & Cucmber only work with junit 4 (and not vintage junit 5) -->
49+
<dependency>
50+
<groupId>junit</groupId>
51+
<artifactId>junit</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
55+
<!-- Serenity and Cucumber -->
56+
<dependency>
57+
<groupId>net.serenity-bdd</groupId>
58+
<artifactId>serenity-core</artifactId>
59+
<version>2.1.8</version>
60+
<scope>test</scope>
61+
<exclusions>
62+
<exclusion>
63+
<groupId>io.cucumber</groupId>
64+
<artifactId>cucumber-core</artifactId>
65+
</exclusion>
66+
</exclusions>
67+
</dependency>
68+
<dependency>
69+
<groupId>net.serenity-bdd</groupId>
70+
<artifactId>serenity-cucumber4</artifactId>
71+
<version>2.1.2</version>
72+
<scope>test</scope>
73+
</dependency>
74+
<!-- Latest cucumber. -->
75+
<dependency>
76+
<groupId>io.cucumber</groupId>
77+
<artifactId>cucumber-core</artifactId>
78+
<version>4.8.1</version>
79+
<scope>test</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>io.cucumber</groupId>
83+
<artifactId>cucumber-junit</artifactId>
84+
<version>4.8.1</version>
85+
<scope>test</scope>
86+
</dependency>
87+
3588
<dependency>
36-
<groupId>org.junit.vintage</groupId>
37-
<artifactId>junit-vintage-engine</artifactId>
89+
<groupId>com.google.guava</groupId>
90+
<artifactId>guava</artifactId>
91+
<version>28.0-jre</version>
3892
<scope>test</scope>
3993
</dependency>
4094

4195
</dependencies>
96+
97+
<build>
98+
<plugins>
99+
<!-- Serenity Report -->
100+
<plugin>
101+
<groupId>net.serenity-bdd.maven.plugins</groupId>
102+
<artifactId>serenity-maven-plugin</artifactId>
103+
<version>2.1.8</version>
104+
<executions>
105+
<execution>
106+
<id>serenity-reports</id>
107+
<phase>post-integration-test</phase>
108+
<goals>
109+
<goal>aggregate</goal>
110+
</goals>
111+
</execution>
112+
</executions>
113+
</plugin>
114+
</plugins>
115+
</build>
42116
</project>

Diff for: model-mock-impl/src/main/java/com/sample/app/model/impl/ClientServicesMockImpl.java

+28-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public List<String> retrieveTables() throws ServiceException {
2727

2828
@Override
2929
public List<CodeOption> retrieveCodes(final String table) throws ServiceException {
30+
// Mock error
31+
if (ERROR_REQ.equals(table)) {
32+
throw new ServiceException("Mock table error");
33+
}
34+
3035
List<CodeOption> options = MockDataUtil.retrieveTableCodes(table);
3136
if (options == null) {
3237
throw new ServiceException("Table not found [" + table + "]");
@@ -37,10 +42,12 @@ public List<CodeOption> retrieveCodes(final String table) throws ServiceExceptio
3742
@Override
3843
public List<ClientDetail> searchClients(final String search) throws ServiceException {
3944

45+
// Mock error
4046
if (ERROR_REQ.equals(search)) {
4147
throw new ServiceException("Mock search error");
4248
}
4349

50+
// None found
4451
if (NONE_REQ.equals(search)) {
4552
return Collections.EMPTY_LIST;
4653
}
@@ -50,6 +57,10 @@ public List<ClientDetail> searchClients(final String search) throws ServiceExcep
5057

5158
@Override
5259
public ClientDetail retrieveClient(final String clientId) throws ServiceException, ClientNotFoundException {
60+
// Mock error
61+
if (ERROR_REQ.equals(clientId)) {
62+
throw new ServiceException("Mock retrieve client error");
63+
}
5364
ClientDetail detail = MockDataUtil.retrieveClient(clientId);
5465
if (detail == null) {
5566
throw new ClientNotFoundException();
@@ -59,6 +70,7 @@ public ClientDetail retrieveClient(final String clientId) throws ServiceExceptio
5970

6071
@Override
6172
public ClientDetail createClient(final ClientDetail detail) throws ServiceException {
73+
// Mock error
6274
if (ERROR_REQ.equals(detail.getName())) {
6375
throw new ServiceException("Mock create client error");
6476
}
@@ -67,13 +79,14 @@ public ClientDetail createClient(final ClientDetail detail) throws ServiceExcept
6779

6880
@Override
6981
public ClientDetail updateClient(final ClientDetail detail) throws ServiceException {
82+
// Mock error
7083
if (ERROR_REQ.equals(detail.getName())) {
7184
throw new ServiceException("Mock update client error");
7285
}
7386

7487
String key = detail.getClientId();
7588
if (MockDataUtil.retrieveClient(key) == null) {
76-
throw new ServiceException("Organisation does not exist [" + key + "].");
89+
throw new ServiceException("Client does not exist [" + key + "].");
7790
}
7891
// Update
7992
MockDataUtil.updateClient(detail);
@@ -82,22 +95,34 @@ public ClientDetail updateClient(final ClientDetail detail) throws ServiceExcept
8295

8396
@Override
8497
public void deleteClient(final String clientId) throws ServiceException {
98+
// Mock error
99+
if (ERROR_REQ.equals(clientId)) {
100+
throw new ServiceException("Mock delete client error");
101+
}
102+
85103
// Check exists
86104
if (MockDataUtil.retrieveClient(clientId) == null) {
87-
throw new ServiceException("Organisation does not exist [" + clientId + "].");
105+
throw new ServiceException("Client does not exist [" + clientId + "].");
88106
}
89107
// Remove
90108
MockDataUtil.deleteClient(clientId);
91109
}
92110

93111
@Override
94112
public List<DocumentDetail> retrieveClientDocuments(final String clientId) throws ServiceException, ClientNotFoundException {
113+
// Mock error
114+
if (ERROR_REQ.equals(clientId)) {
115+
throw new ServiceException("Mock retrieve client documents");
116+
}
95117
return MockDataUtil.getOrCreateClientDocuments(clientId);
96118
}
97119

98120
@Override
99121
public DocumentContent retrieveDocument(final String documentId) throws ServiceException, DocumentNotFoundException {
100-
122+
// Mock error
123+
if (ERROR_REQ.equals(documentId)) {
124+
throw new ServiceException("Mock retrieve document content");
125+
}
101126
DocumentDetail doc = MockDataUtil.retrieveDocument(documentId);
102127
if (doc == null) {
103128
throw new DocumentNotFoundException();

0 commit comments

Comments
 (0)