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);
62 return resourceContext;
67 public void addVnfc(String vnfcName, Map<String, String> params, String prefix) {
69 if (vnfcName.startsWith("ibcx")) {
70 assertEquals("ibcxvm0002func0001", vnfcName);
72 log.info("In AddVnfc " + vnfcName);
73 Map<String, String> expectedParams = getExpectedParams();
76 /* for (Map.Entry<String, String> entry : params.entrySet()) {
77 String key = entry.getKey();
78 String value = entry.getValue();
81 log.info("key= " + key + "value = " + value );
84 assertEquals(params, expectedParams);
89 public void updateResource(String resource, String resourceKey, Map<String, String> params) {
91 Map<String, String> expectedParams = new HashMap<String, String>();
93 expectedParams.put("prov-status", "NVTPROV");
94 assertEquals(params, expectedParams);
96 if ("vserver".equals(resource)) {
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'";
103 assertEquals(key, resourceKey);
104 } else if ("generic-vnf".equals(resource)) {
105 assertEquals(resourceKey, "generic-vnf.vnf-id = 'ibcx000000'");
107 fail("Invalid resource " + resource);
113 public Map<String, String> getExpectedParams() {
114 Map<String, String> vnfcParams = new HashMap<String, String>();
116 vnfcParams.put("vnfc-function-code", "func0");
118 vnfcParams.put("vnfc-type", "ssc0");
120 vnfcParams.put("ipaddress-v4-oam-vip", "000.00.00.00");
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");
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");
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");
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");
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");
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");
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");
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");
158 public void populateVnfcContext(SvcLogicContext ctx, String prefix) {
159 log.info("In populateVnfcContext " + prefix);
161 ctx.setAttribute(prefix + ".vnfc-type", "vnfctype1");
162 ctx.setAttribute(prefix + ".vnfc-function-code", "funccode1");
163 ctx.setAttribute(prefix + ".group-notation", "grpnot1");
166 public void populateVmContext(SvcLogicContext ctx, String prefix) {
167 log.info("In populateVmContext " + prefix);
169 ctx.setAttribute(prefix + ".vserver-name", "ibcx0000000");
171 ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
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",
178 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "test");
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",
185 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value",
186 "ibcx0001vm001vnfc1");
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",
200 public void populateGenericVnfContext(SvcLogicContext ctx, String prefix) {
202 log.info("In populateGenericVnf " + prefix);
203 ctx.setAttribute(prefix + ".vnf-name", "ibvcx0001");
204 ctx.setAttribute(prefix + ".vnf-type", "vUSP-Metaswitch");
206 ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
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");
221 //ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
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",
230 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key",
232 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value",
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",
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");
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",
251 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-key",
253 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-value",
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",
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");
267 ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "junk");
269 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "4");
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",
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",
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",
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");
289 public void populateFirstVnfcData(SvcLogicContext ctx, String prefix) throws Exception {
291 ctx.setAttribute(prefix + "vnf.vm-count", "4");
293 ctx.setAttribute(prefix + "vm[0].vnfc-type", "mmc");
294 ctx.setAttribute(prefix + "vm[0].vnfc-name", "vnfcname1");
296 ctx.setAttribute(prefix + "vm[1].vnfc-type", "mmc");
297 ctx.setAttribute(prefix + "vm[1].vnfc-name", "vnfcname2");
299 ctx.setAttribute(prefix + "vm[2].vnfc-type", "ssc");
300 ctx.setAttribute(prefix + "vm[2].vnfc-name", "vnfcname3");
302 ctx.setAttribute(prefix + "vm[3].vnfc-type", "ssc");
303 ctx.setAttribute(prefix + "vm[3].vnfc-name", "vnfcname4");
307 public void populateGroupNotation(SvcLogicContext ctx, String prefix) throws Exception {
309 ctx.setAttribute(prefix + "vnf.vm-count", "5");
311 ctx.setAttribute(prefix + "vm[0].vserver-name", "ibcxvm0001");
312 ctx.setAttribute(prefix + "vm[0].group-notation", "grpNot1");
314 ctx.setAttribute(prefix + "vm[1].vserver-name", "ibcxvm0002");
315 ctx.setAttribute(prefix + "vm[1].group-notation", "grpNot2");
317 ctx.setAttribute(prefix + "vm[2].vserver-name", "ibcxvm0003");
318 ctx.setAttribute(prefix + "vm[2].group-notation", "grpNot3");
320 ctx.setAttribute(prefix + "vm[3].vserver-name", "ibcxvm0004");
321 ctx.setAttribute(prefix + "vm[3].group-notation", "4");
323 ctx.setAttribute(prefix + "vm[4].vserver-name", "ibcxvm0005");
324 ctx.setAttribute(prefix + "vm[4].group-notation", "4");
328 public void populateVnfcRef(SvcLogicContext ctx) throws Exception {
330 for (int i = 0; i < 2; i++) {
332 String vnfcRefKey = "vnfcReference[" + i + "].";
334 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
335 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
337 //if ( i == 0 || i == 1 ) {
338 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
339 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "2");
342 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "ssc" + i);
344 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "func" + i);
346 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
351 public void populateAllVnfInfo(SvcLogicContext ctx, String prefix) throws Exception {
353 ctx.setAttribute("vnf-id", "ibcx000000");
355 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
356 ctx.setAttribute(prefix + ".vnf.vm-count", "2");
358 ctx.setAttribute(prefix + ".vm[0].vserver-name", "ibcxvm0000");
359 ctx.setAttribute(prefix + ".vm[0].vnfc-name", "VNFCNAME");
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");
366 ctx.setAttribute(prefix + ".vm[0].vf-module-id", "vfModuleId");
368 ctx.setAttribute(prefix + ".vm[1].vserver-name", "ibcxvm0002");
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");
375 ctx.setAttribute(prefix + ".vm[1].vf-module-id", "vfModuleId");
377 //ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002");
382 public void populateAllVnfInfo1(SvcLogicContext ctx, String prefix) throws Exception {
384 ctx.setAttribute("vnf-id", "dbjx0001v");
386 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
387 ctx.setAttribute(prefix + ".vnf.vm-count", "2");
389 ctx.setAttribute(prefix + ".vm[0].vserver-name", "dbjx0001vm001");
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");
396 ctx.setAttribute(prefix + ".vm[0].vf-module-id", "vfModuleId1");
398 ctx.setAttribute(prefix + ".vm[1].vserver-name", "dbjx0001vm002");
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");
405 ctx.setAttribute(prefix + ".vm[1].vf-module-id", "vfModuleId2");
410 public void populateVnfcRefFirstVnfcName(SvcLogicContext ctx) throws Exception {
412 for (int i = 0; i < 2; i++) {
414 String vnfcRefKey = "vnfcReference[" + i + "].";
416 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
417 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
419 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "first-vnfc-name");
420 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "pair");
422 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "vDBE-I? - DBJX");
424 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
426 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
431 public void populateVnfcRefRelValueSame(SvcLogicContext ctx) throws Exception {
433 for (int i = 0; i < 2; i++) {
435 String vnfcRefKey = "vnfcReference[" + i + "].";
437 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
438 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
441 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
442 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "1");
444 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "relative-value");
445 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "same");
448 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "v-I? - DBJX");
450 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
452 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
458 public void populateVnfcRefRelValueNext(SvcLogicContext ctx) throws Exception {
460 for (int i = 0; i < 2; i++) {
462 String vnfcRefKey = "vnfcReference[" + i + "].";
464 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
465 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
468 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
469 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "1");
471 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "relative-value");
472 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "next");
475 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "v-I? - DBJX");
477 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
479 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");