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 java.util.function.Function;
24 import org.onap.policy.controlloop.VirtualControlLoopNotification;
25 import org.onap.policy.drools.system.PolicyController;
26 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
29 * Superclass used for rule tests.
31 public abstract class DroolsRuleTest extends BaseTest {
33 // these may be overridden by junit tests
34 private static Function<String, Rules> ruleMaker = Rules::new;
36 protected static Rules rules;
38 protected PolicyController controller;
41 * Initializes {@link #rules}, {@link #httpClients}, and {@link #simulators}.
43 * @param controllerName the rule controller name
45 public static void initStatics(String controllerName) {
46 rules = ruleMaker.apply(controllerName);
47 BaseTest.initStatics();
51 * Destroys {@link #httpClients}, {@link #simulators}, and {@link #rules}.
53 public static void finishStatics() {
54 BaseTest.finishStatics();
59 * Initializes {@link #topics} and {@link #controller}.
64 controller = rules.getController();
68 * Destroys {@link #topics} and resets the rule facts.
71 public void finish() {
77 * Returns ToscaPolicy from File.
79 * @param fileName a path name
83 protected ToscaPolicy checkPolicy(String fileName) {
84 return rules.setupPolicyFromFile(fileName);
88 * Returns Listener from createListener based on Coder.
89 * @return the Listener
92 protected Listener<VirtualControlLoopNotification> createNoficationTopicListener() {
93 return topics.createListener(POLICY_CL_MGT_TOPIC,
94 VirtualControlLoopNotification.class, controller);