Skip to content

Commit 51e2198

Browse files
Simplified checking result in flow tests, fixed traffic generated test (#84)
* Simplified checking result in flow tests * Fixed traffic generated test
1 parent 1bec12b commit 51e2198

File tree

10 files changed

+1573
-416
lines changed

10 files changed

+1573
-416
lines changed

src/main/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ server.port: 8090
88
rules.path: /ArtifactRules_new.json
99

1010
logging.level.root: INFO
11-
logging.level.org.springframework.web: DEBUG
12-
logging.level.com.ericsson.ei: DEBUG
11+
logging.level.org.springframework.web: INFO
12+
logging.level.com.ericsson.ei: INFO
1313

1414
rabbitmq.host: localhost
1515
rabbitmq.port: 5672

src/test/java/com/ericsson/ei/flowtests/FlowSourceChangeObject.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
*/
1414
package com.ericsson.ei.flowtests;
1515

16+
import com.fasterxml.jackson.databind.JsonNode;
1617
import org.junit.runner.RunWith;
1718
import org.springframework.boot.test.context.SpringBootTest;
1819
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1920

21+
import java.io.IOException;
2022
import java.util.ArrayList;
2123
import java.util.HashMap;
2224
import java.util.List;
@@ -32,17 +34,17 @@ public class FlowSourceChangeObject extends FlowTestBase {
3234
private static final String AGGREGATED_OBJECT_ID = "fb6efi4n-25fb-4d77-b9fd-5f2xrrefe66de47";
3335

3436
@Override
35-
String setRulesFilePath() {
37+
String getRulesFilePath() {
3638
return RULES_FILE_PATH;
3739
}
3840

3941
@Override
40-
String setEventsFilePath() {
42+
String getEventsFilePath() {
4143
return EVENTS_FILE_PATH;
4244
}
4345

4446
@Override
45-
List<String> setEventNamesToSend() {
47+
List<String> getEventNamesToSend() {
4648
List<String> eventNames = new ArrayList<>();
4749
eventNames.add("event_EiffelSourceChangeSubmittedEvent_3");
4850
eventNames.add("event_EiffelSourceChangeCreatedEvent_3");
@@ -61,9 +63,10 @@ List<String> setEventNamesToSend() {
6163
}
6264

6365
@Override
64-
Map<String, String> setCheckInfo() {
65-
Map<String, String> checkInfo = new HashMap<>();
66-
checkInfo.put(AGGREGATED_OBJECT_ID, AGGREGATED_OBJECT_FILE_PATH);
67-
return checkInfo;
66+
Map<String, JsonNode> getCheckData() throws IOException {
67+
JsonNode expectedJSON = getJSONFromFile(AGGREGATED_OBJECT_FILE_PATH);
68+
Map<String, JsonNode> checkData = new HashMap<>();
69+
checkData.put(AGGREGATED_OBJECT_ID, expectedJSON);
70+
return checkData;
6871
}
6972
}

src/test/java/com/ericsson/ei/flowtests/FlowTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.ericsson.ei.erqueryservice.ERQueryService;
2020
import com.ericsson.ei.erqueryservice.SearchOption;
2121
import com.ericsson.ei.handlers.UpStreamEventsHandler;
22+
import com.fasterxml.jackson.databind.JsonNode;
2223
import com.fasterxml.jackson.databind.ObjectMapper;
2324
import com.fasterxml.jackson.databind.node.ObjectNode;
2425
import org.junit.Before;
@@ -70,17 +71,17 @@ public void before() throws IOException {
7071
}
7172

7273
@Override
73-
String setRulesFilePath() {
74+
String getRulesFilePath() {
7475
return RULES_FILE_PATH;
7576
}
7677

7778
@Override
78-
String setEventsFilePath() {
79+
String getEventsFilePath() {
7980
return EVENTS_FILE_PATH;
8081
}
8182

8283
@Override
83-
List<String> setEventNamesToSend() {
84+
List<String> getEventNamesToSend() {
8485
List<String> eventNames = new ArrayList<>();
8586
eventNames.add("event_EiffelConfidenceLevelModifiedEvent_3_2");
8687
eventNames.add("event_EiffelArtifactPublishedEvent_3");
@@ -97,9 +98,10 @@ List<String> setEventNamesToSend() {
9798
}
9899

99100
@Override
100-
Map<String, String> setCheckInfo() {
101-
Map<String, String> checkInfo = new HashMap<>();
102-
checkInfo.put(AGGREGATED_OBJECT_ID, AGGREGATED_OBJECT_FILE_PATH);
103-
return checkInfo;
101+
Map<String, JsonNode> getCheckData() throws IOException {
102+
JsonNode expectedJSON = getJSONFromFile(AGGREGATED_OBJECT_FILE_PATH);
103+
Map<String, JsonNode> checkData = new HashMap<>();
104+
checkData.put(AGGREGATED_OBJECT_ID, expectedJSON);
105+
return checkData;
104106
}
105107
}

src/test/java/com/ericsson/ei/flowtests/FlowTest2.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
*/
1717
package com.ericsson.ei.flowtests;
1818

19+
import com.fasterxml.jackson.databind.JsonNode;
1920
import org.junit.runner.RunWith;
2021

2122
import org.springframework.boot.test.context.SpringBootTest;
2223
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2324

25+
import java.io.IOException;
2426
import java.util.ArrayList;
2527
import java.util.HashMap;
2628
import java.util.List;
@@ -38,17 +40,17 @@ public class FlowTest2 extends FlowTestBase {
3840
private static final String AGGREGATED_OBJECT_ID_2 = "ccce572c-c364-441e-abc9-b62fed080ca2";
3941

4042
@Override
41-
String setRulesFilePath() {
43+
String getRulesFilePath() {
4244
return RULES_FILE_PATH;
4345
}
4446

4547
@Override
46-
String setEventsFilePath() {
48+
String getEventsFilePath() {
4749
return EVENTS_FILE_PATH;
4850
}
4951

5052
@Override
51-
List<String> setEventNamesToSend() {
53+
List<String> getEventNamesToSend() {
5254
List<String> eventNames = new ArrayList<>();
5355
eventNames.add("event_EiffelArtifactCreatedEvent_3");
5456
eventNames.add("event_EiffelArtifactPublishedEvent_3");
@@ -68,10 +70,12 @@ List<String> setEventNamesToSend() {
6870
}
6971

7072
@Override
71-
Map<String, String> setCheckInfo() {
72-
Map<String, String> checkInfo = new HashMap<>();
73-
checkInfo.put(AGGREGATED_OBJECT_ID_1, AGGREGATED_OBJECT_FILE_PATH_1);
74-
checkInfo.put(AGGREGATED_OBJECT_ID_2, AGGREGATED_OBJECT_FILE_PATH_2);
75-
return checkInfo;
73+
Map<String, JsonNode> getCheckData() throws IOException {
74+
JsonNode expectedJSON1 = getJSONFromFile(AGGREGATED_OBJECT_FILE_PATH_1);
75+
JsonNode expectedJSON2 = getJSONFromFile(AGGREGATED_OBJECT_FILE_PATH_2);
76+
Map<String, JsonNode> checkData = new HashMap<>();
77+
checkData.put(AGGREGATED_OBJECT_ID_1, expectedJSON1);
78+
checkData.put(AGGREGATED_OBJECT_ID_2, expectedJSON2);
79+
return checkData;
7680
}
7781
}

src/test/java/com/ericsson/ei/flowtests/FlowTestBase.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
public abstract class FlowTestBase extends FlowTestConfigs {
4343

44-
private static final Logger LOGGER = LoggerFactory.getLogger(FlowTest.class);
44+
private static final Logger LOGGER = LoggerFactory.getLogger(FlowTestBase.class);
4545

4646
@Autowired
4747
private RmqHandler rmqHandler;
@@ -59,7 +59,6 @@ public abstract class FlowTestBase extends FlowTestConfigs {
5959
private String event_map;
6060

6161
private static ObjectMapper objectMapper = new ObjectMapper();
62-
private static JsonNode parsedJson;
6362

6463
@Test
6564
public void flowTest() {
@@ -69,20 +68,20 @@ public void flowTest() {
6968
String exchangeName = "ei-poc-4";
7069
createExchange(exchangeName, queueName);
7170

72-
rulesHandler.setRulePath(setRulesFilePath());
71+
rulesHandler.setRulePath(getRulesFilePath());
7372

74-
List<String> eventNames = setEventNamesToSend();
75-
testParametersChange();
73+
List<String> eventNames = getEventNamesToSend();
74+
JsonNode parsedJSON = getJSONFromFile(getEventsFilePath());
7675
int eventsCount = eventNames.size();
7776
for (String eventName : eventNames) {
78-
JsonNode eventJson = parsedJson.get(eventName);
77+
JsonNode eventJson = parsedJSON.get(eventName);
7978
String event = eventJson.toString();
8079
channel.basicPublish(exchangeName, queueName, null, event.getBytes());
8180
}
8281

8382
// wait for all events to be processed
8483
waitForEventsToBeProcessed(eventsCount);
85-
checkResult(setCheckInfo());
84+
checkResult(getCheckData());
8685
} catch (IOException e) {
8786
LOGGER.error(e.getMessage(), e);
8887
}
@@ -91,28 +90,28 @@ public void flowTest() {
9190
/**
9291
* @return path to file with rules, that is used in flow test
9392
*/
94-
abstract String setRulesFilePath();
93+
abstract String getRulesFilePath();
9594

9695
/**
9796
* @return path to file, with events, that is used in flow test
9897
*/
99-
abstract String setEventsFilePath();
98+
abstract String getEventsFilePath();
10099

101100
/**
102101
* @return list of event names, that will be used in flow test
103102
*/
104-
abstract List<String> setEventNamesToSend();
103+
abstract List<String> getEventNamesToSend();
105104

106105
/**
107106
* @return map, where
108107
* key - _id of expected aggregated object
109-
* value - path to file with expected aggregated object
108+
* value - expected aggregated object
110109
*/
111-
abstract Map<String, String> setCheckInfo();
110+
abstract Map<String, JsonNode> getCheckData() throws IOException;
112111

113-
private void testParametersChange() throws IOException {
114-
String jsonFileContent = FileUtils.readFileToString(new File(setEventsFilePath()), "UTF-8");
115-
parsedJson = objectMapper.readTree(jsonFileContent);
112+
JsonNode getJSONFromFile(String filePath) throws IOException {
113+
String expectedDocument = FileUtils.readFileToString(new File(filePath), "UTF-8");
114+
return objectMapper.readTree(expectedDocument);
116115
}
117116

118117
// count documents that were processed
@@ -136,15 +135,13 @@ private void waitForEventsToBeProcessed(int eventsCount) {
136135
}
137136
}
138137

139-
private void checkResult(final Map<String, String> inputFiles) {
140-
inputFiles.forEach((id, filePath) -> {
138+
private void checkResult(final Map<String, JsonNode> checkData) {
139+
checkData.forEach((id, expectedJSON) -> {
141140
try {
142141
String document = objectHandler.findObjectById(id);
143-
String expectedDocument = FileUtils.readFileToString(new File(filePath), "UTF-8");
144-
JsonNode expectedJson = objectMapper.readTree(expectedDocument);
145-
JsonNode actualJson = objectMapper.readTree(document);
146-
LOGGER.info("Complete aggregated object: " + actualJson);
147-
JSONAssert.assertEquals(expectedJson.toString(), actualJson.toString(), false);
142+
JsonNode actualJSON = objectMapper.readTree(document);
143+
LOGGER.info("Complete aggregated object: " + actualJSON);
144+
JSONAssert.assertEquals(expectedJSON.toString(), actualJSON.toString(), false);
148145
} catch (IOException | JSONException e) {
149146
LOGGER.error(e.getMessage(), e);
150147
}

src/test/java/com/ericsson/ei/flowtests/FlowTestExternalComposition.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/test/java/com/ericsson/ei/flowtests/FlowTestTestExecution.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
*/
1717
package com.ericsson.ei.flowtests;
1818

19+
import com.fasterxml.jackson.databind.JsonNode;
1920
import org.junit.runner.RunWith;
2021
import org.springframework.boot.test.context.SpringBootTest;
2122
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2223

24+
import java.io.IOException;
2325
import java.util.ArrayList;
2426
import java.util.HashMap;
2527
import java.util.List;
@@ -35,17 +37,17 @@ public class FlowTestTestExecution extends FlowTestBase {
3537
private static final String AGGREGATED_OBJECT_ID = "b46ef12d-25gb-4d7y-b9fd-8763re66de47";
3638

3739
@Override
38-
String setRulesFilePath() {
40+
String getRulesFilePath() {
3941
return RULES_FILE_PATH;
4042
}
4143

4244
@Override
43-
String setEventsFilePath() {
45+
String getEventsFilePath() {
4446
return EVENTS_FILE_PATH;
4547
}
4648

4749
@Override
48-
List<String> setEventNamesToSend() {
50+
List<String> getEventNamesToSend() {
4951
ArrayList<String> eventNames = new ArrayList<>();
5052
eventNames.add("event_EiffelActivityTriggeredEvent");
5153
eventNames.add("event_EiffelActivityStartedEvent");
@@ -62,9 +64,10 @@ List<String> setEventNamesToSend() {
6264
}
6365

6466
@Override
65-
Map<String, String> setCheckInfo() {
66-
Map<String, String> checkInfo = new HashMap<>();
67-
checkInfo.put(AGGREGATED_OBJECT_ID, AGGREGATED_OBJECT_FILE_PATH);
68-
return checkInfo;
67+
Map<String, JsonNode> getCheckData() throws IOException {
68+
JsonNode expectedJSON = getJSONFromFile(AGGREGATED_OBJECT_FILE_PATH);
69+
Map<String, JsonNode> checkData = new HashMap<>();
70+
checkData.put(AGGREGATED_OBJECT_ID, expectedJSON);
71+
return checkData;
6972
}
7073
}

0 commit comments

Comments
 (0)