38
38
39
39
@ RunWith (SpringJUnit4ClassRunner .class )
40
40
@ SpringBootTest
41
- public class FlowTest2 {
41
+ public class FlowTest2 extends FlowTestBase {
42
42
43
43
private static Logger log = LoggerFactory .getLogger (FlowTest2 .class );
44
44
45
- public static File qpidConfig = null ;
46
- static AMQPBrokerManager amqpBrocker ;
47
- private static MongodForTestsFactory testsFactory ;
48
- static MongoClient mongoClient = null ;
49
- static Queue queue = null ;
50
- static RabbitAdmin admin ;
51
-
52
- @ Autowired
53
- private MongoDBHandler mongoDBHandler ;
54
-
55
- @ Autowired
56
- RmqHandler rmqHandler ;
57
-
58
- @ Autowired
59
- ObjectHandler objectHandler ;
60
-
61
- public static class AMQPBrokerManager {
62
- private String path ;
63
- private static final String PORT = "8672" ;
64
- private final Broker broker = new Broker ();
65
-
66
- public AMQPBrokerManager (String path ) {
67
- super ();
68
- this .path = path ;
69
- }
70
-
71
- public void startBroker () throws Exception {
72
- final BrokerOptions brokerOptions = new BrokerOptions ();
73
- brokerOptions .setConfigProperty ("qpid.amqp_port" , PORT );
74
- brokerOptions .setConfigProperty ("qpid.pass_file" , "src/test/resources/configs/password.properties" );
75
- brokerOptions .setInitialConfigurationLocation (path );
76
-
77
- broker .startup (brokerOptions );
78
- }
79
-
80
- public void stopBroker () {
81
- broker .shutdown ();
82
- }
83
- }
84
-
85
- static ConnectionFactory cf ;
86
- static Connection conn ;
87
- private static String jsonFileContent ;
88
- private static JsonNode parsedJason ;
89
- private static String jsonFilePath = "src/test/resources/test_events.json" ;
90
- static private final String inputFilePath = "src/test/resources/AggregatedDocument.json" ;
91
45
static private final String inputFilePath2 = "src/test/resources/AggregatedDocument2.json" ;
92
46
93
- @ BeforeClass
94
- public static void setup () throws Exception {
95
- System .setProperty ("flow.test" , "true" );
96
- System .setProperty ("eiffel.intelligence.processedEventsCount" , "0" );
97
- System .setProperty ("eiffel.intelligence.waitListEventsCount" , "0" );
98
- setUpMessageBus ();
99
- setUpEmbeddedMongo ();
100
- }
101
-
102
- @ PostConstruct
103
- public void initMocks () {
104
- mongoDBHandler .setMongoClient (mongoClient );
105
- }
106
-
107
- public static void setUpMessageBus () throws Exception {
108
- System .setProperty ("rabbitmq.port" , "8672" );
109
- System .setProperty ("rabbitmq.user" , "guest" );
110
- System .setProperty ("rabbitmq.password" , "guest" );
111
-
47
+ protected ArrayList <String > getEventNamesToSend () {
48
+ ArrayList <String > eventNames = new ArrayList <>();
49
+ eventNames .add ("event_EiffelArtifactCreatedEvent_3" );
50
+ eventNames .add ("event_EiffelArtifactPublishedEvent_3" );
51
+ eventNames .add ("event_EiffelConfidenceLevelModifiedEvent_3_2" );
52
+ eventNames .add ("event_EiffelTestCaseStartedEvent_3" );
53
+ eventNames .add ("event_EiffelTestCaseFinishedEvent_3" );
112
54
113
- String config = "src/test/resources/configs/qpidConfig.json" ;
114
- jsonFileContent = FileUtils .readFileToString (new File (jsonFilePath ));
115
- ObjectMapper objectmapper = new ObjectMapper ();
116
- parsedJason = objectmapper .readTree (jsonFileContent );
117
- qpidConfig = new File (config );
118
- amqpBrocker = new AMQPBrokerManager (qpidConfig .getAbsolutePath ());
119
- amqpBrocker .startBroker ();
120
- cf = new ConnectionFactory ();
121
- cf .setUsername ("guest" );
122
- cf .setPassword ("guest" );
123
- cf .setPort (8672 );
124
- conn = cf .newConnection ();
125
- }
55
+ eventNames .add ("event_EiffelArtifactCreatedEvent_1" );
56
+ eventNames .add ("event_EiffelArtifactPublishedEvent_1" );
57
+ eventNames .add ("event_EiffelConfidenceLevelModifiedEvent_1" );
58
+ eventNames .add ("event_EiffelTestCaseStartedEvent_1" );
59
+ eventNames .add ("event_EiffelTestCaseFinishedEvent_1" );
126
60
127
- public static void setUpEmbeddedMongo () throws Exception {
128
- testsFactory = MongodForTestsFactory .with (Version .V3_4_1 );
129
- mongoClient = testsFactory .newMongo ();
61
+ return eventNames ;
130
62
}
131
63
132
- @ AfterClass
133
- public static void tearDown () throws Exception {
134
- if ( amqpBrocker != null )
135
- amqpBrocker . stopBroker ();
136
-
137
- try {
138
- conn . close ();
139
- } catch ( Exception e ) {
140
- //We try to close the connection but if
141
- //the connection is closed we just receive the
142
- //exception and go on
64
+ protected void waitForEventsToBeProcessed ( int eventsCount ) {
65
+ // wait for all events to be processed
66
+ int processedEvents = 0 ;
67
+ while ( processedEvents < eventsCount ) {
68
+ String countStr = System . getProperty ( "eiffel.intelligence.processedEventsCount" );
69
+ String waitingCountStr = System . getProperty ( "eiffel.intelligence.waitListEventsCount" );
70
+ if ( waitingCountStr == null )
71
+ waitingCountStr = "0" ;
72
+ Properties props = admin . getQueueProperties ( queue . getName ());
73
+ int messageCount = Integer . parseInt ( props . get ( "QUEUE_MESSAGE_COUNT" ). toString ());
74
+ processedEvents = Integer . parseInt ( countStr ) - Integer . parseInt ( waitingCountStr ) - messageCount ;
143
75
}
144
76
}
145
77
146
- @ Test
147
- public void test2AgregatedObjects () {
78
+ protected void checkResult () {
148
79
try {
149
- String queueName = rmqHandler .getQueueName ();
150
- Channel channel = conn .createChannel ();
151
- String exchange = "ei-poc-4" ;
152
- createExchange (exchange , queueName );
153
-
154
-
155
- ArrayList <String > eventNames = getEventNamesToSend ();
156
- int eventsCount = eventNames .size ();
157
- for (String eventName : eventNames ) {
158
- JsonNode eventJson = parsedJason .get (eventName );
159
- String event = eventJson .toString ();
160
- channel .basicPublish (exchange , queueName , null , event .getBytes ());
161
- }
162
-
163
- // wait for all events to be processed
164
- int processedEvents = 0 ;
165
- while (processedEvents < eventsCount ) {
166
- String countStr = System .getProperty ("eiffel.intelligence.processedEventsCount" );
167
- String waitingCountStr = System .getProperty ("eiffel.intelligence.waitListEventsCount" );
168
- if (waitingCountStr == null )
169
- waitingCountStr = "0" ;
170
- Properties props = admin .getQueueProperties (queue .getName ());
171
- int messageCount = Integer .parseInt (props .get ("QUEUE_MESSAGE_COUNT" ).toString ());
172
- processedEvents = Integer .parseInt (countStr ) - Integer .parseInt (waitingCountStr ) - messageCount ;
173
- }
174
-
175
80
String document = objectHandler .findObjectById ("6acc3c87-75e0-4b6d-88f5-b1a5d4e62b43" );
176
81
String expectedDocument = FileUtils .readFileToString (new File (inputFilePath ));
177
82
ObjectMapper objectmapper = new ObjectMapper ();
@@ -188,32 +93,4 @@ public void test2AgregatedObjects() {
188
93
log .info (e .getMessage (),e );
189
94
}
190
95
}
191
-
192
- private ArrayList <String > getEventNamesToSend () {
193
- ArrayList <String > eventNames = new ArrayList <>();
194
- eventNames .add ("event_EiffelArtifactCreatedEvent_3" );
195
- eventNames .add ("event_EiffelArtifactPublishedEvent_3" );
196
- eventNames .add ("event_EiffelConfidenceLevelModifiedEvent_3_2" );
197
- eventNames .add ("event_EiffelTestCaseStartedEvent_3" );
198
- eventNames .add ("event_EiffelTestCaseFinishedEvent_3" );
199
-
200
- eventNames .add ("event_EiffelArtifactCreatedEvent_1" );
201
- eventNames .add ("event_EiffelArtifactPublishedEvent_1" );
202
- eventNames .add ("event_EiffelConfidenceLevelModifiedEvent_1" );
203
- eventNames .add ("event_EiffelTestCaseStartedEvent_1" );
204
- eventNames .add ("event_EiffelTestCaseFinishedEvent_1" );
205
-
206
- return eventNames ;
207
- }
208
-
209
- private void createExchange (final String exchangeName , final String queueName ) {
210
- final CachingConnectionFactory ccf = new CachingConnectionFactory (cf );
211
- admin = new RabbitAdmin (ccf );
212
- queue = new Queue (queueName , false );
213
- admin .declareQueue (queue );
214
- final TopicExchange exchange = new TopicExchange (exchangeName );
215
- admin .declareExchange (exchange );
216
- admin .declareBinding (BindingBuilder .bind (queue ).to (exchange ).with ("#" ));
217
- ccf .destroy ();
218
- }
219
96
}
0 commit comments