Skip to content

Commit 5c6ce51

Browse files
Double event subscription test (#260)
* update tests for to check that no subscription is triggered again if same event is received again * update linking for SourceChangeRules flow picture
1 parent 685d684 commit 5c6ce51

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

src/functionaltests/java/com/ericsson/ei/subscriptions/trigger/SubscriptionTriggerSteps.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,33 @@ public void check_mail_subscriptions_were_triggered() {
153153

154154
@Then("^Rest subscriptions were triggered$")
155155
public void check_rest_subscriptions_were_triggered() throws Throwable {
156+
restSubscriptionsTriggered(1);
157+
// clean mock server information about requests
158+
mockClient.reset();
159+
}
160+
161+
@When("^I send one previous event again$")
162+
public void send_one_previous_event() throws Throwable {
163+
List<String> eventNamesToSend = new ArrayList<>();
164+
eventNamesToSend.add("event_EiffelArtifactCreatedEvent_3");
165+
eventManager.sendEiffelEvents(EIFFEL_EVENTS_JSON_PATH, eventNamesToSend);
166+
}
167+
168+
@When("^No subscription is retriggered$")
169+
public void no_subscription_is_retriggered() throws Throwable {
170+
restSubscriptionsTriggered(0);
171+
}
172+
173+
private void restSubscriptionsTriggered(int times) throws Throwable {
156174
LOGGER.debug("Verifying REST requests.");
157175
List<String> endpointsToCheck = new ArrayList<>(Arrays.asList(REST_ENDPOINT, REST_ENDPOINT_AUTH,
158176
REST_ENDPOINT_PARAMS, REST_ENDPOINT_AUTH_PARAMS, REST_ENDPOINT_ROW_BODY));
159177

160-
assert (allEndpointsGotAtLeastXCalls(endpointsToCheck, 1));
161-
for (String endpoint : endpointsToCheck) {
162-
assert (requestBodyContainsStatedValues(endpoint));
178+
assert (allEndpointsGotAtLeastXCalls(endpointsToCheck, times));
179+
if (times > 0) {
180+
for (String endpoint : endpointsToCheck) {
181+
assert (requestBodyContainsStatedValues(endpoint));
182+
}
163183
}
164184
}
165185

@@ -233,7 +253,8 @@ private boolean allEndpointsGotAtLeastXCalls(final List<String> endpoints, int e
233253
while (!endpointsToCheck.isEmpty() && stopTime > System.currentTimeMillis()) {
234254
for (String endpoint : endpoints) {
235255
String restBodyData = mockClient.retrieveRecordedRequests(request().withPath(endpoint), Format.JSON);
236-
if ((new JSONArray(restBodyData)).length() >= expectedCalls) {
256+
int actualRestCalls = new JSONArray(restBodyData).length();
257+
if (actualRestCalls >= expectedCalls) {
237258
endpointsToCheck.remove(endpoint);
238259
}
239260
}

src/functionaltests/resources/features/subscriptionTrigger.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ Feature: Subscription trigger test
2727
And Wait for EI to aggregate objects and trigger subscriptions
2828
Then Mail subscriptions were triggered
2929
And Rest subscriptions were triggered
30+
And I send one previous event again
31+
And No subscription is retriggered

src/main/java/com/ericsson/ei/subscriptionhandler/RunSubscription.java

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

19-
import com.ericsson.ei.jmespath.JmesPathInterface;
20-
import com.fasterxml.jackson.databind.JsonNode;
21-
import com.fasterxml.jackson.databind.node.ArrayNode;
22-
2319
import java.util.Iterator;
2420

2521
import org.slf4j.Logger;
2622
import org.slf4j.LoggerFactory;
2723
import org.springframework.beans.factory.annotation.Autowired;
2824
import org.springframework.stereotype.Component;
2925

26+
import com.ericsson.ei.jmespath.JmesPathInterface;
27+
import com.fasterxml.jackson.databind.JsonNode;
28+
import com.fasterxml.jackson.databind.node.ArrayNode;
29+
3030
/**
3131
* This class represents the mechanism to fetch the rule conditions from the
3232
* Subscription Object and match it with the aggregatedObject to check if it is
@@ -75,13 +75,14 @@ public boolean runSubscriptionOnObject(String aggregatedObject, Iterator<JsonNod
7575
"ID has not been passed for given aggregated object. The subscription will be triggered again.");
7676
}
7777

78-
if (subscriptionRepeatFlag == "false" && id != null && subscriptionRepeatDbHandler
79-
.checkIfAggrObjIdExistInSubscriptionAggrIdsMatchedList(subscriptionName, requirementIndex, id)) {
78+
if (subscriptionRepeatFlag == "false" && id != null
79+
&& subscriptionRepeatDbHandler.checkIfAggrObjIdExistInSubscriptionAggrIdsMatchedList(
80+
subscriptionName, requirementIndex, id)) {
8081
LOGGER.info("Subscription has already matched with AggregatedObject Id: " + id + "\nSubscriptionName: "
8182
+ subscriptionName + "\nand has Subscrption Repeat flag set to: " + subscriptionRepeatFlag);
8283
break;
8384
}
84-
85+
8586
JsonNode requirement = requirementIterator.next();
8687

8788
LOGGER.info("The fulfilled requirement which condition will check is : " + requirement.toString());

0 commit comments

Comments
 (0)