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;
24 import org.junit.After;
25 import org.junit.AfterClass;
26 import org.junit.Before;
27 import org.junit.BeforeClass;
28 import org.junit.runner.RunWith;
29 import org.onap.policy.controlloop.common.rules.test.BaseRuleTest;
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.utils.PropertyUtil;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
35 import org.onap.policy.simulators.Util;
38 * Tests use case rules. Only a subset of available tests will work with these rules, thus
39 * a "FilterRunner" is used to filter out the other test cases.
42 * Note: this only runs tests whose names start with "testV" (e.g., testVcpe(),
45 @RunWith(NamedRunner.class)
46 @TestNames(prefixes = {"testV"})
48 public class UsecasesTest extends BaseRuleTest {
51 protected static final String CONTROLLER_NAME = "usecases";
57 public static void setUpBeforeClass() {
58 initStatics(CONTROLLER_NAME);
60 rules.configure("src/main/resources");
61 PropertyUtil.setSystemProperties(rules.getPdpdRepo().getSystemProperties("controlloop"));
62 rules.getPdpd().setEnvironment(rules.getPdpdRepo().getEnvironmentProperties("controlloop.properties"));
65 simulators.start(Util::buildAaiSim, Util::buildSoSim, Util::buildVfcSim, Util::buildGuardSim,
73 public static void tearDownAfterClass() {
89 public void tearDown() {
94 protected void waitForLockAndPermit(ToscaPolicy policy, Listener<VirtualControlLoopNotification> policyClMgt) {
95 String policyName = policy.getIdentifier().getName();
97 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.ACTIVE
98 && (policyName + ".EVENT").equals(notif.getPolicyName()));
100 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
101 && (policyName + ".EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED")
102 .equals(notif.getPolicyName()));
104 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
105 && (policyName + ".GUARD.RESPONSE").equals(notif.getPolicyName())
106 && notif.getMessage().startsWith("Guard result") && notif.getMessage().endsWith("Permit"));
108 policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
109 && (policyName + ".EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED")
110 .equals(notif.getPolicyName()));
114 protected VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
115 Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType) {
117 return policyClMgt.await(notif -> notif.getNotification() == finalType
118 && (policy.getIdentifier().getName() + ".EVENT.MANAGER").equals(notif.getPolicyName()));