Skip to content

Commit 3fb5d33

Browse files
authored
Add integrationtests for artifact created flow. (#218)
* Add integrationtests for artifact created flow. -Added integrationtests for artifact created flow.
1 parent 6fe10a6 commit 3fb5d33

File tree

9 files changed

+615
-27
lines changed

9 files changed

+615
-27
lines changed

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<base-package>com.ericsson.ei.controller</base-package>
2424
<skipTests>false</skipTests>
2525
<skipITs>${skipTests}</skipITs>
26-
<skipUnitTests>${skipTests}</skipUnitTests>
26+
<skipUTs>${skipTests}</skipUTs>
2727
</properties>
2828

2929
<!-- Reporting Plugins -->
@@ -314,6 +314,7 @@
314314
</excludes>
315315
</resource>
316316
</resources>
317+
317318
<plugins>
318319
<plugin>
319320
<groupId>org.springframework.boot</groupId>
@@ -380,8 +381,12 @@
380381
</goals>
381382
<configuration>
382383
<sources>
384+
<source>src/test/java</source>
385+
<source>src/test/resources</source>
383386
<source>src/functionaltests/java</source>
384387
<source>src/functionaltests/resources</source>
388+
<source>src/integrationtests/java</source>
389+
<source>src/integrationtests/resources</source>
385390
</sources>
386391
</configuration>
387392
</execution>
@@ -393,10 +398,11 @@
393398
<artifactId>maven-surefire-plugin</artifactId>
394399
<version>2.20</version>
395400
<configuration>
401+
<skipTests>${skipUTs}</skipTests>
396402
<forkCount>2C</forkCount>
397403
<reuseForks>false</reuseForks>
398-
<skipTests>${skipUnitTests}</skipTests>
399404
<excludes>
405+
<exclude>**/*IT.java</exclude>
400406
<exclude>${someModule.test.excludes}</exclude>
401407
</excludes>
402408
<includes>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.ericsson.ei.artifactintegrationtests;
2+
3+
import org.junit.runner.RunWith;
4+
5+
import cucumber.api.CucumberOptions;
6+
import cucumber.api.junit.Cucumber;
7+
8+
@RunWith(Cucumber.class)
9+
@CucumberOptions(features = "src/integrationtests/resources/features/ArtifactFlowIT.feature", glue = {
10+
"com.ericsson.ei.artifactintegrationtests" }, plugin = { "pretty",
11+
"html:target/cucumber-reports/ArtifactFlowRunnerIT" })
12+
public class ArtifactFlowRunnerIT {
13+
14+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package com.ericsson.ei.artifactintegrationtests;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
import java.net.URL;
9+
import java.time.ZonedDateTime;
10+
import java.util.ArrayList;
11+
import java.util.HashMap;
12+
import java.util.List;
13+
import java.util.Map;
14+
15+
import org.junit.Ignore;
16+
import org.junit.runner.RunWith;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
import org.springframework.amqp.rabbit.core.RabbitTemplate;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.boot.test.context.SpringBootContextLoader;
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.boot.web.server.LocalServerPort;
24+
import org.springframework.http.ResponseEntity;
25+
import org.springframework.test.context.ContextConfiguration;
26+
import org.springframework.test.context.TestExecutionListeners;
27+
import org.springframework.test.context.junit4.SpringRunner;
28+
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
29+
30+
import com.ericsson.ei.App;
31+
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
32+
import com.ericsson.ei.utils.HttpRequest;
33+
import com.ericsson.ei.utils.HttpRequest.HttpMethod;
34+
import com.fasterxml.jackson.databind.JsonNode;
35+
import com.fasterxml.jackson.databind.ObjectMapper;
36+
import com.fasterxml.jackson.databind.node.ArrayNode;
37+
import com.fasterxml.jackson.databind.node.ObjectNode;
38+
39+
import cucumber.api.java.en.Given;
40+
import cucumber.api.java.en.Then;
41+
import cucumber.api.java.en.When;
42+
import util.IntegrationTestBase;
43+
44+
@Ignore
45+
@RunWith(SpringRunner.class)
46+
@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
47+
@ContextConfiguration(classes = App.class, loader = SpringBootContextLoader.class)
48+
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
49+
public class ArtifactFlowStepsIT extends IntegrationTestBase {
50+
private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactFlowStepsIT.class);
51+
52+
private static final String UPSTREAM_INPUT_FILE = "src/test/resources/upStreamInput.json";
53+
private static final String RULES_FILE_PATH = "src/test/resources/ArtifactRules_new.json";
54+
private static final String EVENTS_FILE_PATH = "src/test/resources/test_events.json";
55+
private static final String AGGREGATED_OBJECT_FILE_PATH = "src/test/resources/AggregatedDocumentInternalCompositionLatest.json";
56+
private static final String AGGREGATED_OBJECT_ID = "6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43";
57+
private static final String SUBSCRIPTIONS_PATH = "src/integrationtests/resources/subscriptionsTemplate.json";
58+
private static final String HOST = "localhost";
59+
60+
61+
private long startTime;
62+
private static ObjectMapper objectMapper = new ObjectMapper();
63+
64+
@LocalServerPort
65+
int port;
66+
67+
@Autowired
68+
private RabbitTemplate rabbitMqTemplate;
69+
70+
@Autowired
71+
MongoDBHandler mongoDBHandler;
72+
73+
@Given("^subscriptions are uploaded$")
74+
public void subscriptions_are_created() throws URISyntaxException, IOException {
75+
startTime = System.currentTimeMillis();
76+
77+
URL subscriptionsInput = new File(SUBSCRIPTIONS_PATH).toURI().toURL();
78+
ArrayNode subscriptionsJson = (ArrayNode) objectMapper.readTree(subscriptionsInput);
79+
subscriptionsJson = setSubscriptionFields(subscriptionsJson);
80+
81+
HttpRequest postRequest = new HttpRequest(HttpMethod.POST);
82+
ResponseEntity response = postRequest.setHost(HOST)
83+
.setPort(port)
84+
.setEndpoint("/subscriptions")
85+
.addHeader("Content-type", "application/json")
86+
.setBody(subscriptionsJson.toString())
87+
.performRequest();
88+
assertEquals(200, response.getStatusCodeValue());
89+
}
90+
91+
92+
private ArrayNode setSubscriptionFields(ArrayNode subscriptionJson) {
93+
ObjectNode requirement = ((ObjectNode) subscriptionJson.get(0).get("requirements").get(0).get("conditions").get(0));
94+
requirement.put("jmespath", "id=='1100572b-c3j4-441e-abc9-b62f48080011'");
95+
96+
return subscriptionJson;
97+
}
98+
99+
100+
@When("^eiffel events are sent$")
101+
public void eiffel_events_are_sent() throws Throwable {
102+
103+
final URL upStreamInput = new File(UPSTREAM_INPUT_FILE).toURI().toURL();
104+
ArrayNode upstreamJson = (ArrayNode) objectMapper.readTree(upStreamInput);
105+
if (upstreamJson != null) {
106+
for (JsonNode event : upstreamJson) {
107+
String eventStr = event.toString();
108+
rabbitMqTemplate.convertAndSend(eventStr);
109+
}
110+
}
111+
112+
super.sendEventsAndConfirm();
113+
}
114+
115+
@Then("^mongodb should contain mail\\.$")
116+
public void mongodb_should_contain_mails() throws Throwable {
117+
JsonNode newestMailJson = getMailFromDatabase();
118+
String createdDate = newestMailJson.get("created").get("$date").asText();
119+
120+
long createdDateInMillis = ZonedDateTime.parse(createdDate).toInstant().toEpochMilli();
121+
assert(createdDateInMillis >= startTime): "Mail was not triggered. createdDateInMillis is less than startTime.";
122+
}
123+
124+
@Override
125+
protected String getRulesFilePath() {
126+
return RULES_FILE_PATH;
127+
}
128+
129+
@Override
130+
protected String getEventsFilePath() {
131+
return EVENTS_FILE_PATH;
132+
}
133+
134+
@Override
135+
protected int extraEventsCount() {
136+
return 8;
137+
}
138+
139+
@Override
140+
protected List<String> getEventNamesToSend() {
141+
List<String> eventNames = new ArrayList<>();
142+
eventNames.add("event_EiffelConfidenceLevelModifiedEvent_3_2");
143+
eventNames.add("event_EiffelArtifactPublishedEvent_3");
144+
eventNames.add("event_EiffelArtifactCreatedEvent_3");
145+
eventNames.add("event_EiffelTestCaseTriggeredEvent_3");
146+
eventNames.add("event_EiffelTestCaseStartedEvent_3");
147+
eventNames.add("event_EiffelTestCaseFinishedEvent_3");
148+
eventNames.add("event_EiffelArtifactPublishedEvent_3_1");
149+
eventNames.add("event_EiffelConfidenceLevelModifiedEvent_3");
150+
eventNames.add("event_EiffelTestCaseTriggeredEvent_3_1");
151+
eventNames.add("event_EiffelTestCaseStartedEvent_3_1");
152+
eventNames.add("event_EiffelTestCaseFinishedEvent_3_1");
153+
return eventNames;
154+
}
155+
156+
@Override
157+
protected Map<String, JsonNode> getCheckData() throws IOException {
158+
JsonNode expectedJSON = getJSONFromFile(AGGREGATED_OBJECT_FILE_PATH);
159+
Map<String, JsonNode> checkData = new HashMap<>();
160+
checkData.put(AGGREGATED_OBJECT_ID, expectedJSON);
161+
return checkData;
162+
}
163+
164+
private JsonNode getMailFromDatabase() throws IOException {
165+
ArrayList<String> allMails = mongoDBHandler.getAllDocuments(MAILHOG_DATABASE_NAME, "messages");
166+
String mailString = allMails.get(0);
167+
168+
return objectMapper.readTree(mailString);
169+
}
170+
}

0 commit comments

Comments
 (0)