Skip to content

Unit tests for model #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions model-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@

<packaging>jar</packaging>

<properties>
<spotbugs.excludeFilterFile>${basedir}/spotbugs-exclude-filter.xml</spotbugs.excludeFilterFile>
</properties>

<dependencies>
<!-- Junit -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- POJO Tester -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>com.openpojo</groupId>
<artifactId>openpojo</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
9 changes: 0 additions & 9 deletions model-api/spotbugs-exclude-filter.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.sample.app.model.client;

import com.openpojo.reflection.filters.FilterPackageInfo;
import com.openpojo.validation.Validator;
import com.openpojo.validation.ValidatorBuilder;
import com.openpojo.validation.rule.impl.GetterMustExistRule;
import com.openpojo.validation.rule.impl.SetterMustExistRule;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SerializableTester;
import com.openpojo.validation.test.impl.SetterTester;
import org.junit.Test;

/**
* Unit tests for model POJOs.
*/
public class ModelPojoTest {

// The package to test
private static final String POJO_PACKAGE = "com.sample.app.model.client";

@Test
public void testPojoStructureAndBehavior() {
Validator validator = ValidatorBuilder.create()
// Add Rules to validate structure for POJO_PACKAGE
// See com.openpojo.validation.rule.impl for more ...
.with(new GetterMustExistRule())
.with(new SetterMustExistRule())
// Add Testers to validate behaviour for POJO_PACKAGE
// See com.openpojo.validation.test.impl for more ...
.with(new SetterTester())
.with(new GetterTester())
.with(new SerializableTester())
.build();

validator.validate(POJO_PACKAGE, new FilterPackageInfo());
}
}
2 changes: 1 addition & 1 deletion model-bdd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

<artifactId>model-bdd</artifactId>
<name>model-bdd</name>
</project>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Feature: Retrieve client details
User wants to retrieve a client

Background: Client service available
Given A client retrieve service is available

Scenario: Retrieve a valid client
When User retrieves client "ORG1"
Then User gets "ORG1" client

Scenario: Retrieve an invalid client
When User retrieves a client that does not exist
Then User gets client not found exception for retrieve

Scenario: Retrieve a client has a system error
When User retrieves client that causes a service exception
Then User gets service exception for retrieve
26 changes: 26 additions & 0 deletions model-bdd/src/main/resources/api/bdd/features/UpdateClient.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: Update client details
User wants to update a client

Background: Client service available
Given A client update service is available

Scenario: Update a client
When User retrieves client "ORG1"
And User updates client name to "foo"
And User submits client "ORG1"
Then User gets updated client "ORG1"

Scenario: Update a client with validation error
When User retrieves client "ORG1"
And User updates client name to blank
And User submits client "ORG1"
Then User gets validation exception for "ORG1"

Scenario: Update an invalid client
When User submits a client that does not exist
Then User gets client not found exception for update

Scenario: Update a client has a system error
When User retrieves client "ORG1"
And User submits a client that receives a service exception
Then User gets service exception for update
78 changes: 76 additions & 2 deletions model-mock-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,100 @@
<description>MOCK Model API Implemention</description>

<properties>
<enforcer.fail>false</enforcer.fail>
<spotbugs.excludeFilterFile>${basedir}/spotbugs-exclude-filter.xml</spotbugs.excludeFilterFile>
</properties>


<dependencies>

<!-- Model API -->
<dependency>
<groupId>com.github.bordertech.sample.app</groupId>
<artifactId>model-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>

<!-- Model BDD -->
<dependency>
<groupId>com.github.bordertech.sample.app</groupId>
<artifactId>model-bdd</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<!-- Serenity & Cucmber only work with junit 4 (and not vintage junit 5) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- Serenity and Cucumber -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>2.1.8</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-cucumber4</artifactId>
<version>2.1.2</version>
<scope>test</scope>
</dependency>
<!-- Latest cucumber. -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<!-- Serenity Report -->
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>2.1.8</version>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public List<String> retrieveTables() throws ServiceException {

@Override
public List<CodeOption> retrieveCodes(final String table) throws ServiceException {
// Mock error
if (ERROR_REQ.equals(table)) {
throw new ServiceException("Mock table error");
}

List<CodeOption> options = MockDataUtil.retrieveTableCodes(table);
if (options == null) {
throw new ServiceException("Table not found [" + table + "]");
Expand All @@ -37,10 +42,12 @@ public List<CodeOption> retrieveCodes(final String table) throws ServiceExceptio
@Override
public List<ClientDetail> searchClients(final String search) throws ServiceException {

// Mock error
if (ERROR_REQ.equals(search)) {
throw new ServiceException("Mock search error");
}

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

@Override
public ClientDetail retrieveClient(final String clientId) throws ServiceException, ClientNotFoundException {
// Mock error
if (ERROR_REQ.equals(clientId)) {
throw new ServiceException("Mock retrieve client error");
}
ClientDetail detail = MockDataUtil.retrieveClient(clientId);
if (detail == null) {
throw new ClientNotFoundException();
Expand All @@ -59,6 +70,7 @@ public ClientDetail retrieveClient(final String clientId) throws ServiceExceptio

@Override
public ClientDetail createClient(final ClientDetail detail) throws ServiceException {
// Mock error
if (ERROR_REQ.equals(detail.getName())) {
throw new ServiceException("Mock create client error");
}
Expand All @@ -67,13 +79,14 @@ public ClientDetail createClient(final ClientDetail detail) throws ServiceExcept

@Override
public ClientDetail updateClient(final ClientDetail detail) throws ServiceException {
// Mock error
if (ERROR_REQ.equals(detail.getName())) {
throw new ServiceException("Mock update client error");
}

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

@Override
public void deleteClient(final String clientId) throws ServiceException {
// Mock error
if (ERROR_REQ.equals(clientId)) {
throw new ServiceException("Mock delete client error");
}

// Check exists
if (MockDataUtil.retrieveClient(clientId) == null) {
throw new ServiceException("Organisation does not exist [" + clientId + "].");
throw new ServiceException("Client does not exist [" + clientId + "].");
}
// Remove
MockDataUtil.deleteClient(clientId);
}

@Override
public List<DocumentDetail> retrieveClientDocuments(final String clientId) throws ServiceException, ClientNotFoundException {
// Mock error
if (ERROR_REQ.equals(clientId)) {
throw new ServiceException("Mock retrieve client documents");
}
return MockDataUtil.getOrCreateClientDocuments(clientId);
}

@Override
public DocumentContent retrieveDocument(final String documentId) throws ServiceException, DocumentNotFoundException {

// Mock error
if (ERROR_REQ.equals(documentId)) {
throw new ServiceException("Mock retrieve document content");
}
DocumentDetail doc = MockDataUtil.retrieveDocument(documentId);
if (doc == null) {
throw new DocumentNotFoundException();
Expand Down
Loading