16
16
*/
17
17
package com .ericsson .ei .waitlist ;
18
18
19
- import static org .junit .Assert .assertFalse ;
20
- import static org .junit .Assert .assertTrue ;
21
-
22
19
import com .ericsson .ei .flowtests .AMQPBrokerManager ;
20
+ import com .ericsson .ei .handlers .EventToObjectMapHandler ;
23
21
import com .ericsson .ei .handlers .MatchIdRulesHandler ;
24
22
import com .ericsson .ei .jmespath .JmesPathInterface ;
25
23
import com .ericsson .ei .mongodbhandler .MongoDBHandler ;
26
24
import com .ericsson .ei .rmqhandler .RmqHandler ;
27
25
import com .ericsson .ei .rules .RulesHandler ;
28
26
import com .ericsson .ei .rules .RulesObject ;
29
27
import com .fasterxml .jackson .databind .JsonNode ;
30
- import com .rabbitmq .client .AMQP ;
31
- import com .rabbitmq .client .Channel ;
32
- import com .rabbitmq .client .Connection ;
33
- import com .rabbitmq .client .ConnectionFactory ;
34
- import com .rabbitmq .client .Consumer ;
35
- import com .rabbitmq .client .DefaultConsumer ;
36
- import com .rabbitmq .client .Envelope ;
37
-
38
- import java .io .File ;
39
- import java .io .IOException ;
40
- import java .util .ArrayList ;
41
-
28
+ import com .rabbitmq .client .*;
42
29
import org .apache .commons .io .FileUtils ;
30
+ import org .json .JSONException ;
43
31
import org .junit .After ;
44
32
import org .junit .Before ;
45
33
import org .junit .Test ;
54
42
import org .springframework .amqp .rabbit .core .RabbitAdmin ;
55
43
import org .springframework .util .SocketUtils ;
56
44
45
+ import java .io .File ;
46
+ import java .io .IOException ;
47
+ import java .util .ArrayList ;
48
+ import java .util .List ;
49
+
50
+ import static org .junit .Assert .assertFalse ;
51
+ import static org .junit .Assert .assertTrue ;
52
+
57
53
public class TestWaitListWorker {
58
54
55
+ private static final String EVENT_PATH = "src/test/resources/EiffelArtifactCreatedEvent.json" ;
56
+ private static final String INPUT_1 = "src/test/resources/testWaitListinput1.json" ;
57
+ private static final String INPUT_2 = "src/test/resources/testWaitListinput2.json" ;
58
+
59
59
private static File qpidConfig = null ;
60
+ private static String jsonFileContent ;
60
61
static AMQPBrokerManager amqpBrocker ;
61
62
static ConnectionFactory cf ;
62
63
static Connection conn ;
63
- private static String jsonFileContent ;
64
- private ArrayList <String > list = new ArrayList <>();
65
- private final static String eventPath = "src/test/resources/EiffelArtifactCreatedEvent.json" ;
66
- private final String input1 = "src/test/resources/testWaitListinput1.json" ;
67
- private final String input2 = "src/test/resources/testWaitListinput2.json" ;
68
- protected String message ;
64
+
65
+ private List <String > list ;
66
+ private String message ;
69
67
70
68
@ InjectMocks
71
- WaitListWorker waitListWorker ;
69
+ private WaitListWorker waitListWorker ;
72
70
@ Mock
73
- RulesHandler rulesHandler ;
71
+ private RulesHandler rulesHandler ;
74
72
@ Mock
75
- MatchIdRulesHandler matchId ;
73
+ private MatchIdRulesHandler matchId ;
76
74
@ Mock
77
- RmqHandler rmqHandler ;
75
+ private RmqHandler rmqHandler ;
78
76
@ Mock
79
- WaitListStorageHandler waitListStorageHandler ;
77
+ private WaitListStorageHandler waitListStorageHandler ;
80
78
@ Mock
81
- MongoDBHandler mongoDBHandler ;
79
+ private MongoDBHandler mongoDBHandler ;
82
80
@ Mock
83
- ArrayList < String > newList ;
81
+ private JmesPathInterface jmesPathInterface ;
84
82
@ Mock
85
- JmesPathInterface jmesPathInterface ;
83
+ private JsonNode jsonNode ;
86
84
@ Mock
87
- JsonNode jsonNode ;
85
+ private RulesObject rulesObject ;
88
86
@ Mock
89
- RulesObject rulesObject ;
87
+ private EventToObjectMapHandler eventToObjectMapHandler ;
90
88
91
89
@ Before
92
90
public void init () throws Exception {
93
91
MockitoAnnotations .initMocks (this );
94
92
setupMB ();
95
- list .add (FileUtils .readFileToString (new File (input1 ), "UTF-8" ));
96
- list .add (FileUtils .readFileToString (new File (input2 ), "UTF-8" ));
93
+ list = new ArrayList <>();
94
+ list .add (FileUtils .readFileToString (new File (INPUT_1 ), "UTF-8" ));
95
+ list .add (FileUtils .readFileToString (new File (INPUT_2 ), "UTF-8" ));
97
96
Mockito .when (waitListStorageHandler .getWaitList ()).thenReturn (list );
98
97
Mockito .when (rulesHandler .getRulesForEvent (Mockito .anyString ())).thenReturn (rulesObject );
99
98
Mockito .when (jmesPathInterface .runRuleOnEvent (Mockito .anyString (), Mockito .anyString ())).thenReturn (jsonNode );
@@ -105,7 +104,7 @@ void setupMB() throws Exception {
105
104
System .setProperty ("rabbitmq.user" , "guest" );
106
105
System .setProperty ("rabbitmq.password" , "guest" );
107
106
String config = "src/test/resources/configs/qpidConfig.json" ;
108
- jsonFileContent = FileUtils .readFileToString (new File (eventPath ), "UTF-8" );
107
+ jsonFileContent = FileUtils .readFileToString (new File (EVENT_PATH ), "UTF-8" );
109
108
qpidConfig = new File (config );
110
109
amqpBrocker = new AMQPBrokerManager (qpidConfig .getAbsolutePath (), port );
111
110
amqpBrocker .startBroker ();
@@ -119,8 +118,22 @@ void setupMB() throws Exception {
119
118
}
120
119
121
120
@ Test
122
- public void testRunWithoutMatchObjects () {
123
- Mockito .when (matchId .fetchObjectsById (Mockito .anyObject (), Mockito .anyString ())).thenReturn (newList );
121
+ public void testRunWithoutMatchObjects () throws JSONException {
122
+ Mockito .when (eventToObjectMapHandler .isEventInEventObjectMap (Mockito .anyString ())).thenReturn (false );
123
+ Mockito .when (matchId .fetchObjectsById (Mockito .any (RulesObject .class ), Mockito .anyString ())).thenReturn (new ArrayList <>());
124
+ try {
125
+ waitListWorker .run ();
126
+ assertTrue (true );
127
+ } catch (Exception e ) {
128
+ assertFalse (true );
129
+ e .printStackTrace ();
130
+ }
131
+ }
132
+
133
+ @ Test
134
+ public void testRunWithMatchObjects () {
135
+ Mockito .when (eventToObjectMapHandler .isEventInEventObjectMap (Mockito .anyString ())).thenReturn (false );
136
+ Mockito .when (matchId .fetchObjectsById (Mockito .any (RulesObject .class ), Mockito .anyString ())).thenReturn (list );
124
137
try {
125
138
waitListWorker .run ();
126
139
assertTrue (true );
@@ -131,8 +144,8 @@ public void testRunWithoutMatchObjects() {
131
144
}
132
145
133
146
@ Test
134
- public void testRunWithMatchbjects () {
135
- Mockito .when (matchId . fetchObjectsById (Mockito .anyObject (), Mockito . anyString ())).thenReturn (list );
147
+ public void testRunIfEventExistsInEventObjectMap () {
148
+ Mockito .when (eventToObjectMapHandler . isEventInEventObjectMap (Mockito .anyString ())).thenReturn (true );
136
149
try {
137
150
waitListWorker .run ();
138
151
assertTrue (true );
@@ -157,7 +170,7 @@ public void testRunWithMatchbjects() {
157
170
// }
158
171
159
172
@ Test
160
- public void testPublishandReceiveEvent () {
173
+ public void testPublishAndReceiveEvent () {
161
174
try {
162
175
Channel channel = conn .createChannel ();
163
176
String queueName = "er001-eiffelxxx.eiffelintelligence.messageConsumer.durable" ;
0 commit comments