From e4211cdd64e59989bb03dfbdd8c255aea8152c63 Mon Sep 17 00:00:00 2001 From: "Balaji, Ramya (rb111y)" Date: Tue, 6 Mar 2018 15:20:22 -0500 Subject: [PATCH] Code changes to processing new group notation type Code and Unit Test cases to proces for group notation type existing-value Issue-ID: APPC-621 Change-Id: I8446f5f66c7b240018b0bee00d8b28c6baf673df Signed-off-by: Balaji, Ramya (rb111y) --- .../org/onap/appc/aai/client/aai/AaiService.java | 47 ++- .../onap/appc/aai/client/aai/TestAaiService.java | 456 +++++++++++---------- 2 files changed, 290 insertions(+), 213 deletions(-) diff --git a/appc-outbound/appc-aai-client/provider/src/main/java/org/onap/appc/aai/client/aai/AaiService.java b/appc-outbound/appc-aai-client/provider/src/main/java/org/onap/appc/aai/client/aai/AaiService.java index cb439ee16..c1f42a73d 100644 --- a/appc-outbound/appc-aai-client/provider/src/main/java/org/onap/appc/aai/client/aai/AaiService.java +++ b/appc-outbound/appc-aai-client/provider/src/main/java/org/onap/appc/aai/client/aai/AaiService.java @@ -247,7 +247,7 @@ public class AaiService { String vserverName = ctx.getAttribute(aaiRefKey + "vserver-name"); String vnfcName = vserverName + vnfcFuncCode + "001"; String groupNotation = getGroupNotation(groupNotationType, groupNotationValue, vnfcName, vserverName, - prefix, ctx, vnfcType); + prefix, ctx, vnfcType, vnfcFuncCode, vmCount); String ipAddressV4OamVip = null; if ("Y".equals(populateIpAddressV4OamVip)) { @@ -372,7 +372,7 @@ public class AaiService { } public String getGroupNotation(String groupNotationType, String groupNotationValue, String vnfcName, - String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType) throws Exception { + String vserverName, String prefix, SvcLogicContext ctx, String vnfcRefVnfcType, String vnfcFuncCode, int vmCount) throws Exception { String grpNotation = null; @@ -446,11 +446,54 @@ public class AaiService { } } } + else if ("existing-value".equals(groupNotationType)) { + /* This is a new value being added. Find the existing vnfc records in A&AI inventory with the same vnfc-function code as the value in vnfc_reference table. + * Verify that the group-notation value is the same for all such records found in inventory. + * if all records do not have the same group-notation value, write the new vnfc record to A&AI inventory without a group-notation value and continue to the next VM in the vnfc_reference table. A 501 intermediate error message should be sent after all new VNFC records have been added to A&AI. + If all records match, use the same group-notation value for the new vnfc record as found in the existing vnfc records. +*/ + grpNotation = getGroupNotationForExistigValue(ctx, prefix, vnfcFuncCode, vmCount); + } log.info("RETURNED GROUPNOTATION " + grpNotation); return grpNotation; } + public String getGroupNotationForExistigValue(SvcLogicContext ctx, String prefix, String vnfcFuncCode, int vmCount) { + String vfModuleId = ctx.getAttribute("req-vf-module-id"); //Coming from request-params + boolean first=true; + String aaiGroupNotationValue=null; + for (int i=0;i inParams = new HashMap(); - inParams.put("vnfId", "ibcxvm0000"); - inParams.put("responsePrefix", "tmp.vnfInfo"); + Map inParams = new HashMap(); + inParams.put("vnfId", "ibcxvm0000"); + inParams.put("responsePrefix", "tmp.vnfInfo"); - SvcLogicContext ctx = new SvcLogicContext(); + SvcLogicContext ctx = new SvcLogicContext(); - mockAai.getGenericVnfInfo(inParams, ctx); + 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"); - } + 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 { + @Test + public void testGetVmInfo() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + 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"); + 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(); + SvcLogicContext ctx = new SvcLogicContext(); - mockAai.getVMInfo(inParams, ctx); + mockAai.getVMInfo(inParams, ctx); - printContext(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"); + 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 { + @Test + public void testGetVnfcInfo() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + MockAaiService mockAai = new MockAaiService(aaiClient); - Map inParams = new HashMap(); - inParams.put("vnfcName", "vnfcName1"); + Map inParams = new HashMap(); + inParams.put("vnfcName", "vnfcName1"); - inParams.put("responsePrefix", "tmp.vnfInfo"); + inParams.put("responsePrefix", "tmp.vnfInfo"); - SvcLogicContext ctx = new SvcLogicContext(); + SvcLogicContext ctx = new SvcLogicContext(); - mockAai.getVnfcInfo(inParams, ctx); + mockAai.getVnfcInfo(inParams, ctx); - printContext(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"); + 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 { + @Test + public void testGetFirstVnfcNameForVnfcType() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + MockAaiService mockAai = new MockAaiService(aaiClient); - String prefix = "tmp.vnfInfo."; + 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"); + 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 + 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); + 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 { + @Test + public void testGroupNotation() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + MockAaiService mockAai = new MockAaiService(aaiClient); - String prefix = "tmp.vnfInfo."; + String prefix = "tmp.vnfInfo."; - SvcLogicContext ctx = new SvcLogicContext(); - mockAai.populateGroupNotation(ctx, prefix); + SvcLogicContext ctx = new SvcLogicContext(); + mockAai.populateGroupNotation(ctx, prefix); - // printContext(ctx); - String grpNotation = mockAai.getGroupNotationForVServer(ctx, prefix, "ibcxvm0002"); - assertEquals(grpNotation, "grpNot2"); + // 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 + 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); + 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 { + @Test + public void testGetGroupNotation() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + MockAaiService mockAai = new MockAaiService(aaiClient); - String prefix = "tmp.vnfInfo."; + String prefix = "tmp.vnfInfo."; - SvcLogicContext ctx = new SvcLogicContext(); + SvcLogicContext ctx = new SvcLogicContext(); - String grpNotation = mockAai.getGroupNotation("fixed-value", "2", null, null, null, null, null); - assertEquals(grpNotation, "2"); + String grpNotation = mockAai.getGroupNotation("fixed-value", "2", null, null, null, null, null,null, 0); + 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"); + mockAai.populateFirstVnfcData(ctx, prefix); // Existing VNFC Found + grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix, + ctx, "ssc", null, 0); + 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(); // no vnfcs exist in A&AI- Use current + // vnfcName + grpNotation = mockAai.getGroupNotation("first-vnfc-name", "2", "currentVnfcName", "currentVServerName", prefix, + ctx, "ssc", null, 0); + 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", "same", "currentVnfcName", "ibcxvm0003", prefix, ctx, + "ssc", null, 0); + 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", "ibcxvm0006", prefix, ctx, + "ssc",null,0); + 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 + ctx = new SvcLogicContext(); + mockAai.populateGroupNotation(ctx, prefix); + grpNotation = mockAai.getGroupNotation("relative-value", "next", "currentVnfcName", "ibcxvm0003", prefix, ctx, + "ssc",null,0); + assertEquals(grpNotation, null); // Null if grpNotation is not numeric - } + } - @Test - public void testInsertVnfcs() throws Exception { +@Test + public void testInsertVnfcs() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + MockAaiService mockAai = new MockAaiService(aaiClient); - Map inParams = new HashMap(); + Map inParams = new HashMap(); - inParams.put("responsePrefix", "tmp.vnfInfo"); + inParams.put("responsePrefix", "tmp.vnfInfo"); - SvcLogicContext ctx = new SvcLogicContext(); + SvcLogicContext ctx = new SvcLogicContext(); - mockAai.populateVnfcRef(ctx); + mockAai.populateVnfcRef(ctx); - mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); + mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); - // mockAai.insertVnfcs(inParams,ctx,2, 2) ; - } + // mockAai.insertVnfcs(inParams,ctx,2, 2) ; + } - @Test - public void testUpdateVServerStatus() throws Exception { + @Test + public void testUpdateVServerStatus() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + MockAaiService mockAai = new MockAaiService(aaiClient); - Map inParams = new HashMap(); + Map inParams = new HashMap(); - inParams.put("responsePrefix", "tmp.vnfInfo"); + inParams.put("responsePrefix", "tmp.vnfInfo"); - SvcLogicContext ctx = new SvcLogicContext(); + SvcLogicContext ctx = new SvcLogicContext(); - mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); + mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); - mockAai.updateVServerStatus(inParams, ctx, 2); - } + mockAai.updateVServerStatus(inParams, ctx, 2); + } - @Test - public void testInsertVnfcsForFirstVnfc() throws Exception { + @Test + public void testInsertVnfcsForFirstVnfc() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + MockAaiService mockAai = new MockAaiService(aaiClient); - Map inParams = new HashMap(); + Map inParams = new HashMap(); - inParams.put("responsePrefix", "tmp.vnfInfo"); + inParams.put("responsePrefix", "tmp.vnfInfo"); - SvcLogicContext ctx = new SvcLogicContext(); + SvcLogicContext ctx = new SvcLogicContext(); - mockAai.populateVnfcRefFirstVnfcName(ctx); + mockAai.populateVnfcRefFirstVnfcName(ctx); - mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); + mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); - mockAai.insertVnfcs(inParams, ctx, 2, 2); + mockAai.insertVnfcs(inParams, ctx, 2, 2); - - } - @Test - public void testInsertVnfcsForRelativeValueSame() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); + } + @Test + public void testInsertVnfcsForRelativeValueSame() throws Exception { - Map inParams = new HashMap(); + MockAaiService mockAai = new MockAaiService(aaiClient); - inParams.put("responsePrefix", "tmp.vnfInfo"); + Map inParams = new HashMap(); - SvcLogicContext ctx = new SvcLogicContext(); + inParams.put("responsePrefix", "tmp.vnfInfo"); - mockAai.populateVnfcRefRelValueSame(ctx); + SvcLogicContext ctx = new SvcLogicContext(); - mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); + mockAai.populateVnfcRefRelValueSame(ctx); - mockAai.insertVnfcs(inParams, ctx, 2, 2); + mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); - 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"); - } + mockAai.insertVnfcs(inParams, ctx, 2, 2); - @Test - public void testInsertVnfcsForRelativeValueNext() throws Exception { + 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"); + } - MockAaiService mockAai = new MockAaiService(aaiClient); + @Test + public void testInsertVnfcsForRelativeValueNext() throws Exception { - Map inParams = new HashMap(); + MockAaiService mockAai = new MockAaiService(aaiClient); - inParams.put("responsePrefix", "tmp.vnfInfo"); + Map inParams = new HashMap(); - SvcLogicContext ctx = new SvcLogicContext(); + inParams.put("responsePrefix", "tmp.vnfInfo"); - mockAai.populateVnfcRefRelValueNext(ctx); + SvcLogicContext ctx = new SvcLogicContext(); - mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); + mockAai.populateVnfcRefRelValueNext(ctx); - mockAai.insertVnfcs(inParams, ctx, 2, 2); + mockAai.populateAllVnfInfo1(ctx, "tmp.vnfInfo"); - - - 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"); - } + mockAai.insertVnfcs(inParams, ctx, 2, 2); - @Test - public void testUpdateVnfStatus() throws Exception { - MockAaiService mockAai = new MockAaiService(aaiClient); - Map inParams = new HashMap(); + 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"); + } - inParams.put("responsePrefix", "tmp.vnfInfo"); + @Test + public void testUpdateVnfStatus() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); + MockAaiService mockAai = new MockAaiService(aaiClient); - mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); + Map inParams = new HashMap(); - mockAai.updateVnfStatus(inParams, ctx); - } + inParams.put("responsePrefix", "tmp.vnfInfo"); - @Test - public void testReadResource() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); - MockAaiService mockAai = new MockAaiService(aaiClient); - // AaiService mockAai = new AaiService(new AAIClientMock()); + mockAai.populateAllVnfInfo(ctx, "tmp.vnfInfo"); - String vnfId = "ibcx0001v"; - String resourceKey = "generic-vnf.vnf-id = '" + vnfId + "'"; - String resourceType = "generic-vnf"; - String queryPrefix = "vnfInfo"; - SvcLogicContext ctx = mockAai.readResource(resourceKey, queryPrefix, resourceType); + mockAai.updateVnfStatus(inParams, ctx); + } - // System.out.println("VNF TYPE " + queryPrefix + ".vnf.vnf-type"); + @Test + public void testReadResource() throws Exception { - assertEquals(ctx.getAttribute("vnfInfo.vnf-type"), "vUSP-Metaswitch"); + MockAaiService mockAai = new MockAaiService(aaiClient); + // AaiService mockAai = new AaiService(new AAIClientMock()); - } - private void printContext(SvcLogicContext ctx) throws Exception { - for (String key : ctx.getAttributeKeySet()) { - log.info(" KEY " + key); - log.info(" VALUE " + ctx.getAttribute(key)); - } - } + 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)); + } + } + + @Test + public void testGetGroupNotationForExistingValue() throws Exception { + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("req-vf-module-id", "vfmodule01"); + ctx.setAttribute("tmp.vnfInfo.vm[0].vf-module-id", "vfmodule01"); + ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code", "fc1"); + ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn1"); + ctx.setAttribute("tmp.vnfInfo.vm[1].vf-module-id", "vfmodule01"); + ctx.setAttribute("tmp.vnfInfo.vm[1].vnfc-function-code", "fc1"); + ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-function-code", "fc1"); + ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn2"); + MockAaiService aai=new MockAaiService(aaiClient); + String groupNotationValue1 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 2); + assertEquals (groupNotationValue1,null); + + ctx.setAttribute("tmp.vnfInfo.vm[0].group-notation", "gn1"); + ctx.setAttribute("tmp.vnfInfo.vm[1].group-notation", "gn1"); + String groupNotationValue2 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 2); + assertEquals (groupNotationValue2,"gn1"); + + ctx.setAttribute("tmp.vnfInfo.vm[2].vf-module-id", "vfmodule01"); + ctx.setAttribute("tmp.vnfInfo.vm[2].vnfc-function-code", "fc1"); + ctx.setAttribute("tmp.vnfInfo.vm[2].group-notation", "gn2"); + String groupNotationValue3 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 3); + assertEquals (groupNotationValue3,null); + + ctx.setAttribute("tmp.vnfInfo.vm[2].group-notation", "gn1"); + String groupNotationValue4 = aai.getGroupNotationForExistigValue(ctx, "tmp.vnfInfo", "fc1", 3); + assertEquals (groupNotationValue4,"gn1"); + + } } -- 2.16.6