diff options
Diffstat (limited to 'appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/TestAAIResourceNode.java')
-rw-r--r-- | appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/node/TestAAIResourceNode.java | 209 |
1 files changed, 136 insertions, 73 deletions
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 index b3944b700..cb0758406 100644 --- 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 @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,33 +25,26 @@ package org.onap.appc.aai.client.node; -import static org.junit.Assert.*; -import java.io.File; -import java.nio.charset.Charset; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; 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.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; 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.adaptors.aai.AAIClient; 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.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.ObjectMapper; public class TestAAIResourceNode { @@ -58,27 +53,40 @@ public class TestAAIResourceNode { private static final EELFLogger log = EELFManager.getInstance().getLogger(TestAAIResourceNode.class); - @Test - public void sortVServer() throws Exception{ + @Rule + public ExpectedException expectedEx = ExpectedException.none(); - //log.info("Test"); + @Test + public void testGetVnfInfo() throws Exception { + AAIResourceNode aai = Mockito.spy(new AAIResourceNode()); + Map<String, String> inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vm[0].cloud-owner", "TEST"); + ctx.setAttribute("vm[0].cloud-region-id", "TEST"); + AaiService aaiService = Mockito.mock(AaiService.class); + Mockito.doReturn(aaiService).when(aai).getAaiService(); + aai.getVnfInfo(inParams, ctx); + Mockito.verify(aaiService).getIdentityUrl(Mockito.anyMap(), Mockito.any(SvcLogicContext.class)); + } + @Test + public void sortVServer() throws Exception{ ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>(); - HashMap<String, String> vserverMap = new HashMap<String, String>(); + Map<String, String> 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<String, String>(); + 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<String, String>(); + vserverMap = new HashMap<>(); vserverMap.put("vserver-id", "vserverId3"); vserverMap.put("tenant-id", "tenantId3"); vserverMap.put("cloud-owner", "cloudOwner3"); @@ -104,7 +112,7 @@ public class TestAAIResourceNode { MockAAIResourceNode mrn = new MockAAIResourceNode(); SvcLogicContext ctx = new SvcLogicContext(); populateAllVServerInfo(ctx, "tmp.vnfInfo"); - Map<String, String> inParams =new HashMap<String, String>(); + Map<String, String> inParams = new HashMap<>(); inParams.put("responsePrefix", "tmp.vnfInfo"); mrn.getAllVServersVnfcsInfo(inParams, ctx); assertEquals(ctx.getAttribute("tmp.vnfInfo.vm-count"), "2"); @@ -138,6 +146,18 @@ public class TestAAIResourceNode { assertEquals(ctx.getAttribute("tmp.vnfInfo.vnf.vm-count-for-vf-module"),"1"); } + @Test + public void testAllVServerExceptionFlow() throws Exception{ + AAIResourceNode aai = Mockito.spy(new AAIResourceNode()); + Map<String, String> inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + AaiService aaiService = Mockito.mock(AaiService.class); + Mockito.doReturn(aaiService).when(aai).getAaiService(); + expectedEx.expect(SvcLogicException.class); + expectedEx.expectMessage("Unable to get VServers for the VNF"); + aai.getAllVServersVnfcsInfo(inParams, ctx); + } + public void populateAllVServerInfo(SvcLogicContext ctx, String prefix) throws Exception { ctx.setAttribute("vnf-id", "ibcx0001v"); ctx.setAttribute("vnf-host-ip-address", "000.00.00.00"); @@ -150,7 +170,6 @@ public class TestAAIResourceNode { 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 { @@ -165,10 +184,9 @@ public class TestAAIResourceNode { @Test public void testPopulateContext() throws Exception{ - ArrayList<Map<String, String>> vservers = new ArrayList<Map<String, String>>(); - HashMap<String, String> vserverMap = new HashMap<String, String>(); - vserverMap = new HashMap<String, String>(); + Map<String, String> vserverMap = new HashMap<>(); + vserverMap = new HashMap<>(); vserverMap.put("vserver-id", "vserverId1"); vserverMap.put("tenant-id", "tenantId1"); vserverMap.put("cloud-owner", "cloudOwner1"); @@ -176,14 +194,14 @@ public class TestAAIResourceNode { vserverMap.put("vserver-name", "vServerName1"); vserverMap.put("vnfc-name", "vnfcName1"); vservers.add(vserverMap); - vserverMap = new HashMap<String, String>(); + 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<String, String>(); + vserverMap = new HashMap<>(); vserverMap.put("vserver-id", "vserverId9"); vserverMap.put("tenant-id", "tenantId9"); vserverMap.put("cloud-owner", "cloudOwner9"); @@ -202,84 +220,107 @@ public class TestAAIResourceNode { } @Test - public final void testGetVnfInfo() { + public final void testGetVnfInfoExceptionFlow() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); - AAIResourceNode aai = new AAIResourceNode(); -Map<String, String> inParams =new HashMap<String, String>(); - inParams.put("responsePrefix", "tmp.vnfInfo"); - try { - aai.getVnfInfo(inParams, ctx); - } catch (SvcLogicException e) { - e.printStackTrace(); - } + AAIResourceNode aai = Mockito.spy(new AAIResourceNode()); + Map<String, String> inParams = new HashMap<>(); + ctx.setAttribute("vm[0].cloud-owner", "TEST"); + ctx.setAttribute("vm[0].cloud-region-id", "TEST"); + AaiService aaiService = Mockito.mock(AaiService.class); + Mockito.doThrow(new SvcLogicException("TEST")).when(aaiService).getIdentityUrl(Mockito.anyMap(), Mockito.any(SvcLogicContext.class)); + Mockito.doReturn(aaiService).when(aai).getAaiService(); + expectedEx.expect(SvcLogicException.class); + expectedEx.expectMessage("TEST"); + aai.getVnfInfo(inParams, ctx); + } + @Test + public final void testaddVnfcs() throws SvcLogicException + { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnfcReference_length", "1"); + ctx.setAttribute("vnf.vm-count", "1"); + AAIResourceNode aai = Mockito.spy(new AAIResourceNode()); + Map<String, String> inParams = new HashMap<>(); + AaiService aaiService = Mockito.mock(AaiService.class); + Mockito.doReturn(aaiService).when(aai).getAaiService(); + aai.addVnfcs(inParams, ctx); } + @Test - public final void testaddVnfcs() + public final void testaddVnfcsExceptionFlow() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); - AAIResourceNode aai = new AAIResourceNode(); -Map<String, String> inParams =new HashMap<String, String>(); + AAIResourceNode aai = Mockito.spy(new AAIResourceNode()); + Map<String, String> inParams = new HashMap<>(); inParams.put("responsePrefix", "tmp.vnfInfo"); - try { - aai.addVnfcs(inParams, ctx); - } catch (SvcLogicException e) { - e.printStackTrace(); - } + AaiService aaiService = Mockito.mock(AaiService.class); + Mockito.doThrow(new SvcLogicException("TEST")).when(aaiService).getIdentityUrl(Mockito.anyMap(), Mockito.any(SvcLogicContext.class)); + Mockito.doReturn(aaiService).when(aai).getAaiService(); + expectedEx.expect(SvcLogicException.class); + aai.addVnfcs(inParams, ctx); + } + @Test + public final void testupdateVnfAndVServerStatus() throws SvcLogicException{ + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf.vm-count", "1"); + AAIResourceNode aai = Mockito.spy(new AAIResourceNode()); + Map<String, String> inParams = new HashMap<>(); + AaiService aaiService = Mockito.mock(AaiService.class); + Mockito.doReturn(aaiService).when(aai).getAaiService(); + aai.updateVnfAndVServerStatus(inParams, ctx); + assertEquals(AppcAaiClientConstant.OUTPUT_STATUS_SUCCESS, ctx.getAttribute(AppcAaiClientConstant.OUTPUT_PARAM_STATUS)); } + @Test - public final void testupdateVnfAndVServerStatus(){ + public final void testupdateVnfAndVServerStatusExceptionFlow() throws SvcLogicException{ SvcLogicContext ctx = new SvcLogicContext(); AAIResourceNode aai = new AAIResourceNode(); -Map<String, String> inParams =new HashMap<String, String>(); - - inParams.put("responsePrefix", "tmp.vnfInfo"); - try { - aai.updateVnfAndVServerStatus(inParams, ctx); - } catch (SvcLogicException e) { - e.printStackTrace(); - } + Map<String, String> inParams = new HashMap<>(); + expectedEx.expect(SvcLogicException.class); + aai.updateVnfAndVServerStatus(inParams, ctx); } @Test public void testgetVfModduleModelInfo() throws Exception{ SvcLogicContext ctx = new SvcLogicContext(); AAIResourceNode aai = new AAIResourceNode(); - AAIClient aaic=null; - MockAaiService aaiService=new MockAaiService(aaic); - Map<String, String> inParams =new HashMap<String, String>(); + AAIClient aaic = null; + MockAaiService aaiService = new MockAaiService(aaic); + Map<String, String> inParams = new HashMap<>(); inParams.put("responsePrefix", "tmp.vnfInfo"); - aai.processForVfModuleModelInfo(aaiService,inParams, ctx); - assertEquals(ctx.getAttribute("template-model-id"),"model0001"); - + aai.processForVfModuleModelInfo(aaiService, inParams, ctx); + assertEquals(ctx.getAttribute("template-model-id"), "model0001"); } + @Test public final void testSetVmParams() { SvcLogicContext ctx = new SvcLogicContext(); String vServerId = "vserver02"; ctx.setAttribute("tmp.vnfInfo.vm-count","3"); - ctx.setAttribute("tmp.vnfInfo.vm[0].vserver-id","vserver01"); - ctx.setAttribute("tmp.vnfInfo.vm[1].vserver-id","vserver02"); - ctx.setAttribute("tmp.vnfInfo.vm[1].tenant-id","ten01"); - ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-region-id","cr01"); - ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-owner","co01"); + ctx.setAttribute("tmp.vnfInfo.vm[0].vserver-id", "vserver01"); + ctx.setAttribute("tmp.vnfInfo.vm[1].vserver-id", "vserver02"); + ctx.setAttribute("tmp.vnfInfo.vm[1].tenant-id", "ten01"); + ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-region-id", "cr01"); + ctx.setAttribute("tmp.vnfInfo.vm[1].cloud-owner", "co01"); AAIResourceNode aairn= new AAIResourceNode(); - Map <String, String> params = aairn.setVmParams(ctx, vServerId); + Map <String, String> params = aairn.setVmParams(ctx, vServerId); assertNotNull(params); } + @Test public final void testGetVnfcInformationForVserver() throws Exception{ MockAAIResourceNode aairn = new MockAAIResourceNode(); SvcLogicContext ctx = new SvcLogicContext(); SvcLogicContext newVnfcCtx = new SvcLogicContext(); - Map<String,String> inParams = new HashMap<String, String>(); - Map<String,String> vnfcParams = new HashMap<String, String>(); - String responsePrefix="test."; + Map<String, String> inParams = new HashMap<>(); + Map<String, String> vnfcParams = new HashMap<>(); + String responsePrefix = "test."; inParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, "test"); vnfcParams.put("vnfcName", "vnfcName2"); aairn.getVnfcInformationForVserver(vnfcParams, newVnfcCtx, inParams, ctx, aairn.getAaiService(), responsePrefix); - assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-name"),"vnfcName2"); + assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-name"), "vnfcName2"); assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-type"), "vnfcType2"); assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-function-code"), "vnfcFuncCode2"); assertEquals(ctx.getAttribute("test.vm.vnfc.vnfc-group-notation"), "vnfcGrpNot2"); @@ -289,12 +330,11 @@ Map<String, String> inParams =new HashMap<String, String>(); public final void testGetFormattedValue() throws Exception{ MockAAIResourceNode aairn = new MockAAIResourceNode(); SvcLogicContext ctx = new SvcLogicContext(); - Map<String,String> inParams = new HashMap<String, String>(); + Map<String, String> inParams = new HashMap<>(); inParams.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX, "test"); inParams.put("inputParameter", "Some/Value/With/ Many Spaces"); aairn.getFormattedValue(inParams, ctx); - assertEquals(ctx.getAttribute("template-model-id"),"Some_Value_With_ManySpaces"); - + assertEquals(ctx.getAttribute("template-model-id"), "Some_Value_With_ManySpaces"); } @Test @@ -307,7 +347,30 @@ Map<String, String> inParams =new HashMap<String, String>(); ctx.setAttribute("test.vnf.vm-with-no-vnfcs-count-vf-module", "0"); ctx.setAttribute("test.vnf.vm-count-for-vf-module", "2"); aairn.processCheckForVfModule("vfmoduleId1", ctx, "test.", 2); + } + @Test + public void testGetVserverInfo() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("tmp.vnfInfo.vm-count", "1"); + AAIResourceNode aai = Mockito.spy(new AAIResourceNode()); + Map<String, String> inParams = new HashMap<>(); + AaiService aaiService = Mockito.mock(AaiService.class); + Mockito.doReturn(aaiService).when(aai).getAaiService(); + aai.getVserverInfo(inParams, ctx); + Mockito.verify(aaiService).getVMInfo(Mockito.anyMap(), Mockito.any(SvcLogicContext.class)); + } + @Test + public void testGetVserverInfoExceptionFlow() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("tmp.vnfInfo.vm-count", "1"); + Map<String, String> inParams = new HashMap<>(); + AaiService aaiService = Mockito.mock(AaiService.class); + AAIResourceNode aai = Mockito.spy(new AAIResourceNode()); + Mockito.doThrow(new SvcLogicException("TEST")).when(aaiService).getVMInfo(Mockito.anyMap(), Mockito.any(SvcLogicContext.class)); + Mockito.doReturn(aaiService).when(aai).getAaiService(); + aai.getVserverInfo(inParams, ctx); + assertEquals("TEST", ctx.getAttribute(AppcAaiClientConstant.OUTPUT_PARAM_ERROR_MESSAGE)); } } |