2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2022 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop;
24 import org.junit.jupiter.api.AfterAll;
25 import org.junit.jupiter.api.AfterEach;
26 import org.junit.jupiter.api.BeforeAll;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.extension.ExtendWith;
29 import org.onap.policy.controlloop.common.rules.test.DroolsRuleTest;
30 import org.onap.policy.controlloop.common.rules.test.Listener;
31 import org.onap.policy.controlloop.common.rules.test.NamedRunner;
32 import org.onap.policy.controlloop.common.rules.test.TestNames;
33 import org.onap.policy.drools.apps.controller.usecases.UsecasesEventManager;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
35 import org.onap.policy.simulators.Util;
38 * Tests use cases using Usecases rules.
41 * Note: this runs ALL tests (i.e., any whose names start with "test").
43 @ExtendWith(NamedRunner.class)
44 @TestNames(prefixes = {"test"})
45 class UsecasesTest extends DroolsRuleTest {
46 protected static final String CONTROLLER_NAME = "usecases";
53 public static void setUpBeforeClass() {
54 initStatics(CONTROLLER_NAME);
56 rules.configure("src/main/resources");
57 httpClients.addClients("usecases");
58 simulators.start(Util::buildAaiSim, Util::buildSoSim, Util::buildVfcSim, Util::buildXacmlSim,
68 public static void tearDownAfterClass() {
84 public void tearDown() {
89 protected void waitForLockAndPermit(ToscaPolicy policy, Listener<VirtualControlLoopNotification> policyClMgt) {
90 String policyName = policy.getIdentifier().getName();
92 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.ACTIVE
93 && "EVENT.MANAGER.ACCEPT".equals(notif.getPolicyScope())
94 && policyName.equals(notif.getPolicyName()));
96 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
97 && "EVENT.MANAGER.PROCESS.GUARD.OUTCOME".equals(notif.getPolicyScope())
98 && policyName.equals(notif.getPolicyName())
99 && notif.getMessage().startsWith("Sending guard query"));
101 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
102 && "EVENT.MANAGER.PROCESS.GUARD.OUTCOME".equals(notif.getPolicyScope())
103 && policyName.equals(notif.getPolicyName())
104 && notif.getMessage().startsWith("Guard result")
105 && notif.getMessage().endsWith("Permit"));
107 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
108 && "EVENT.MANAGER.PROCESS.POLICY.STARTED".equals(notif.getPolicyScope())
109 && policyName.equals(notif.getPolicyName())
110 && notif.getMessage().startsWith("actor="));
114 protected VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
115 Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType) {
117 return policyClMgt.await(notif -> notif.getNotification() == finalType
118 && "EVENT.MANAGER.FINAL".equals(notif.getPolicyScope())
119 && (policy.getIdentifier().getName()).equals(notif.getPolicyName()));
123 protected long getCreateCount() {
124 return UsecasesEventManager.getCreateCount();