Skip to content

Commit 41078fa

Browse files
change flow to run as system test with local ER
change flow to run as system test with local ER, MongoDB and Rabbitmq.
1 parent db231b4 commit 41078fa

File tree

10 files changed

+441
-50
lines changed

10 files changed

+441
-50
lines changed

pom.xml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
<output-relative-path>src/main/java</output-relative-path>
2121
<raml-path>src/main/resources/public/raml/instance_info.raml</raml-path>
2222
<raml-path>src/main/resources/public/raml/eiffel-intelligence.raml</raml-path>
23-
<base-package>com.ericsson.ei.controller</base-package>
23+
<base-package>com.ericsson.ei.controller</base-package>
24+
<skipTests>false</skipTests>
25+
<skipITs>${skipTests}</skipITs>
26+
<skipUnitTests>${skipTests}</skipUnitTests>
2427
</properties>
2528

2629
<repositories>
@@ -350,7 +353,8 @@
350353
<version>2.20</version>
351354
<configuration>
352355
<forkCount>2C</forkCount>
353-
<reuseForks>false</reuseForks>
356+
<reuseForks>false</reuseForks>
357+
<skipTests>${skipUnitTests}</skipTests>
354358
<excludes>
355359
<exclude>${someModule.test.excludes}</exclude>
356360
</excludes>
@@ -359,6 +363,40 @@
359363
</includes>
360364
</configuration>
361365
</plugin>
366+
367+
<plugin>
368+
<groupId>org.apache.maven.plugins</groupId>
369+
<artifactId>maven-failsafe-plugin</artifactId>
370+
<version>3.0.0-M1</version>
371+
<executions>
372+
<execution>
373+
<id>integration-test</id>
374+
<goals>
375+
<goal>integration-test</goal>
376+
<goal>verify</goal>
377+
</goals>
378+
<phase>integration-test</phase>
379+
<configuration>
380+
<skipTests>${skipTests}</skipTests>
381+
<skipITs>${skipITs}</skipITs>
382+
<systemPropertyVariables>
383+
<systemTest>true</systemTest>
384+
<er.url>http://localhost:8080/eventrepository/search/</er.url>
385+
</systemPropertyVariables>
386+
<excludes>
387+
<exclude>**/test/*</exclude>
388+
<exclude>**/functionaltests/*</exclude>
389+
</excludes>
390+
<includes>
391+
<include>**/FlowTest.class</include>
392+
</includes>
393+
<additionalClasspathElements>
394+
<additionalClasspathElement>${basedir}/target/classes</additionalClasspathElement>
395+
</additionalClasspathElements>
396+
</configuration>
397+
</execution>
398+
</executions>
399+
</plugin>
362400

363401
<plugin>
364402
<groupId>org.apache.maven.plugins</groupId>

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ ldap.username:
126126
# password should be encoded. It will be decoded in EndpointSecurity.java.
127127
# Password needs to be encoded with base64.
128128
ldap.password:
129-
ldap.user.filter:
129+
ldap.user.filter:

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.junit.runner.RunWith;
3434
import org.mockito.Mock;
3535
import org.mockito.MockitoAnnotations;
36+
import org.springframework.amqp.rabbit.core.RabbitTemplate;
3637
import org.springframework.beans.factory.annotation.Autowired;
3738
import org.springframework.boot.test.context.SpringBootTest;
3839
import org.springframework.http.HttpStatus;
@@ -47,6 +48,7 @@
4748
import com.ericsson.ei.handlers.UpStreamEventsHandler;
4849
import com.fasterxml.jackson.databind.JsonNode;
4950
import com.fasterxml.jackson.databind.ObjectMapper;
51+
import com.fasterxml.jackson.databind.node.ArrayNode;
5052
import com.fasterxml.jackson.databind.node.ObjectNode;
5153

5254
@RunWith(SpringJUnit4ClassRunner.class)
@@ -55,6 +57,7 @@
5557
public class FlowTest extends FlowTestBase {
5658

5759
private static final String UPSTREAM_RESULT_FILE = "upStreamResultFile.json";
60+
private static final String UPSTREAM_INPUT_FILE = "upStreamInput.json";
5861
private static final String RULES_FILE_PATH = "src/test/resources/ArtifactRules_new.json";
5962
private static final String EVENTS_FILE_PATH = "src/test/resources/test_events.json";
6063
private static final String AGGREGATED_OBJECT_FILE_PATH = "src/test/resources/AggregatedDocumentInternalCompositionLatest.json";
@@ -66,19 +69,35 @@ public class FlowTest extends FlowTestBase {
6669
@Mock
6770
private ERQueryService erQueryService;
6871

72+
@Autowired
73+
private RabbitTemplate rabbitMqTemplate;
74+
6975
@Before
7076
public void before() throws IOException {
71-
MockitoAnnotations.initMocks(this);
72-
upStreamEventsHandler.setEventRepositoryQueryService(erQueryService);
73-
74-
final URL upStreamResult = this.getClass().getClassLoader().getResource(UPSTREAM_RESULT_FILE);
7577
ObjectMapper objectMapper = new ObjectMapper();
76-
ObjectNode objectNode = objectMapper.createObjectNode();
77-
objectNode.set("upstreamLinkObjects", objectMapper.readTree(upStreamResult));
78-
objectNode.set("downstreamLinkObjects", objectMapper.createArrayNode());
7978

80-
when(erQueryService.getEventStreamDataById(anyString(), any(SearchOption.class), anyInt(), anyInt(),
81-
anyBoolean())).thenReturn(new ResponseEntity<>(objectNode, HttpStatus.OK));
79+
if (!systemTest) {
80+
final URL upStreamResult = this.getClass().getClassLoader().getResource(UPSTREAM_RESULT_FILE);
81+
MockitoAnnotations.initMocks(this);
82+
upStreamEventsHandler.setEventRepositoryQueryService(erQueryService);
83+
84+
ObjectNode objectNode = objectMapper.createObjectNode();
85+
JsonNode upstreamJson = objectMapper.readTree(upStreamResult);
86+
objectNode.set("upstreamLinkObjects", upstreamJson);
87+
objectNode.set("downstreamLinkObjects", objectMapper.createArrayNode());
88+
89+
when(erQueryService.getEventStreamDataById(anyString(), any(SearchOption.class), anyInt(), anyInt(),
90+
anyBoolean())).thenReturn(new ResponseEntity<>(objectNode, HttpStatus.OK));
91+
} else {
92+
final URL upStreamInput = this.getClass().getClassLoader().getResource(UPSTREAM_INPUT_FILE);
93+
ArrayNode upstreamJson = (ArrayNode) objectMapper.readTree(upStreamInput);
94+
if (upstreamJson != null) {
95+
for (JsonNode event : upstreamJson) {
96+
String eventStr = event.toString();
97+
rabbitMqTemplate.convertAndSend(eventStr);
98+
}
99+
}
100+
}
82101
}
83102

84103
@Override

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

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

16-
import com.ericsson.ei.handlers.ObjectHandler;
17-
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
18-
import com.ericsson.ei.rmqhandler.RmqHandler;
19-
import com.ericsson.ei.rules.RulesHandler;
20-
import com.ericsson.ei.waitlist.WaitListStorageHandler;
21-
import com.fasterxml.jackson.databind.JsonNode;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import com.mongodb.client.MongoCollection;
24-
import com.mongodb.client.MongoDatabase;
25-
import com.rabbitmq.client.Channel;
26-
2716
import java.io.File;
2817
import java.io.IOException;
2918
import java.util.HashMap;
@@ -40,11 +29,24 @@
4029
import org.skyscreamer.jsonassert.JSONAssert;
4130
import org.slf4j.Logger;
4231
import org.slf4j.LoggerFactory;
32+
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
4333
import org.springframework.beans.factory.annotation.Autowired;
4434
import org.springframework.beans.factory.annotation.Value;
4535
import org.springframework.test.context.TestContext;
4636
import org.springframework.test.context.support.AbstractTestExecutionListener;
4737

38+
import com.ericsson.ei.handlers.ObjectHandler;
39+
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
40+
import com.ericsson.ei.rmqhandler.RmqHandler;
41+
import com.ericsson.ei.rules.RulesHandler;
42+
import com.ericsson.ei.waitlist.WaitListStorageHandler;
43+
import com.fasterxml.jackson.databind.JsonNode;
44+
import com.fasterxml.jackson.databind.ObjectMapper;
45+
import com.mongodb.MongoClient;
46+
import com.mongodb.client.MongoCollection;
47+
import com.mongodb.client.MongoDatabase;
48+
import com.rabbitmq.client.Channel;
49+
4850
/**
4951
* @author evasiba
5052
*
@@ -65,6 +67,9 @@ public abstract class FlowTestBase extends AbstractTestExecutionListener {
6567
@Autowired
6668
private MongoDBHandler mongoDBHandler;
6769

70+
@Autowired
71+
private ConnectionFactory connectionFactory;
72+
6873
@Autowired
6974
private WaitListStorageHandler waitlist;
7075

@@ -78,24 +83,36 @@ public abstract class FlowTestBase extends AbstractTestExecutionListener {
7883

7984
private static HashMap<String, FlowTestConfigs> configsMap = new HashMap<String, FlowTestConfigs>();
8085

86+
@Value("${systemTest:false}")
87+
protected boolean systemTest;
88+
8189
@Override
8290
public void beforeTestClass(TestContext testContext) throws Exception {
83-
System.setProperty("flow.test", "true");
84-
createFlowTestConfigs();
85-
getFlowTestConfigs().init();
91+
String systemTestProperty = System.getProperty("systemTest");
92+
Boolean systemTestValue = Boolean.parseBoolean(systemTestProperty);
93+
if (!systemTestValue) {
94+
System.setProperty("flow.test", "true");
95+
createFlowTestConfigs();
96+
getFlowTestConfigs().init();
97+
}
8698
}
8799

88100
@PostConstruct
89101
public void init() {
90-
mongoDBHandler.setMongoClient(getFlowTestConfigs().getMongoClient());
91-
waitlist.setMongoDbHandler(mongoDBHandler);
102+
LOGGER.info("System Test is: " + systemTest);
103+
if (!systemTest) {
104+
mongoDBHandler.setMongoClient(getFlowTestConfigs().getMongoClient());
105+
waitlist.setMongoDbHandler(mongoDBHandler);
106+
}
92107
}
93108

94109
@After
95110
public void teardown() {
96-
mongoDBHandler.setMongoClient(null);
97-
getFlowTestConfigs().tearDown();
98-
cleanFlowTestConfigs();
111+
if (!systemTest) {
112+
mongoDBHandler.setMongoClient(null);
113+
getFlowTestConfigs().tearDown();
114+
cleanFlowTestConfigs();
115+
}
99116
}
100117

101118
protected FlowTestConfigs getFlowTestConfigs() {
@@ -128,8 +145,8 @@ public void setFirstEventWaitTime(int value) {
128145

129146
/**
130147
* Override this if you have more events that will be registered to event to
131-
* object map but it is not visible in the test. For example from upstream
132-
* or downstream from event repository
148+
* object map but it is not visible in the test. For example from upstream or
149+
* downstream from event repository
133150
*
134151
* @return
135152
*/
@@ -141,9 +158,16 @@ protected int extraEventsCount() {
141158
public void flowTest() {
142159
try {
143160
String queueName = rmqHandler.getQueueName();
144-
Channel channel = getFlowTestConfigs().getConn().createChannel();
161+
Channel channel = null;
162+
if (!systemTest) {
163+
channel = getFlowTestConfigs().getConn().createChannel();
164+
} else {
165+
channel = connectionFactory.createConnection().createChannel(true);
166+
}
145167
String exchangeName = "ei-poc-4";
146-
getFlowTestConfigs().createExchange(exchangeName, queueName);
168+
if (!systemTest) {
169+
getFlowTestConfigs().createExchange(exchangeName, queueName);
170+
}
147171

148172
rulesHandler.setRulePath(getRulesFilePath());
149173

@@ -155,7 +179,11 @@ public void flowTest() {
155179
for (String eventName : eventNames) {
156180
JsonNode eventJson = parsedJSON.get(eventName);
157181
String event = eventJson.toString();
158-
channel.basicPublish(exchangeName, queueName, null, event.getBytes());
182+
if (!systemTest) {
183+
channel.basicPublish(exchangeName, queueName, null, event.getBytes());
184+
} else {
185+
rmqHandler.publishObjectToWaitlistQueue(event);
186+
}
159187
if (!alreadyExecuted) {
160188
try {
161189
TimeUnit.MILLISECONDS.sleep(firstEventWaitTime);
@@ -191,8 +219,8 @@ public void flowTest() {
191219
abstract List<String> getEventNamesToSend();
192220

193221
/**
194-
* @return map, where key - _id of expected aggregated object value -
195-
* expected aggregated object
222+
* @return map, where key - _id of expected aggregated object value - expected
223+
* aggregated object
196224
*
197225
*/
198226
abstract Map<String, JsonNode> getCheckData() throws IOException;
@@ -204,7 +232,13 @@ JsonNode getJSONFromFile(String filePath) throws IOException {
204232

205233
// count documents that were processed
206234
private long countProcessedEvents(String database, String collection) {
207-
MongoDatabase db = getFlowTestConfigs().getMongoClient().getDatabase(database);
235+
MongoClient mongoClient = null;
236+
if (!systemTest) {
237+
mongoClient = getFlowTestConfigs().getMongoClient();
238+
} else {
239+
mongoClient = mongoDBHandler.getMongoClient();
240+
}
241+
MongoDatabase db = mongoClient.getDatabase(database);
208242
MongoCollection table = db.getCollection(collection);
209243
return table.count();
210244
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.ericsson.ei.flowtests;
22

3-
import com.mongodb.MongoClient;
4-
import com.rabbitmq.client.Connection;
5-
import com.rabbitmq.client.ConnectionFactory;
6-
73
import java.io.File;
84
import java.io.IOException;
95

@@ -16,6 +12,10 @@
1612
import org.springframework.amqp.rabbit.core.RabbitAdmin;
1713
import org.springframework.util.SocketUtils;
1814

15+
import com.mongodb.MongoClient;
16+
import com.rabbitmq.client.Connection;
17+
import com.rabbitmq.client.ConnectionFactory;
18+
1919
import de.flapdoodle.embed.mongo.distribution.Version;
2020
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
2121
import lombok.Getter;
@@ -48,7 +48,7 @@ private void setUpMessageBus() throws Exception {
4848
System.setProperty("rabbitmq.password", "guest");
4949
System.setProperty("waitlist.initialDelayResend", "500");
5050
System.setProperty("waitlist.fixedRateResend", "100");
51-
51+
LOGGER.info("setting up message buss");
5252
String config = "src/test/resources/configs/qpidConfig.json";
5353
File qpidConfig = new File(config);
5454
amqpBroker = new AMQPBrokerManager(qpidConfig.getAbsolutePath(), port);
@@ -68,7 +68,7 @@ private void setUpEmbeddedMongo() throws IOException {
6868
try {
6969
testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
7070
mongoClient = testsFactory.newMongo();
71-
String port = "" + mongoClient.getAddress().getPort();
71+
String port = "" + mongoClient.getAddress().getPort();
7272
System.setProperty("spring.data.mongodb.port", port);
7373
} catch (Exception e) {
7474
LOGGER.error(e.getMessage(), e);

src/test/resources/AggregatedDocumentInternalCompositionLatest.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
},
5454
"issues":[
5555

56-
]
57-
},
56+
],
57+
"sourceCreations":[
5858
{
5959
"SCCEventId":"552ad6a4-c522-47e2-9195-0481930979e4",
6060
"author":null,
@@ -68,6 +68,8 @@
6868
}
6969
]
7070
}
71+
]
72+
}
7173
]
7274
}
7375
],

src/test/resources/test_events.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
"type": "COMPOSITION"
197197
},
198198
{
199-
"target": "1100572b-c3j4-441e-abc9-b62f48080011",
199+
"target": "1100572b-c3b4-461e-abc9-b62f48087011",
200200
"type": "PREVIOUS_VERSION"
201201
},
202202
{

0 commit comments

Comments
 (0)