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;
33 import org.junit.Ignore;
34 import org.junit.Test;
35 import org.onap.policy.appc.Request;
36 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
37 import org.onap.policy.common.utils.coder.Coder;
38 import org.onap.policy.common.utils.coder.StandardCoder;
39 import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
40 import org.onap.policy.controlloop.ControlLoopNotificationType;
41 import org.onap.policy.controlloop.VirtualControlLoopNotification;
42 import org.onap.policy.drools.system.PolicyController;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
44 import org.onap.policy.sdnr.PciMessage;
47 * Superclass used for rule tests.
49 public abstract class BaseRuleTest {
50 private static final String APPC_RESTART_OP = "restart";
51 private static final String APPC_MODIFY_CONFIG_OP = "ModifyConfig";
54 * Canonical Topic Names.
56 protected static final String DCAE_TOPIC = "DCAE_TOPIC";
57 protected static final String APPC_LCM_WRITE_TOPIC = "APPC-LCM-WRITE";
58 protected static final String POLICY_CL_MGT_TOPIC = "POLICY-CL-MGT";
59 protected static final String APPC_LCM_READ_TOPIC = "APPC-LCM-READ";
60 protected static final String APPC_CL_TOPIC = "APPC-CL";
61 protected static final String SDNR_CL_TOPIC = "SDNR-CL";
62 protected static final String SDNR_CL_RSP_TOPIC = "SDNR-CL-RSP";
65 * Constants for each test case.
68 // service123 (i.e., multi-operation policy)
69 private static final String SERVICE123_TOSCA_COMPLIANT_POLICY = "service123/tosca-compliant-service123.json";
70 private static final String SERVICE123_ONSET = "service123/service123.onset.json";
71 private static final String SERVICE123_APPC_RESTART_FAILURE = "service123/service123.appc.restart.failure.json";
72 private static final String SERVICE123_APPC_REBUILD_FAILURE = "service123/service123.appc.rebuild.failure.json";
73 private static final String SERVICE123_APPC_MIGRATE_SUCCESS = "service123/service123.appc.migrate.success.json";
75 // duplicates (i.e., mutliple events in the engine at the same time)
76 private static final String DUPLICATES_TOSCA_COMPLIANT_POLICY = "duplicates/tosca-compliant-duplicates.json";
77 private static final String DUPLICATES_ONSET_1 = "duplicates/duplicates.onset.1.json";
78 private static final String DUPLICATES_ONSET_2 = "duplicates/duplicates.onset.2.json";
79 private static final String DUPLICATES_APPC_SUCCESS = "duplicates/duplicates.appc.success.json";
82 private static final String VCPE_TOSCA_LEGACY_POLICY = "vcpe/tosca-legacy-vcpe.json";
83 private static final String VCPE_TOSCA_COMPLIANT_POLICY = "vcpe/tosca-compliant-vcpe.json";
84 private static final String VCPE_ONSET_1 = "vcpe/vcpe.onset.1.json";
85 private static final String VCPE_ONSET_2 = "vcpe/vcpe.onset.2.json";
86 private static final String VCPE_ONSET_3 = "vcpe/vcpe.onset.3.json";
87 private static final String VCPE_APPC_SUCCESS = "vcpe/vcpe.appc.success.json";
90 private static final String VDNS_TOSCA_LEGACY_POLICY = "vdns/tosca-legacy-vdns.json";
91 private static final String VDNS_TOSCA_COMPLIANT_POLICY = "vdns/tosca-compliant-vdns.json";
92 private static final String VDNS_ONSET = "vdns/vdns.onset.json";
95 private static final String VFW_TOSCA_LEGACY_POLICY = "vfw/tosca-vfw.json";
96 private static final String VFW_TOSCA_COMPLIANT_POLICY = "vfw/tosca-compliant-vfw.json";
97 private static final String VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY = "vfw/tosca-compliant-timeout-vfw.json";
98 private static final String VFW_ONSET = "vfw/vfw.onset.json";
99 private static final String VFW_APPC_SUCCESS = "vfw/vfw.appc.success.json";
100 private static final String VFW_APPC_FAILURE = "vfw/vfw.appc.failure.json";
103 private static final String VPCI_TOSCA_POLICY = "vpci/tosca-vpci.json";
104 private static final String VPCI_TOSCA_COMPLIANT_POLICY = "vpci/tosca-compliant-vpci.json";
105 private static final String VPCI_ONSET = "vpci/vpci.onset.json";
106 private static final String VPCI_SDNR_SUCCESS = "vpci/vpci.sdnr.success.json";
109 private static final String VSONH_TOSCA_POLICY = "vsonh/tosca-vsonh.json";
110 private static final String VSONH_TOSCA_COMPLIANT_POLICY = "vsonh/tosca-compliant-vsonh.json";
111 private static final String VSONH_ONSET = "vsonh/vsonh.onset.json";
112 private static final String VSONH_SDNR_SUCCESS = "vsonh/vsonh.sdnr.success.json";
115 * Coders used to decode requests and responses.
117 private static final Coder APPC_LEGACY_CODER = new StandardCoderInstantAsMillis();
118 private static final Coder APPC_LCM_CODER = new StandardCoder();
121 * Coders used to decode requests and responses.
123 private static final Coder SDNR_CODER = new StandardCoder();
125 // these may be overridden by junit tests
126 private static Function<String, Rules> ruleMaker = Rules::new;
127 private static Supplier<HttpClients> httpClientMaker = HttpClients::new;
128 private static Supplier<Simulators> simMaker = Simulators::new;
129 private static Supplier<Topics> topicMaker = Topics::new;
131 protected static Rules rules;
132 protected static HttpClients httpClients;
133 protected static Simulators simulators;
135 // used to inject and wait for messages
136 @Getter(AccessLevel.PROTECTED)
137 private Topics topics;
139 // used to wait for messages on SINK topics
140 protected Listener<VirtualControlLoopNotification> policyClMgt;
141 protected Listener<Request> appcClSink;
142 protected Listener<AppcLcmDmaapWrapper> appcLcmRead;
143 protected Listener<PciMessage> sdnrClSink;
145 protected PolicyController controller;
148 * Tosca Policy that was loaded.
150 protected ToscaPolicy policy;
154 * Initializes {@link #rules}, {@link #httpClients}, and {@link #simulators}.
156 * @param controllerName the rule controller name
158 public static void initStatics(String controllerName) {
159 rules = ruleMaker.apply(controllerName);
160 httpClients = httpClientMaker.get();
161 simulators = simMaker.get();
165 * Destroys {@link #httpClients}, {@link #simulators}, and {@link #rules}.
167 public static void finishStatics() {
168 httpClients.destroy();
169 simulators.destroy();
174 * Initializes {@link #topics} and {@link #controller}.
177 topics = topicMaker.get();
178 controller = rules.getController();
182 * Destroys {@link #topics} and resets the rule facts.
184 public void finish() {
189 // Service123 (i.e., Policy with multiple operations)
192 * Service123 with Tosca Compliant Policy.
195 public void testService123Compliant() {
196 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
197 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
199 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
200 policy = rules.setupPolicyFromFile(SERVICE123_TOSCA_COMPLIANT_POLICY);
201 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
203 // inject an ONSET event over the DCAE topic
204 topics.inject(DCAE_TOPIC, SERVICE123_ONSET);
206 /* Wait to acquire a LOCK and a PDP-X PERMIT */
207 waitForLockAndPermit(policy, policyClMgt);
209 // restart request should be sent and fail four times (i.e., because retry=3)
210 for (int count = 0; count < 4; ++count) {
211 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
213 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_RESTART_FAILURE,
214 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
217 // rebuild request should be sent and fail once
218 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> "rebuild".equals(req.getRpcName()));
220 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_REBUILD_FAILURE,
221 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
223 // migrate request should be sent and succeed
224 appcreq = appcLcmRead.await(req -> "migrate".equals(req.getRpcName()));
226 topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_MIGRATE_SUCCESS,
227 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
229 /* --- Operation Completed --- */
231 waitForOperationSuccess();
233 /* --- Transaction Completed --- */
234 waitForFinalSuccess(policy, policyClMgt);
240 * This test case tests the scenario where 3 events occur and 2 of the requests refer
241 * to the same target entity while the 3rd is for another entity. The expected result
242 * is that the event with the duplicate target entity will have a final success result
243 * for one of the events, and a rejected message for the one that was unable to obtain
244 * the lock. The event that is referring to a different target entity should be able
245 * to obtain a lock since it is a different target. After processing of all events
246 * there should only be the policy and params objects left in memory.
248 // Ignoring test due to TimeoutException (for some reason this test fails only on docker build)
249 // https://jenkins.onap.org/job/policy-drools-applications-maven-docker-stage-master/294/
252 public void testDuplicatesEvents() {
253 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
254 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
256 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
257 policy = rules.setupPolicyFromFile(DUPLICATES_TOSCA_COMPLIANT_POLICY);
258 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
261 * Inject ONSET events over the DCAE topic. First and last have the same target
262 * entity, but different request IDs - only one should succeed. The middle one is
263 * for a different target entity, so it should succeed.
265 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
266 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_2);
267 topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
269 // one should immediately generate a FINAL failure
270 waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_FAILURE);
272 // should see two restarts
273 for (int count = 0; count < 2; ++count) {
274 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
277 topics.inject(APPC_LCM_WRITE_TOPIC, DUPLICATES_APPC_SUCCESS,
278 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
281 // should see two FINAL successes
282 VirtualControlLoopNotification notif1 = waitForFinalSuccess(policy, policyClMgt);
283 VirtualControlLoopNotification notif2 = waitForFinalSuccess(policy, policyClMgt);
285 // get the list of target names so we can ensure there's one of each
286 List<String> actual = List.of(notif1, notif2).stream().map(notif -> notif.getAai().get("generic-vnf.vnf-id"))
287 .sorted().collect(Collectors.toList());
289 assertEquals(List.of("duplicate-VNF", "vCPE_Infrastructure_vGMUX_demo_app").toString(), actual.toString());
295 * Sunny Day with Legacy Tosca Policy.
298 public void testVcpeSunnyDayLegacy() {
299 appcLcmSunnyDay(VCPE_TOSCA_LEGACY_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
303 * Sunny Day with Tosca Compliant Policy.
306 public void testVcpeSunnyDayCompliant() {
307 appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
311 * An ONSET flood prevention test that injects a few ONSETs at once. It attempts to
312 * simulate the flooding behavior of the DCAE TCA microservice. TCA could blast tens
313 * or hundreds of ONSETs within sub-second intervals.
316 public void testVcpeOnsetFloodPrevention() {
317 appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, List.of(VCPE_ONSET_1, VCPE_ONSET_2, VCPE_ONSET_3),
324 * Sunny Day with Legacy Tosca Policy.
327 public void testVdnsSunnyDayLegacy() {
328 httpSunnyDay(VDNS_TOSCA_LEGACY_POLICY, VDNS_ONSET);
332 * Sunny Day with Tosca Compliant Policy.
335 public void testVdnsSunnyDayCompliant() {
336 httpSunnyDay(VDNS_TOSCA_COMPLIANT_POLICY, VDNS_ONSET);
342 * VFW Sunny Day with Legacy Tosca Policy.
345 public void testVfwSunnyDayLegacy() {
346 appcLegacySunnyDay(VFW_TOSCA_LEGACY_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
350 * VFW Sunny Day with Tosca Compliant Policy.
353 public void testVfwSunnyDayCompliant() {
354 appcLegacySunnyDay(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
358 * VFW Rainy Day using legacy tosca policy (operation and final failure).
361 public void testVfwRainyDayLegacyFailure() {
362 appcLegacyRainyDay(VFW_TOSCA_LEGACY_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
366 * VFW Rainy Day using compliant tosca policy (final failure).
369 public void testVfwRainyDayOverallTimeout() {
370 appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
374 * VFW Rainy day using compliant tosca policy (final failure due to timeout).
377 public void testVfwRainyDayCompliantTimeout() {
378 appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, APPC_MODIFY_CONFIG_OP);
382 * VPCI Sunny Day with Legacy Tosca Policy.
385 public void testVpciSunnyDayLegacy() {
386 sdnrSunnyDay(VPCI_TOSCA_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig");
390 * VPCI Sunny Day Tosca Policy.
393 public void testVpciSunnyDayCompliant() {
394 sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig");
400 * VSONH Sunny Day with Legacy Tosca Policy.
403 public void testVsonhSunnyDayLegacy() {
404 sdnrSunnyDay(VSONH_TOSCA_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR");
408 * VSONH Sunny Day with Tosca Policy.
411 public void testVsonhSunnyDayCompliant() {
412 sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR");
416 * Sunny day scenario for use cases that use APPC-LCM.
418 * @param policyFile file containing the ToscaPolicy to be loaded
419 * @param onsetFile file containing the ONSET to be injected
420 * @param operation expected APPC operation request
422 protected void appcLcmSunnyDay(String policyFile, String onsetFile, String operation) {
423 appcLcmSunnyDay(policyFile, List.of(onsetFile), operation);
427 * Sunny day scenario for use cases that use APPC-LCM.
429 * @param policyFile file containing the ToscaPolicy to be loaded
430 * @param onsetFiles list of files containing the ONSET to be injected
431 * @param operation expected APPC operation request
433 protected void appcLcmSunnyDay(String policyFile, List<String> onsetFiles, String operation) {
434 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
435 appcLcmRead = topics.createListener(APPC_LCM_READ_TOPIC, AppcLcmDmaapWrapper.class, APPC_LCM_CODER);
437 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
438 policy = rules.setupPolicyFromFile(policyFile);
439 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
441 // inject several ONSET events over the DCAE topic
442 for (String onsetFile : onsetFiles) {
443 topics.inject(DCAE_TOPIC, onsetFile);
446 /* Wait to acquire a LOCK and a PDP-X PERMIT */
447 waitForLockAndPermit(policy, policyClMgt);
450 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
452 AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> operation.equals(req.getRpcName()));
455 * Inject a 400 APPC Response Return over the APPC topic, with appropriate
458 topics.inject(APPC_LCM_WRITE_TOPIC, VCPE_APPC_SUCCESS,
459 appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
461 /* --- Operation Completed --- */
463 waitForOperationSuccess();
465 /* --- Transaction Completed --- */
466 waitForFinalSuccess(policy, policyClMgt);
470 * Sunny day scenario for use cases that use Legacy APPC.
472 * @param policyFile file containing the ToscaPolicy to be loaded
473 * @param onsetFile file containing the ONSET to be injected
474 * @param operation expected APPC operation request
476 protected void appcLegacySunnyDay(String policyFile, String onsetFile, String operation) {
477 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
478 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
480 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
481 policy = rules.setupPolicyFromFile(policyFile);
482 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
484 /* Inject an ONSET event over the DCAE topic */
485 topics.inject(DCAE_TOPIC, onsetFile);
487 /* Wait to acquire a LOCK and a PDP-X PERMIT */
488 waitForLockAndPermit(policy, policyClMgt);
491 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
493 Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
496 * Inject a 400 APPC Response Return over the APPC topic, with appropriate
499 topics.inject(APPC_CL_TOPIC, VFW_APPC_SUCCESS, appcreq.getCommonHeader().getSubRequestId());
501 /* --- Operation Completed --- */
503 waitForOperationSuccess();
505 /* --- Transaction Completed --- */
506 waitForFinalSuccess(policy, policyClMgt);
510 * Rainy day scenario for use cases that use Legacy APPC.
512 * @param policyFile file containing the ToscaPolicy to be loaded
513 * @param onsetFile file containing the ONSET to be injected
514 * @param operation expected APPC operation request
515 * @param checkOperation flag to determine whether or not to wait for operation timeout
517 protected void appcLegacyRainyDay(String policyFile, String onsetFile, String operation) {
518 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
519 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
521 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
522 policy = rules.setupPolicyFromFile(policyFile);
523 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
525 /* Inject an ONSET event over the DCAE topic */
526 topics.inject(DCAE_TOPIC, onsetFile);
528 /* Wait to acquire a LOCK and a PDP-X PERMIT */
529 waitForLockAndPermit(policy, policyClMgt);
532 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
534 Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
537 * Inject a 401 APPC Response Return over the APPC topic, with appropriate
540 topics.inject(APPC_CL_TOPIC, VFW_APPC_FAILURE, appcreq.getCommonHeader().getSubRequestId());
542 /* --- Operation Completed --- */
543 waitForOperationFailure();
545 /* --- Transaction Completed --- */
546 waitForFinalFailure(policy, policyClMgt);
550 * Rainy day scenario for use cases that use Legacy APPC.
551 * Expected to fail due to timeout.
553 * @param policyFile file containing the ToscaPolicy to be loaded
554 * @param onsetFile file containing the ONSET to be injected
555 * @param operation expected APPC operation request
557 protected void appcLegacyRainyDayNoResponse(String policyFile, String onsetFile, String operation) {
558 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
559 appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
561 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
562 policy = rules.setupPolicyFromFile(policyFile);
563 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
565 /* Inject an ONSET event over the DCAE topic */
566 topics.inject(DCAE_TOPIC, onsetFile);
568 /* Wait to acquire a LOCK and a PDP-X PERMIT */
569 waitForLockAndPermit(policy, policyClMgt);
572 * Ensure that an APPC RESTART request was sent in response to the matching ONSET
574 appcClSink.await(req -> operation.equals(req.getAction()));
577 * Do not inject an APPC Response.
580 /* --- Transaction Completed --- */
581 waitForFinalFailure(policy, policyClMgt);
585 * Sunny day scenario for use cases that use SDNR.
587 * @param policyFile file containing the ToscaPolicy to be loaded
588 * @param onsetFile file containing the ONSET to be injected
589 * @param operation expected SDNR operation request
591 protected void sdnrSunnyDay(String policyFile, String onsetFile, String successFile, String operation) {
592 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC,
593 VirtualControlLoopNotification.class, controller);
594 sdnrClSink = topics.createListener(SDNR_CL_TOPIC, PciMessage.class, SDNR_CODER);
596 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
597 policy = rules.setupPolicyFromFile(policyFile);
598 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
600 /* Inject an ONSET event over the DCAE topic */
601 topics.inject(DCAE_TOPIC, onsetFile);
603 /* Wait to acquire a LOCK and a PDP-X PERMIT */
604 waitForLockAndPermit(policy, policyClMgt);
607 * Ensure that an SDNR RESTART request was sent in response to the matching ONSET
609 PciMessage pcireq = sdnrClSink.await(req -> operation.equals(req.getBody().getInput().getAction()));
614 topics.inject(SDNR_CL_RSP_TOPIC, successFile, pcireq.getBody().getInput().getCommonHeader().getSubRequestId());
616 /* --- Operation Completed --- */
618 waitForOperationSuccess();
620 /* --- Transaction Completed --- */
621 waitForFinalSuccess(policy, policyClMgt);
625 * Sunny day scenario for use cases that use an HTTP simulator.
627 * @param policyFile file containing the ToscaPolicy to be loaded
628 * @param onsetFile file containing the ONSET to be injected
629 * @param operation expected APPC operation request
631 protected void httpSunnyDay(String policyFile, String onsetFile) {
632 policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
634 assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
635 policy = rules.setupPolicyFromFile(policyFile);
636 assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
638 /* Inject an ONSET event over the DCAE topic */
639 topics.inject(DCAE_TOPIC, onsetFile);
641 /* Wait to acquire a LOCK and a PDP-X PERMIT */
642 waitForLockAndPermit(policy, policyClMgt);
644 /* --- Operation Completed --- */
646 waitForOperationSuccess();
648 /* --- Transaction Completed --- */
649 waitForFinalSuccess(policy, policyClMgt);
653 * Waits for a OPERATION SUCCESS transaction notification.
655 protected void waitForOperationSuccess() {
656 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_SUCCESS);
660 * Waits for a FINAL SUCCESS transaction notification.
662 * @return the FINAL SUCCESS notification
664 protected VirtualControlLoopNotification waitForFinalSuccess(ToscaPolicy policy,
665 Listener<VirtualControlLoopNotification> policyClMgt) {
667 return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_SUCCESS);
671 * Waits for a OPERATION FAILURE transaction notification.
673 protected void waitForOperationFailure() {
674 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_FAILURE);
678 * Waits for a FINAL FAILURE transaction notification.
680 * @return the FINAL FAILURE notification
682 protected VirtualControlLoopNotification waitForFinalFailure(ToscaPolicy policy,
683 Listener<VirtualControlLoopNotification> policyClMgt) {
685 return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_FAILURE);
689 * Waits for notifications for LOCK acquisition and GUARD Permit so that event
690 * processing may proceed.
692 protected abstract void waitForLockAndPermit(ToscaPolicy policy,
693 Listener<VirtualControlLoopNotification> policyClMgt);
696 * Waits for a FINAL transaction notification.
698 * @param finalType FINAL_xxx type for which to wait
700 * @return the FINAL notification
702 protected abstract VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
703 Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType);