Update css file name in conf.py
[policy/engine.git] / PolicyEngineClient / src / test / java / org / onap / policyengine / Handler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineClient
4  * ================================================================================
5  * Copyright (C) 2017, 2019 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policyengine;
22
23 import java.util.Collection;
24
25 import org.onap.policy.api.LoadedPolicy;
26 import org.onap.policy.api.NotificationHandler;
27 import org.onap.policy.api.NotificationType;
28 import org.onap.policy.api.PDPNotification;
29 import org.onap.policy.api.PolicyConfig;
30 import org.onap.policy.api.PolicyConfigException;
31 import org.onap.policy.api.PolicyConfigStatus;
32 import org.onap.policy.api.PolicyEngine;
33 import org.onap.policy.api.PolicyEngineException;
34 import org.onap.policy.api.RemovedPolicy;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
37
38 public class Handler implements NotificationHandler {
39
40     private static final Logger LOGGER = FlexLogger.getLogger(Handler.class);
41
42     @Override
43     public void notificationReceived(PDPNotification notification) {
44         System.out.println("Notification Received...");
45         System.out.println(notification.getNotificationType());
46         if (notification.getNotificationType().equals(NotificationType.REMOVE)) {
47             System.out.println("Removed Policies: \n");
48             for (RemovedPolicy removedPolicy : notification.getRemovedPolicies()) {
49                 System.out.println(removedPolicy.getPolicyName());
50                 System.out.println(removedPolicy.getVersionNo());
51             }
52         } else if (notification.getNotificationType().equals(NotificationType.UPDATE)) {
53             System.out.println("Updated Policies: \n");
54             for (LoadedPolicy updatedPolicy : notification.getLoadedPolicies()) {
55                 System.out.println("policyName : " + updatedPolicy.getPolicyName());
56                 System.out.println("policyVersion :" + updatedPolicy.getVersionNo());
57                 if (updatedPolicy.getPolicyName().contains(".Config_")) {
58                     System.out.println("Matches: " + updatedPolicy.getMatches());
59                     System.out.println("UpdateType: " + updatedPolicy.getUpdateType());
60                     // Checking the Name is correct or not.
61                     try {
62                         PolicyEngine policyEngine = new PolicyEngine("config.properties");
63                         @SuppressWarnings("deprecation")
64                         Collection<PolicyConfig> policyConfigs =
65                                 policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName());
66                         for (PolicyConfig policyConfig : policyConfigs) {
67                             if (policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)) {
68                                 System.out.println("Policy Retrieved with this Name notified. ");
69                             } else {
70                                 System.err.println("\n\n Fail to retrieve policy !!!!\n\n");
71                             }
72                             // Also Test this case.
73                             if (policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())) {
74                                 System.out.println("Policy Name is good. ");
75                             } else {
76                                 System.err.println("\n\n Fail to check Name \n\n");
77                             }
78                         }
79                     } catch (PolicyEngineException e) {
80                         LOGGER.error("Exception Occured" + e);
81                     } catch (PolicyConfigException e) {
82                         LOGGER.error("Exception Occured" + e);
83                     }
84                 }
85             }
86         } else if (notification.getNotificationType().equals(NotificationType.BOTH)) {
87             System.out.println("Both updated and Removed Notification: \n");
88             System.out.println("Removed Policies: \n");
89             for (RemovedPolicy removedPolicy : notification.getRemovedPolicies()) {
90                 System.out.println(removedPolicy.getPolicyName());
91                 System.out.println(removedPolicy.getVersionNo());
92             }
93             System.out.println("Updated Policies: \n");
94             for (LoadedPolicy updatedPolicy : notification.getLoadedPolicies()) {
95                 System.out.println("policyName : " + updatedPolicy.getPolicyName());
96                 System.out.println("policyVersion :" + updatedPolicy.getVersionNo());
97                 System.out.println("Matches: " + updatedPolicy.getMatches());
98                 System.out.println("UpdateType: " + updatedPolicy.getUpdateType());
99                 // Checking the Name is correct or not.
100                 try {
101                     PolicyEngine policyEngine = new PolicyEngine("config.properties");
102                     @SuppressWarnings("deprecation")
103                     Collection<PolicyConfig> policyConfigs =
104                             policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName());
105                     for (PolicyConfig policyConfig : policyConfigs) {
106                         if (policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)) {
107                             System.out.println("Policy Retrieved with this Name notified. ");
108                         } else {
109                             System.err.println("\n\n Fail to retrieve policy !!!!\n\n");
110                         }
111                         // Also Test this case.
112                         if (policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())) {
113                             System.out.println("Policy Name is good. ");
114                         } else {
115                             System.err.println("\n\n Fail to check Name \n\n");
116                         }
117                     }
118                 } catch (PolicyEngineException e) {
119                     LOGGER.error("Exception Occured" + e);
120                 } catch (PolicyConfigException e) {
121                     LOGGER.error("Exception Occured" + e);
122                 }
123             }
124         }
125     }
126
127 }