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.common.rules.test;
24 import java.util.function.Function;
25 import org.onap.policy.controlloop.VirtualControlLoopNotification;
26 import org.onap.policy.drools.system.PolicyController;
27 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
30 * Superclass used for rule tests.
32 public abstract class DroolsRuleTest extends BaseTest {
34 // these may be overridden by junit tests
35 private static Function<String, Rules> ruleMaker = Rules::new;
37 protected static Rules rules;
39 protected PolicyController controller;
42 * Initializes {@link #rules}, {@link #httpClients}, and {@link #simulators}.
44 * @param controllerName the rule controller name
46 public static void initStatics(String controllerName) {
47 rules = ruleMaker.apply(controllerName);
48 BaseTest.initStatics();
52 * Destroys {@link #httpClients}, {@link #simulators}, and {@link #rules}.
54 public static void finishStatics() {
55 BaseTest.finishStatics();
60 * Initializes {@link #topics} and {@link #controller}.
65 controller = rules.getController();
69 * Destroys {@link #topics} and resets the rule facts.
72 public void finish() {
78 * Returns ToscaPolicy from File.
80 * @param fileName a path name
84 protected ToscaPolicy checkPolicy(String fileName) {
85 return rules.setupPolicyFromFile(fileName);
89 * Returns Listener from createListener based on Coder.
90 * @return the Listener
93 protected Listener<VirtualControlLoopNotification> createNoficationTopicListener() {
94 return topics.createListener(POLICY_CL_MGT_TOPIC,
95 VirtualControlLoopNotification.class, controller);