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;
26 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.fail;
31 import java.util.HashMap;
34 import org.apache.commons.lang3.StringUtils;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
40 import org.onap.ccsdk.sli.adaptors.aai.AAIClient;
42 public class MockAaiService extends AaiService {
46 private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class);
47 private AAIClient aaiClient;
49 public MockAaiService(AAIClient aaic) {
54 /*public MockAaiService() {
55 super(new AAIClientMock());
58 public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception {
59 log.info("In MockRead Resource");
60 SvcLogicContext resourceContext = new SvcLogicContext();
62 //prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : "";
63 if ( "generic-vnf".equals(resourceType) ) {
64 populateGenericVnfContext(resourceContext, prefix);
66 else if("vserver".equals(resourceType) ) {
67 populateVmContext(resourceContext, prefix);
69 else if("vnfc".equals(resourceType) ) {
70 populateVnfcContext(resourceContext, prefix);
74 return resourceContext;
80 public void addVnfc(String vnfcName, Map<String, String> params, String prefix) throws Exception {
83 if ( vnfcName.startsWith("ibcx")) {
84 assertEquals("ibcxvm0002func0001", vnfcName);
87 log.info("In AddVnfc " + vnfcName);
88 Map<String, String> expectedParams = getExpectedParams();
91 /* for (Map.Entry<String, String> entry : params.entrySet()) {
92 String key = entry.getKey();
93 String value = entry.getValue();
96 log.info("key= " + key + "value = " + value );
99 assertEquals(params, expectedParams);
104 public void updateResource( String resource, String resourceKey, Map<String, String> params) throws Exception {
106 Map<String, String> expectedParams = new HashMap<String, String>();
109 expectedParams.put("prov-status", "NVTPROV");
110 assertEquals(params, expectedParams);
112 if ( "vserver".equals(resource)) {
114 String key = "vserver.vserver-id = 'ibcx00000'" +
115 " AND tenant.tenant-id = 'tenantId'" +
116 " AND cloud-region.cloud-owner = 'cloudOwner'" +
117 " AND cloud-region.cloud-region-id = 'cloudRegionId'";
119 assertEquals(key, resourceKey);
121 else if ( "generic-vnf".equals(resource)) {
122 assertEquals(resourceKey, "generic-vnf.vnf-id = 'ibcx000000'");
125 fail("Invalid resource " + resource);
132 public Map<String, String> getExpectedParams() throws Exception {
133 Map<String, String> vnfcParams = new HashMap<String, String>();
135 vnfcParams.put("vnfc-function-code", "func0");
139 vnfcParams.put("vnfc-type", "ssc0");
141 vnfcParams.put("ipaddress-v4-oam-vip", "000.00.00.00");
143 vnfcParams.put("prov-status", "NVTPROV");
144 vnfcParams.put("orchestration-status", "CONFIGURED");
145 vnfcParams.put("in-maint", "false");
146 vnfcParams.put("is-closed-loop", "false");
147 vnfcParams.put("group-notation","2");
150 vnfcParams.put("relationship-list.relationship[0].related-to","vserver");
151 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id");
152 vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value","ibcx00000");
155 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id");
156 vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value","tenantId");
159 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner");
160 vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value","cloudOwner");
163 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id");
164 vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value","cloudRegionId");
167 vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf");
168 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id");
169 vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value","ibcx000000");
172 vnfcParams.put("relationship-list.relationship[2].related-to","vf-module");
173 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id");
174 vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value","ibcx000000");
177 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id");
178 vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value","vfModuleId");
182 public void populateVnfcContext(SvcLogicContext ctx, String prefix) {
183 log.info("In populateVnfcContext " + prefix);
185 ctx.setAttribute(prefix + ".vnfc-type", "vnfctype1");
186 ctx.setAttribute(prefix + ".vnfc-function-code", "funccode1");
187 ctx.setAttribute(prefix + ".group-notation", "grpnot1");
190 public void populateVmContext(SvcLogicContext ctx, String prefix) {
191 log.info("In populateVmContext " + prefix);
193 ctx.setAttribute(prefix + ".vserver-name", "ibcx0000000");
196 ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
199 ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "test");
200 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "1");
201 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vnfc.vnfc-name");
202 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "test");
207 ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vnfc");
208 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "1");
209 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key", "vnfc.vnfc-name");
210 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx0001vm001vnfc1");
215 ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "vf-module");
216 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "1");
217 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "vf-module.vf-module-id");
218 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value", "vfModule1");
223 public void populateGenericVnfContext(SvcLogicContext ctx, String prefix) throws Exception {
225 log.info("In populateGenericVnf " + prefix);
226 ctx.setAttribute(prefix + ".vnf-name", "ibvcx0001");
227 ctx.setAttribute(prefix + ".vnf-type", "vUSP-Metaswitch");
229 ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
232 ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver");
233 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4");
234 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
235 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id");
236 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
237 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant");
238 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
239 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC");
240 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id");
241 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid");
244 //ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3");
247 ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver");
248 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4");
249 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id");
250 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id");
251 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id");
252 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant");
253 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
254 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC");
255 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id");
256 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid");
260 ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vserver");
261 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "4");
262 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key", "vserver.vserver-id");
263 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx000000");
266 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-key", "tenant.tenant-id");
267 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-value", "sometenant");
269 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[2].relationship-key", "cloud-region.cloud-owner");
270 ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC");
272 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-key", "cloud-region.cloud-region-id");
273 ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-value", "testcloudregionid");
277 ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "junk");
279 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "4");
282 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "test");
283 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value", "ibcx000000");
286 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-key", "test1");
287 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-value", "sometenant");
289 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-key", "test2");
290 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-value", "ATTAIC");
292 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-key", "test3");
293 ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-value", "testcloudregionid");
298 public void populateFirstVnfcData(SvcLogicContext ctx, String prefix) throws Exception {
302 ctx.setAttribute(prefix + "vnf.vm-count", "4");
304 ctx.setAttribute(prefix+ "vm[0].vnfc-type", "mmc");
305 ctx.setAttribute(prefix+ "vm[0].vnfc-name", "vnfcname1");
307 ctx.setAttribute(prefix+ "vm[1].vnfc-type", "mmc");
308 ctx.setAttribute(prefix+ "vm[1].vnfc-name", "vnfcname2");
310 ctx.setAttribute(prefix+ "vm[2].vnfc-type", "ssc");
311 ctx.setAttribute(prefix+ "vm[2].vnfc-name", "vnfcname3");
313 ctx.setAttribute(prefix+ "vm[3].vnfc-type", "ssc");
314 ctx.setAttribute(prefix+ "vm[3].vnfc-name", "vnfcname4");
319 public void populateGroupNotation(SvcLogicContext ctx, String prefix) throws Exception {
323 ctx.setAttribute(prefix + "vnf.vm-count", "5");
325 ctx.setAttribute(prefix+ "vm[0].vserver-name", "ibcxvm0001");
326 ctx.setAttribute(prefix+ "vm[0].group-notation", "grpNot1");
328 ctx.setAttribute(prefix+ "vm[1].vserver-name", "ibcxvm0002");
329 ctx.setAttribute(prefix+ "vm[1].group-notation", "grpNot2");
332 ctx.setAttribute(prefix+ "vm[2].vserver-name", "ibcxvm0003");
333 ctx.setAttribute(prefix+ "vm[2].group-notation", "grpNot3");
335 ctx.setAttribute(prefix+ "vm[3].vserver-name", "ibcxvm0004");
336 ctx.setAttribute(prefix+ "vm[3].group-notation", "4");
338 ctx.setAttribute(prefix+ "vm[4].vserver-name", "ibcxvm0005");
339 ctx.setAttribute(prefix+ "vm[4].group-notation", "4");
343 public void populateVnfcRef(SvcLogicContext ctx) throws Exception {
345 for (int i = 0; i < 2; i++ ) {
347 String vnfcRefKey = "vnfcReference[" + i+ "].";
351 ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i));
352 ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1");
355 //if ( i == 0 || i == 1 ) {
356 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value");
357 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "2");
360 ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "ssc"+i );
362 ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "func" +i);
364 ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y");
369 public void populateAllVnfInfo(SvcLogicContext ctx, String prefix) throws Exception {
371 ctx.setAttribute("vnf-id", "ibcx000000");
373 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
374 ctx.setAttribute(prefix + ".vnf.vm-count", "2");
379 ctx.setAttribute(prefix+ ".vm[0].vserver-name", "ibcxvm0000");
380 ctx.setAttribute(prefix+ ".vm[0].vnfc-name", "VNFCNAME");
382 ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcxvm0001id");
383 ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid");
384 ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner");
385 ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId");
387 ctx.setAttribute(prefix+ ".vm[0].vf-module-id", "vfModuleId");
391 ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002");
393 ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcx00000");
394 ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantId");
395 ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner");
396 ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId");
398 ctx.setAttribute(prefix+ ".vm[1].vf-module-id", "vfModuleId");
401 //ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002");
410 public void populateAllVnfInfo1(SvcLogicContext ctx, String prefix) throws Exception {
412 ctx.setAttribute("vnf-id", "dbjx0001v");
414 ctx.setAttribute("vnf-host-ip-address", "000.00.00.00");
415 ctx.setAttribute(prefix + ".vnf.vm-count", "2");
420 ctx.setAttribute(prefix+ ".vm[0].vserver-name", "dbjx0001vm001");
423 ctx.setAttribute(prefix+ ".vm[0].vserver-id", "dbjx0001vm0001id");
424 ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid1");
425 ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner1");
426 ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId1");
428 ctx.setAttribute(prefix+ ".vm[0].vf-module-id", "vfModuleId1");
432 ctx.setAttribute(prefix+ ".vm[1].vserver-name", "dbjx0001vm002");
434 ctx.setAttribute(prefix+ ".vm[1].vserver-id", "dbjx0001vm0002id");
435 ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantId2");
436 ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner2");
437 ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId2");
439 ctx.setAttribute(prefix+ ".vm[1].vf-module-id", "vfModuleId2");
445 public void populateVnfcRefFirstVnfcName(SvcLogicContext ctx) throws Exception {
448 for (int i = 0; i < 2; i++ ) {
450 String vnfcRefKey = "vnfcReference[" + i+ "].";
454 ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i));
455 ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1");
459 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "first-vnfc-name");
460 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "pair");
463 ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "vDBE-I? - DBJX" );
465 ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj");
467 ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y");
472 public void populateVnfcRefRelValueSame(SvcLogicContext ctx) throws Exception {
475 for (int i = 0; i < 2; i++ ) {
477 String vnfcRefKey = "vnfcReference[" + i+ "].";
481 ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i));
482 ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1");
487 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value");
488 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "1");
491 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "relative-value");
492 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "same");
497 ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "v-I? - DBJX" );
499 ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj");
501 ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y");
507 public void populateVnfcRefRelValueNext(SvcLogicContext ctx) throws Exception {
510 for (int i = 0; i < 2; i++ ) {
512 String vnfcRefKey = "vnfcReference[" + i+ "].";
516 ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i));
517 ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1");
522 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value");
523 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "1");
526 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "relative-value");
527 ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "next");
532 ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "v-I? - DBJX" );
534 ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj");
536 ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y");