13
13
*/
14
14
package com .ericsson .ei .flowtests ;
15
15
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
-
27
16
import java .io .File ;
28
17
import java .io .IOException ;
29
18
import java .util .HashMap ;
40
29
import org .skyscreamer .jsonassert .JSONAssert ;
41
30
import org .slf4j .Logger ;
42
31
import org .slf4j .LoggerFactory ;
32
+ import org .springframework .amqp .rabbit .connection .ConnectionFactory ;
43
33
import org .springframework .beans .factory .annotation .Autowired ;
44
34
import org .springframework .beans .factory .annotation .Value ;
45
35
import org .springframework .test .context .TestContext ;
46
36
import org .springframework .test .context .support .AbstractTestExecutionListener ;
47
37
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
+
48
50
/**
49
51
* @author evasiba
50
52
*
@@ -65,6 +67,9 @@ public abstract class FlowTestBase extends AbstractTestExecutionListener {
65
67
@ Autowired
66
68
private MongoDBHandler mongoDBHandler ;
67
69
70
+ @ Autowired
71
+ private ConnectionFactory connectionFactory ;
72
+
68
73
@ Autowired
69
74
private WaitListStorageHandler waitlist ;
70
75
@@ -78,24 +83,36 @@ public abstract class FlowTestBase extends AbstractTestExecutionListener {
78
83
79
84
private static HashMap <String , FlowTestConfigs > configsMap = new HashMap <String , FlowTestConfigs >();
80
85
86
+ @ Value ("${systemTest:false}" )
87
+ protected boolean systemTest ;
88
+
81
89
@ Override
82
90
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
+ }
86
98
}
87
99
88
100
@ PostConstruct
89
101
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
+ }
92
107
}
93
108
94
109
@ After
95
110
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
+ }
99
116
}
100
117
101
118
protected FlowTestConfigs getFlowTestConfigs () {
@@ -128,8 +145,8 @@ public void setFirstEventWaitTime(int value) {
128
145
129
146
/**
130
147
* 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
133
150
*
134
151
* @return
135
152
*/
@@ -141,9 +158,16 @@ protected int extraEventsCount() {
141
158
public void flowTest () {
142
159
try {
143
160
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
+ }
145
167
String exchangeName = "ei-poc-4" ;
146
- getFlowTestConfigs ().createExchange (exchangeName , queueName );
168
+ if (!systemTest ) {
169
+ getFlowTestConfigs ().createExchange (exchangeName , queueName );
170
+ }
147
171
148
172
rulesHandler .setRulePath (getRulesFilePath ());
149
173
@@ -155,7 +179,11 @@ public void flowTest() {
155
179
for (String eventName : eventNames ) {
156
180
JsonNode eventJson = parsedJSON .get (eventName );
157
181
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
+ }
159
187
if (!alreadyExecuted ) {
160
188
try {
161
189
TimeUnit .MILLISECONDS .sleep (firstEventWaitTime );
@@ -191,8 +219,8 @@ public void flowTest() {
191
219
abstract List <String > getEventNamesToSend ();
192
220
193
221
/**
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
196
224
*
197
225
*/
198
226
abstract Map <String , JsonNode > getCheckData () throws IOException ;
@@ -204,7 +232,13 @@ JsonNode getJSONFromFile(String filePath) throws IOException {
204
232
205
233
// count documents that were processed
206
234
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 );
208
242
MongoCollection table = db .getCollection (collection );
209
243
return table .count ();
210
244
}
0 commit comments