Skip to content

Commit 5348b80

Browse files
Generated complete Artifact object (#76)
1 parent 2330c28 commit 5348b80

File tree

7 files changed

+220
-32
lines changed

7 files changed

+220
-32
lines changed

src/main/java/com/ericsson/ei/handlers/ProcessRulesHandler.java

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

19+
import com.ericsson.ei.rules.RulesHandler;
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,13 +30,16 @@
2930
@Component
3031
public class ProcessRulesHandler {
3132

32-
static Logger log = (Logger) LoggerFactory.getLogger(ProcessRulesHandler.class);
33+
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(ProcessRulesHandler.class);
3334

3435
@Autowired
35-
JmesPathInterface jmespath;
36+
private JmesPathInterface jmespath;
3637

3738
@Autowired
38-
MergeHandler mergeHandler;
39+
private MergeHandler mergeHandler;
40+
41+
@Autowired
42+
private RulesHandler rulesHandler;
3943

4044
public void setJmesPathInterface(JmesPathInterface jmesPathInterface) {
4145
this.jmespath = jmesPathInterface;
@@ -48,9 +52,16 @@ public void setMergeHandler(MergeHandler mergeHandler) {
4852
public String runProcessRules(String event, RulesObject rulesObject, String aggregationObject, String objectId, String mergeId) {
4953
String processRules = rulesObject.fetchProcessRules();
5054
if (processRules != null) {
51-
log.info("processRules: " + processRules);
52-
log.info("aggregationObject: " + aggregationObject);
53-
log.info("event: " + event);
55+
String identifyRule = rulesHandler.getRulesForEvent(event).getIdentifyRules();
56+
String id = jmespath.runRuleOnEvent(identifyRule, event).get(0).textValue();
57+
58+
if(processRules.contains("%IdentifyRules%")) {
59+
processRules = processRules.replace("%IdentifyRules%", id);
60+
}
61+
62+
LOGGER.info("processRules: " + processRules);
63+
LOGGER.info("aggregationObject: " + aggregationObject);
64+
LOGGER.info("event: " + event);
5465
JsonNode ruleResult = jmespath.runRuleOnEvent(processRules, aggregationObject);
5566
return mergeHandler.mergeObject(objectId, mergeId, rulesObject, event, ruleResult);
5667
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ protected ArrayList<String> getEventNamesToSend() {
7474
eventNames.add("event_EiffelTestCaseTriggeredEvent_3");
7575
eventNames.add("event_EiffelTestCaseStartedEvent_3");
7676
eventNames.add("event_EiffelTestCaseFinishedEvent_3");
77+
eventNames.add("event_EiffelArtifactPublishedEvent_3_1");
78+
eventNames.add("event_EiffelConfidenceLevelModifiedEvent_3");
79+
eventNames.add("event_EiffelTestCaseTriggeredEvent_3_1");
80+
eventNames.add("event_EiffelTestCaseStartedEvent_3_1");
81+
eventNames.add("event_EiffelTestCaseFinishedEvent_3_1");
7782

7883
return eventNames;
7984
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ protected void waitForEventsToBeProcessed(int eventsCount) {
237237
processedEvents = countProcessedEvents(database, event_map);
238238
log.info("Have gotten: " + processedEvents + " out of: " + eventsCount);
239239
try {
240-
TimeUnit.MILLISECONDS.sleep(1000);
240+
TimeUnit.MILLISECONDS.sleep(3000);
241241
} catch (Exception e) {
242242
log.info(e.getMessage(),e);
243243
}
@@ -254,7 +254,7 @@ protected void checkResult() throws JSONException {
254254
JsonNode actualJson = objectmapper.readTree(document);
255255
String breakString = "breakHere";
256256
System.out.println(actualJson);
257-
JSONAssert.assertEquals(expectedJson.toString(), actualJson.toString(), true);
257+
JSONAssert.assertEquals(expectedJson.toString(), actualJson.toString(), false);
258258
} catch (IOException e) {
259259
log.info(e.getMessage(),e);
260260
}

src/test/resources/AggregatedDocumentInternalComposition.json

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
"TemplateName": "ARTIFACT_1",
55
"fileInformation": [
66
{
7-
"extension": "jar",
8-
"classifier": ""
7+
"classifier": "debug",
8+
"extension": "jar"
9+
},
10+
{
11+
"classifier": "test",
12+
"extension": "txt"
13+
},
14+
{
15+
"classifier": "application",
16+
"extension": "exe"
917
}
1018
],
1119
"buildCommand": null,
@@ -15,6 +23,12 @@
1523
"name": "readyForDelivery",
1624
"time": 1481875944272,
1725
"value": "SUCCESS"
26+
},
27+
{
28+
"eventId": "f37d59a3-069e-4f4c-8cc5-a52e73501a76",
29+
"name": "performance",
30+
"time": 1481875988767,
31+
"value": "SUCCESS"
1832
}
1933
],
2034
"internalComposition":{
@@ -61,24 +75,45 @@
6175
"name":"My composition",
6276
"time":2000
6377
}
78+
],
79+
"artifacts": [
80+
{
81+
"id": "1100572b-c3j4-441e-abc9-b62f48080011"
82+
}
6483
]
6584
},
6685
"testCaseExecutions": [
6786
{
68-
"testCaseTrigeredEventId": "6d3df0e0-404d-46ee-ab4f-3118457148f4",
69-
"testCaseTrigeredTime": 1490777327230,
70-
"testCaseFinishEventId": "11109351-41e0-474a-bc1c-f6e81e58a1c9",
87+
"testCaseTriggeredEventId": "6d3df0e0-404d-46ee-ab4f-3118457148f4",
88+
"testCaseTriggeredTime": 1490777327230,
89+
"testCaseFinishedEventId": "cb9d64b0-a6e9-4419-8b5d-a650c27c1111",
7190
"testCaseStartedTime": 1481875925916,
7291
"testCaseStartedEventId": "cb9d64b0-a6e9-4419-8b5d-a650c27c59ca",
7392
"testCaseFinishedTime": 1481875935919,
7493
"testCaseDuration": 10003,
75-
"testCase": {
94+
"outcome": {
7695
"conclusion": "SUCCESSFUL",
7796
"verdict": "PASSED",
7897
"tracker": "My Other Test Management System",
7998
"id": "TC5",
8099
"uri": "https://other-tm.company.com/testCase/TC5"
81100
}
101+
},
102+
{
103+
"testCaseTriggeredEventId": "6d3df0e0-404d-46ee-ab4f-3118457148f5",
104+
"testCaseTriggeredTime": 1490777357289,
105+
"testCaseStartedEventId": "e06defd8-fcf0-4e08-bf32-43bbc06cf655",
106+
"testCaseStartedTime": 1481875925918,
107+
"testCaseFinishedEventId": "17b20d3a-23a6-41c6-8da0-a87a240b4c2f",
108+
"testCaseFinishedTime": 1481875938919,
109+
"testCaseDuration": 13001,
110+
"outcome": {
111+
"conclusion": "SUCCESSFUL",
112+
"verdict": "PASSED",
113+
"tracker": "My Other Test Management System",
114+
"id": "TC6",
115+
"uri": "https://other-tm.company.com/testCase/TC6"
116+
}
82117
}
83118
],
84119
"id": "6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43",
@@ -99,6 +134,16 @@
99134
}
100135
],
101136
"time": 1481875921763
137+
},
138+
{
139+
"eventId": "33d05e6f-9bd9-4138-83b6-e20cc74681b5",
140+
"locations": [
141+
{
142+
"type": "ARTIFACTORY",
143+
"uri": "https://myrepository.com/artifactory"
144+
}
145+
],
146+
"time": 1481875921843
102147
}
103148
]
104149
}

src/test/resources/ArtifactRules_new.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"DownstreamExtractionRules" : "{artifacts: [{id : meta.id}]}",
1414
"ArrayMergeOptions": "",
1515
"HistoryIdentifyRules":"links | [?type=='COMPOSITION'].target",
16-
"HistoryExtractionRules":"{internalComposition:{artifacts: [{id : meta.id}]}}",
17-
"HistoryPathRules": "{artifacts: {id: meta.id}}",
16+
"HistoryExtractionRules":"{id : meta.id}",
17+
"HistoryPathRules": "{internalComposition: {artifacts: [{id: meta.id}]}}",
1818
"ProcessRules" : null,
1919
"ProcessFunction" : null
2020
},
@@ -26,7 +26,8 @@
2626
"StartEvent": "NO",
2727
"IdentifyRules" : "links | [?type=='ARTIFACT'].target",
2828
"MatchIdRules": {"_id": "%IdentifyRules_objid%"},
29-
"ExtractionRules" : "{ publications :[ { eventId : meta.id, time : meta.time, locations : data.locations }] }",
29+
"ExtractionRules" : "{ eventId : meta.id, time : meta.time, locations : data.locations }",
30+
"MergeResolverRules": "[ {NONEPATH:NONE}, {publications: [{ eventId: meta.id }]} ]",
3031
"ArrayMergeOptions": "",
3132
"HistoryIdentifyRules": "",
3233
"HistoryExtractionRules": "",
@@ -41,7 +42,8 @@
4142
"StartEvent": "NO",
4243
"IdentifyRules" : "links | [?type=='SUBJECT'].target",
4344
"MatchIdRules": {"_id": "%IdentifyRules_objid%"},
44-
"ExtractionRules" : "{confidenceLevels :[{ eventId:meta.id, time:meta.time, name:data.name, value:data.value}]}",
45+
"ExtractionRules" : "{ eventId:meta.id, time:meta.time, name:data.name, value:data.value }",
46+
"MergeResolverRules": "[ {NONEPATH:NONE}, {confidenceLevels: [{ eventId: meta.id }]} ]",
4547
"ArrayMergeOptions": "",
4648
"HistoryIdentifyRules": "",
4749
"HistoryExtractionRules": "",
@@ -56,7 +58,8 @@
5658
"StartEvent": "NO",
5759
"IdentifyRules" : "links | [?type=='IUT'].target",
5860
"MatchIdRules": {"_id": "%IdentifyRules_objid%"},
59-
"ExtractionRules" : "{testCaseExecutions :[{ testCaseTrigeredEventId:meta.id, testCaseTrigeredTime:meta.time, testCase:data.testCase}]}",
61+
"ExtractionRules" : "{ testCaseTriggeredEventId:meta.id, testCaseTriggeredTime:meta.time, outcome:data.testCase }",
62+
"MergeResolverRules": "[ {NONEPATH:NONE}, {testCaseExecutions: [{ testCaseTriggeredEventId: meta.id }]} ]",
6063
"ArrayOptions": "",
6164
"HistoryIdentifyRules": "",
6265
"HistoryExtractionRules": "",
@@ -71,8 +74,8 @@
7174
"StartEvent": "NO",
7275
"IdentifyRules" : "links | [?type=='TEST_CASE_EXECUTION'].target",
7376
"MatchIdRules": {"_id": "%IdentifyRules_objid%"},
74-
"ExtractionRules" : "{testCaseExecutions :[{ testCaseStartedEventId:meta.id, testCaseStartedTime:meta.time, testCase:data.testCase}]}",
75-
"MergeResolverRules" : "{\"testCaseTrigeredEventId\":%IdentifyRules%}",
77+
"ExtractionRules" : "{ testCaseStartedEventId:meta.id, testCaseStartedTime:meta.time, outcome:data.testCase }",
78+
"MergeResolverRules": "[{NONEPATH:NONE}, {testCaseExecutions: [{ testCaseTriggeredEventId: links | [?type=='TEST_CASE_EXECUTION'] | [0].target }] }]",
7679
"ArrayOptions": "",
7780
"HistoryIdentifyRules": "",
7881
"HistoryExtractionRules": "",
@@ -87,12 +90,12 @@
8790
"StartEvent": "NO",
8891
"IdentifyRules" : "links | [?type=='TEST_CASE_EXECUTION'].target",
8992
"MatchIdRules": { "$and": [{"aggregatedObject.testCaseExecutions.testCaseStartedEventId": "%IdentifyRules%"}]},
90-
"ExtractionRules" : "{ testCaseFinishEventId:meta.id, testCaseFinishedTime:meta.time, testCase:data.outcome}",
93+
"ExtractionRules" : "{ testCaseFinishedEventId:meta.id, testCaseFinishedTime:meta.time, outcome:data.outcome}",
9194
"MergeResolverRules" : "{\"testCaseStartedEventId\":%IdentifyRules%}",
9295
"ArrayMergeOptions": "",
9396
"HistoryIdentifyRules": "",
9497
"HistoryExtractionRules": "",
95-
"ProcessRules":"{testCaseDuration : diff(testCaseExecutions[0].testCaseFinishedTime, testCaseExecutions[0].testCaseStartedTime)}",
98+
"ProcessRules": "{testCaseDuration : diff(testCaseExecutions | [?testCaseStartedEventId=='%IdentifyRules%'].testCaseFinishedTime | [0], testCaseExecutions | [?testCaseStartedEventId=='%IdentifyRules%'].testCaseStartedTime | [0])}",
9699
"ProcessFunction" : "difference"
97100
},
98101
{

0 commit comments

Comments
 (0)