AaiService sonar fixes
[appc.git] / appc-outbound / appc-aai-client / provider / src / test / java / org / onap / appc / aai / client / aai / MockAaiService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.aai.client.aai;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.fail;
29
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import java.util.HashMap;
33 import java.util.Map;
34 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
37
38 public class MockAaiService extends AaiService {
39
40     //ONAP migration
41
42     private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class);
43     private AAIClient aaiClient;
44
45     public MockAaiService(AAIClient aaic) {
46         super(aaic);
47     }
48
49     public SvcLogicContext readResource(String query, String prefix, String resourceType)
50         throws AaiServiceInternalException, SvcLogicException {
51         log.info("In MockRead Resource");
52         SvcLogicContext resourceContext = new SvcLogicContext();
53
54         //prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
55         if ("generic-vnf".equals(resourceType)) {
56             populateGenericVnfContext(resourceContext, prefix);
57         } else if ("vserver".equals(resourceType)) {
58             populateVmContext(resourceContext, prefix);
59         } else if ("vnfc".equals(resourceType)) {
60             populateVnfcContext(resourceContext, prefix);
61         }
62
63         return resourceContext;
64
65
66     }
67
68     public void addVnfc(String vnfcName, Map<String, String> params, String prefix) {
69
70         if (vnfcName.startsWith("ibcx")) {
71             assertEquals("ibcxvm0002func0001", vnfcName);
72
73             log.info("In AddVnfc " + vnfcName);
74             Map<String, String> expectedParams = getExpectedParams();
75                  
76                  
77                 /*    for (Map.Entry<String, String> entry : params.entrySet()) {
78                             String key = entry.getKey();
79                             String value = entry.getValue();
80         
81         
82                            log.info("key= " + key + "value = " + value );
83                          
84                     }*/
85             assertEquals(params, expectedParams);
86         }
87     }
88
89
90     public void updateResource(String resource, String resourceKey, Map<String, String> params) {
91
92         Map<String, String> expectedParams = new HashMap<String, String>();
93
94         expectedParams.put("prov-status", "NVTPROV");
95         assertEquals(params, expectedParams);
96
97         if ("vserver".equals(resource)) {
98
99             String key = "vserver.vserver-id = 'ibcx00000'" +
100                 " AND tenant.tenant-id = 'tenantId'" +
101                 " AND cloud-region.cloud-owner = 'cloudOwner'" +
102                 " AND cloud-region.cloud-region-id = 'cloudRegionId'";
103
104             assertEquals(key, resourceKey);
105         } else if ("generic-vnf".equals(resource)) {
106             assertEquals(resourceKey, "generic-vnf.vnf-id = 'ibcx000000'");
107         } else {
108             fail("Invalid resource " + resource);
109         }
110
111
112     }
113
114     public Map<String, String> getExpectedParams() {
115         Map<String, String> vnfcParams = new HashMap<String, String>();
116
117         vnfcParams.put("vnfc-function-code", "func0");
118
119         vnfcParams.put("vnfc-type", "ssc0");
120
121         vnfcParams.put("ipaddress-v4-oam-vip", "000.00.00.00");
122
123         vnfcParams.put("prov-status", "NVTPROV");
124         vnfcParams.put("orchestration-status", "CONFIGURED");
125         vnfcParams.put("in-maint", "false");
126         vnfcParams.put("is-closed-loop", "false");
127         vnfcParams.put("group-notation", "2");
128
129         vnfcParams.put("relationship-list.relationship[0].related-to", "vserver");
130         vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
131         vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx00000");
132
133         vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
134         vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value", "tenantId");
135
136         vnfcParams
137             .put("relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
138         vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value", "cloudOwner");
139
140         vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key",
141             "cloud-region.cloud-region-id");
142         vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value", "cloudRegionId");
143
144         vnfcParams.put("relationship-list.relationship[1].related-to", "generic-vnf");
145         vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
146         vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx000000");
147
148         vnfcParams.put("relationship-list.relationship[2].related-to", "vf-module");
149         vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
150         vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value", "ibcx000000");
151
152         vnfcParams
153             .put("relationship-list.relationship[2].relationship-data[1].relationship-key", "vf-module.vf-module-id");
154         vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value", "vfModuleId");
155
156         return vnfcParams;
157     }
158
159     public void populateVnfcContext(SvcLogicContext ctx, String prefix) {
160         log.info("In populateVnfcContext " + prefix);
161
162         ctx.setAttribute(prefix + ".vnfc-type", "vnfctype1");
163         ctx.setAttribute(prefix + ".vnfc-function-code", "funccode1");
164         ctx.setAttribute(prefix + ".group-notation", "grpnot1");
165     }
166
167     public void populateVmContext(SvcLogicContext ctx, String prefix) {
168         log.info("In populateVmContext " + prefix);
169
170         ctx.setAttribute(prefix + ".vserver-name", "ibcx0000000");
171
172         ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
173
174         // Junk
175         ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "test");
176         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "1");
177         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key",
178             "vnfc.vnfc-name");
179         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "test");
180
181         // VNFC
182         ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vnfc");
183         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "1");
184         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key",
185             "vnfc.vnfc-name");
186         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value",
187             "ibcx0001vm001vnfc1");
188
189         // VFModule
190
191         ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "vf-module");
192         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "1");
193         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key",
194             "vf-module.vf-module-id");
195         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value",
196             "vfModule1");
197
198
199     }
200
201     public void populateGenericVnfContext(SvcLogicContext ctx, String prefix) {
202
203         log.info("In populateGenericVnf " + prefix);
204         ctx.setAttribute(prefix + ".vnf-name", "ibvcx0001");
205         ctx.setAttribute(prefix + ".vnf-type", "vUSP-Metaswitch");
206
207         ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
208              
209             /* // VM1
210              ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver");
211              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4");
212              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
213              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id");
214              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
215              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant");
216              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
217              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC");
218              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id");
219              ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid");
220            
221              
222              //ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
223 */
224         // VM1
225         ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver");
226         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4");
227         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key",
228             "vserver.vserver-id");
229         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value",
230             "ibcx001vm001-id");
231         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key",
232             "tenant.tenant-id");
233         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value",
234             "sometenant");
235         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key",
236             "cloud-region.cloud-owner");
237         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value",
238             "ATTAIC");
239         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key",
240             "cloud-region.cloud-region-id");
241         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value",
242             "testcloudregionid");
243
244         // VM2
245         ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vserver");
246         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "4");
247         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key",
248             "vserver.vserver-id");
249         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value",
250             "ibcx000000");
251
252         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-key",
253             "tenant.tenant-id");
254         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-value",
255             "sometenant");
256
257         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[2].relationship-key",
258             "cloud-region.cloud-owner");
259         ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value",
260             "ATTAIC");
261
262         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-key",
263             "cloud-region.cloud-region-id");
264         ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-value",
265             "testcloudregionid");
266
267         // Unrelated
268         ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "junk");
269
270         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "4");
271
272         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "test");
273         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value",
274             "ibcx000000");
275
276         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-key", "test1");
277         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-value",
278             "sometenant");
279
280         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-key", "test2");
281         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-value",
282             "ATTAIC");
283
284         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-key", "test3");
285         ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-value",
286             "testcloudregionid");
287     }
288
289
290     public void populateFirstVnfcData(SvcLogicContext ctx, String prefix) throws Exception {
291
292         ctx.setAttribute(prefix + "vnf.vm-count", "4");
293
294         ctx.setAttribute(prefix + "vm[0].vnfc-type", "mmc");
295         ctx.setAttribute(prefix + "vm[0].vnfc-name", "vnfcname1");
296
297         ctx.setAttribute(prefix + "vm[1].vnfc-type", "mmc");
298         ctx.setAttribute(prefix + "vm[1].vnfc-name", "vnfcname2");
299
300         ctx.setAttribute(prefix + "vm[2].vnfc-type", "ssc");
301         ctx.setAttribute(prefix + "vm[2].vnfc-name", "vnfcname3");
302
303         ctx.setAttribute(prefix + "vm[3].vnfc-type", "ssc");
304         ctx.setAttribute(prefix + "vm[3].vnfc-name", "vnfcname4");
305     }
306
307
308     public void populateGroupNotation(SvcLogicContext ctx, String prefix) throws Exception {
309
310         ctx.setAttribute(prefix + "vnf.vm-count", "5");
311
312         ctx.setAttribute(prefix + "vm[0].vserver-name", "ibcxvm0001");
313         ctx.setAttribute(prefix + "vm[0].group-notation", "grpNot1");
314
315         ctx.setAttribute(prefix + "vm[1].vserver-name", "ibcxvm0002");
316         ctx.setAttribute(prefix + "vm[1].group-notation", "grpNot2");
317
318         ctx.setAttribute(prefix + "vm[2].vserver-name", "ibcxvm0003");
319         ctx.setAttribute(prefix + "vm[2].group-notation", "grpNot3");
320
321         ctx.setAttribute(prefix + "vm[3].vserver-name", "ibcxvm0004");
322         ctx.setAttribute(prefix + "vm[3].group-notation", "4");
323
324         ctx.setAttribute(prefix + "vm[4].vserver-name", "ibcxvm0005");
325         ctx.setAttribute(prefix + "vm[4].group-notation", "4");
326     }
327
328
329     public void populateVnfcRef(SvcLogicContext ctx) throws Exception {
330
331         for (int i = 0; i < 2; i++) {
332
333             String vnfcRefKey = "vnfcReference[" + i + "].";
334
335             ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
336             ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
337
338             //if ( i == 0 || i == 1 ) {
339             ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
340             ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "2");
341             //}
342
343             ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "ssc" + i);
344
345             ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "func" + i);
346
347             ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
348         }
349
350     }
351
352     public void populateAllVnfInfo(SvcLogicContext ctx, String prefix) throws Exception {
353
354         ctx.setAttribute("vnf-id", "ibcx000000");
355
356         ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
357         ctx.setAttribute(prefix + ".vnf.vm-count", "2");
358
359         ctx.setAttribute(prefix + ".vm[0].vserver-name", "ibcxvm0000");
360         ctx.setAttribute(prefix + ".vm[0].vnfc-name", "VNFCNAME");
361
362         ctx.setAttribute(prefix + ".vm[0].vserver-id", "ibcxvm0001id");
363         ctx.setAttribute(prefix + ".vm[0].tenant-id", "tenantid");
364         ctx.setAttribute(prefix + ".vm[0].cloud-owner", "cloudOwner");
365         ctx.setAttribute(prefix + ".vm[0].cloud-region-id", "cloudRegionId");
366
367         ctx.setAttribute(prefix + ".vm[0].vf-module-id", "vfModuleId");
368
369         ctx.setAttribute(prefix + ".vm[1].vserver-name", "ibcxvm0002");
370
371         ctx.setAttribute(prefix + ".vm[1].vserver-id", "ibcx00000");
372         ctx.setAttribute(prefix + ".vm[1].tenant-id", "tenantId");
373         ctx.setAttribute(prefix + ".vm[1].cloud-owner", "cloudOwner");
374         ctx.setAttribute(prefix + ".vm[1].cloud-region-id", "cloudRegionId");
375
376         ctx.setAttribute(prefix + ".vm[1].vf-module-id", "vfModuleId");
377
378         //ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002");
379
380     }
381
382
383     public void populateAllVnfInfo1(SvcLogicContext ctx, String prefix) throws Exception {
384
385         ctx.setAttribute("vnf-id", "dbjx0001v");
386
387         ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
388         ctx.setAttribute(prefix + ".vnf.vm-count", "2");
389
390         ctx.setAttribute(prefix + ".vm[0].vserver-name", "dbjx0001vm001");
391
392         ctx.setAttribute(prefix + ".vm[0].vserver-id", "dbjx0001vm0001id");
393         ctx.setAttribute(prefix + ".vm[0].tenant-id", "tenantid1");
394         ctx.setAttribute(prefix + ".vm[0].cloud-owner", "cloudOwner1");
395         ctx.setAttribute(prefix + ".vm[0].cloud-region-id", "cloudRegionId1");
396
397         ctx.setAttribute(prefix + ".vm[0].vf-module-id", "vfModuleId1");
398
399         ctx.setAttribute(prefix + ".vm[1].vserver-name", "dbjx0001vm002");
400
401         ctx.setAttribute(prefix + ".vm[1].vserver-id", "dbjx0001vm0002id");
402         ctx.setAttribute(prefix + ".vm[1].tenant-id", "tenantId2");
403         ctx.setAttribute(prefix + ".vm[1].cloud-owner", "cloudOwner2");
404         ctx.setAttribute(prefix + ".vm[1].cloud-region-id", "cloudRegionId2");
405
406         ctx.setAttribute(prefix + ".vm[1].vf-module-id", "vfModuleId2");
407
408
409     }
410
411     public void populateVnfcRefFirstVnfcName(SvcLogicContext ctx) throws Exception {
412
413         for (int i = 0; i < 2; i++) {
414
415             String vnfcRefKey = "vnfcReference[" + i + "].";
416
417             ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
418             ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
419
420             ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "first-vnfc-name");
421             ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "pair");
422
423             ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "vDBE-I? - DBJX");
424
425             ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
426
427             ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
428         }
429
430     }
431
432     public void populateVnfcRefRelValueSame(SvcLogicContext ctx) throws Exception {
433
434         for (int i = 0; i < 2; i++) {
435
436             String vnfcRefKey = "vnfcReference[" + i + "].";
437
438             ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
439             ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
440
441             if (i == 0) {
442                 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
443                 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "1");
444             } else {
445                 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "relative-value");
446                 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "same");
447             }
448
449             ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "v-I? - DBJX");
450
451             ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
452
453             ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
454         }
455
456     }
457
458
459     public void populateVnfcRefRelValueNext(SvcLogicContext ctx) throws Exception {
460
461         for (int i = 0; i < 2; i++) {
462
463             String vnfcRefKey = "vnfcReference[" + i + "].";
464
465             ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
466             ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
467
468             if (i == 0) {
469                 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
470                 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "1");
471             } else {
472                 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "relative-value");
473                 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "next");
474             }
475
476             ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "v-I? - DBJX");
477
478             ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
479
480             ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
481         }
482
483     }
484
485 }