2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop.common.rules.test;
23 import static org.junit.Assert.assertEquals;
25 import java.util.List;
26 import java.util.UUID;
27 import java.util.function.Function;
28 import java.util.function.Supplier;
29 import java.util.stream.Collectors;
30 import lombok.AccessLevel;
32 import org.junit.Test;
33 import org.onap.policy.appc.Request;
34 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
35 import org.onap.policy.common.utils.coder.Coder;
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.drools.system.PolicyController;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
43 import org.onap.policy.sdnr.PciMessage;
46 * Superclass used for rule tests.
48 public abstract class BaseRuleTest {
49 private static final String APPC_RESTART_OP = "restart";
50 private static final String APPC_MODIFY_CONFIG_OP = "ModifyConfig";
53 * Canonical Topic Names.
55 protected static final String DCAE_TOPIC = "DCAE_TOPIC";
56 protected static final String APPC_LCM_WRITE_TOPIC = "APPC-LCM-WRITE";
57 protected static final String POLICY_CL_MGT_TOPIC = "POLICY-CL-MGT";
58 protected static final String APPC_LCM_READ_TOPIC = "APPC-LCM-READ";
59 protected static final String APPC_CL_TOPIC = "APPC-CL";
60 protected static final String SDNR_CL_TOPIC = "SDNR-CL";
61 protected static final String SDNR_CL_RSP_TOPIC = "SDNR-CL-RSP";
64 * Constants for each test case.
67 // service123 (i.e., multi-operation policy)
68 private static final String SERVICE123_TOSCA_COMPLIANT_POLICY = "service123/tosca-compliant-service123.json";
69 private static final String SERVICE123_ONSET = "service123/service123.onset.json";
70 private static final String SERVICE123_APPC_RESTART_FAILURE = "service123/service123.appc.restart.failure.json";
71 private static final String SERVICE123_APPC_REBUILD_FAILURE = "service123/service123.appc.rebuild.failure.json";
72 private static final String SERVICE123_APPC_MIGRATE_SUCCESS = "service123/service123.appc.migrate.success.json";
74 // duplicates (i.e., mutliple events in the engine at the same time)
75 private static final String DUPLICATES_TOSCA_COMPLIANT_POLICY = "duplicates/tosca-compliant-duplicates.json";
76 private static final String DUPLICATES_ONSET_1 = "duplicates/duplicates.onset.1.json";
77 private static final String DUPLICATES_ONSET_2 = "duplicates/duplicates.onset.2.json";
78 private static final String DUPLICATES_APPC_SUCCESS = "duplicates/duplicates.appc.success.json";
81 private static final String VCPE_TOSCA_LEGACY_POLICY = "vcpe/tosca-legacy-vcpe.json";
82 private static final String VCPE_TOSCA_COMPLIANT_POLICY = "vcpe/tosca-compliant-vcpe.json";
83 private static final String VCPE_ONSET_1 = "vcpe/vcpe.onset.1.json";
84 private static final String VCPE_ONSET_2 = "vcpe/vcpe.onset.2.json";
85 private static final String VCPE_ONSET_3 = "vcpe/vcpe.onset.3.json";
86 private static final String VCPE_APPC_SUCCESS = "vcpe/vcpe.appc.success.json";
89 private static final String VDNS_TOSCA_LEGACY_POLICY = "vdns/tosca-legacy-vdns.json";
90 private static final String VDNS_TOSCA_COMPLIANT_POLICY = "vdns/tosca-compliant-vdns.json";
91 private static final String VDNS_ONSET = "vdns/vdns.onset.json";
94 private static final String VFW_TOSCA_LEGACY_POLICY = "vfw/tosca-vfw.json";
95 private static final String VFW_TOSCA_COMPLIANT_POLICY = "vfw/tosca-compliant-vfw.json";
96 private static final String VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY = "vfw/tosca-compliant-timeout-vfw.json";
97 private static final String VFW_ONSET = "vfw/vfw.onset.json";
98 private static final String VFW_APPC_SUCCESS = "vfw/vfw.appc.success.json";
99 private static final String VFW_APPC_FAILURE = "vfw/vfw.appc.failure.json";
102 private static final String VPCI_TOSCA_POLICY = "vpci/tosca-vpci.json";
103 private static final String VPCI_TOSCA_COMPLIANT_POLICY = "vpci/tosca-compliant-vpci.json";
104 private static final String VPCI_ONSET = "vpci/vpci.onset.json";
105 private static final String VPCI_SDNR_SUCCESS = "vpci/vpci.sdnr.success.json";
108 private static final String VSONH_TOSCA_POLICY = "vsonh/tosca-vsonh.json";
109 private static final String VSONH_TOSCA_COMPLIANT_POLICY = "vsonh/tosca-compliant-vsonh.json";
110 private static final String VSONH_ONSET = "vsonh/vsonh.onset.json";
111 private static final String VSONH_SDNR_SUCCESS = "vsonh/vsonh.sdnr.success.json";
114 * Coders used to decode requests and responses.
116 private static final Coder APPC_LEGACY_CODER = new StandardCoderInstantAsMillis();
117 private static final Coder APPC_LCM_CODER = new StandardCoder();
120 * Coders used to decode requests and responses.
122 private static final Coder SDNR_CODER = new StandardCoder();
124 // these may be overridden by junit tests
125 private static Function<String, Rules> ruleMaker = Rules::new;
126 private static Supplier<HttpClients> httpClientMaker = HttpClients::new;
127 private static Supplier<Simulators> simMaker = Simulators::new;
128 private static Supplier<Topics> topicMaker = Topics::new;
130 protected static Rules rules;
131 protected static HttpClients httpClients;
132 protected static Simulators simulators;
134 // used to inject and wait for messages
135 @Getter(AccessLevel.PROTECTED)
136 private Topics topics;
138 // used to wait for messages on SINK topics
139 protected Listener<VirtualControlLoopNotification> policyClMgt;
140 protected Listener<Request> appcClSink;
141 protected Listener<AppcLcmDmaapWrapper> appcLcmRead;
142 protected Listener<PciMessage> sdnrClSink;
144 protected PolicyController controller;
147 * Tosca Policy that was loaded.
149 protected ToscaPolicy policy;
153 * Initializes {@link #rules}, {@link #httpClients}, and {@link #simulators}.
155 * @param controllerName the rule controller name
157 public static void initStatics(String controllerName) {
158 rules = ruleMaker.apply(controllerName);
159 httpClients = httpClientMaker.get();
160 simulators = simMaker.get();
164 * Destroys {@link #httpClients}, {@link #simulators}, and {@link #rules}.
166 public static void finishStatics() {
167 httpClients.destroy();
168 simulators.destroy();
173 * Initializes {@link #topics} and {@link #controller}.
176 topics = topicMaker.get();
177 controller = rules.getController();
181 * Destroys {@link #topics} and resets the rule facts.
183 public void finish() {
188 // Service123 (i.e., Policy with multiple operations)
191 * Service123 with Tosca Compliant Policy.
194 public void testService123Compliant() {
195 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
196 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
198 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
199 policy = rules.setupPolicyFromFile(SERVICE123_TOSCA_COMPLIANT_POLICY);
200 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
202 // inject an ONSET event over the DCAE topic
203 topics.inject(DCAE_TOPIC, SERVICE123_ONSET);
205 /* Wait to acquire a LOCK and a PDP-X PERMIT */
206 waitForLockAndPermit(policy, policyClMgt);
208 // restart request should be sent and fail four times (i.e., because retry=3)
209 for (int count = 0; count < 4; ++count) {
210 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
212 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_RESTART_FAILURE,
213 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
216 // rebuild request should be sent and fail once
217 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> "rebuild".equals(req.getRpcName()));
219 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_REBUILD_FAILURE,
220 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
222 // migrate request should be sent and succeed
223 appcreq = appcLcmRead.await(req -> "migrate".equals(req.getRpcName()));
225 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_MIGRATE_SUCCESS,
226 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
228 /* --- Operation Completed --- */
230 waitForOperationSuccess();
232 /* --- Transaction Completed --- */
233 waitForFinalSuccess(policy, policyClMgt);
239 * This test case tests the scenario where 3 events occur and 2 of the requests refer
240 * to the same target entity while the 3rd is for another entity. The expected result
241 * is that the event with the duplicate target entity will have a final success result
242 * for one of the events, and a rejected message for the one that was unable to obtain
243 * the lock. The event that is referring to a different target entity should be able
244 * to obtain a lock since it is a different target. After processing of all events
245 * there should only be the policy and params objects left in memory.
248 public void testDuplicatesEvents() {
249 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
250 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
252 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
253 policy = rules.setupPolicyFromFile(DUPLICATES_TOSCA_COMPLIANT_POLICY);
254 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
256 final long initCount = getCreateCount();
259 * Inject ONSET events over the DCAE topic. First and last have the same target
260 * entity, but different request IDs - only one should succeed. The middle one is
261 * for a different target entity, so it should succeed.
263 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
264 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_2);
265 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
267 // should see two restarts
268 for (int count = 0; count < 2; ++count) {
269 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
272 topics.inject(APPC_LCM_WRITE_TOPIC, DUPLICATES_APPC_SUCCESS,
273 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
276 // should see two FINAL successes
277 VirtualControlLoopNotification notif1 = waitForFinalSuccess(policy, policyClMgt);
278 VirtualControlLoopNotification notif2 = waitForFinalSuccess(policy, policyClMgt);
280 // get the list of target names so we can ensure there's one of each
281 List<String> actual = List.of(notif1, notif2).stream().map(notif -> notif.getAai().get("generic-vnf.vnf-id"))
282 .sorted().collect(Collectors.toList());
284 assertEquals(List.of("duplicate-VNF", "vCPE_Infrastructure_vGMUX_demo_app").toString(), actual.toString());
286 long added = getCreateCount() - initCount;
287 assertEquals(2, added);
293 * Sunny Day with Legacy Tosca Policy.
296 public void testVcpeSunnyDayLegacy() {
297 appcLcmSunnyDay(VCPE_TOSCA_LEGACY_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
301 * Sunny Day with Tosca Compliant Policy.
304 public void testVcpeSunnyDayCompliant() {
305 appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
309 * An ONSET flood prevention test that injects a few ONSETs at once. It attempts to
310 * simulate the flooding behavior of the DCAE TCA microservice. TCA could blast tens
311 * or hundreds of ONSETs within sub-second intervals.
314 public void testVcpeOnsetFloodPrevention() {
315 appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, List.of(VCPE_ONSET_1, VCPE_ONSET_2, VCPE_ONSET_3),
322 * Sunny Day with Legacy Tosca Policy.
325 public void testVdnsSunnyDayLegacy() {
326 httpSunnyDay(VDNS_TOSCA_LEGACY_POLICY, VDNS_ONSET);
330 * Sunny Day with Tosca Compliant Policy.
333 public void testVdnsSunnyDayCompliant() {
334 httpSunnyDay(VDNS_TOSCA_COMPLIANT_POLICY, VDNS_ONSET);
340 * VFW Sunny Day with Legacy Tosca Policy.
343 public void testVfwSunnyDayLegacy() {
344 appcLegacySunnyDay(VFW_TOSCA_LEGACY_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
348 * VFW Sunny Day with Tosca Compliant Policy.
351 public void testVfwSunnyDayCompliant() {
352 appcLegacySunnyDay(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
356 * VFW Rainy Day using legacy tosca policy (operation and final failure).
359 public void testVfwRainyDayLegacyFailure() {
360 appcLegacyRainyDay(VFW_TOSCA_LEGACY_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
364 * VFW Rainy Day using compliant tosca policy (final failure).
367 public void testVfwRainyDayOverallTimeout() {
368 appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
372 * VFW Rainy day using compliant tosca policy (final failure due to timeout).
375 public void testVfwRainyDayCompliantTimeout() {
376 appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
380 * VPCI Sunny Day with Legacy Tosca Policy.
383 public void testVpciSunnyDayLegacy() {
384 sdnrSunnyDay(VPCI_TOSCA_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig");
388 * VPCI Sunny Day Tosca Policy.
391 public void testVpciSunnyDayCompliant() {
392 sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig");
398 * VSONH Sunny Day with Legacy Tosca Policy.
401 public void testVsonhSunnyDayLegacy() {
402 sdnrSunnyDay(VSONH_TOSCA_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR");
406 * VSONH Sunny Day with Tosca Policy.
409 public void testVsonhSunnyDayCompliant() {
410 sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR");
414 * Sunny day scenario for use cases that use APPC-LCM.
416 * @param policyFile file containing the ToscaPolicy to be loaded
417 * @param onsetFile file containing the ONSET to be injected
418 * @param operation expected APPC operation request
420 protected void appcLcmSunnyDay(String policyFile, String onsetFile, String operation) {
421 appcLcmSunnyDay(policyFile, List.of(onsetFile), operation);
425 * Sunny day scenario for use cases that use APPC-LCM.
427 * @param policyFile file containing the ToscaPolicy to be loaded
428 * @param onsetFiles list of files containing the ONSET to be injected
429 * @param operation expected APPC operation request
431 protected void appcLcmSunnyDay(String policyFile, List<String> onsetFiles, String operation) {
432 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
433 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
435 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
436 policy = rules.setupPolicyFromFile(policyFile);
437 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
439 // inject several ONSET events over the DCAE topic
440 for (String onsetFile : onsetFiles) {
441 topics.inject(DCAE_TOPIC, onsetFile);
444 /* Wait to acquire a LOCK and a PDP-X PERMIT */
445 waitForLockAndPermit(policy, policyClMgt);
448 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
450 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> operation.equals(req.getRpcName()));
453 * Inject a 400 APPC Response Return over the APPC topic, with appropriate
456 topics.inject(APPC_LCM_WRITE_TOPIC, VCPE_APPC_SUCCESS,
457 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
459 /* --- Operation Completed --- */
461 waitForOperationSuccess();
463 /* --- Transaction Completed --- */
464 waitForFinalSuccess(policy, policyClMgt);
468 * Sunny day scenario for use cases that use Legacy APPC.
470 * @param policyFile file containing the ToscaPolicy to be loaded
471 * @param onsetFile file containing the ONSET to be injected
472 * @param operation expected APPC operation request
474 protected void appcLegacySunnyDay(String policyFile, String onsetFile, String operation) {
475 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
476 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
478 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
479 policy = rules.setupPolicyFromFile(policyFile);
480 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
482 /* Inject an ONSET event over the DCAE topic */
483 topics.inject(DCAE_TOPIC, onsetFile);
485 /* Wait to acquire a LOCK and a PDP-X PERMIT */
486 waitForLockAndPermit(policy, policyClMgt);
489 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
491 Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
494 * Inject a 400 APPC Response Return over the APPC topic, with appropriate
497 topics.inject(APPC_CL_TOPIC, VFW_APPC_SUCCESS, appcreq.getCommonHeader().getSubRequestId());
499 /* --- Operation Completed --- */
501 waitForOperationSuccess();
503 /* --- Transaction Completed --- */
504 waitForFinalSuccess(policy, policyClMgt);
508 * Rainy day scenario for use cases that use Legacy APPC.
510 * @param policyFile file containing the ToscaPolicy to be loaded
511 * @param onsetFile file containing the ONSET to be injected
512 * @param operation expected APPC operation request
513 * @param checkOperation flag to determine whether or not to wait for operation timeout
515 protected void appcLegacyRainyDay(String policyFile, String onsetFile, String operation) {
516 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
517 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
519 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
520 policy = rules.setupPolicyFromFile(policyFile);
521 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
523 /* Inject an ONSET event over the DCAE topic */
524 topics.inject(DCAE_TOPIC, onsetFile);
526 /* Wait to acquire a LOCK and a PDP-X PERMIT */
527 waitForLockAndPermit(policy, policyClMgt);
530 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
532 Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
535 * Inject a 401 APPC Response Return over the APPC topic, with appropriate
538 topics.inject(APPC_CL_TOPIC, VFW_APPC_FAILURE, appcreq.getCommonHeader().getSubRequestId());
540 /* --- Operation Completed --- */
541 waitForOperationFailure();
543 /* --- Transaction Completed --- */
544 waitForFinalFailure(policy, policyClMgt);
548 * Rainy day scenario for use cases that use Legacy APPC.
549 * Expected to fail due to timeout.
551 * @param policyFile file containing the ToscaPolicy to be loaded
552 * @param onsetFile file containing the ONSET to be injected
553 * @param operation expected APPC operation request
555 protected void appcLegacyRainyDayNoResponse(String policyFile, String onsetFile, String operation) {
556 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
557 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
559 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
560 policy = rules.setupPolicyFromFile(policyFile);
561 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
563 /* Inject an ONSET event over the DCAE topic */
564 topics.inject(DCAE_TOPIC, onsetFile);
566 /* Wait to acquire a LOCK and a PDP-X PERMIT */
567 waitForLockAndPermit(policy, policyClMgt);
570 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
572 appcClSink.await(req -> operation.equals(req.getAction()));
575 * Do not inject an APPC Response.
578 /* --- Transaction Completed --- */
579 waitForFinalFailure(policy, policyClMgt);
583 * Sunny day scenario for use cases that use SDNR.
585 * @param policyFile file containing the ToscaPolicy to be loaded
586 * @param onsetFile file containing the ONSET to be injected
587 * @param operation expected SDNR operation request
589 protected void sdnrSunnyDay(String policyFile, String onsetFile, String successFile, String operation) {
590 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC,
591 VirtualControlLoopNotification.class, controller);
592 sdnrClSink = topics.createListener(SDNR_CL_TOPIC, PciMessage.class, SDNR_CODER);
594 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
595 policy = rules.setupPolicyFromFile(policyFile);
596 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
598 /* Inject an ONSET event over the DCAE topic */
599 topics.inject(DCAE_TOPIC, onsetFile);
601 /* Wait to acquire a LOCK and a PDP-X PERMIT */
602 waitForLockAndPermit(policy, policyClMgt);
605 * Ensure that an SDNR RESTART request was sent in response to the matching ONSET
607 PciMessage pcireq = sdnrClSink.await(req -> operation.equals(req.getBody().getInput().getAction()));
612 topics.inject(SDNR_CL_RSP_TOPIC, successFile, pcireq.getBody().getInput().getCommonHeader().getSubRequestId());
614 /* --- Operation Completed --- */
616 waitForOperationSuccess();
618 /* --- Transaction Completed --- */
619 waitForFinalSuccess(policy, policyClMgt);
623 * Sunny day scenario for use cases that use an HTTP simulator.
625 * @param policyFile file containing the ToscaPolicy to be loaded
626 * @param onsetFile file containing the ONSET to be injected
627 * @param operation expected APPC operation request
629 protected void httpSunnyDay(String policyFile, String onsetFile) {
630 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
632 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
633 policy = rules.setupPolicyFromFile(policyFile);
634 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
636 /* Inject an ONSET event over the DCAE topic */
637 topics.inject(DCAE_TOPIC, onsetFile);
639 /* Wait to acquire a LOCK and a PDP-X PERMIT */
640 waitForLockAndPermit(policy, policyClMgt);
642 /* --- Operation Completed --- */
644 waitForOperationSuccess();
646 /* --- Transaction Completed --- */
647 waitForFinalSuccess(policy, policyClMgt);
650 protected long getCreateCount() {
651 return ControlLoopEventManager2.getCreateCount();
655 * Waits for a OPERATION SUCCESS transaction notification.
657 protected void waitForOperationSuccess() {
658 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_SUCCESS);
662 * Waits for a FINAL SUCCESS transaction notification.
664 * @return the FINAL SUCCESS notification
666 protected VirtualControlLoopNotification waitForFinalSuccess(ToscaPolicy policy,
667 Listener<VirtualControlLoopNotification> policyClMgt) {
669 return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_SUCCESS);
673 * Waits for a OPERATION FAILURE transaction notification.
675 protected void waitForOperationFailure() {
676 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_FAILURE);
680 * Waits for a FINAL FAILURE transaction notification.
682 * @return the FINAL FAILURE notification
684 protected VirtualControlLoopNotification waitForFinalFailure(ToscaPolicy policy,
685 Listener<VirtualControlLoopNotification> policyClMgt) {
687 return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_FAILURE);
691 * Waits for notifications for LOCK acquisition and GUARD Permit so that event
692 * processing may proceed.
694 protected abstract void waitForLockAndPermit(ToscaPolicy policy,
695 Listener<VirtualControlLoopNotification> policyClMgt);
698 * Waits for a FINAL transaction notification.
700 * @param finalType FINAL_xxx type for which to wait
702 * @return the FINAL notification
704 protected abstract VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
705 Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType);