2e208748f61350a13c32b90d0ac11f7731957c18
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * unit test
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
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.policy.controlloop.eventmanager;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.fail;
25
26 import java.time.Instant;
27 import java.util.HashMap;
28 import java.util.UUID;
29
30 import org.junit.Test;
31 import org.onap.policy.aai.AAIGETVnfResponse;
32 import org.onap.policy.aai.AAIGETVserverResponse;
33 import org.onap.policy.aai.RelatedToProperty;
34 import org.onap.policy.aai.RelatedToPropertyItem;
35 import org.onap.policy.aai.Relationship;
36 import org.onap.policy.aai.RelationshipData;
37 import org.onap.policy.aai.RelationshipDataItem;
38 import org.onap.policy.aai.RelationshipList;
39 import org.onap.policy.controlloop.ControlLoopEventStatus;
40 import org.onap.policy.controlloop.Util;
41 import org.onap.policy.controlloop.VirtualControlLoopEvent;
42 import org.onap.policy.controlloop.policy.ControlLoopPolicy;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45
46 public class ControlLoopEventManagerTest {
47         private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManagerTest.class);
48         
49         private static VirtualControlLoopEvent onset;
50         static {
51                 onset = new VirtualControlLoopEvent();
52                 onset.closedLoopControlName = "ControlLoop-vUSP"; 
53                 onset.requestID = UUID.randomUUID();
54                 onset.target = "VM_NAME";
55                 onset.closedLoopAlarmStart = Instant.now();
56                 onset.AAI = new HashMap<String, String>();
57                 onset.AAI.put("cloud-region.identity-url", "foo");
58                 onset.AAI.put("vserver.selflink", "bar");
59                 onset.AAI.put("generic-vnf.vnf-id", "83f674e8-7555-44d7-9a39-bdc3770b0491");
60                 onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
61         }
62         
63         @Test
64         public void testGetAAIInfo() {
65                 final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
66                 onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
67                 try {
68                         @SuppressWarnings("unused")
69                         ControlLoopEventManager eventManager = new ControlLoopEventManager(onset.closedLoopControlName, onset.requestID);
70                         onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET; 
71                          
72                         String user = "POLICY";
73                         String password = "POLICY";
74                         String vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
75                         String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf/";                    
76                         AAIGETVnfResponse response = getQueryByVnfID2(url, user, password, onset.requestID, vnfID);  
77                         assertNotNull(response);
78                         logger.info("testGetAAIInfo test result is " + (response == null ? "null" : "not null"));
79                 } catch (Exception e) {
80                         fail(e.getMessage());
81                         logger.error("testGetAAIInfo Exception: ", e);
82                 }
83         }
84
85         @Test
86         public void testIsClosedLoopDisabled() {
87                 //
88                 // Load up the policy
89                 //
90                 final Util.Pair<ControlLoopPolicy, String> pair = Util.loadYaml("src/test/resources/test.yaml");
91                 onset.closedLoopControlName = pair.a.getControlLoop().getControlLoopName();
92                 
93                 try {
94                         onset.closedLoopEventStatus = ControlLoopEventStatus.ONSET; 
95                         
96                         logger.info("testIsClosedLoopDisabled --");
97                         String user = "POLICY";
98                         String password = "POLICY";
99                         String vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491";
100                         String url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf/"; 
101                         AAIGETVnfResponse response = getQueryByVnfID2(url, user, password, onset.requestID, vnfID); 
102                         assertNotNull(response);
103                         boolean disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
104                         logger.info("QueryByVnfID - isClosedLoopDisabled: " + disabled); 
105
106                         String vnfName = "lll_vnf_010317";
107                         url = "https://aai-ext1.test.att.com:8443/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; 
108                         response = getQueryByVnfName2(url, user, password, onset.requestID, vnfName); 
109                         assertNotNull(response);
110                         disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
111                         logger.info("QueryByVnfName2 - isClosedLoopDisabled: " + disabled); 
112
113                         String vserverName = "USMSO1SX7NJ0103UJZZ01-vjunos0";
114                         url = "https://aai-ext1.test.att.com:8443//aai/v11/nodes/vservers?vserver-name="; 
115                         @SuppressWarnings("unused")
116                         AAIGETVserverResponse response2 = getQueryByVserverName2(url, user, password, onset.requestID, vserverName); 
117                         assertNotNull(response);
118                         disabled = ControlLoopEventManager.isClosedLoopDisabled(response);
119                         logger.info("QueryByVserverName - isClosedLoopDisabled: " + disabled); 
120                 } catch (Exception e) {
121                         fail(e.getMessage());
122                 }
123         }
124         
125         // Simulate a response 
126         public static AAIGETVnfResponse getQueryByVnfID2(String urlGet, String username, String password, UUID requestID, String key) {
127                 AAIGETVnfResponse response = new AAIGETVnfResponse();
128                 
129                 response.vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491"; 
130                 response.vnfName = "lll_vnf_010317";
131                 response.vnfType = "Basa-122216-Service/VidVsamp12BaseVolume 1";
132                 response.serviceId = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb";
133                 response.orchestrationStatus = "Created";
134                 response.inMaint = "false";
135                 response.isClosedLoopDisabled = "false";
136                 response.resourceVersion = "1494001988835";
137                 response.modelInvariantId = "f18be3cd-d446-456e-9109-121d9b62feaa";
138                   
139         RelationshipList relationshipList = new RelationshipList();
140         Relationship     relationship = new Relationship();
141         RelationshipData relationshipData = new RelationshipData();
142         RelationshipDataItem relationshipDataItem = new RelationshipDataItem();
143         
144         relationshipDataItem.relationshipKey   = "customer.global-customer-id"; 
145         relationshipDataItem.relationshipValue = "MSO_1610_ST"; 
146         relationshipData.relationshipData.add(relationshipDataItem);
147         
148         relationshipDataItem.relationshipKey   = "service-subscription.service-type"; 
149         relationshipDataItem.relationshipValue = "MSO-dev-service-type"; 
150         relationshipData.relationshipData.add(relationshipDataItem);
151         
152         relationshipDataItem.relationshipKey   = "service-instance.service-instance-id"; 
153         relationshipDataItem.relationshipValue = "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970"; 
154         relationshipData.relationshipData.add(relationshipDataItem);
155         
156         RelatedToProperty relatedToProperty = new RelatedToProperty();
157         RelatedToPropertyItem item = new RelatedToPropertyItem();  
158         item.propertyKey = "service-instance.service-instance-name"; 
159         item.propertyValue = "lll_svc_010317"; 
160         relatedToProperty.relatedTo.add(item);
161         
162         relationship.relatedTo = "service-instance";
163         relationship.relatedLink = "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
164         relationship.relationshipData = relationshipData;
165         relationship.relatedToProperty = relatedToProperty;
166        
167         relationshipList.relationshipList.add(relationship);
168         response.relationshipList = relationshipList; 
169
170                 return response;
171         }
172
173         public static AAIGETVnfResponse getQueryByVnfName2(String urlGet, String username, String password, UUID requestID, String key) {
174                 AAIGETVnfResponse response = new AAIGETVnfResponse();
175                 
176                 response.vnfID = "83f674e8-7555-44d7-9a39-bdc3770b0491"; 
177                 response.vnfName = "lll_vnf_010317";
178                 response.vnfType = "Basa-122216-Service/VidVsamp12BaseVolume 1";
179                 response.serviceId = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb";
180                 response.orchestrationStatus = "Created";
181                 response.inMaint = "false";
182                 response.isClosedLoopDisabled = "false";
183                 response.resourceVersion = "1494001988835";
184                 response.modelInvariantId = "f18be3cd-d446-456e-9109-121d9b62feaa";
185                   
186         RelationshipList relationshipList = new RelationshipList();
187         Relationship     relationship = new Relationship();
188         RelationshipData relationshipData = new RelationshipData();
189         RelationshipDataItem relationshipDataItem = new RelationshipDataItem();
190         
191         relationshipDataItem.relationshipKey   = "customer.global-customer-id"; 
192         relationshipDataItem.relationshipValue = "MSO_1610_ST"; 
193         relationshipData.relationshipData.add(relationshipDataItem);
194         
195         relationshipDataItem.relationshipKey   = "service-subscription.service-type"; 
196         relationshipDataItem.relationshipValue = "MSO-dev-service-type"; 
197         relationshipData.relationshipData.add(relationshipDataItem);
198         
199         relationshipDataItem.relationshipKey   = "service-instance.service-instance-id"; 
200         relationshipDataItem.relationshipValue = "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970"; 
201         relationshipData.relationshipData.add(relationshipDataItem);
202         
203         RelatedToProperty relatedToProperty = new RelatedToProperty();
204         RelatedToPropertyItem item = new RelatedToPropertyItem();  
205         item.propertyKey = "service-instance.service-instance-name"; 
206         item.propertyValue = "lll_svc_010317"; 
207         relatedToProperty.relatedTo.add(item);
208         
209         relationship.relatedTo = "service-instance";
210         relationship.relatedLink = "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
211         relationship.relationshipData = relationshipData;
212         relationship.relatedToProperty = relatedToProperty;
213        
214         relationshipList.relationshipList.add(relationship);
215         response.relationshipList = relationshipList; 
216
217                 return response;
218         }
219
220         public static AAIGETVserverResponse getQueryByVserverName2(String urlGet, String username, String password, UUID requestID, String key) {
221                 AAIGETVserverResponse response = new AAIGETVserverResponse();
222                 
223                 response.vserverID = "d0668d4f-c25e-4a1b-87c4-83845c01efd8"; 
224                 response.vserverName = "USMSO1SX7NJ0103UJZZ01-vjunos0"; 
225                 response.vserverName2 = "vjunos0"; 
226                 response.vserverSelflink = "https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8"; 
227                 response.inMaint = "false"; 
228                 response.isClosedLoopDisabled = "false"; 
229                 response.resourceVersion = "1494001931513"; 
230                   
231         RelationshipList relationshipList = new RelationshipList();
232         Relationship     relationship = new Relationship();
233         RelationshipData relationshipData = new RelationshipData();
234         RelationshipDataItem relationshipDataItem = new RelationshipDataItem();
235         
236         relationshipDataItem.relationshipKey   = "customer.global-customer-id"; 
237         relationshipDataItem.relationshipValue = "MSO_1610_ST"; 
238         relationshipData.relationshipData.add(relationshipDataItem);
239         
240         relationshipDataItem.relationshipKey   = "service-subscription.service-type"; 
241         relationshipDataItem.relationshipValue = "MSO-dev-service-type"; 
242         relationshipData.relationshipData.add(relationshipDataItem);
243         
244         relationshipDataItem.relationshipKey   = "service-instance.service-instance-id"; 
245         relationshipDataItem.relationshipValue = "e1e9c97c-02c0-4919-9b4c-eb5d5ef68970"; 
246         relationshipData.relationshipData.add(relationshipDataItem);
247         
248         RelatedToProperty relatedToProperty = new RelatedToProperty();
249         RelatedToPropertyItem item = new RelatedToPropertyItem();  
250         item.propertyKey = "service-instance.service-instance-name"; 
251         item.propertyValue = "lll_svc_010317"; 
252         relatedToProperty.relatedTo.add(item);
253         
254         relationship.relatedTo = "service-instance";
255         relationship.relatedLink = "/aai/v11/business/customers/customer/MSO_1610_ST/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/e1e9c97c-02c0-4919-9b4c-eb5d5ef68970";
256         relationship.relationshipData = relationshipData;
257         relationship.relatedToProperty = relatedToProperty;
258        
259         relationshipList.relationshipList.add(relationship);
260         response.relationshipList = relationshipList; 
261
262                 return response;
263         }
264 }