2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.aai.client.aai;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.fail;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
31 import java.util.HashMap;
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;
37 public class MockAaiService extends AaiService {
41 private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class);
42 private AAIClient aaiClient;
44 public MockAaiService(AAIClient aaic) {
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();
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 } else if ("cloud-region".equals(resourceType)) {
61 resourceContext.setAttribute(prefix + ".identity-url", "TestUrl");
64 return resourceContext;
69 public void addVnfc(String vnfcName, Map<String, String> params, String prefix) {
71 if (vnfcName.startsWith("ibcx")) {
72 assertEquals("ibcxvm0002func0001", vnfcName);
74 log.info("In AddVnfc " + vnfcName);
75 Map<String, String> expectedParams = getExpectedParams();
78 /* for (Map.Entry<String, String> entry : params.entrySet()) {
79 String key = entry.getKey();
80 String value = entry.getValue();
83 log.info("key= " + key + "value = " + value );
86 assertEquals(params, expectedParams);
91 public void updateResource(String resource, String resourceKey, Map<String, String> params) {
93 Map<String, String> expectedParams = new HashMap<String, String>();
95 expectedParams.put("prov-status", "NVTPROV");
96 assertEquals(params, expectedParams);
98 if ("vserver".equals(resource)) {
100 String key = "vserver.vserver-id = 'ibcx00000'" +
101 " AND tenant.tenant-id = 'tenantId'" +
102 " AND cloud-region.cloud-owner = 'cloudOwner'" +
103 " AND cloud-region.cloud-region-id = 'cloudRegionId'";
105 assertEquals(key, resourceKey);
106 } else if ("generic-vnf".equals(resource)) {
107 assertEquals(resourceKey, "generic-vnf.vnf-id = 'ibcx000000'");
109 fail("Invalid resource " + resource);
115 public Map<String, String> getExpectedParams() {
116 Map<String, String> vnfcParams = new HashMap<String, String>();
118 vnfcParams.put("vnfc-function-code", "func0");
120 vnfcParams.put("vnfc-type", "ssc0");
122 vnfcParams.put("ipaddress-v4-oam-vip", "000.00.00.00");
124 vnfcParams.put("prov-status", "NVTPROV");
125 vnfcParams.put("orchestration-status", "CONFIGURED");
126 vnfcParams.put("in-maint", "false");
127 vnfcParams.put("is-closed-loop", "false");
128 vnfcParams.put("group-notation", "2");
130 vnfcParams.put("relationship-list.relationship[0].related-to", "vserver");
131 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
132 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx00000");
134 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
135 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value", "tenantId");
138 .put("relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
139 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value", "cloudOwner");
141 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key",
142 "cloud-region.cloud-region-id");
143 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value", "cloudRegionId");
145 vnfcParams.put("relationship-list.relationship[1].related-to", "generic-vnf");
146 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
147 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx000000");
149 vnfcParams.put("relationship-list.relationship[2].related-to", "vf-module");
150 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key", "generic-vnf.vnf-id");
151 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value", "ibcx000000");
154 .put("relationship-list.relationship[2].relationship-data[1].relationship-key", "vf-module.vf-module-id");
155 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value", "vfModuleId");
160 public void populateVnfcContext(SvcLogicContext ctx, String prefix) {
161 log.info("In populateVnfcContext " + prefix);
163 ctx.setAttribute(prefix + ".vnfc-type", "vnfctype1");
164 ctx.setAttribute(prefix + ".vnfc-function-code", "funccode1");
165 ctx.setAttribute(prefix + ".group-notation", "grpnot1");
168 public void populateVmContext(SvcLogicContext ctx, String prefix) {
169 log.info("In populateVmContext " + prefix);
171 ctx.setAttribute(prefix + ".vserver-name", "ibcx0000000");
173 ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
176 ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "test");
177 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "1");
178 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key",
180 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "test");
183 ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vnfc");
184 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "1");
185 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key",
187 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value",
188 "ibcx0001vm001vnfc1");
192 ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "vf-module");
193 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "1");
194 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key",
195 "vf-module.vf-module-id");
196 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value",
202 public void populateGenericVnfContext(SvcLogicContext ctx, String prefix) {
204 log.info("In populateGenericVnf " + prefix);
205 ctx.setAttribute(prefix + ".vnf-name", "ibvcx0001");
206 ctx.setAttribute(prefix + ".vnf-type", "vUSP-Metaswitch");
208 ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
211 ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver");
212 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4");
213 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
214 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id");
215 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
216 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant");
217 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
218 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC");
219 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id");
220 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid");
223 //ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
226 ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver");
227 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4");
228 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key",
229 "vserver.vserver-id");
230 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value",
232 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key",
234 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value",
236 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key",
237 "cloud-region.cloud-owner");
238 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value",
240 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key",
241 "cloud-region.cloud-region-id");
242 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value",
243 "testcloudregionid");
246 ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vserver");
247 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "4");
248 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key",
249 "vserver.vserver-id");
250 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value",
253 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-key",
255 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-value",
258 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[2].relationship-key",
259 "cloud-region.cloud-owner");
260 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value",
263 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-key",
264 "cloud-region.cloud-region-id");
265 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-value",
266 "testcloudregionid");
269 ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "junk");
271 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "4");
273 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "test");
274 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value",
277 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-key", "test1");
278 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-value",
281 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-key", "test2");
282 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-value",
285 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-key", "test3");
286 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-value",
287 "testcloudregionid");
291 public void populateFirstVnfcData(SvcLogicContext ctx, String prefix) throws Exception {
293 ctx.setAttribute(prefix + "vnf.vm-count", "4");
295 ctx.setAttribute(prefix + "vm[0].vnfc-type", "mmc");
296 ctx.setAttribute(prefix + "vm[0].vnfc-name", "vnfcname1");
298 ctx.setAttribute(prefix + "vm[1].vnfc-type", "mmc");
299 ctx.setAttribute(prefix + "vm[1].vnfc-name", "vnfcname2");
301 ctx.setAttribute(prefix + "vm[2].vnfc-type", "ssc");
302 ctx.setAttribute(prefix + "vm[2].vnfc-name", "vnfcname3");
304 ctx.setAttribute(prefix + "vm[3].vnfc-type", "ssc");
305 ctx.setAttribute(prefix + "vm[3].vnfc-name", "vnfcname4");
309 public void populateGroupNotation(SvcLogicContext ctx, String prefix) throws Exception {
311 ctx.setAttribute(prefix + "vnf.vm-count", "5");
313 ctx.setAttribute(prefix + "vm[0].vserver-name", "ibcxvm0001");
314 ctx.setAttribute(prefix + "vm[0].group-notation", "grpNot1");
316 ctx.setAttribute(prefix + "vm[1].vserver-name", "ibcxvm0002");
317 ctx.setAttribute(prefix + "vm[1].group-notation", "grpNot2");
319 ctx.setAttribute(prefix + "vm[2].vserver-name", "ibcxvm0003");
320 ctx.setAttribute(prefix + "vm[2].group-notation", "grpNot3");
322 ctx.setAttribute(prefix + "vm[3].vserver-name", "ibcxvm0004");
323 ctx.setAttribute(prefix + "vm[3].group-notation", "4");
325 ctx.setAttribute(prefix + "vm[4].vserver-name", "ibcxvm0005");
326 ctx.setAttribute(prefix + "vm[4].group-notation", "4");
330 public void populateVnfcRef(SvcLogicContext ctx) throws Exception {
332 for (int i = 0; i < 2; i++) {
334 String vnfcRefKey = "vnfcReference[" + i + "].";
336 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
337 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
339 //if ( i == 0 || i == 1 ) {
340 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
341 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "2");
344 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "ssc" + i);
346 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "func" + i);
348 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
353 public void populateAllVnfInfo(SvcLogicContext ctx, String prefix) throws Exception {
355 ctx.setAttribute("vnf-id", "ibcx000000");
357 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
358 ctx.setAttribute(prefix + ".vnf.vm-count", "2");
360 ctx.setAttribute(prefix + ".vm[0].vserver-name", "ibcxvm0000");
361 ctx.setAttribute(prefix + ".vm[0].vnfc-name", "VNFCNAME");
363 ctx.setAttribute(prefix + ".vm[0].vserver-id", "ibcxvm0001id");
364 ctx.setAttribute(prefix + ".vm[0].tenant-id", "tenantid");
365 ctx.setAttribute(prefix + ".vm[0].cloud-owner", "cloudOwner");
366 ctx.setAttribute(prefix + ".vm[0].cloud-region-id", "cloudRegionId");
368 ctx.setAttribute(prefix + ".vm[0].vf-module-id", "vfModuleId");
370 ctx.setAttribute(prefix + ".vm[1].vserver-name", "ibcxvm0002");
372 ctx.setAttribute(prefix + ".vm[1].vserver-id", "ibcx00000");
373 ctx.setAttribute(prefix + ".vm[1].tenant-id", "tenantId");
374 ctx.setAttribute(prefix + ".vm[1].cloud-owner", "cloudOwner");
375 ctx.setAttribute(prefix + ".vm[1].cloud-region-id", "cloudRegionId");
377 ctx.setAttribute(prefix + ".vm[1].vf-module-id", "vfModuleId");
379 //ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002");
384 public void populateAllVnfInfo1(SvcLogicContext ctx, String prefix) throws Exception {
386 ctx.setAttribute("vnf-id", "dbjx0001v");
388 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
389 ctx.setAttribute(prefix + ".vnf.vm-count", "2");
391 ctx.setAttribute(prefix + ".vm[0].vserver-name", "dbjx0001vm001");
393 ctx.setAttribute(prefix + ".vm[0].vserver-id", "dbjx0001vm0001id");
394 ctx.setAttribute(prefix + ".vm[0].tenant-id", "tenantid1");
395 ctx.setAttribute(prefix + ".vm[0].cloud-owner", "cloudOwner1");
396 ctx.setAttribute(prefix + ".vm[0].cloud-region-id", "cloudRegionId1");
398 ctx.setAttribute(prefix + ".vm[0].vf-module-id", "vfModuleId1");
400 ctx.setAttribute(prefix + ".vm[1].vserver-name", "dbjx0001vm002");
402 ctx.setAttribute(prefix + ".vm[1].vserver-id", "dbjx0001vm0002id");
403 ctx.setAttribute(prefix + ".vm[1].tenant-id", "tenantId2");
404 ctx.setAttribute(prefix + ".vm[1].cloud-owner", "cloudOwner2");
405 ctx.setAttribute(prefix + ".vm[1].cloud-region-id", "cloudRegionId2");
407 ctx.setAttribute(prefix + ".vm[1].vf-module-id", "vfModuleId2");
412 public void populateVnfcRefFirstVnfcName(SvcLogicContext ctx) throws Exception {
414 for (int i = 0; i < 2; i++) {
416 String vnfcRefKey = "vnfcReference[" + i + "].";
418 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
419 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
421 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "first-vnfc-name");
422 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "pair");
424 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "vDBE-I? - DBJX");
426 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
428 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
433 public void populateVnfcRefRelValueSame(SvcLogicContext ctx) throws Exception {
435 for (int i = 0; i < 2; i++) {
437 String vnfcRefKey = "vnfcReference[" + i + "].";
439 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
440 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
443 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
444 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "1");
446 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "relative-value");
447 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "same");
450 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "v-I? - DBJX");
452 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
454 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
460 public void populateVnfcRefRelValueNext(SvcLogicContext ctx) throws Exception {
462 for (int i = 0; i < 2; i++) {
464 String vnfcRefKey = "vnfcReference[" + i + "].";
466 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
467 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
470 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
471 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "1");
473 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "relative-value");
474 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "next");
477 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "v-I? - DBJX");
479 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
481 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");