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=========================================================
21 package org.openecomp.policy.std.test;
23 import java.util.Collection;
25 import org.openecomp.policy.api.LoadedPolicy;
26 import org.openecomp.policy.api.NotificationHandler;
27 import org.openecomp.policy.api.NotificationType;
28 import org.openecomp.policy.api.PDPNotification;
29 import org.openecomp.policy.api.PolicyConfig;
30 import org.openecomp.policy.api.PolicyConfigException;
31 import org.openecomp.policy.api.PolicyConfigStatus;
32 import org.openecomp.policy.api.PolicyEngine;
33 import org.openecomp.policy.api.PolicyEngineException;
34 import org.openecomp.policy.api.RemovedPolicy;
36 public class Handler implements NotificationHandler{
39 public void notificationReceived(PDPNotification notification) {
40 System.out.println("Notification Received...");
41 System.out.println(notification.getNotificationType());
42 if(notification.getNotificationType().equals(NotificationType.REMOVE)){
43 System.out.println("Removed Policies: \n");
44 for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){
45 System.out.println(removedPolicy.getPolicyName());
46 System.out.println(removedPolicy.getVersionNo());
48 }else if(notification.getNotificationType().equals(NotificationType.UPDATE)){
49 System.out.println("Updated Policies: \n");
50 for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){
51 System.out.println("policyName : " + updatedPolicy.getPolicyName());
52 System.out.println("policyVersion :" + updatedPolicy.getVersionNo());
53 if(updatedPolicy.getPolicyName().contains(".Config_")){
54 System.out.println("Matches: " + updatedPolicy.getMatches());
55 System.out.println("UpdateType: "+ updatedPolicy.getUpdateType());
56 // Checking the Name is correct or not.
58 PolicyEngine policyEngine = new PolicyEngine("config.properties");
59 Collection<PolicyConfig> policyConfigs = policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName());
60 for(PolicyConfig policyConfig: policyConfigs){
61 if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){
62 System.out.println("Policy Retrieved with this Name notified. ");
64 System.err.println("\n\n Fail to retrieve policy !!!!\n\n");
66 // Also Test this case.
67 if(policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())){
68 System.out.println("Policy Name is good. ");
70 System.err.println("\n\n Fail to check Name \n\n");
73 } catch (PolicyEngineException e) {
75 } catch (PolicyConfigException e) {
80 }else if(notification.getNotificationType().equals(NotificationType.BOTH)){
81 System.out.println("Both updated and Removed Notification: \n");
82 System.out.println("Removed Policies: \n");
83 for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){
84 System.out.println(removedPolicy.getPolicyName());
85 System.out.println(removedPolicy.getVersionNo());
87 System.out.println("Updated Policies: \n");
88 for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){
89 System.out.println("policyName : " + updatedPolicy.getPolicyName());
90 System.out.println("policyVersion :" + updatedPolicy.getVersionNo());
91 System.out.println("Matches: " + updatedPolicy.getMatches());
92 System.out.println("UpdateType: "+ updatedPolicy.getUpdateType());
93 // Checking the Name is correct or not.
95 PolicyEngine policyEngine = new PolicyEngine("config.properties");
96 Collection<PolicyConfig> policyConfigs = policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName());
97 for(PolicyConfig policyConfig: policyConfigs){
98 if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){
99 System.out.println("Policy Retrieved with this Name notified. ");
101 System.err.println("\n\n Fail to retrieve policy !!!!\n\n");
103 // Also Test this case.
104 if(policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())){
105 System.out.println("Policy Name is good. ");
107 System.err.println("\n\n Fail to check Name \n\n");
110 } catch (PolicyEngineException e) {
112 } catch (PolicyConfigException e) {