2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.aai.client.aai;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.fail;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import java.util.HashMap;
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;
38 public class MockAaiService extends AaiService {
42 private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class);
43 private AAIClient aaiClient;
45 public MockAaiService(AAIClient aaic) {
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();
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);
63 return resourceContext;
68 public void addVnfc(String vnfcName, Map<String, String> params, String prefix) {
70 if (vnfcName.startsWith("ibcx")) {
71 assertEquals("ibcxvm0002func0001", vnfcName);
73 log.info("In AddVnfc " + vnfcName);
74 Map<String, String> expectedParams = getExpectedParams();
77 /* for (Map.Entry<String, String> entry : params.entrySet()) {
78 String key = entry.getKey();
79 String value = entry.getValue();
82 log.info("key= " + key + "value = " + value );
85 assertEquals(params, expectedParams);
90 public void updateResource(String resource, String resourceKey, Map<String, String> params) {
92 Map<String, String> expectedParams = new HashMap<String, String>();
94 expectedParams.put("prov-status", "NVTPROV");
95 assertEquals(params, expectedParams);
97 if ("vserver".equals(resource)) {
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'";
104 assertEquals(key, resourceKey);
105 } else if ("generic-vnf".equals(resource)) {
106 assertEquals(resourceKey, "generic-vnf.vnf-id = 'ibcx000000'");
108 fail("Invalid resource " + resource);
114 public Map<String, String> getExpectedParams() {
115 Map<String, String> vnfcParams = new HashMap<String, String>();
117 vnfcParams.put("vnfc-function-code", "func0");
119 vnfcParams.put("vnfc-type", "ssc0");
121 vnfcParams.put("ipaddress-v4-oam-vip", "000.00.00.00");
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");
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");
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");
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");
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");
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");
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");
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");
159 public void populateVnfcContext(SvcLogicContext ctx, String prefix) {
160 log.info("In populateVnfcContext " + prefix);
162 ctx.setAttribute(prefix + ".vnfc-type", "vnfctype1");
163 ctx.setAttribute(prefix + ".vnfc-function-code", "funccode1");
164 ctx.setAttribute(prefix + ".group-notation", "grpnot1");
167 public void populateVmContext(SvcLogicContext ctx, String prefix) {
168 log.info("In populateVmContext " + prefix);
170 ctx.setAttribute(prefix + ".vserver-name", "ibcx0000000");
172 ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
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",
179 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "test");
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",
186 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value",
187 "ibcx0001vm001vnfc1");
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",
201 public void populateGenericVnfContext(SvcLogicContext ctx, String prefix) {
203 log.info("In populateGenericVnf " + prefix);
204 ctx.setAttribute(prefix + ".vnf-name", "ibvcx0001");
205 ctx.setAttribute(prefix + ".vnf-type", "vUSP-Metaswitch");
207 ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
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");
222 //ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
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",
231 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key",
233 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value",
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",
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");
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",
252 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-key",
254 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-value",
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",
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");
268 ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "junk");
270 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "4");
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",
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",
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",
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");
290 public void populateFirstVnfcData(SvcLogicContext ctx, String prefix) throws Exception {
292 ctx.setAttribute(prefix + "vnf.vm-count", "4");
294 ctx.setAttribute(prefix + "vm[0].vnfc-type", "mmc");
295 ctx.setAttribute(prefix + "vm[0].vnfc-name", "vnfcname1");
297 ctx.setAttribute(prefix + "vm[1].vnfc-type", "mmc");
298 ctx.setAttribute(prefix + "vm[1].vnfc-name", "vnfcname2");
300 ctx.setAttribute(prefix + "vm[2].vnfc-type", "ssc");
301 ctx.setAttribute(prefix + "vm[2].vnfc-name", "vnfcname3");
303 ctx.setAttribute(prefix + "vm[3].vnfc-type", "ssc");
304 ctx.setAttribute(prefix + "vm[3].vnfc-name", "vnfcname4");
308 public void populateGroupNotation(SvcLogicContext ctx, String prefix) throws Exception {
310 ctx.setAttribute(prefix + "vnf.vm-count", "5");
312 ctx.setAttribute(prefix + "vm[0].vserver-name", "ibcxvm0001");
313 ctx.setAttribute(prefix + "vm[0].group-notation", "grpNot1");
315 ctx.setAttribute(prefix + "vm[1].vserver-name", "ibcxvm0002");
316 ctx.setAttribute(prefix + "vm[1].group-notation", "grpNot2");
318 ctx.setAttribute(prefix + "vm[2].vserver-name", "ibcxvm0003");
319 ctx.setAttribute(prefix + "vm[2].group-notation", "grpNot3");
321 ctx.setAttribute(prefix + "vm[3].vserver-name", "ibcxvm0004");
322 ctx.setAttribute(prefix + "vm[3].group-notation", "4");
324 ctx.setAttribute(prefix + "vm[4].vserver-name", "ibcxvm0005");
325 ctx.setAttribute(prefix + "vm[4].group-notation", "4");
329 public void populateVnfcRef(SvcLogicContext ctx) throws Exception {
331 for (int i = 0; i < 2; i++) {
333 String vnfcRefKey = "vnfcReference[" + i + "].";
335 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
336 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
338 //if ( i == 0 || i == 1 ) {
339 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
340 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "2");
343 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "ssc" + i);
345 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "func" + i);
347 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
352 public void populateAllVnfInfo(SvcLogicContext ctx, String prefix) throws Exception {
354 ctx.setAttribute("vnf-id", "ibcx000000");
356 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
357 ctx.setAttribute(prefix + ".vnf.vm-count", "2");
359 ctx.setAttribute(prefix + ".vm[0].vserver-name", "ibcxvm0000");
360 ctx.setAttribute(prefix + ".vm[0].vnfc-name", "VNFCNAME");
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");
367 ctx.setAttribute(prefix + ".vm[0].vf-module-id", "vfModuleId");
369 ctx.setAttribute(prefix + ".vm[1].vserver-name", "ibcxvm0002");
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");
376 ctx.setAttribute(prefix + ".vm[1].vf-module-id", "vfModuleId");
378 //ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002");
383 public void populateAllVnfInfo1(SvcLogicContext ctx, String prefix) throws Exception {
385 ctx.setAttribute("vnf-id", "dbjx0001v");
387 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
388 ctx.setAttribute(prefix + ".vnf.vm-count", "2");
390 ctx.setAttribute(prefix + ".vm[0].vserver-name", "dbjx0001vm001");
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");
397 ctx.setAttribute(prefix + ".vm[0].vf-module-id", "vfModuleId1");
399 ctx.setAttribute(prefix + ".vm[1].vserver-name", "dbjx0001vm002");
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");
406 ctx.setAttribute(prefix + ".vm[1].vf-module-id", "vfModuleId2");
411 public void populateVnfcRefFirstVnfcName(SvcLogicContext ctx) throws Exception {
413 for (int i = 0; i < 2; i++) {
415 String vnfcRefKey = "vnfcReference[" + i + "].";
417 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
418 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
420 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "first-vnfc-name");
421 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "pair");
423 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "vDBE-I? - DBJX");
425 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
427 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
432 public void populateVnfcRefRelValueSame(SvcLogicContext ctx) throws Exception {
434 for (int i = 0; i < 2; i++) {
436 String vnfcRefKey = "vnfcReference[" + i + "].";
438 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
439 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
442 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
443 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "1");
445 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "relative-value");
446 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "same");
449 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "v-I? - DBJX");
451 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
453 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");
459 public void populateVnfcRefRelValueNext(SvcLogicContext ctx) throws Exception {
461 for (int i = 0; i < 2; i++) {
463 String vnfcRefKey = "vnfcReference[" + i + "].";
465 ctx.setAttribute(vnfcRefKey + "VM-INSTANCE", String.valueOf(i));
466 ctx.setAttribute(vnfcRefKey + "VNFC-INSTANCE", "1");
469 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "fixed-value");
470 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "1");
472 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-TYPE", "relative-value");
473 ctx.setAttribute(vnfcRefKey + "GROUP-NOTATION-VALUE", "next");
476 ctx.setAttribute(vnfcRefKey + "VNFC-TYPE", "v-I? - DBJX");
478 ctx.setAttribute(vnfcRefKey + "VNFC-FUNCTION-CODE", "dbj");
480 ctx.setAttribute(vnfcRefKey + "IPADDRESS-V4-OAM-VIP", "Y");