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