2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
20 package org.onap.policyengine;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Collection;
26 import java.util.UUID;
28 import org.onap.policy.api.DecisionResponse;
29 import org.onap.policy.api.LoadedPolicy;
30 import org.onap.policy.api.NotificationScheme;
31 import org.onap.policy.api.PolicyConfig;
32 import org.onap.policy.api.PolicyConfigException;
33 import org.onap.policy.api.PolicyDecisionException;
34 import org.onap.policy.api.PolicyEngine;
35 import org.onap.policy.api.PolicyEventException;
36 import org.onap.policy.api.PolicyResponse;
37 import org.onap.policy.api.RemovedPolicy;
40 * Class contains static functions which make call to policy engine using API.
41 * This class is used by generalTestClient.java
47 public class PolicyEngineTestClient {
49 * This fuction make API call to policy engine to get config. And returns
50 * policy name, policy version and policy configStatus
52 * @param org.onap.policyEngine
53 * @param onapComponentName
55 * @param configAttributes
59 @SuppressWarnings("deprecation")
60 public static ArrayList<String> getConfig(PolicyEngine policyEngine,
61 String onapComponentName, String configName,
62 Map<String, String> configAttributes) {
63 ArrayList<String> resultReceived = new ArrayList<>();
65 UUID requestID = UUID.randomUUID();
66 Collection<PolicyConfig> policyConfigs;
67 if (configName == null) {
68 policyConfigs = policyEngine.getConfig(onapComponentName, requestID);
70 if (configAttributes == null) {
71 policyConfigs = policyEngine.getConfig(onapComponentName,
72 configName, requestID);
75 policyConfigs = policyEngine.getConfig(onapComponentName,
76 configName, configAttributes, requestID);
79 if (policyConfigs != null && !policyConfigs.isEmpty()) {
80 for (PolicyConfig policyConfig : policyConfigs) {
81 resultReceived.add("Policy Name: "
82 + policyConfig.getPolicyName()
84 + policyConfig.getPolicyVersion() + " - "
85 + policyConfig.getPolicyConfigStatus());
88 } catch (PolicyConfigException e) {
89 // logger.error("Exception Occured"+e);
90 resultReceived.add(""+e);
92 return resultReceived;
96 * This functions make API call to policy engine to get decision. And
97 * returns policy Decision
99 * @param org.onap.policyEngine
100 * @param onapComponentName
101 * @param decisionAttributes
104 public static ArrayList<String> getDecision(PolicyEngine policyEngine,
105 String onapComponentName, Map<String, String> decisionAttributes) {
106 ArrayList<String> resultReceived = new ArrayList<>();
109 UUID requestID = UUID.randomUUID();
110 @SuppressWarnings("deprecation")
111 DecisionResponse policyDecision = policyEngine.getDecision(
112 onapComponentName, decisionAttributes, requestID);
113 resultReceived.add(policyDecision.getDecision().toString());
114 } catch (PolicyDecisionException e) {
115 // logger.error("Exception Occured"+e);
116 resultReceived.add(""+e);
118 return resultReceived;
122 * This function makes API call to policy engine to get action. And returns
123 * responseMessage and responseStatus
125 * @param org.onap.policyEngine
126 * @param eventAttributes
129 public static ArrayList<String> getAction(PolicyEngine policyEngine,
130 Map<String, String> eventAttributes) {
131 ArrayList<String> resultReceived = new ArrayList<>();
133 UUID requestID = UUID.randomUUID();
134 @SuppressWarnings("deprecation")
135 Collection<PolicyResponse> policyResponses = policyEngine
136 .sendEvent(eventAttributes, requestID);
137 if (policyResponses != null && !policyResponses.isEmpty()) {
138 for (PolicyResponse policyResponse : policyResponses) {
139 resultReceived.add(policyResponse
140 .getPolicyResponseMessage()
142 + policyResponse.getPolicyResponseStatus());
145 } catch (PolicyEventException e) {
146 // logger.error("Exception Occured"+e);
147 resultReceived.add(""+e);
149 return resultReceived;
153 * This function makes API call to policy engine to get manual
156 * @param org.onap.policyEngine
159 public static void getManualNotifications(PolicyEngine policyEngine) {
160 policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS);
161 System.out.println(policyEngine.getNotification().getNotificationType());
162 for (LoadedPolicy updated : policyEngine.getNotification().getLoadedPolicies()) {
163 System.out.println(updated.getPolicyName());
164 System.out.println(updated.getVersionNo());
165 System.out.println(updated.getMatches());
167 for (RemovedPolicy removed : policyEngine.getNotification()
168 .getRemovedPolicies()) {
169 System.out.println(removed.getPolicyName());
170 System.out.println(removed.getVersionNo());
175 * This function makes API call to policy engine to get automatic
178 * @param org.onap.policyEngine
180 public static void getAutoNotifications(PolicyEngine policyEngine) {
181 Handler handler = new Handler();
182 policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS,
185 System.out.println("Enter a any key to exit");
188 } catch (IOException e) {