Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #49 from open-prevo/feature/17_IntegrationTest
Browse files Browse the repository at this point in the history
Add integration test
  • Loading branch information
MarkusTiede authored Jul 5, 2018
2 parents 56f5f06 + 02da170 commit 29881a6
Show file tree
Hide file tree
Showing 40 changed files with 729 additions and 156 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
language: java

sudo: required
services:
- docker
5 changes: 5 additions & 0 deletions adapter-dummy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:8
RUN mkdir /opt/app
COPY build/libs/adapter-dummy-0.0.1-SNAPSHOT.jar /opt/app/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/opt/app/app.jar"]
EXPOSE 8080
3 changes: 3 additions & 0 deletions adapter-dummy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ repositories {

dependencies {
compile(project(":node"))

testCompile('org.springframework.boot:spring-boot-starter-test')

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package ch.prevo.open.node.data.provider;

import static java.util.Collections.emptyList;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Repository;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

import ch.prevo.open.data.api.JobEnd;
import ch.prevo.open.data.api.JobStart;

/**
* Sample json dummy adapter to provide hardcoded test data.
*/
@Repository
public class JsonAdapter implements JobStartProvider, JobEndProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(JsonAdapter.class);

@Value("${open.prevo.json.adapter.files.jobstart}")
private String jobStartJsonFile;

@Value("${open.prevo.json.adapter.files.jobend}")
private String jobEndJsonFile;

@Inject
private ResourceLoader resourceLoader;

@Inject
private ObjectMapper objectMapper;

private List<JobStart> jobStartInformation;
private List<JobEnd> jobEndInformation;

@PostConstruct
public void init() {
this.jobStartInformation = new ArrayList<>(readJsonFile(jobStartJsonFile, JobStart.class));
this.jobEndInformation = new ArrayList<>(readJsonFile(jobEndJsonFile, JobEnd.class));
}

private <T> List<T> readJsonFile(String filePath, Class<T> clazz) {
LOGGER.debug("Read json file {} in adapter", filePath);
try {
Resource jsonResource = resourceLoader.getResource(filePath);
String jsonString = IOUtils.toString(jsonResource.getInputStream(), Charset.forName("UTF-8"));
JavaType type = objectMapper.getTypeFactory().constructParametricType(List.class, clazz);
return objectMapper.readValue(jsonString, type);
} catch (Exception e) {
LOGGER.error("Could not initialize dummy json adapter", e);
}
return emptyList();
}

@Override
public List<JobStart> getJobStarts() {
return jobStartInformation;
}

@Override
public List<JobEnd> getJobEnds() {
return jobEndInformation;
}
}
3 changes: 3 additions & 0 deletions adapter-dummy/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# open prevo properties
open.prevo.json.adapter.files.jobstart=classpath:sample-job-start-data.json
open.prevo.json.adapter.files.jobend=classpath:sample-job-end-data.json
32 changes: 32 additions & 0 deletions adapter-dummy/src/main/resources/pakt-sample-job-end-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.537.488-Helvetia-Prisma-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.1234.5678.97",
"internalPersonId": "",
"date": null
}
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.537.488-Helvetia-Prisma-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.3421.5678.97",
"internalPersonId": "",
"date": null
}
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.537.488-Helvetia-Prisma-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.3324.5678.58",
"internalPersonId": "",
"date": null
}
}
]
35 changes: 35 additions & 0 deletions adapter-dummy/src/main/resources/pakt-sample-job-start-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.537.488-Helvetia-Prisma-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.1335.5778.23",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.537.488-Helvetia-Prisma-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.9874.5778.58",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.537.488-Helvetia-Prisma-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.3256.6598.23",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
}
]
32 changes: 32 additions & 0 deletions adapter-dummy/src/main/resources/sample-job-end-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.084-Baloise-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.1335.5778.23",
"internalPersonId": "",
"date": null
}
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.084-Baloise-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.3412.8844.97",
"internalPersonId": "",
"date": null
}
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.084-Baloise-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.9534.5271.94",
"internalPersonId": "",
"date": null
}
}
]
35 changes: 35 additions & 0 deletions adapter-dummy/src/main/resources/sample-job-start-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.084-Baloise-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.1234.5678.97",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.084-Baloise-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.1298.6578.97",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.084-Baloise-Sammelstiftung",
"internalReferenz": "",
"oasiNumber": "756.5678.1234.17",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ch.prevo.open.node.data.provider;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import javax.inject.Inject;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import ch.prevo.open.data.api.JobEnd;
import ch.prevo.open.data.api.JobStart;
import ch.prevo.open.node.NodeApplication;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = NodeApplication.class)
public class JsonAdapterTest {

@Inject
private JsonAdapter jsonAdapter;

@Test
public void getJobStartInformation() {
List<JobStart> jobEndInformation = jsonAdapter.getJobStarts();
assertThat(jobEndInformation).hasSize(3);
}

@Test
public void getJobEndInformation() {
List<JobEnd> jobEndInformation = jsonAdapter.getJobEnds();
assertThat(jobEndInformation).hasSize(3);
}
}
3 changes: 3 additions & 0 deletions adapter-dummy/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# open prevo properties
open.prevo.json.adapter.files.jobstart=classpath:node-rest-test-jobstart.json
open.prevo.json.adapter.files.jobend=classpath:node-rest-test-jobend.json
33 changes: 33 additions & 0 deletions adapter-dummy/src/test/resources/node-rest-test-jobend.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

[
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.084",
"internalReferenz": "",
"oasiNumber": "756.1335.5778.23",
"internalPersonId": "",
"date": null
}
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.537.488",
"internalReferenz": "",
"oasiNumber": "756.3412.8844.97",
"internalPersonId": "",
"date": null
}
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.078",
"internalReferenz": "",
"oasiNumber": "756.9534.5271.94",
"internalPersonId": "",
"date": null
}
}
]
35 changes: 35 additions & 0 deletions adapter-dummy/src/test/resources/node-rest-test-jobstart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.084",
"internalReferenz": "",
"oasiNumber": "756.1234.5678.9",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.537.488",
"internalReferenz": "",
"oasiNumber": "756.1298.6578.97",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
},
{
"techId": "",
"jobInfo": {
"retirementFundUid": "CHE-109.740.078",
"internalReferenz": "",
"oasiNumber": "756.5678.1234.17",
"internalPersonId": "",
"date": null
},
"capitalTransferInfo": null
}
]
5 changes: 4 additions & 1 deletion doc/arc42/src/04_solution_strategy.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ In the team we've decided to use the following technologies:
* Language: Java 8
* Framework: link:https://spring.io/projects/spring-boot[Spring Boot]
* REST API
** link:https://swagger.io/specification/[OpenAPI] Swagger for documentation
** link:https://swagger.io/specification/[OpenAPI] Swagger for documentation
* used during development
** link:https://www.docker.com/open-source[Docker container] for integration testing
** link:https://www.eclipse.org/openj9/[OpenJ9]-JVM
Loading

0 comments on commit 29881a6

Please sign in to comment.