Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 878d4db

Browse files
author
vlad-ciucescu
authored
Merge pull request SORMAS-Foundation#3697 from hzi-braunschweig/SORMAS-Foundation#3649-EXTERNAL-JOURNAL]-The-ExternalvisitsResourceTest-does-not-work
SORMAS-Foundation#3649 external journal - the externalvisits resource test does not work
2 parents 1aa653c + a1c1a22 commit 878d4db

3 files changed

Lines changed: 1836 additions & 1022 deletions

File tree

sormas-rest/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@
118118
<plugin>
119119
<groupId>io.openapitools.swagger</groupId>
120120
<artifactId>swagger-maven-plugin</artifactId>
121+
<executions>
122+
<execution>
123+
<id>generate-swagger</id>
124+
<phase>generate-test-resources</phase>
125+
<goals>
126+
<goal>generate</goal>
127+
</goals>
128+
</execution>
129+
</executions>
121130
<configuration>
122131
<!-- Swagger Generation Config -->
123132
<resourcePackages>

sormas-rest/src/test/java/de/symeda/sormas/rest/ExternalVisitsResourceTest.java

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import java.nio.file.Files;
99
import java.nio.file.Path;
1010
import java.nio.file.Paths;
11-
import java.util.ArrayList;
1211
import java.util.Arrays;
1312
import java.util.Collections;
13+
import java.util.HashMap;
1414
import java.util.List;
1515
import java.util.Map;
1616

@@ -33,16 +33,16 @@ public void testIfRelevantSwaggerDocumentationIsUnchanged() throws IOException {
3333
//load released and new swagger docu information
3434
Map<String, Object> releasedSwaggerDocuMap = loadJson("./src/test/resources/swagger.json");
3535

36-
Map<String, Object> newSwaggerDocuMap = loadJson("./target/test-classes/swagger.json");
36+
Map<String, Object> newSwaggerDocuMap = loadJson("./target/swagger.json");
3737

3838
// Check whether path information is equal in new and released swagger docu
39-
ArrayList<Object> releasedControllerList = new ArrayList<>();
40-
extractPathsOfController(releasedSwaggerDocuMap, "External Visits Controller", releasedControllerList);
39+
Map<String, Object> releasedControllerMap = new HashMap<String, Object>();
40+
extractPathsOfController(releasedSwaggerDocuMap, "External Visits Controller", releasedControllerMap);
4141

42-
ArrayList<Object> newControllerList = new ArrayList<>();
43-
extractPathsOfController(newSwaggerDocuMap, "External Visits Controller", newControllerList);
42+
Map<String, Object> newControllerMap = new HashMap<String, Object>();
43+
extractPathsOfController(newSwaggerDocuMap, "External Visits Controller", newControllerMap);
4444

45-
assertEquals(releasedControllerList, newControllerList);
45+
assertEquals(releasedControllerMap, newControllerMap);
4646

4747
// Check whether related enum information is equal
4848
List<String> enumNames = Arrays.asList(
@@ -56,15 +56,14 @@ public void testIfRelevantSwaggerDocumentationIsUnchanged() throws IOException {
5656
"SymptomState",
5757
"YesNoUnknown",
5858
"TemperatureSource");
59+
Map<String, Object> releasedDetailMap = new HashMap<String, Object>();
60+
Map<String, Object> newDetailMap = new HashMap<String, Object>();
5961

6062
for (String name : enumNames) {
61-
ArrayList<Object> releasedDetailList = new ArrayList<>();
62-
ArrayList<Object> newDetailList = new ArrayList<>();
63-
extractDetail(releasedSwaggerDocuMap, name, releasedDetailList);
64-
extractDetail(newSwaggerDocuMap, name, newDetailList);
65-
66-
assertEquals("", releasedDetailList, newDetailList);
63+
extractDetail(releasedSwaggerDocuMap, name, releasedDetailMap);
64+
extractDetail(newSwaggerDocuMap, name, newDetailMap);
6765
}
66+
assertEquals(releasedDetailMap, newDetailMap);
6867
}
6968

7069
/**
@@ -73,22 +72,19 @@ public void testIfRelevantSwaggerDocumentationIsUnchanged() throws IOException {
7372
* Nested Map from which to extract the information. It's supposed to be a mapped swagger.json
7473
* @param controller
7574
* The name of the controller, e.g. External Visits Controller
76-
* @param list
77-
* Extracted information is stored in this list
75+
* @param resultMap
76+
* Extracted information is stored in this map
7877
* @return Documentation about any path found for the specified controller (e.g. /visits-external/person/{personUuid} for the External
7978
* Visits Controller). This includes parameter names for that path, but not information about related enums.
8079
*/
81-
private static void extractPathsOfController(Map<String, Object> level1, String controller, ArrayList<Object> list) {
82-
level1.entrySet().forEach(e1 -> {
83-
String key1 = e1.getKey();
84-
Object value1 = e1.getValue();
80+
private static void extractPathsOfController(Map<String, Object> level1, String controller, Map resultMap) {
81+
level1.forEach((key1, value1) -> {
8582
if (isInnerNode(value1)) {
8683
Map<String, Object> level2 = innerNode(value1);
8784
if (hasTag(level2, controller)) {
88-
list.add(key1);
89-
list.add(value1);
85+
resultMap.put(key1, value1);
9086
}
91-
extractPathsOfController(level2, controller, list);
87+
extractPathsOfController(level2, controller, resultMap);
9288
}
9389
});
9490
}
@@ -100,9 +96,7 @@ private static boolean hasTag(Map<String, Object> level2, String controller) {
10096
.map(ExternalVisitsResourceTest::innerNode)
10197
// tags are always represented in the third layer and as ArrayLists
10298
.map(ExternalVisitsResourceTest::tags)
103-
.filter(t -> t.contains(controller))
104-
.findFirst()
105-
.isPresent();
99+
.anyMatch(t -> t.contains(controller));
106100
}
107101

108102
@SuppressWarnings("unchecked")
@@ -121,20 +115,18 @@ private static List<Object> tags(Map<String, Object> innerNode) {
121115
* Nested Map from which to extract the information. It's supposed to be a mapped swagger.json
122116
* @param detailName
123117
* The name of the detail, e.g. JournalPersonDto.
124-
* @param list
125-
* Extracted information is stored in this list
118+
* @param resultMap
119+
* Extracted information is stored in this map
126120
* @return
127121
* Documentation found about the detail. The Map is searched for a key equal to detailName, an it, plus the according value is
128122
* added to the list.
129123
*/
130-
private static void extractDetail(Map<String, Object> level1, String detailName, ArrayList<Object> list) {
131-
level1.entrySet().stream().forEach(e1 -> {
132-
Object value1 = e1.getValue();
133-
if (detailName.equals(e1.getKey())) {
134-
list.add(detailName);
135-
list.add(value1);
124+
private static void extractDetail(Map<String, Object> level1, String detailName, Map resultMap) {
125+
level1.forEach((key, value1) -> {
126+
if (detailName.equals(key)) {
127+
resultMap.put(detailName, value1);
136128
} else if (isInnerNode(value1)) {
137-
extractDetail(innerNode(value1), detailName, list);
129+
extractDetail(innerNode(value1), detailName, resultMap);
138130
}
139131
});
140132
}

0 commit comments

Comments
 (0)