From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../onap/appc/aai/client/aai/MockAaiService.java | 541 +++++++++++++++++++++ .../onap/appc/aai/client/aai/TestAaiService.java | 351 +++++++++++++ .../onap/appc/aai/client/node/MockAaiService.java | 88 ++++ .../appc/aai/client/node/TestAAIResourceNode.java | 238 +++++++++ .../appc/aai/client/aai/MockAaiService.java | 541 --------------------- .../appc/aai/client/aai/TestAaiService.java | 351 ------------- .../appc/aai/client/node/MockAaiService.java | 88 ---- .../appc/aai/client/node/TestAAIResourceNode.java | 238 --------- 8 files changed, 1218 insertions(+), 1218 deletions(-) create mode 100644 appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/MockAaiService.java create mode 100644 appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/TestAaiService.java create mode 100644 appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/MockAaiService.java create mode 100644 appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/TestAAIResourceNode.java delete mode 100644 appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/MockAaiService.java delete mode 100644 appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/TestAaiService.java delete mode 100644 appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/MockAaiService.java delete mode 100644 appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/TestAAIResourceNode.java (limited to 'appc-outbound/appc-aai-client/provider/src/test/java') diff --git a/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/MockAaiService.java b/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/MockAaiService.java new file mode 100644 index 000000000..724c8bf3b --- /dev/null +++ b/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/MockAaiService.java @@ -0,0 +1,541 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.aai.client.aai; +import static org.junit.Assert.assertEquals; + +import static org.junit.Assert.fail; + + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; + +public class MockAaiService extends AaiService { + + //ONAP migration + + private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class); + private AAIClient aaiClient; + + public MockAaiService(AAIClient aaic) { + super(aaic); + } + + + /*public MockAaiService() { + super(new AAIClientMock()); + }*/ + + public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception { + log.info("In MockRead Resource"); + SvcLogicContext resourceContext = new SvcLogicContext(); + + //prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : ""; + if ( "generic-vnf".equals(resourceType) ) { + populateGenericVnfContext(resourceContext, prefix); + } + else if("vserver".equals(resourceType) ) { + populateVmContext(resourceContext, prefix); + } + else if("vnfc".equals(resourceType) ) { + populateVnfcContext(resourceContext, prefix); + } + + + return resourceContext; + + + + } + + public void addVnfc(String vnfcName, Map params, String prefix) throws Exception { + + + if ( vnfcName.startsWith("ibcx")) { + assertEquals("ibcxvm0002func0001", vnfcName); + + + log.info("In AddVnfc " + vnfcName); + Map expectedParams = getExpectedParams(); + + + /* for (Map.Entry entry : params.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + + + log.info("key= " + key + "value = " + value ); + + }*/ + assertEquals(params, expectedParams); + } + } + + + public void updateResource( String resource, String resourceKey, Map params) throws Exception { + + Map expectedParams = new HashMap(); + + + expectedParams.put("prov-status", "NVTPROV"); + assertEquals(params, expectedParams); + + if ( "vserver".equals(resource)) { + + String key = "vserver.vserver-id = 'ibcx00000'" + + " AND tenant.tenant-id = 'tenantId'" + + " AND cloud-region.cloud-owner = 'cloudOwner'" + + " AND cloud-region.cloud-region-id = 'cloudRegionId'"; + + assertEquals(key, resourceKey); + } + else if ( "generic-vnf".equals(resource)) { + assertEquals(resourceKey, "generic-vnf.vnf-id = 'ibcx000000'"); + } + else + fail("Invalid resource " + resource); + + + + + } + + public Map getExpectedParams() throws Exception { + Map vnfcParams = new HashMap(); + + vnfcParams.put("vnfc-function-code", "func0"); + + + + vnfcParams.put("vnfc-type", "ssc0"); + + vnfcParams.put("ipaddress-v4-oam-vip", "000.00.00.00"); + + vnfcParams.put("prov-status", "NVTPROV"); + vnfcParams.put("orchestration-status", "CONFIGURED"); + vnfcParams.put("in-maint", "false"); + vnfcParams.put("is-closed-loop", "false"); + vnfcParams.put("group-notation","2"); + + + vnfcParams.put("relationship-list.relationship[0].related-to","vserver"); + vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id"); + vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value","ibcx00000"); + + + vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id"); + vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value","tenantId"); + + + vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner"); + vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value","cloudOwner"); + + + vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id"); + vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value","cloudRegionId"); + + + vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf"); + vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id"); + vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value","ibcx000000"); + + + vnfcParams.put("relationship-list.relationship[2].related-to","vf-module"); + vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id"); + vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value","ibcx000000"); + + + vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id"); + vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value","vfModuleId"); + + return vnfcParams; + } + public void populateVnfcContext(SvcLogicContext ctx, String prefix) { + log.info("In populateVnfcContext " + prefix); + + ctx.setAttribute(prefix + ".vnfc-type", "vnfctype1"); + ctx.setAttribute(prefix + ".vnfc-function-code", "funccode1"); + ctx.setAttribute(prefix + ".group-notation", "grpnot1"); + } + + public void populateVmContext(SvcLogicContext ctx, String prefix) { + log.info("In populateVmContext " + prefix); + + ctx.setAttribute(prefix + ".vserver-name", "ibcx0000000"); + + + ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3"); + + // Junk + ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "test"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "1"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vnfc.vnfc-name"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "test"); + + + + // VNFC + ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vnfc"); + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "1"); + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key", "vnfc.vnfc-name"); + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx0001vm001vnfc1"); + + + // VFModule + + ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "vf-module"); + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "1"); + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "vf-module.vf-module-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value", "vfModule1"); + + + } + + public void populateGenericVnfContext(SvcLogicContext ctx, String prefix) throws Exception { + + log.info("In populateGenericVnf " + prefix); + ctx.setAttribute(prefix + ".vnf-name", "ibvcx0001"); + ctx.setAttribute(prefix + ".vnf-type", "vUSP-Metaswitch"); + + ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3"); + + /* // VM1 + ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid"); + + + //ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3"); +*/ + // VM1 + ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid"); + + + // VM2 + ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vserver"); + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "4"); + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key", "vserver.vserver-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx000000"); + + + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-key", "tenant.tenant-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-value", "sometenant"); + + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[2].relationship-key", "cloud-region.cloud-owner"); + ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC"); + + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-key", "cloud-region.cloud-region-id"); + ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-value", "testcloudregionid"); + + + // Unrelated + ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "junk"); + + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "4"); + + + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "test"); + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value", "ibcx000000"); + + + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-key", "test1"); + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-value", "sometenant"); + + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-key", "test2"); + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-value", "ATTAIC"); + + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-key", "test3"); + ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-value", "testcloudregionid"); + } + + + + public void populateFirstVnfcData(SvcLogicContext ctx, String prefix) throws Exception { + + + + ctx.setAttribute(prefix + "vnf.vm-count", "4"); + + ctx.setAttribute(prefix+ "vm[0].vnfc-type", "mmc"); + ctx.setAttribute(prefix+ "vm[0].vnfc-name", "vnfcname1"); + + ctx.setAttribute(prefix+ "vm[1].vnfc-type", "mmc"); + ctx.setAttribute(prefix+ "vm[1].vnfc-name", "vnfcname2"); + + ctx.setAttribute(prefix+ "vm[2].vnfc-type", "ssc"); + ctx.setAttribute(prefix+ "vm[2].vnfc-name", "vnfcname3"); + + ctx.setAttribute(prefix+ "vm[3].vnfc-type", "ssc"); + ctx.setAttribute(prefix+ "vm[3].vnfc-name", "vnfcname4"); + } + + + + public void populateGroupNotation(SvcLogicContext ctx, String prefix) throws Exception { + + + + ctx.setAttribute(prefix + "vnf.vm-count", "5"); + + ctx.setAttribute(prefix+ "vm[0].vserver-name", "ibcxvm0001"); + ctx.setAttribute(prefix+ "vm[0].group-notation", "grpNot1"); + + ctx.setAttribute(prefix+ "vm[1].vserver-name", "ibcxvm0002"); + ctx.setAttribute(prefix+ "vm[1].group-notation", "grpNot2"); + + + ctx.setAttribute(prefix+ "vm[2].vserver-name", "ibcxvm0003"); + ctx.setAttribute(prefix+ "vm[2].group-notation", "grpNot3"); + + ctx.setAttribute(prefix+ "vm[3].vserver-name", "ibcxvm0004"); + ctx.setAttribute(prefix+ "vm[3].group-notation", "4"); + + ctx.setAttribute(prefix+ "vm[4].vserver-name", "ibcxvm0005"); + ctx.setAttribute(prefix+ "vm[4].group-notation", "4"); + } + + + public void populateVnfcRef(SvcLogicContext ctx) throws Exception { + + for (int i = 0; i < 2; i++ ) { + + String vnfcRefKey = "vnfcReference[" + i+ "]."; + + + + ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i)); + ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1"); + + + //if ( i == 0 || i == 1 ) { + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value"); + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "2"); + //} + + ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "ssc"+i ); + + ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "func" +i); + + ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y"); + } + + } + + public void populateAllVnfInfo(SvcLogicContext ctx, String prefix) throws Exception { + + ctx.setAttribute("vnf-id", "ibcx000000"); + + ctx.setAttribute("vnf-host-ip-address", "000.00.00.00"); + ctx.setAttribute(prefix + ".vnf.vm-count", "2"); + + + + + ctx.setAttribute(prefix+ ".vm[0].vserver-name", "ibcxvm0000"); + ctx.setAttribute(prefix+ ".vm[0].vnfc-name", "VNFCNAME"); + + ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcxvm0001id"); + ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid"); + ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner"); + ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId"); + + ctx.setAttribute(prefix+ ".vm[0].vf-module-id", "vfModuleId"); + + + + ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002"); + + ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcx00000"); + ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantId"); + ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner"); + ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId"); + + ctx.setAttribute(prefix+ ".vm[1].vf-module-id", "vfModuleId"); + + + //ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002"); + + + + + } + + + + public void populateAllVnfInfo1(SvcLogicContext ctx, String prefix) throws Exception { + + ctx.setAttribute("vnf-id", "dbjx0001v"); + + ctx.setAttribute("vnf-host-ip-address", "000.00.00.00"); + ctx.setAttribute(prefix + ".vnf.vm-count", "2"); + + + + + ctx.setAttribute(prefix+ ".vm[0].vserver-name", "dbjx0001vm001"); + + + ctx.setAttribute(prefix+ ".vm[0].vserver-id", "dbjx0001vm0001id"); + ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid1"); + ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner1"); + ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId1"); + + ctx.setAttribute(prefix+ ".vm[0].vf-module-id", "vfModuleId1"); + + + + ctx.setAttribute(prefix+ ".vm[1].vserver-name", "dbjx0001vm002"); + + ctx.setAttribute(prefix+ ".vm[1].vserver-id", "dbjx0001vm0002id"); + ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantId2"); + ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner2"); + ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId2"); + + ctx.setAttribute(prefix+ ".vm[1].vf-module-id", "vfModuleId2"); + + + + } + + public void populateVnfcRefFirstVnfcName(SvcLogicContext ctx) throws Exception { + + + for (int i = 0; i < 2; i++ ) { + + String vnfcRefKey = "vnfcReference[" + i+ "]."; + + + + ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i)); + ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1"); + + + + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "first-vnfc-name"); + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "pair"); + + + ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "vDBE-I? - DBJX" ); + + ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj"); + + ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y"); + } + + } + + public void populateVnfcRefRelValueSame(SvcLogicContext ctx) throws Exception { + + + for (int i = 0; i < 2; i++ ) { + + String vnfcRefKey = "vnfcReference[" + i+ "]."; + + + + ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i)); + ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1"); + + + + if ( i == 0 ) { + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value"); + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "1"); + } + else { + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "relative-value"); + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "same"); + } + + + + ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "v-I? - DBJX" ); + + ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj"); + + ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y"); + } + + } + + + public void populateVnfcRefRelValueNext(SvcLogicContext ctx) throws Exception { + + + for (int i = 0; i < 2; i++ ) { + + String vnfcRefKey = "vnfcReference[" + i+ "]."; + + + + ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i)); + ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1"); + + + + if ( i == 0 ) { + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value"); + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "1"); + } + else { + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "relative-value"); + ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "next"); + } + + + + ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "v-I? - DBJX" ); + + ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj"); + + ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y"); + } + + } + +} diff --git a/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/TestAaiService.java b/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/TestAaiService.java new file mode 100644 index 000000000..aa807087f --- /dev/null +++ b/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/TestAaiService.java @@ -0,0 +1,351 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.aai.client.aai; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class TestAaiService { + // ONAP merging + + private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAaiService.class); + private AAIClient aaiClient; + + @Test + public void testGetGenericVnfInfo() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + inParams.put("vnfId", "ibcxvm0000"); + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.getGenericVnfInfo(inParams, ctx); + + assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"), "vUSP-Metaswitch"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcx001vm001-id"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcx000000"); + } + + @Test + public void testGetVmInfo() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + inParams.put("vserverId", "vserverId1"); + inParams.put("tenantId", "tenantId1"); + inParams.put("cloudOwner", "cloudOwner1"); + inParams.put("cloudRegionId", "cloudRegionId1"); + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.getVMInfo(inParams, ctx); + + printContext(ctx); + + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vserver-name"), "ibcx0000000"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc-count"), "1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vf-module-id"), "vfModule1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc[0].vnfc-name"), "ibcx0001vm001vnfc1"); + + } + + @Test + public void testGetVnfcInfo() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + inParams.put("vnfcName", "vnfcName1"); + + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.getVnfcInfo(inParams, ctx); + + printContext(ctx); + + assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-type"), null); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-function-code"), null); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.group-notation"), "grpnot1"); + + } + + @Test + public void testGetFirstVnfcNameForVnfcType() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + String prefix = "tmp.vnfInfo."; + + SvcLogicContext ctx = new SvcLogicContext(); // VNFC with specified vnfc + // type found + mockAai.populateFirstVnfcData(ctx, prefix); + String firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc"); + assertEquals(firstVnfcName, "vnfcname3"); + + ctx = new SvcLogicContext(); // no VMS found + firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc"); + assertEquals(firstVnfcName, null); + + ctx = new SvcLogicContext(); // no VMS found with specified type + mockAai.populateFirstVnfcData(ctx, prefix); + firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "test"); + assertEquals(firstVnfcName, null); + + } + + @Test + public void testGroupNotation() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + String prefix = "tmp.vnfInfo."; + + SvcLogicContext ctx = new SvcLogicContext(); + mockAai.populateGroupNotation(ctx, prefix); + + // printContext(ctx); + String grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002"); + assertEquals(grpNotation, "grpNot2"); + + ctx = new SvcLogicContext(); // no VMS found + grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002"); + assertEquals(grpNotation, null); + + ctx = new SvcLogicContext(); // no VMS found with specified name + mockAai.populateGroupNotation(ctx, prefix); + grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "test"); + assertEquals(grpNotation, null); + + } + + @Test + public void testGetGroupNotation() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + String prefix = "tmp.vnfInfo."; + + SvcLogicContext ctx = new SvcLogicContext(); + + String grpNotation = mockAai.getGroupNotation("fixed-value", "2", null, null, null, null, null); + assertEquals(grpNotation, "2"); + + mockAai.populateFirstVnfcData(ctx, prefix); // Existing VNFC Found + grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix, + ctx, "ssc"); + assertEquals(grpNotation, "vnfcname32"); + + ctx = new SvcLogicContext(); // no vnfcs exist in A&AI- Use current + // vnfcName + grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix, + ctx, "ssc"); + assertEquals(grpNotation, "currentVnfcName2"); + + ctx = new SvcLogicContext(); + mockAai.populateGroupNotation(ctx, prefix); + grpNotation = mockAai.getGroupNotation("relative-value", "same", "currentVnfcName", "ibcxvm0003", prefix, ctx, + "ssc"); + assertEquals(grpNotation, "grpNot2"); + + ctx = new SvcLogicContext(); + mockAai.populateGroupNotation(ctx, prefix); + grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0006", prefix, ctx, + "ssc"); + assertEquals(grpNotation, "5"); + + ctx = new SvcLogicContext(); + mockAai.populateGroupNotation(ctx, prefix); + grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0003", prefix, ctx, + "ssc"); + assertEquals(grpNotation, null); // Null if grpNotation is not numeric + + } + + @Test + public void testInsertVnfcs() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.populateVnfcRef(ctx); + + mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); + + // mockAai.insertVnfcs(inParams,ctx,2, 2) ; + } + + @Test + public void testUpdateVServerStatus() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); + + mockAai.updateVServerStatus(inParams, ctx, 2); + } + + @Test + public void testInsertVnfcsForFirstVnfc() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.populateVnfcRefFirstVnfcName(ctx); + + mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); + + mockAai.insertVnfcs(inParams, ctx, 2, 2); + + + } + @Test + public void testInsertVnfcsForRelativeValueSame() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.populateVnfcRefRelValueSame(ctx); + + mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); + + mockAai.insertVnfcs(inParams, ctx, 2, 2); + + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "1"); + } + + @Test + public void testInsertVnfcsForRelativeValueNext() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.populateVnfcRefRelValueNext(ctx); + + mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); + + mockAai.insertVnfcs(inParams, ctx, 2, 2); + + + + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "2"); + } + + @Test + public void testUpdateVnfStatus() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + + Map inParams = new HashMap(); + + inParams.put("responsePrefix", "tmp.vnfInfo"); + + SvcLogicContext ctx = new SvcLogicContext(); + + mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); + + mockAai.updateVnfStatus(inParams, ctx); + } + + @Test + public void testReadResource() throws Exception { + + MockAaiService mockAai = new MockAaiService(aaiClient); + // AaiService mockAai = new AaiService(new AAIClientMock()); + + String vnfId = "ibcx0001v"; + String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'"; + String resourceType = "generic-vnf"; + String queryPrefix = "vnfInfo"; + SvcLogicContext ctx = mockAai.readResource(resourceKey, queryPrefix, resourceType); + + // System.out.println("VNF TYPE " + queryPrefix + ".vnf.vnf-type"); + + assertEquals(ctx.getAttribute("vnfInfo.vnf-type"), "vUSP-Metaswitch"); + + } + private void printContext(SvcLogicContext ctx) throws Exception { + for (String key : ctx.getAttributeKeySet()) { + log.info(" KEY " + key); + log.info(" VALUE " + ctx.getAttribute(key)); + } + } +} diff --git a/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/MockAaiService.java b/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/MockAaiService.java new file mode 100644 index 000000000..2e03e6b5a --- /dev/null +++ b/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/MockAaiService.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + +package org.onap.appc.aai.client.node; +import static junit.framework.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.aai.client.AppcAaiClientConstant; +//import org.onap.appc.aai.client.aai.AAIClientMock; +import org.onap.appc.aai.client.aai.AaiService; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; + +public class MockAaiService extends AaiService { + + // ONAP merging + private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class); + private AAIClient aaiClient; + + /*public MockAaiService() { + super(new AAIClientMock()); + }*/ + + + public MockAaiService(AAIClient aaic) { + super(aaic); + } + + public void getVMInfo(Map params,SvcLogicContext ctx ) throws Exception { + log.info("Received Mock getVmInfo call with params : " + params); + String vserverId = params.get("vserverId"); + String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX); + if ( vserverId.equals("ibcm0001id")) { + ctx.setAttribute(prefix + ".vm.vserver-name", "vserverName1"); + ctx.setAttribute(prefix + ".vm.vf-module-id", "vfModule1"); + } + else { + ctx.setAttribute(prefix + ".vm.vserver-name", "vserverName2"); + ctx.setAttribute(prefix + ".vm.vf-module-id", "vfModule2"); + ctx.setAttribute(prefix + ".vm.vnfc[0].vnfc-name", "vnfcName2"); + } + + } + + + public void getVnfcInfo(Map params,SvcLogicContext ctx ) throws Exception { + log.info("Received Mock getVmInfo call with params : " + params); + String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX); + + String vnfcName = params.get("vnfcName"); + + if ( vnfcName.equals("vnfcName2") ) { + ctx.setAttribute(prefix + ".vnfc.vnfc-type", "vnfcType2"); + ctx.setAttribute(prefix + ".vnfc.vnfc-function-code", "vnfcFuncCode2"); + ctx.setAttribute(prefix + ".vnfc.group-notation", "vnfcGrpNot2"); + } + + + } +} diff --git a/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/TestAAIResourceNode.java b/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/TestAAIResourceNode.java new file mode 100644 index 000000000..6b05c08bb --- /dev/null +++ b/appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/TestAAIResourceNode.java @@ -0,0 +1,238 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.aai.client.node; + +import static org.junit.Assert.*; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.aai.client.AppcAaiClientConstant; +import org.onap.appc.aai.client.aai.AaiService; +import org.onap.appc.aai.client.aai.TestAaiService; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.adaptors.aai.AAIClient; + +import com.fasterxml.jackson.databind.ObjectMapper; + + +public class TestAAIResourceNode { + + //Removed for ONAP integration + + private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAAIResourceNode.class); + + @Test + public void sortVServer() throws Exception{ + + //log.info("Test"); + + ArrayList> vservers = new ArrayList>(); + HashMap vserverMap = new HashMap(); + vserverMap.put("vserver-id", "vserverId9"); + vserverMap.put("tenant-id", "tenantId9"); + vserverMap.put("cloud-owner", "cloudOwner9"); + vserverMap.put("cloud-region-id", "cloudRegionId9"); + vserverMap.put("vserver-name", "vServerName9"); + vservers.add(vserverMap); + vserverMap = new HashMap(); + vserverMap.put("vserver-id", "vserverId1"); + vserverMap.put("tenant-id", "tenantId1"); + vserverMap.put("cloud-owner", "cloudOwner1"); + vserverMap.put("cloud-region-id", "cloudRegionId1"); + vserverMap.put("vserver-name", "vServerName1"); + vservers.add(vserverMap); + vserverMap = new HashMap(); + vserverMap.put("vserver-id", "vserverId3"); + vserverMap.put("tenant-id", "tenantId3"); + vserverMap.put("cloud-owner", "cloudOwner3"); + vserverMap.put("cloud-region-id", "cloudRegionId3"); + vserverMap.put("vserver-name", "vServerName3"); + vservers.add(vserverMap); + Collections.sort(vservers, new Comparator>() { + @Override + public int compare(Map o1, Map o2) { + return o1.get("vserver-name").compareTo(o2.get("vserver-name")); + } + }); + + SvcLogicContext ctx = new SvcLogicContext(); + AAIResourceNode aai = new AAIResourceNode(); + aai.populateContext(vservers, ctx, "vserver."); + log.info(ctx.getAttribute("vserver.vm[0].vserver-name")); + } + + @Test + public void testAllVServer() throws Exception{ + + MockAAIResourceNode mrn = new MockAAIResourceNode(); + SvcLogicContext ctx = new SvcLogicContext(); + populateAllVServerInfo(ctx, "tmp.vnfInfo"); + Map inParams =new HashMap(); + inParams.put("responsePrefix", "tmp.vnfInfo"); + mrn.getAllVServersVnfcsInfo(inParams, ctx); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-count"), "2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-with-no-vnfcs-count"), "0"); + // VM1 + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcsm0002id"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantid2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vserverName2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vf-module-id"), "vfModule2"); + //assertNull(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")); + + // VM2 + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcxvm0001id"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].tenant-id"), "tenantid1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-owner"), "cloudOwner1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-region-id"), "cloudRegionId1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-name"), "vserverName2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vf-module-id"), "vfModule2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "vnfcName2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "vnfcType2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "vnfcFuncCode2"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "vnfcGrpNot2"); + } + public void populateAllVServerInfo(SvcLogicContext ctx, String prefix) throws Exception { + ctx.setAttribute("vnf-id", "ibcx0001v"); + ctx.setAttribute("vnf-host-ip-address", "000.00.00.00"); + ctx.setAttribute(prefix + ".vm-count", "2"); + ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcsm0002id"); + ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid2"); + ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner2"); + ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId2"); + ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcxvm0001id"); + ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantid1"); + ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner1"); + ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId1"); + + } + + public static class MockAAIResourceNode extends AAIResourceNode { + private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAAIResourceNode.class); + private AAIClient aaiClient; + + public AaiService getAaiService() { + log.info("In MockAAI"); + return new MockAaiService(aaiClient); + } + } + + @Test + public void testPopulateContext() throws Exception{ + + ArrayList> vservers = new ArrayList>(); + HashMap vserverMap = new HashMap(); + vserverMap = new HashMap(); + vserverMap.put("vserver-id", "vserverId1"); + vserverMap.put("tenant-id", "tenantId1"); + vserverMap.put("cloud-owner", "cloudOwner1"); + vserverMap.put("cloud-region-id", "cloudRegionId1"); + vserverMap.put("vserver-name", "vServerName1"); + vserverMap.put("vnfc-name", "vnfcName1"); + vservers.add(vserverMap); + vserverMap = new HashMap(); + vserverMap.put("vserver-id", "vserverId3"); + vserverMap.put("tenant-id", "tenantId3"); + vserverMap.put("cloud-owner", "cloudOwner3"); + vserverMap.put("cloud-region-id", "cloudRegionId3"); + vserverMap.put("vserver-name", "vServerName3"); + vservers.add(vserverMap); + vserverMap = new HashMap(); + vserverMap.put("vserver-id", "vserverId9"); + vserverMap.put("tenant-id", "tenantId9"); + vserverMap.put("cloud-owner", "cloudOwner9"); + vserverMap.put("cloud-region-id", "cloudRegionId9"); + vserverMap.put("vserver-name", "vServerName9"); + vservers.add(vserverMap); + SvcLogicContext ctx = new SvcLogicContext(); + AAIResourceNode aai = new AAIResourceNode(); + aai.populateContext(vservers, ctx, "tmp.vnfInfo."); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vServerName1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantId1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId1"); + assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "vserverId1"); + assertEquals(ctx.getAttribute("vm-name"), "vServerName3"); + } + + @Test + public final void testGetVnfInfo() { + SvcLogicContext ctx = new SvcLogicContext(); + AAIResourceNode aai = new AAIResourceNode(); +Map inParams =new HashMap(); + inParams.put("responsePrefix", "tmp.vnfInfo"); + try { + aai.getVnfInfo(inParams, ctx); + } catch (SvcLogicException e) { + e.printStackTrace(); + } + + } + @Test + public final void testaddVnfcs() + { + SvcLogicContext ctx = new SvcLogicContext(); + AAIResourceNode aai = new AAIResourceNode(); +Map inParams =new HashMap(); + inParams.put("responsePrefix", "tmp.vnfInfo"); + try { + aai.addVnfcs(inParams, ctx); + } catch (SvcLogicException e) { + e.printStackTrace(); + } + + } + @Test + public final void testupdateVnfAndVServerStatus(){ + SvcLogicContext ctx = new SvcLogicContext(); + AAIResourceNode aai = new AAIResourceNode(); +Map inParams =new HashMap(); + + inParams.put("responsePrefix", "tmp.vnfInfo"); + try { + aai.updateVnfAndVServerStatus(inParams, ctx); + } catch (SvcLogicException e) { + e.printStackTrace(); + } + } +} diff --git a/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/MockAaiService.java b/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/MockAaiService.java deleted file mode 100644 index 724c8bf3b..000000000 --- a/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/MockAaiService.java +++ /dev/null @@ -1,541 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.aai.client.aai; -import static org.junit.Assert.assertEquals; - -import static org.junit.Assert.fail; - - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; - -public class MockAaiService extends AaiService { - - //ONAP migration - - private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class); - private AAIClient aaiClient; - - public MockAaiService(AAIClient aaic) { - super(aaic); - } - - - /*public MockAaiService() { - super(new AAIClientMock()); - }*/ - - public SvcLogicContext readResource(String query, String prefix, String resourceType) throws Exception { - log.info("In MockRead Resource"); - SvcLogicContext resourceContext = new SvcLogicContext(); - - //prefix = StringUtils.isNotBlank(prefix) ? (prefix+".") : ""; - if ( "generic-vnf".equals(resourceType) ) { - populateGenericVnfContext(resourceContext, prefix); - } - else if("vserver".equals(resourceType) ) { - populateVmContext(resourceContext, prefix); - } - else if("vnfc".equals(resourceType) ) { - populateVnfcContext(resourceContext, prefix); - } - - - return resourceContext; - - - - } - - public void addVnfc(String vnfcName, Map params, String prefix) throws Exception { - - - if ( vnfcName.startsWith("ibcx")) { - assertEquals("ibcxvm0002func0001", vnfcName); - - - log.info("In AddVnfc " + vnfcName); - Map expectedParams = getExpectedParams(); - - - /* for (Map.Entry entry : params.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - - - log.info("key= " + key + "value = " + value ); - - }*/ - assertEquals(params, expectedParams); - } - } - - - public void updateResource( String resource, String resourceKey, Map params) throws Exception { - - Map expectedParams = new HashMap(); - - - expectedParams.put("prov-status", "NVTPROV"); - assertEquals(params, expectedParams); - - if ( "vserver".equals(resource)) { - - String key = "vserver.vserver-id = 'ibcx00000'" + - " AND tenant.tenant-id = 'tenantId'" + - " AND cloud-region.cloud-owner = 'cloudOwner'" + - " AND cloud-region.cloud-region-id = 'cloudRegionId'"; - - assertEquals(key, resourceKey); - } - else if ( "generic-vnf".equals(resource)) { - assertEquals(resourceKey, "generic-vnf.vnf-id = 'ibcx000000'"); - } - else - fail("Invalid resource " + resource); - - - - - } - - public Map getExpectedParams() throws Exception { - Map vnfcParams = new HashMap(); - - vnfcParams.put("vnfc-function-code", "func0"); - - - - vnfcParams.put("vnfc-type", "ssc0"); - - vnfcParams.put("ipaddress-v4-oam-vip", "000.00.00.00"); - - vnfcParams.put("prov-status", "NVTPROV"); - vnfcParams.put("orchestration-status", "CONFIGURED"); - vnfcParams.put("in-maint", "false"); - vnfcParams.put("is-closed-loop", "false"); - vnfcParams.put("group-notation","2"); - - - vnfcParams.put("relationship-list.relationship[0].related-to","vserver"); - vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-key","vserver.vserver-id"); - vnfcParams.put("relationship-list.relationship[0].relationship-data[0].relationship-value","ibcx00000"); - - - vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-key","tenant.tenant-id"); - vnfcParams.put("relationship-list.relationship[0].relationship-data[1].relationship-value","tenantId"); - - - vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-key","cloud-region.cloud-owner"); - vnfcParams.put("relationship-list.relationship[0].relationship-data[2].relationship-value","cloudOwner"); - - - vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-key","cloud-region.cloud-region-id"); - vnfcParams.put("relationship-list.relationship[0].relationship-data[3].relationship-value","cloudRegionId"); - - - vnfcParams.put("relationship-list.relationship[1].related-to","generic-vnf"); - vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-key","generic-vnf.vnf-id"); - vnfcParams.put("relationship-list.relationship[1].relationship-data[0].relationship-value","ibcx000000"); - - - vnfcParams.put("relationship-list.relationship[2].related-to","vf-module"); - vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-key","generic-vnf.vnf-id"); - vnfcParams.put("relationship-list.relationship[2].relationship-data[0].relationship-value","ibcx000000"); - - - vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-key","vf-module.vf-module-id"); - vnfcParams.put("relationship-list.relationship[2].relationship-data[1].relationship-value","vfModuleId"); - - return vnfcParams; - } - public void populateVnfcContext(SvcLogicContext ctx, String prefix) { - log.info("In populateVnfcContext " + prefix); - - ctx.setAttribute(prefix + ".vnfc-type", "vnfctype1"); - ctx.setAttribute(prefix + ".vnfc-function-code", "funccode1"); - ctx.setAttribute(prefix + ".group-notation", "grpnot1"); - } - - public void populateVmContext(SvcLogicContext ctx, String prefix) { - log.info("In populateVmContext " + prefix); - - ctx.setAttribute(prefix + ".vserver-name", "ibcx0000000"); - - - ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3"); - - // Junk - ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "test"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "1"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vnfc.vnfc-name"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "test"); - - - - // VNFC - ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vnfc"); - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "1"); - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key", "vnfc.vnfc-name"); - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx0001vm001vnfc1"); - - - // VFModule - - ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "vf-module"); - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "1"); - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "vf-module.vf-module-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value", "vfModule1"); - - - } - - public void populateGenericVnfContext(SvcLogicContext ctx, String prefix) throws Exception { - - log.info("In populateGenericVnf " + prefix); - ctx.setAttribute(prefix + ".vnf-name", "ibvcx0001"); - ctx.setAttribute(prefix + ".vnf-type", "vUSP-Metaswitch"); - - ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3"); - - /* // VM1 - ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid"); - - - //ctx.setAttribute(prefix + ".relationship-list.relationship_length", "3"); -*/ - // VM1 - ctx.setAttribute(prefix + ".relationship-list.relationship[0].related-to", "vserver"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data_length", "4"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-key", "vserver.vserver-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[0].relationship-value", "ibcx001vm001-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-key", "tenant.tenant-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[1].relationship-value", "sometenant"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-key", "cloud-region.cloud-owner"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-key", "cloud-region.cloud-region-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[3].relationship-value", "testcloudregionid"); - - - // VM2 - ctx.setAttribute(prefix + ".relationship-list.relationship[1].related-to", "vserver"); - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data_length", "4"); - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-key", "vserver.vserver-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[0].relationship-value", "ibcx000000"); - - - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-key", "tenant.tenant-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[1].relationship-value", "sometenant"); - - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[2].relationship-key", "cloud-region.cloud-owner"); - ctx.setAttribute(prefix + ".relationship-list.relationship[0].relationship-data[2].relationship-value", "ATTAIC"); - - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-key", "cloud-region.cloud-region-id"); - ctx.setAttribute(prefix + ".relationship-list.relationship[1].relationship-data[3].relationship-value", "testcloudregionid"); - - - // Unrelated - ctx.setAttribute(prefix + ".relationship-list.relationship[2].related-to", "junk"); - - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data_length", "4"); - - - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-key", "test"); - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[0].relationship-value", "ibcx000000"); - - - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-key", "test1"); - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[1].relationship-value", "sometenant"); - - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-key", "test2"); - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[2].relationship-value", "ATTAIC"); - - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-key", "test3"); - ctx.setAttribute(prefix + ".relationship-list.relationship[2].relationship-data[3].relationship-value", "testcloudregionid"); - } - - - - public void populateFirstVnfcData(SvcLogicContext ctx, String prefix) throws Exception { - - - - ctx.setAttribute(prefix + "vnf.vm-count", "4"); - - ctx.setAttribute(prefix+ "vm[0].vnfc-type", "mmc"); - ctx.setAttribute(prefix+ "vm[0].vnfc-name", "vnfcname1"); - - ctx.setAttribute(prefix+ "vm[1].vnfc-type", "mmc"); - ctx.setAttribute(prefix+ "vm[1].vnfc-name", "vnfcname2"); - - ctx.setAttribute(prefix+ "vm[2].vnfc-type", "ssc"); - ctx.setAttribute(prefix+ "vm[2].vnfc-name", "vnfcname3"); - - ctx.setAttribute(prefix+ "vm[3].vnfc-type", "ssc"); - ctx.setAttribute(prefix+ "vm[3].vnfc-name", "vnfcname4"); - } - - - - public void populateGroupNotation(SvcLogicContext ctx, String prefix) throws Exception { - - - - ctx.setAttribute(prefix + "vnf.vm-count", "5"); - - ctx.setAttribute(prefix+ "vm[0].vserver-name", "ibcxvm0001"); - ctx.setAttribute(prefix+ "vm[0].group-notation", "grpNot1"); - - ctx.setAttribute(prefix+ "vm[1].vserver-name", "ibcxvm0002"); - ctx.setAttribute(prefix+ "vm[1].group-notation", "grpNot2"); - - - ctx.setAttribute(prefix+ "vm[2].vserver-name", "ibcxvm0003"); - ctx.setAttribute(prefix+ "vm[2].group-notation", "grpNot3"); - - ctx.setAttribute(prefix+ "vm[3].vserver-name", "ibcxvm0004"); - ctx.setAttribute(prefix+ "vm[3].group-notation", "4"); - - ctx.setAttribute(prefix+ "vm[4].vserver-name", "ibcxvm0005"); - ctx.setAttribute(prefix+ "vm[4].group-notation", "4"); - } - - - public void populateVnfcRef(SvcLogicContext ctx) throws Exception { - - for (int i = 0; i < 2; i++ ) { - - String vnfcRefKey = "vnfcReference[" + i+ "]."; - - - - ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i)); - ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1"); - - - //if ( i == 0 || i == 1 ) { - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value"); - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "2"); - //} - - ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "ssc"+i ); - - ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "func" +i); - - ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y"); - } - - } - - public void populateAllVnfInfo(SvcLogicContext ctx, String prefix) throws Exception { - - ctx.setAttribute("vnf-id", "ibcx000000"); - - ctx.setAttribute("vnf-host-ip-address", "000.00.00.00"); - ctx.setAttribute(prefix + ".vnf.vm-count", "2"); - - - - - ctx.setAttribute(prefix+ ".vm[0].vserver-name", "ibcxvm0000"); - ctx.setAttribute(prefix+ ".vm[0].vnfc-name", "VNFCNAME"); - - ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcxvm0001id"); - ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid"); - ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner"); - ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId"); - - ctx.setAttribute(prefix+ ".vm[0].vf-module-id", "vfModuleId"); - - - - ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002"); - - ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcx00000"); - ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantId"); - ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner"); - ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId"); - - ctx.setAttribute(prefix+ ".vm[1].vf-module-id", "vfModuleId"); - - - //ctx.setAttribute(prefix+ ".vm[1].vserver-name", "ibcxvm0002"); - - - - - } - - - - public void populateAllVnfInfo1(SvcLogicContext ctx, String prefix) throws Exception { - - ctx.setAttribute("vnf-id", "dbjx0001v"); - - ctx.setAttribute("vnf-host-ip-address", "000.00.00.00"); - ctx.setAttribute(prefix + ".vnf.vm-count", "2"); - - - - - ctx.setAttribute(prefix+ ".vm[0].vserver-name", "dbjx0001vm001"); - - - ctx.setAttribute(prefix+ ".vm[0].vserver-id", "dbjx0001vm0001id"); - ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid1"); - ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner1"); - ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId1"); - - ctx.setAttribute(prefix+ ".vm[0].vf-module-id", "vfModuleId1"); - - - - ctx.setAttribute(prefix+ ".vm[1].vserver-name", "dbjx0001vm002"); - - ctx.setAttribute(prefix+ ".vm[1].vserver-id", "dbjx0001vm0002id"); - ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantId2"); - ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner2"); - ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId2"); - - ctx.setAttribute(prefix+ ".vm[1].vf-module-id", "vfModuleId2"); - - - - } - - public void populateVnfcRefFirstVnfcName(SvcLogicContext ctx) throws Exception { - - - for (int i = 0; i < 2; i++ ) { - - String vnfcRefKey = "vnfcReference[" + i+ "]."; - - - - ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i)); - ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1"); - - - - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "first-vnfc-name"); - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "pair"); - - - ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "vDBE-I? - DBJX" ); - - ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj"); - - ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y"); - } - - } - - public void populateVnfcRefRelValueSame(SvcLogicContext ctx) throws Exception { - - - for (int i = 0; i < 2; i++ ) { - - String vnfcRefKey = "vnfcReference[" + i+ "]."; - - - - ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i)); - ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1"); - - - - if ( i == 0 ) { - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value"); - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "1"); - } - else { - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "relative-value"); - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "same"); - } - - - - ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "v-I? - DBJX" ); - - ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj"); - - ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y"); - } - - } - - - public void populateVnfcRefRelValueNext(SvcLogicContext ctx) throws Exception { - - - for (int i = 0; i < 2; i++ ) { - - String vnfcRefKey = "vnfcReference[" + i+ "]."; - - - - ctx.setAttribute(vnfcRefKey+ "VM-INSTANCE", String.valueOf(i)); - ctx.setAttribute(vnfcRefKey+ "VNFC-INSTANCE", "1"); - - - - if ( i == 0 ) { - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "fixed-value"); - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "1"); - } - else { - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-TYPE", "relative-value"); - ctx.setAttribute(vnfcRefKey+ "GROUP-NOTATION-VALUE", "next"); - } - - - - ctx.setAttribute(vnfcRefKey+ "VNFC-TYPE", "v-I? - DBJX" ); - - ctx.setAttribute(vnfcRefKey+ "VNFC-FUNCTION-CODE", "dbj"); - - ctx.setAttribute(vnfcRefKey+ "IPADDRESS-V4-OAM-VIP", "Y"); - } - - } - -} diff --git a/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/TestAaiService.java b/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/TestAaiService.java deleted file mode 100644 index aa807087f..000000000 --- a/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/aai/TestAaiService.java +++ /dev/null @@ -1,351 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.aai.client.aai; - -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -public class TestAaiService { - // ONAP merging - - private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAaiService.class); - private AAIClient aaiClient; - - @Test - public void testGetGenericVnfInfo() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - inParams.put("vnfId", "ibcxvm0000"); - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.getGenericVnfInfo(inParams, ctx); - - assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"), "vUSP-Metaswitch"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcx001vm001-id"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcx000000"); - } - - @Test - public void testGetVmInfo() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - inParams.put("vserverId", "vserverId1"); - inParams.put("tenantId", "tenantId1"); - inParams.put("cloudOwner", "cloudOwner1"); - inParams.put("cloudRegionId", "cloudRegionId1"); - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.getVMInfo(inParams, ctx); - - printContext(ctx); - - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vserver-name"), "ibcx0000000"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc-count"), "1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vf-module-id"), "vfModule1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm.vnfc[0].vnfc-name"), "ibcx0001vm001vnfc1"); - - } - - @Test - public void testGetVnfcInfo() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - inParams.put("vnfcName", "vnfcName1"); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.getVnfcInfo(inParams, ctx); - - printContext(ctx); - - assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-type"), null); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.vnfc-function-code"), null); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vnfc.group-notation"), "grpnot1"); - - } - - @Test - public void testGetFirstVnfcNameForVnfcType() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - String prefix = "tmp.vnfInfo."; - - SvcLogicContext ctx = new SvcLogicContext(); // VNFC with specified vnfc - // type found - mockAai.populateFirstVnfcData(ctx, prefix); - String firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc"); - assertEquals(firstVnfcName, "vnfcname3"); - - ctx = new SvcLogicContext(); // no VMS found - firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "ssc"); - assertEquals(firstVnfcName, null); - - ctx = new SvcLogicContext(); // no VMS found with specified type - mockAai.populateFirstVnfcData(ctx, prefix); - firstVnfcName = mockAai.getFirstVnfcNameForVnfcType(ctx, prefix, "test"); - assertEquals(firstVnfcName, null); - - } - - @Test - public void testGroupNotation() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - String prefix = "tmp.vnfInfo."; - - SvcLogicContext ctx = new SvcLogicContext(); - mockAai.populateGroupNotation(ctx, prefix); - - // printContext(ctx); - String grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002"); - assertEquals(grpNotation, "grpNot2"); - - ctx = new SvcLogicContext(); // no VMS found - grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002"); - assertEquals(grpNotation, null); - - ctx = new SvcLogicContext(); // no VMS found with specified name - mockAai.populateGroupNotation(ctx, prefix); - grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "test"); - assertEquals(grpNotation, null); - - } - - @Test - public void testGetGroupNotation() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - String prefix = "tmp.vnfInfo."; - - SvcLogicContext ctx = new SvcLogicContext(); - - String grpNotation = mockAai.getGroupNotation("fixed-value", "2", null, null, null, null, null); - assertEquals(grpNotation, "2"); - - mockAai.populateFirstVnfcData(ctx, prefix); // Existing VNFC Found - grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix, - ctx, "ssc"); - assertEquals(grpNotation, "vnfcname32"); - - ctx = new SvcLogicContext(); // no vnfcs exist in A&AI- Use current - // vnfcName - grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix, - ctx, "ssc"); - assertEquals(grpNotation, "currentVnfcName2"); - - ctx = new SvcLogicContext(); - mockAai.populateGroupNotation(ctx, prefix); - grpNotation = mockAai.getGroupNotation("relative-value", "same", "currentVnfcName", "ibcxvm0003", prefix, ctx, - "ssc"); - assertEquals(grpNotation, "grpNot2"); - - ctx = new SvcLogicContext(); - mockAai.populateGroupNotation(ctx, prefix); - grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0006", prefix, ctx, - "ssc"); - assertEquals(grpNotation, "5"); - - ctx = new SvcLogicContext(); - mockAai.populateGroupNotation(ctx, prefix); - grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0003", prefix, ctx, - "ssc"); - assertEquals(grpNotation, null); // Null if grpNotation is not numeric - - } - - @Test - public void testInsertVnfcs() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.populateVnfcRef(ctx); - - mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); - - // mockAai.insertVnfcs(inParams,ctx,2, 2) ; - } - - @Test - public void testUpdateVServerStatus() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); - - mockAai.updateVServerStatus(inParams, ctx, 2); - } - - @Test - public void testInsertVnfcsForFirstVnfc() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.populateVnfcRefFirstVnfcName(ctx); - - mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); - - mockAai.insertVnfcs(inParams, ctx, 2, 2); - - - } - @Test - public void testInsertVnfcsForRelativeValueSame() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.populateVnfcRefRelValueSame(ctx); - - mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); - - mockAai.insertVnfcs(inParams, ctx, 2, 2); - - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "1"); - } - - @Test - public void testInsertVnfcsForRelativeValueNext() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.populateVnfcRefRelValueNext(ctx); - - mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); - - mockAai.insertVnfcs(inParams, ctx, 2, 2); - - - - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name"), "dbjx0001vm001dbj001"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code"), "dbj"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type"), "v-I? - DBJX"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].group-notation"), "1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "dbjx0001vm002dbj001"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "dbj"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "v-I? - DBJX"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "2"); - } - - @Test - public void testUpdateVnfStatus() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - - Map inParams = new HashMap(); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - - SvcLogicContext ctx = new SvcLogicContext(); - - mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); - - mockAai.updateVnfStatus(inParams, ctx); - } - - @Test - public void testReadResource() throws Exception { - - MockAaiService mockAai = new MockAaiService(aaiClient); - // AaiService mockAai = new AaiService(new AAIClientMock()); - - String vnfId = "ibcx0001v"; - String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'"; - String resourceType = "generic-vnf"; - String queryPrefix = "vnfInfo"; - SvcLogicContext ctx = mockAai.readResource(resourceKey, queryPrefix, resourceType); - - // System.out.println("VNF TYPE " + queryPrefix + ".vnf.vnf-type"); - - assertEquals(ctx.getAttribute("vnfInfo.vnf-type"), "vUSP-Metaswitch"); - - } - private void printContext(SvcLogicContext ctx) throws Exception { - for (String key : ctx.getAttributeKeySet()) { - log.info(" KEY " + key); - log.info(" VALUE " + ctx.getAttribute(key)); - } - } -} diff --git a/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/MockAaiService.java b/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/MockAaiService.java deleted file mode 100644 index 2e03e6b5a..000000000 --- a/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/MockAaiService.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - -package org.onap.appc.aai.client.node; -import static junit.framework.Assert.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.onap.appc.aai.client.AppcAaiClientConstant; -//import org.onap.appc.aai.client.aai.AAIClientMock; -import org.onap.appc.aai.client.aai.AaiService; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; - -public class MockAaiService extends AaiService { - - // ONAP merging - private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAaiService.class); - private AAIClient aaiClient; - - /*public MockAaiService() { - super(new AAIClientMock()); - }*/ - - - public MockAaiService(AAIClient aaic) { - super(aaic); - } - - public void getVMInfo(Map params,SvcLogicContext ctx ) throws Exception { - log.info("Received Mock getVmInfo call with params : " + params); - String vserverId = params.get("vserverId"); - String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX); - if ( vserverId.equals("ibcm0001id")) { - ctx.setAttribute(prefix + ".vm.vserver-name", "vserverName1"); - ctx.setAttribute(prefix + ".vm.vf-module-id", "vfModule1"); - } - else { - ctx.setAttribute(prefix + ".vm.vserver-name", "vserverName2"); - ctx.setAttribute(prefix + ".vm.vf-module-id", "vfModule2"); - ctx.setAttribute(prefix + ".vm.vnfc[0].vnfc-name", "vnfcName2"); - } - - } - - - public void getVnfcInfo(Map params,SvcLogicContext ctx ) throws Exception { - log.info("Received Mock getVmInfo call with params : " + params); - String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX); - - String vnfcName = params.get("vnfcName"); - - if ( vnfcName.equals("vnfcName2") ) { - ctx.setAttribute(prefix + ".vnfc.vnfc-type", "vnfcType2"); - ctx.setAttribute(prefix + ".vnfc.vnfc-function-code", "vnfcFuncCode2"); - ctx.setAttribute(prefix + ".vnfc.group-notation", "vnfcGrpNot2"); - } - - - } -} diff --git a/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/TestAAIResourceNode.java b/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/TestAAIResourceNode.java deleted file mode 100644 index 6b05c08bb..000000000 --- a/appc-outbound/appc-aai-client/provider/src/test/java/org/openecomp/appc/aai/client/node/TestAAIResourceNode.java +++ /dev/null @@ -1,238 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.aai.client.node; - -import static org.junit.Assert.*; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.aai.client.AppcAaiClientConstant; -import org.onap.appc.aai.client.aai.AaiService; -import org.onap.appc.aai.client.aai.TestAaiService; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; - -import com.fasterxml.jackson.databind.ObjectMapper; - - -public class TestAAIResourceNode { - - //Removed for ONAP integration - - private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAAIResourceNode.class); - - @Test - public void sortVServer() throws Exception{ - - //log.info("Test"); - - ArrayList> vservers = new ArrayList>(); - HashMap vserverMap = new HashMap(); - vserverMap.put("vserver-id", "vserverId9"); - vserverMap.put("tenant-id", "tenantId9"); - vserverMap.put("cloud-owner", "cloudOwner9"); - vserverMap.put("cloud-region-id", "cloudRegionId9"); - vserverMap.put("vserver-name", "vServerName9"); - vservers.add(vserverMap); - vserverMap = new HashMap(); - vserverMap.put("vserver-id", "vserverId1"); - vserverMap.put("tenant-id", "tenantId1"); - vserverMap.put("cloud-owner", "cloudOwner1"); - vserverMap.put("cloud-region-id", "cloudRegionId1"); - vserverMap.put("vserver-name", "vServerName1"); - vservers.add(vserverMap); - vserverMap = new HashMap(); - vserverMap.put("vserver-id", "vserverId3"); - vserverMap.put("tenant-id", "tenantId3"); - vserverMap.put("cloud-owner", "cloudOwner3"); - vserverMap.put("cloud-region-id", "cloudRegionId3"); - vserverMap.put("vserver-name", "vServerName3"); - vservers.add(vserverMap); - Collections.sort(vservers, new Comparator>() { - @Override - public int compare(Map o1, Map o2) { - return o1.get("vserver-name").compareTo(o2.get("vserver-name")); - } - }); - - SvcLogicContext ctx = new SvcLogicContext(); - AAIResourceNode aai = new AAIResourceNode(); - aai.populateContext(vservers, ctx, "vserver."); - log.info(ctx.getAttribute("vserver.vm[0].vserver-name")); - } - - @Test - public void testAllVServer() throws Exception{ - - MockAAIResourceNode mrn = new MockAAIResourceNode(); - SvcLogicContext ctx = new SvcLogicContext(); - populateAllVServerInfo(ctx, "tmp.vnfInfo"); - Map inParams =new HashMap(); - inParams.put("responsePrefix", "tmp.vnfInfo"); - mrn.getAllVServersVnfcsInfo(inParams, ctx); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-count"), "2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-with-no-vnfcs-count"), "0"); - // VM1 - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "ibcsm0002id"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantid2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vserverName2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vf-module-id"), "vfModule2"); - //assertNull(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")); - - // VM2 - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id"), "ibcxvm0001id"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].tenant-id"), "tenantid1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-owner"), "cloudOwner1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].cloud-region-id"), "cloudRegionId1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-name"), "vserverName2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vf-module-id"), "vfModule2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name"), "vnfcName2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type"), "vnfcType2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code"), "vnfcFuncCode2"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[1].group-notation"), "vnfcGrpNot2"); - } - public void populateAllVServerInfo(SvcLogicContext ctx, String prefix) throws Exception { - ctx.setAttribute("vnf-id", "ibcx0001v"); - ctx.setAttribute("vnf-host-ip-address", "000.00.00.00"); - ctx.setAttribute(prefix + ".vm-count", "2"); - ctx.setAttribute(prefix+ ".vm[0].vserver-id", "ibcsm0002id"); - ctx.setAttribute(prefix+ ".vm[0].tenant-id", "tenantid2"); - ctx.setAttribute(prefix+ ".vm[0].cloud-owner", "cloudOwner2"); - ctx.setAttribute(prefix+ ".vm[0].cloud-region-id", "cloudRegionId2"); - ctx.setAttribute(prefix+ ".vm[1].vserver-id", "ibcxvm0001id"); - ctx.setAttribute(prefix+ ".vm[1].tenant-id", "tenantid1"); - ctx.setAttribute(prefix+ ".vm[1].cloud-owner", "cloudOwner1"); - ctx.setAttribute(prefix+ ".vm[1].cloud-region-id", "cloudRegionId1"); - - } - - public static class MockAAIResourceNode extends AAIResourceNode { - private static final EELFLogger log = EELFManager.getInstance().getLogger(MockAAIResourceNode.class); - private AAIClient aaiClient; - - public AaiService getAaiService() { - log.info("In MockAAI"); - return new MockAaiService(aaiClient); - } - } - - @Test - public void testPopulateContext() throws Exception{ - - ArrayList> vservers = new ArrayList>(); - HashMap vserverMap = new HashMap(); - vserverMap = new HashMap(); - vserverMap.put("vserver-id", "vserverId1"); - vserverMap.put("tenant-id", "tenantId1"); - vserverMap.put("cloud-owner", "cloudOwner1"); - vserverMap.put("cloud-region-id", "cloudRegionId1"); - vserverMap.put("vserver-name", "vServerName1"); - vserverMap.put("vnfc-name", "vnfcName1"); - vservers.add(vserverMap); - vserverMap = new HashMap(); - vserverMap.put("vserver-id", "vserverId3"); - vserverMap.put("tenant-id", "tenantId3"); - vserverMap.put("cloud-owner", "cloudOwner3"); - vserverMap.put("cloud-region-id", "cloudRegionId3"); - vserverMap.put("vserver-name", "vServerName3"); - vservers.add(vserverMap); - vserverMap = new HashMap(); - vserverMap.put("vserver-id", "vserverId9"); - vserverMap.put("tenant-id", "tenantId9"); - vserverMap.put("cloud-owner", "cloudOwner9"); - vserverMap.put("cloud-region-id", "cloudRegionId9"); - vserverMap.put("vserver-name", "vServerName9"); - vservers.add(vserverMap); - SvcLogicContext ctx = new SvcLogicContext(); - AAIResourceNode aai = new AAIResourceNode(); - aai.populateContext(vservers, ctx, "tmp.vnfInfo."); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-name"), "vServerName1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].tenant-id"), "tenantId1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-owner"), "cloudOwner1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].cloud-region-id"), "cloudRegionId1"); - assertEquals(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id"), "vserverId1"); - assertEquals(ctx.getAttribute("vm-name"), "vServerName3"); - } - - @Test - public final void testGetVnfInfo() { - SvcLogicContext ctx = new SvcLogicContext(); - AAIResourceNode aai = new AAIResourceNode(); -Map inParams =new HashMap(); - inParams.put("responsePrefix", "tmp.vnfInfo"); - try { - aai.getVnfInfo(inParams, ctx); - } catch (SvcLogicException e) { - e.printStackTrace(); - } - - } - @Test - public final void testaddVnfcs() - { - SvcLogicContext ctx = new SvcLogicContext(); - AAIResourceNode aai = new AAIResourceNode(); -Map inParams =new HashMap(); - inParams.put("responsePrefix", "tmp.vnfInfo"); - try { - aai.addVnfcs(inParams, ctx); - } catch (SvcLogicException e) { - e.printStackTrace(); - } - - } - @Test - public final void testupdateVnfAndVServerStatus(){ - SvcLogicContext ctx = new SvcLogicContext(); - AAIResourceNode aai = new AAIResourceNode(); -Map inParams =new HashMap(); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - try { - aai.updateVnfAndVServerStatus(inParams, ctx); - } catch (SvcLogicException e) { - e.printStackTrace(); - } - } -} -- cgit 1.2.3-korg