76048f53415b8ddab0ef1c2fde20e88248ee945c
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.common.rules.test;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.List;
26 import java.util.UUID;
27 import java.util.function.Supplier;
28 import java.util.stream.Collectors;
29 import lombok.AccessLevel;
30 import lombok.Getter;
31 import org.junit.Test;
32 import org.onap.policy.appc.Request;
33 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
34 import org.onap.policy.common.utils.coder.Coder;
35 import org.onap.policy.common.utils.coder.CoderException;
36 import org.onap.policy.common.utils.coder.StandardCoder;
37 import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
38 import org.onap.policy.controlloop.ControlLoopNotificationType;
39 import org.onap.policy.controlloop.VirtualControlLoopNotification;
40 import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager2;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
42 import org.onap.policy.sdnr.PciMessage;
43
44 /**
45  * Superclass used for rule tests.
46  */
47 public abstract class BaseTest {
48     private static final String APPC_RESTART_OP = "restart";
49     private static final String APPC_MODIFY_CONFIG_OP = "ModifyConfig";
50
51     /*
52      * Canonical Topic Names.
53      */
54     protected static final String DCAE_TOPIC = "DCAE_TOPIC";
55     protected static final String APPC_LCM_WRITE_TOPIC = "APPC-LCM-WRITE";
56     protected static final String POLICY_CL_MGT_TOPIC = "POLICY-CL-MGT";
57     protected static final String APPC_LCM_READ_TOPIC = "APPC-LCM-READ";
58     protected static final String APPC_CL_TOPIC = "APPC-CL";
59     protected static final String SDNR_CL_TOPIC = "SDNR-CL";
60     protected static final String SDNR_CL_RSP_TOPIC = "SDNR-CL-RSP";
61
62     /*
63      * Constants for each test case.
64      */
65
66     // service123 (i.e., multi-operation policy)
67     private static final String SERVICE123_TOSCA_COMPLIANT_POLICY = "service123/tosca-compliant-service123.json";
68     private static final String SERVICE123_ONSET = "service123/service123.onset.json";
69     private static final String SERVICE123_APPC_RESTART_FAILURE = "service123/service123.appc.restart.failure.json";
70     private static final String SERVICE123_APPC_REBUILD_FAILURE = "service123/service123.appc.rebuild.failure.json";
71     private static final String SERVICE123_APPC_MIGRATE_SUCCESS = "service123/service123.appc.migrate.success.json";
72
73     // duplicates (i.e., mutliple events in the engine at the same time)
74     private static final String DUPLICATES_TOSCA_COMPLIANT_POLICY = "duplicates/tosca-compliant-duplicates.json";
75     private static final String DUPLICATES_ONSET_1 = "duplicates/duplicates.onset.1.json";
76     private static final String DUPLICATES_ONSET_2 = "duplicates/duplicates.onset.2.json";
77     private static final String DUPLICATES_APPC_SUCCESS = "duplicates/duplicates.appc.success.json";
78
79     // VCPE
80     private static final String VCPE_TOSCA_COMPLIANT_POLICY = "vcpe/tosca-compliant-vcpe.json";
81     private static final String VCPE_ONSET_1 = "vcpe/vcpe.onset.1.json";
82     private static final String VCPE_ONSET_2 = "vcpe/vcpe.onset.2.json";
83     private static final String VCPE_ONSET_3 = "vcpe/vcpe.onset.3.json";
84     private static final String VCPE_APPC_SUCCESS = "vcpe/vcpe.appc.success.json";
85
86     // VDNS
87     private static final String VDNS_TOSCA_COMPLIANT_POLICY = "vdns/tosca-compliant-vdns.json";
88     private static final String VDNS_TOSCA_COMPLIANT_RAINY_POLICY = "vdns/tosca-compliant-vdns-rainy.json";
89     private static final String VDNS_ONSET = "vdns/vdns.onset.json";
90
91     // VFW
92     private static final String VFW_TOSCA_COMPLIANT_POLICY = "vfw/tosca-compliant-vfw.json";
93     private static final String VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY = "vfw/tosca-compliant-timeout-vfw.json";
94     private static final String VFW_ONSET = "vfw/vfw.onset.json";
95     private static final String VFW_APPC_SUCCESS = "vfw/vfw.appc.success.json";
96     private static final String VFW_APPC_FAILURE = "vfw/vfw.appc.failure.json";
97
98     // VPCI
99     private static final String VPCI_TOSCA_COMPLIANT_POLICY = "vpci/tosca-compliant-vpci.json";
100     private static final String VPCI_ONSET = "vpci/vpci.onset.json";
101     private static final String VPCI_SDNR_SUCCESS = "vpci/vpci.sdnr.success.json";
102
103     // VSONH
104     private static final String VSONH_TOSCA_COMPLIANT_POLICY = "vsonh/tosca-compliant-vsonh.json";
105     private static final String VSONH_ONSET = "vsonh/vsonh.onset.json";
106     private static final String VSONH_SDNR_SUCCESS = "vsonh/vsonh.sdnr.success.json";
107
108     /*
109      * Coders used to decode requests and responses.
110      */
111     protected static final Coder APPC_LEGACY_CODER = new StandardCoderInstantAsMillis();
112     protected static final Coder APPC_LCM_CODER = new StandardCoder();
113     protected static final Coder POLICY_CL_MGT_CODER = new PolicyClMgtCoder();
114
115     /*
116      * Coders used to decode requests and responses.
117      */
118     private static final Coder SDNR_CODER = new StandardCoder();
119
120     // these may be overridden by junit tests
121     protected static Supplier<HttpClients> httpClientMaker = HttpClients::new;
122     protected static Supplier<Simulators> simMaker = Simulators::new;
123     protected static Supplier<Topics> topicMaker = Topics::new;
124
125     protected static Rules rules;
126     protected static HttpClients httpClients;
127     protected static Simulators simulators;
128
129     // used to inject and wait for messages
130     @Getter(AccessLevel.PROTECTED)
131     protected static Topics topics;
132
133     // used to wait for messages on SINK topics
134     protected Listener<VirtualControlLoopNotification> policyClMgt;
135     protected Listener<Request> appcClSink;
136     protected Listener<AppcLcmDmaapWrapper> appcLcmRead;
137     protected Listener<PciMessage> sdnrClSink;
138
139     /*
140      * Tosca Policy that was loaded.
141      */
142     protected ToscaPolicy policy;
143
144     /**
145      * Initializes {@link #rules}, {@link #httpClients}, and {@link #simulators}.
146      */
147     public static void initStatics() {
148         httpClients = httpClientMaker.get();
149         simulators = simMaker.get();
150     }
151
152     /**
153      * Destroys {@link #httpClients}, {@link #simulators}, and {@link #rules}.
154      */
155     public static void finishStatics() {
156         httpClients.destroy();
157         simulators.destroy();
158     }
159
160     /**
161      * Initializes {@link #topics} and {@link #controller}.
162      */
163     public void init() {
164         topics = topicMaker.get();
165     }
166
167     /**
168      * Destroys {@link #topics} and resets the rule facts.
169      */
170     public void finish() {
171         topics.destroy();
172     }
173
174     // Service123 (i.e., Policy with multiple operations)
175
176     /**
177      * Service123 with Tosca Compliant Policy.
178      */
179     @Test
180     public void testService123Compliant() {
181         policyClMgt = createNoficationTopicListener();
182         appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
183         policy = checkPolicy(SERVICE123_TOSCA_COMPLIANT_POLICY);
184
185         // inject an ONSET event over the DCAE topic
186         topics.inject(DCAE_TOPIC, SERVICE123_ONSET);
187         /* Wait to acquire a LOCK and a PDP-X PERMIT */
188
189         waitForLockAndPermit(policy, policyClMgt);
190
191         // restart request should be sent and fail four times (i.e., because retry=3)
192         for (int count = 0; count < 4; ++count) {
193             AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
194
195             topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_RESTART_FAILURE,
196                             appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
197         }
198         // rebuild request should be sent and fail once
199         AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> "rebuild".equals(req.getRpcName()));
200         topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_REBUILD_FAILURE,
201                         appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
202         // migrate request should be sent and succeed
203         appcreq = appcLcmRead.await(req -> "migrate".equals(req.getRpcName()));
204         topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_MIGRATE_SUCCESS,
205                         appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
206         /* --- Operation Completed --- */
207         waitForOperationSuccess();
208         /* --- Transaction Completed --- */
209         waitForFinalSuccess(policy, policyClMgt);
210     }
211
212     // Duplicate events
213
214     /**
215      * This test case tests the scenario where 3 events occur and 2 of the requests refer
216      * to the same target entity while the 3rd is for another entity. The expected result
217      * is that the event with the duplicate target entity will have a final success result
218      * for one of the events, and a rejected message for the one that was unable to obtain
219      * the lock. The event that is referring to a different target entity should be able
220      * to obtain a lock since it is a different target. After processing of all events
221      * there should only be the policy and params objects left in memory.
222      */
223     @Test
224     public void testDuplicatesEvents() {
225         policyClMgt = createNoficationTopicListener();
226         appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
227
228         policy = checkPolicy(DUPLICATES_TOSCA_COMPLIANT_POLICY);
229
230         final long initCount = getCreateCount();
231
232         /*
233          * Inject ONSET events over the DCAE topic. First and last have the same target
234          * entity, but different request IDs - only one should succeed. The middle one is
235          * for a different target entity, so it should succeed.
236          */
237         topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
238         topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_2);
239         topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
240
241         // should see two restarts
242         for (int count = 0; count < 2; ++count) {
243             AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
244
245             // indicate success
246             topics.inject(APPC_LCM_WRITE_TOPIC, DUPLICATES_APPC_SUCCESS,
247                             appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
248         }
249
250         // should see two FINAL successes
251         VirtualControlLoopNotification notif1 = waitForFinalSuccess(policy, policyClMgt);
252         VirtualControlLoopNotification notif2 = waitForFinalSuccess(policy, policyClMgt);
253
254         // get the list of target names so we can ensure there's one of each
255         List<String> actual = List.of(notif1, notif2).stream().map(notif -> notif.getAai().get("generic-vnf.vnf-id"))
256                         .sorted().collect(Collectors.toList());
257
258         assertEquals(List.of("duplicate-VNF", "vCPE_Infrastructure_vGMUX_demo_app").toString(), actual.toString());
259
260         long added = getCreateCount() - initCount;
261         assertEquals(2, added);
262     }
263
264     // VCPE
265
266     /**
267      * Sunny Day with Tosca Compliant Policy.
268      */
269     @Test
270     public void testVcpeSunnyDayCompliant() {
271         appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
272     }
273
274     /**
275      * An ONSET flood prevention test that injects a few ONSETs at once. It attempts to
276      * simulate the flooding behavior of the DCAE TCA microservice. TCA could blast tens
277      * or hundreds of ONSETs within sub-second intervals.
278      */
279     @Test
280     public void testVcpeOnsetFloodPrevention() {
281         appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, List.of(VCPE_ONSET_1, VCPE_ONSET_2, VCPE_ONSET_3),
282                         APPC_RESTART_OP);
283     }
284
285     // VDNS
286
287     /**
288      * Sunny Day with Tosca Compliant Policy.
289      */
290     @Test
291     public void testVdnsSunnyDayCompliant() {
292         httpSunnyDay(VDNS_TOSCA_COMPLIANT_POLICY, VDNS_ONSET);
293     }
294
295     /**
296       * Vdns Rainy Day with Compliant Tosca Policy.
297       */
298     @Test
299     public void testVdnsRainyDayCompliant() {
300         httpRainyDay(VDNS_TOSCA_COMPLIANT_RAINY_POLICY, VDNS_ONSET);
301     }
302
303
304     // VFW
305
306     /**
307      * VFW Sunny Day with Tosca Compliant Policy.
308      */
309     @Test
310     public void testVfwSunnyDayCompliant() {
311         appcLegacySunnyDay(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
312     }
313
314     /**
315      * VFW Rainy Day using compliant tosca policy (final failure).
316      */
317     @Test
318     public void testVfwRainyDayOverallTimeout() {
319         appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
320     }
321
322     /**
323      * VFW Rainy day using compliant tosca policy (final failure due to timeout).
324      */
325     @Test
326     public void testVfwRainyDayCompliantTimeout() {
327         appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
328     }
329
330     /**
331      * VPCI Sunny Day Tosca Policy.
332      */
333     @Test
334     public void testVpciSunnyDayCompliant() {
335         sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig");
336     }
337
338     // VSONH
339
340     /**
341      * VSONH Sunny Day with Tosca Policy.
342      */
343     @Test
344     public void testVsonhSunnyDayCompliant() {
345         sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR");
346     }
347
348     /**
349      * Sunny day scenario for use cases that use APPC-LCM.
350      *
351      * @param policyFile file containing the ToscaPolicy to be loaded
352      * @param onsetFile file containing the ONSET to be injected
353      * @param operation expected APPC operation request
354      */
355     protected void appcLcmSunnyDay(String policyFile, String onsetFile, String operation) {
356         appcLcmSunnyDay(policyFile, List.of(onsetFile), operation);
357     }
358
359     /**
360      * Sunny day scenario for use cases that use APPC-LCM.
361      *
362      * @param policyFile file containing the ToscaPolicy to be loaded
363      * @param onsetFiles list of files containing the ONSET to be injected
364      * @param operation expected APPC operation request
365      */
366     protected void appcLcmSunnyDay(String policyFile, List<String> onsetFiles, String operation) {
367         policyClMgt = createNoficationTopicListener();
368         appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
369
370         policy = checkPolicy(policyFile);
371
372
373         // inject several ONSET events over the DCAE topic
374         for (String onsetFile : onsetFiles) {
375             topics.inject(DCAE_TOPIC, onsetFile);
376         }
377
378         /* Wait to acquire a LOCK and a PDP-X PERMIT */
379         waitForLockAndPermit(policy, policyClMgt);
380
381         /*
382          * Ensure that an APPC RESTART request was sent in response to the matching ONSET
383          */
384         AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> operation.equals(req.getRpcName()));
385
386         /*
387          * Inject a 400 APPC Response Return over the APPC topic, with appropriate
388          * subRequestId
389          */
390         topics.inject(APPC_LCM_WRITE_TOPIC, VCPE_APPC_SUCCESS,
391                         appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
392
393         /* --- Operation Completed --- */
394
395         waitForOperationSuccess();
396
397         /* --- Transaction Completed --- */
398         waitForFinalSuccess(policy, policyClMgt);
399     }
400
401     /**
402      * Sunny day scenario for use cases that use Legacy APPC.
403      *
404      * @param policyFile file containing the ToscaPolicy to be loaded
405      * @param onsetFile file containing the ONSET to be injected
406      * @param operation expected APPC operation request
407      */
408     protected void appcLegacySunnyDay(String policyFile, String onsetFile, String operation) {
409         policyClMgt = createNoficationTopicListener();
410         appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
411
412         policy = checkPolicy(policyFile);
413
414         /* Inject an ONSET event over the DCAE topic */
415         topics.inject(DCAE_TOPIC, onsetFile);
416
417         /* Wait to acquire a LOCK and a PDP-X PERMIT */
418         waitForLockAndPermit(policy, policyClMgt);
419
420         /*
421          * Ensure that an APPC RESTART request was sent in response to the matching ONSET
422          */
423         Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
424
425         /*
426          * Inject a 400 APPC Response Return over the APPC topic, with appropriate
427          * subRequestId
428          */
429         topics.inject(APPC_CL_TOPIC, VFW_APPC_SUCCESS, appcreq.getCommonHeader().getSubRequestId());
430
431         /* --- Operation Completed --- */
432
433         waitForOperationSuccess();
434
435         /* --- Transaction Completed --- */
436         waitForFinalSuccess(policy, policyClMgt);
437     }
438
439     /**
440      * Rainy day scenario for use cases that use Legacy APPC.
441      *
442      * @param policyFile file containing the ToscaPolicy to be loaded
443      * @param onsetFile file containing the ONSET to be injected
444      * @param operation expected APPC operation request
445      * @param checkOperation flag to determine whether or not to wait for operation timeout
446      */
447     protected void appcLegacyRainyDay(String policyFile, String onsetFile, String operation) {
448         policyClMgt = createNoficationTopicListener();
449         appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
450
451         policy = checkPolicy(policyFile);
452
453         /* Inject an ONSET event over the DCAE topic */
454         topics.inject(DCAE_TOPIC, onsetFile);
455
456         /* Wait to acquire a LOCK and a PDP-X PERMIT */
457         waitForLockAndPermit(policy, policyClMgt);
458
459         /*
460          * Ensure that an APPC RESTART request was sent in response to the matching ONSET
461          */
462         Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
463
464         /*
465          * Inject a 401 APPC Response Return over the APPC topic, with appropriate
466          * subRequestId
467          */
468         topics.inject(APPC_CL_TOPIC, VFW_APPC_FAILURE, appcreq.getCommonHeader().getSubRequestId());
469
470         /* --- Operation Completed --- */
471         waitForOperationFailure();
472
473         /* --- Transaction Completed --- */
474         waitForFinalFailure(policy, policyClMgt);
475     }
476
477     /**
478      * Rainy day scenario for use cases that use Legacy APPC.
479      * Expected to fail due to timeout.
480      *
481      * @param policyFile file containing the ToscaPolicy to be loaded
482      * @param onsetFile file containing the ONSET to be injected
483      * @param operation expected APPC operation request
484      */
485     protected void appcLegacyRainyDayNoResponse(String policyFile, String onsetFile, String operation) {
486         policyClMgt = createNoficationTopicListener();
487         appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
488
489         policy = checkPolicy(policyFile);
490
491         /* Inject an ONSET event over the DCAE topic */
492         topics.inject(DCAE_TOPIC, onsetFile);
493
494         /* Wait to acquire a LOCK and a PDP-X PERMIT */
495         waitForLockAndPermit(policy, policyClMgt);
496
497         /*
498          * Ensure that an APPC RESTART request was sent in response to the matching ONSET
499          */
500         appcClSink.await(req -> operation.equals(req.getAction()));
501
502         /*
503          * Do not inject an APPC Response.
504          */
505
506         /* --- Transaction Completed --- */
507         waitForFinalFailure(policy, policyClMgt);
508     }
509
510     /**
511      * Sunny day scenario for use cases that use SDNR.
512      *
513      * @param policyFile file containing the ToscaPolicy to be loaded
514      * @param onsetFile file containing the ONSET to be injected
515      * @param operation expected SDNR operation request
516      */
517     protected void sdnrSunnyDay(String policyFile, String onsetFile, String successFile, String operation) {
518         policyClMgt = createNoficationTopicListener();
519         sdnrClSink = topics.createListener(SDNR_CL_TOPIC, PciMessage.class, SDNR_CODER);
520
521         policy = checkPolicy(policyFile);
522
523         /* Inject an ONSET event over the DCAE topic */
524         topics.inject(DCAE_TOPIC, onsetFile);
525
526         /* Wait to acquire a LOCK and a PDP-X PERMIT */
527         waitForLockAndPermit(policy, policyClMgt);
528
529         /*
530          * Ensure that an SDNR RESTART request was sent in response to the matching ONSET
531          */
532         PciMessage pcireq = sdnrClSink.await(req -> operation.equals(req.getBody().getInput().getAction()));
533
534         /*
535          * Inject response.
536          */
537         topics.inject(SDNR_CL_RSP_TOPIC, successFile, pcireq.getBody().getInput().getCommonHeader().getSubRequestId());
538
539         /* --- Operation Completed --- */
540
541         waitForOperationSuccess();
542
543         /* --- Transaction Completed --- */
544         waitForFinalSuccess(policy, policyClMgt);
545     }
546
547     /**
548      * Sunny day scenario for use cases that use an HTTP simulator.
549      *
550      * @param policyFile file containing the ToscaPolicy to be loaded
551      * @param onsetFile file containing the ONSET to be injected
552      * @param operation expected APPC operation request
553      */
554     protected void httpSunnyDay(String policyFile, String onsetFile) {
555         policyClMgt = createNoficationTopicListener();
556
557         policy = checkPolicy(policyFile);
558
559         /* Inject an ONSET event over the DCAE topic */
560         topics.inject(DCAE_TOPIC, onsetFile);
561
562         /* Wait to acquire a LOCK and a PDP-X PERMIT */
563         waitForLockAndPermit(policy, policyClMgt);
564
565         /* --- Operation Completed --- */
566
567         waitForOperationSuccess();
568
569         /* --- Transaction Completed --- */
570         waitForFinalSuccess(policy, policyClMgt);
571     }
572
573     /**
574      * Rainy day scenario for use cases that use an HTTP simulator.
575      *
576      * @param policyFile file containing the ToscaPolicy to be loaded
577      * @param onsetFile file containing the ONSET to be injected
578      * @param operation expected APPC operation request
579      */
580     protected void httpRainyDay(String policyFile, String onsetFile) {
581         policyClMgt = createNoficationTopicListener();
582
583         policy = checkPolicy(policyFile);
584
585         /* Inject an ONSET event over the DCAE topic */
586         topics.inject(DCAE_TOPIC, onsetFile);
587
588         /* Wait to acquire a LOCK and a PDP-X PERMIT */
589         waitForLockAndPermit(policy, policyClMgt);
590
591         /* --- Operation Completed --- */
592         waitForOperationFailure();
593
594         /* --- Transaction Completed --- */
595         waitForFinalFailure(policy, policyClMgt);
596     }
597
598     protected long getCreateCount() {
599         return ControlLoopEventManager2.getCreateCount();
600     }
601
602     /**
603      * Waits for a OPERATION SUCCESS transaction notification.
604      */
605     protected void waitForOperationSuccess() {
606         policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_SUCCESS);
607     }
608
609     /**
610      * Waits for a FINAL SUCCESS transaction notification.
611      *
612      * @return the FINAL SUCCESS notification
613      */
614     protected VirtualControlLoopNotification waitForFinalSuccess(ToscaPolicy policy,
615                     Listener<VirtualControlLoopNotification> policyClMgt) {
616
617         return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_SUCCESS);
618     }
619
620     /**
621      * Waits for a OPERATION FAILURE transaction notification.
622      */
623     protected void waitForOperationFailure() {
624         policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_FAILURE);
625     }
626
627     /**
628      * Waits for a FINAL FAILURE transaction notification.
629      *
630      * @return the FINAL FAILURE notification
631      */
632     protected VirtualControlLoopNotification waitForFinalFailure(ToscaPolicy policy,
633                     Listener<VirtualControlLoopNotification> policyClMgt) {
634
635         return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_FAILURE);
636     }
637
638     /**
639      * Waits for notifications for LOCK acquisition and GUARD Permit so that event
640      * processing may proceed.
641      */
642     protected abstract void waitForLockAndPermit(ToscaPolicy policy,
643                     Listener<VirtualControlLoopNotification> policyClMgt);
644
645     /**
646      * Waits for a FINAL transaction notification.
647      *
648      * @param finalType FINAL_xxx type for which to wait
649      *
650      * @return the FINAL notification
651      */
652     protected abstract VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
653                     Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType);
654
655     /**
656      * Returns ToscaPolicy from File.
657      *
658      * @param fileName a path name
659      * @return ToscaPolicy
660      */
661     protected ToscaPolicy checkPolicy(String fileName)  {
662         try {
663             return Rules.getPolicyFromFile(fileName);
664         } catch (CoderException e) {
665             throw new IllegalArgumentException(fileName, e);
666         }
667     }
668
669     /**
670      * Creates a Coder for PolicyClMgt from StandardCoder.
671      *
672      */
673     public static class PolicyClMgtCoder extends StandardCoder {
674         public PolicyClMgtCoder() {
675             super(org.onap.policy.controlloop.util.Serialization.gson,
676                   org.onap.policy.controlloop.util.Serialization.gsonPretty);
677         }
678     }
679
680     /**
681      * Returns Listener from createListner based on Coder.
682      * @return the Listener
683      */
684     protected Listener<VirtualControlLoopNotification> createNoficationTopicListener() {
685         return topics.createListener(POLICY_CL_MGT_TOPIC,
686             VirtualControlLoopNotification.class, POLICY_CL_MGT_CODER);
687     }
688 }