diff options
author | George, Lina (lg941u) <lg941u@att.com> | 2019-02-07 11:33:37 -0500 |
---|---|---|
committer | Patrick Brady <patrick.brady@att.com> | 2019-02-08 16:58:52 +0000 |
commit | 899c2f1520b1ec529bf6b4faef6623ea566634dd (patch) | |
tree | 85e92286f1a52bb22a22651d71c142746cbcacee /appc-config/appc-flow-controller/provider/src/test/java | |
parent | 3188cd1b2770159eca5de4fbb64a5d1c90aa803e (diff) |
Changes to config bundle for vnf level enhancement
Issue-ID: APPC-1380
Change-Id: Icfdc202a4763b7e708007573505e5b3be9d1454e
Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src/test/java')
4 files changed, 326 insertions, 277 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java index dc5e2553c..14c513dfc 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/ResponseHandlerImpl/DefaultResponseHandlerTest.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,20 +28,23 @@ import org.junit.Test; import org.onap.appc.flow.controller.data.Response; import org.onap.appc.flow.controller.data.ResponseAction; import org.onap.appc.flow.controller.data.Transaction; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class DefaultResponseHandlerTest { @Test public void handlerResponse_shouldReturnEmptyResponseAction_whenTransactionResponsesAreNull() { Transaction transaction = new Transaction(); - assertExpectedResponseAction(transaction, new ResponseAction()); + SvcLogicContext ctx = new SvcLogicContext(); + assertExpectedResponseAction(transaction, new ResponseAction(), ctx); } @Test public void handlerResponse_shouldReturnEmptyResponseAction_whenTransactionResponsesAreEmpty() { Transaction transaction = new Transaction(); transaction.setResponses(Collections.emptyList()); - assertExpectedResponseAction(transaction, new ResponseAction()); + SvcLogicContext ctx = new SvcLogicContext(); + assertExpectedResponseAction(transaction, new ResponseAction(), ctx); } @Test @@ -49,14 +53,12 @@ public class DefaultResponseHandlerTest { ResponseAction expectedResponseAction = createExpectedResponseAction(); String responseCode = "404"; + SvcLogicContext ctx = new SvcLogicContext(); Transaction transaction = new Transaction(); transaction.setStatusCode(responseCode); - transaction.setResponses(Lists.newArrayList( - createResponse(null, null), - createResponse(null, "500"), - createResponse(expectedResponseAction, responseCode))); + transaction.setResponses(Lists.newArrayList(createResponse(expectedResponseAction, responseCode))); - assertExpectedResponseAction(transaction, expectedResponseAction); + assertExpectedResponseAction(transaction, expectedResponseAction, ctx); } private ResponseAction createExpectedResponseAction() { @@ -72,14 +74,16 @@ public class DefaultResponseHandlerTest { private Response createResponse(ResponseAction expectedResponseAction, String responseCode) { Response response = new Response(); + response.setResponseMessage("failure"); response.setResponseCode(responseCode); response.setResponseAction(expectedResponseAction); return response; } - private void assertExpectedResponseAction(Transaction transaction, ResponseAction expectedResponseAction) { + private void assertExpectedResponseAction(Transaction transaction, ResponseAction expectedResponseAction, + SvcLogicContext ctx) { // WHEN - ResponseAction responseAction = new DefaultResponseHandler().handlerResponse(transaction); + ResponseAction responseAction = new DefaultResponseHandler().handlerResponse(transaction, ctx); // THEN assertEquals(expectedResponseAction.isIntermediateMessage(), responseAction.isIntermediateMessage()); diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java index c373840ab..1c0fe87a4 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/CapabilitiesDataExtractorTest.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,38 +32,52 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class CapabilitiesDataExtractorTest { - private CapabilitiesDataExtractor capabilitiesDataExtractor; - private FlowControlDBService dbService; - private SvcLogicContext ctx; + private CapabilitiesDataExtractor capabilitiesDataExtractor; + private FlowControlDBService dbService; + private SvcLogicContext ctx; - @Before - public void setUp() { - dbService = mock(FlowControlDBService.class); - ctx = mock(SvcLogicContext.class); - capabilitiesDataExtractor = new CapabilitiesDataExtractor(dbService); - } + @Before + public void setUp() { + dbService = mock(FlowControlDBService.class); + ctx = mock(SvcLogicContext.class); + capabilitiesDataExtractor = new CapabilitiesDataExtractor(dbService); + } - @Test - public void should_handle_capabilities_full_config() throws Exception { + @Test + public void should_handle_capabilities_full_config() throws Exception { - String jsonPayload = "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':['vm-1', 'vm-2']}"; - when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'","\"")); + String jsonPayload = "{'capabilities':{'vnfc':[],'vm':[{'AttachVolume':[]},{'DetachVolume':[]},{'Evacuate':['pld','ssc']},{'Migrate':['pld','ssc']},{'Reboot':['pld','ssc']},{'Rebuild':['pld','ssc']},{'Restart':['pld','ssc']},{'Snapshot':['pld','ssc']},{'Start':['pld','ssc']},{'Stop':['pld','ssc']}],'vf-module':[],'vnf':['Configure','AllAction','ConfigModify','OpenStack Actions']}}"; + when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\"")); - Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); + Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); + Assert.assertEquals( + "Capabilities [vnf=[Configure, AllAction, ConfigModify, OpenStack Actions], vfModule=[], vm={Evacuate=[pld, ssc], DetachVolume=[], Snapshot=[pld, ssc], AttachVolume=[], Start=[pld, ssc], Stop=[pld, ssc], Migrate=[pld, ssc], Restart=[pld, ssc], Reboot=[pld, ssc], Rebuild=[pld, ssc]}, vnfc=[]]", + capabilitiesData.toString()); + } - Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1, vf-module-2], vm=[vm-1, vm-2], vnfc=[vnfc-1, vnfc-2]]", capabilitiesData.toString()); - } + @Test + public void should_handle_capabilities_config_with_missing_params1() throws Exception { - @Test - public void should_handle_capabilities_config_with_missing_params() throws Exception { + // CASE: vm is empty, vnfc is absent + String jsonPayload = "{'capabilities':{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1'],'vm':[]}}"; + when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\"")); - // CASE: vm is empty, vnfc is absent - String jsonPayload = "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1'],'vm':[]}"; - when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'","\"")); + Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); - Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); + Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm={}, vnfc=[]]", + capabilitiesData.toString()); + } - Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[vf-module-1], vm=[], vnfc=[]]", capabilitiesData.toString()); - } + @Test + public void should_handle_capabilities_config_with_missing_params2() throws Exception { -}
\ No newline at end of file + // CASE: vm has action+vnfc format, vf-module is empty, vnfc is absent + String jsonPayload = "{'capabilities':{'vnf':['vnf-1', 'vnf-2'],'vf-module':[],'vm':[{'AttachVolume':['vnfc-1']}]}}"; + when(dbService.getCapabilitiesData(ctx)).thenReturn(jsonPayload.replaceAll("'", "\"")); + + Capabilities capabilitiesData = capabilitiesDataExtractor.getCapabilitiesData(ctx); + + Assert.assertEquals("Capabilities [vnf=[vnf-1, vnf-2], vfModule=[], vm={AttachVolume=[vnfc-1]}, vnfc=[]]", + capabilitiesData.toString()); + } +} diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java index 951c38dc5..6d1141459 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InputParamsCollectorTest.java @@ -3,7 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,84 +47,112 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class InputParamsCollectorTest { - private SvcLogicContext ctx; - private FlowControlDBService dbService; - private EnvVariables envVariables; - private InputParamsCollector inputParamsCollector; - - @Before - public void setUp() { - - ctx = mock(SvcLogicContext.class); - dbService = mock(FlowControlDBService.class); - envVariables = mock(EnvVariables.class); - - when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("./src/test/resources"); - - inputParamsCollector = new InputParamsCollector(envVariables, dbService); - } - - @Test - public void should_collect_input_params() throws Exception { - - when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id"); - when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action"); - when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level"); - when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload"); - when(ctx.getAttribute(VSERVER_ID)).thenReturn("some-vserver-id"); - when(ctx.getAttribute(VNFC_NAME)).thenReturn("some-vnfc-name"); - - when(dbService.getCapabilitiesData(ctx)).thenReturn( - "{'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':['vm-1', 'vm-2']}" - .replaceAll("'", "\"")); - when(dbService.getDependencyInfo(ctx)).thenReturn(dependencyInfoPayload()); - - Transaction transaction = inputParamsCollector.collectInputParams(ctx); - - Assert.assertEquals("{\"input\":{\"request-info\":{\"action\":\"some-request-action\",\"payload\":\"some-payload\",\"action-level\":\"some-action-level\",\"action-identifier\":{\"vnf-id\":\"some-vnf-id\",\"vserver-id\":\"some-vserver-id\",\"vnfc-name\":\"some-vnfc-name\"}},\"inventory-info\":{\"vnf-info\":{\"vnf-id\":\"some-vnf-id\",\"identity-url\":\"\",\"vm\":[]}},\"capabilities\":{\"vnf\":[\"vnf-1\",\"vnf-2\"],\"vm\":[\"vm-1\",\"vm-2\"],\"vnfc\":[\"vnfc-1\",\"vnfc-2\"],\"vf-module\":[\"vf-module-1\",\"vf-module-2\"]}}}", - transaction.getPayload()); - Assert.assertEquals("POST", transaction.getExecutionRPC()); - Assert.assertEquals("seq-generator-uid", transaction.getuId()); - Assert.assertEquals("some-pswd", transaction.getPswd()); - Assert.assertEquals("exec-endpoint", transaction.getExecutionEndPoint()); - } - - @Test - public void should_handle_dependency_config() throws Exception { - - Vnfcs vnfcs = new Vnfcs(); - vnfcs.setVnfcType("some-type"); - vnfcs.setResilience("some-resilience"); - vnfcs.setMandatory("some-mandatory"); - Map<String, List<Vnfcs>> input = new HashMap<>(); - List<Vnfcs> list = new ArrayList<>(); - list.add(vnfcs); - list.add(vnfcs); - input.put("vnfcs", list); - - String jsonPayload = new ObjectMapper().writeValueAsString(input); - - when(dbService.getDependencyInfo(ctx)).thenReturn(jsonPayload); - - DependencyInfo dependencyInfo = inputParamsCollector.getDependencyInfo(ctx); - - Assert.assertEquals( - "DependencyInfo [vnfcs=[Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]], Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]]]]", - dependencyInfo.toString()); - } - - private String dependencyInfoPayload() throws JsonProcessingException { - Vnfcs vnfcs = new Vnfcs(); - vnfcs.setVnfcType("some-type"); - vnfcs.setResilience("some-resilience"); - vnfcs.setMandatory("some-mandatory"); - Map<String, List<Vnfcs>> input = new HashMap<>(); - List<Vnfcs> list = new ArrayList<>(); - list.add(vnfcs); - list.add(vnfcs); - input.put("vnfcs", list); - - return new ObjectMapper().writeValueAsString(input); - } + private SvcLogicContext ctx; + private FlowControlDBService dbService; + private EnvVariables envVariables; + private InputParamsCollector inputParamsCollector; + + @Before + public void setUp() { + + ctx = mock(SvcLogicContext.class); + dbService = mock(FlowControlDBService.class); + envVariables = mock(EnvVariables.class); + + when(envVariables.getenv(SDNC_CONFIG_DIR_VAR)).thenReturn("./src/test/resources"); + + inputParamsCollector = new InputParamsCollector(envVariables, dbService); + } + + @Test + public void should_collect_input_params() throws Exception { + + when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id"); + when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action"); + when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level"); + when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload"); + when(ctx.getAttribute(VSERVER_ID)).thenReturn("some-vserver-id"); + when(ctx.getAttribute(VNFC_NAME)).thenReturn("some-vnfc-name"); + when(ctx.getAttribute("identity-url")).thenReturn("test_url"); + + when(dbService.getCapabilitiesData(ctx)).thenReturn( + "{'capabilities': { 'vnf':['vnf-1', 'vnf-2'],'vf-module':['vf-module-1', 'vf-module-2'],'vnfc':['vnfc-1', 'vnfc-2'],'vm':[{'Start':['vnfc-1','vnfc-2']},{'Stop':[]}]}}" + .replaceAll("'", "\"")); + when(dbService.getDependencyInfo(ctx)).thenReturn(dependencyInfoPayload()); + + Transaction transaction = inputParamsCollector.collectInputParams(ctx); + + Assert.assertEquals( + "{\"input\":{\"request-info\":{\"action\":\"some-request-action\",\"payload\":\"some-payload\",\"action-level\":\"some-action-level\",\"action-identifier\":{\"vnf-id\":\"some-vnf-id\",\"vserver-id\":\"some-vserver-id\",\"vnfc-name\":\"some-vnfc-name\"}},\"inventory-info\":{\"vnf-info\":{\"vnf-id\":\"some-vnf-id\",\"identity-url\":\"test_url\",\"vm\":[]}},\"capabilities\":{\"vnf\":[\"vnf-1\",\"vnf-2\"],\"vm\":{\"Start\":[\"vnfc-1\",\"vnfc-2\"],\"Stop\":[]},\"vnfc\":[\"vnfc-1\",\"vnfc-2\"],\"vf-module\":[\"vf-module-1\",\"vf-module-2\"]}}}", + transaction.getPayload()); + Assert.assertEquals("POST", transaction.getExecutionRPC()); + Assert.assertEquals("seq-generator-uid", transaction.getuId()); + Assert.assertEquals("some-pswd", transaction.getPswd()); + Assert.assertEquals("exec-endpoint", transaction.getExecutionEndPoint()); + } + + @Test + public void should_handle_dependency_config() throws Exception { + + Vnfcs vnfcs = new Vnfcs(); + vnfcs.setVnfcType("some-type"); + vnfcs.setResilience("some-resilience"); + vnfcs.setMandatory("some-mandatory"); + Map<String, List<Vnfcs>> input = new HashMap<>(); + List<Vnfcs> list = new ArrayList<>(); + list.add(vnfcs); + list.add(vnfcs); + input.put("vnfcs", list); + + String jsonPayload = new ObjectMapper().writeValueAsString(input); + + when(dbService.getDependencyInfo(ctx)).thenReturn(jsonPayload); + + DependencyInfo dependencyInfo = inputParamsCollector.getDependencyInfo(ctx); + + Assert.assertEquals( + "DependencyInfo [vnfcs=[Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]], Vnfcs [vnfcType=some-type, mandatory=some-mandatory, resilience=some-resilience, parents=[]]]]", + dependencyInfo.toString()); + } + + @Test + public void should_collect_input_params_null_caps() throws Exception { + + when(ctx.getAttribute(VNF_ID)).thenReturn("some-vnf-id"); + when(ctx.getAttribute(REQUEST_ACTION)).thenReturn("some-request-action"); + when(ctx.getAttribute(ACTION_LEVEL)).thenReturn("some-action-level"); + when(ctx.getAttribute(PAYLOAD)).thenReturn("some-payload"); + when(ctx.getAttribute(VSERVER_ID)).thenReturn("some-vserver-id"); + when(ctx.getAttribute(VNFC_NAME)).thenReturn("some-vnfc-name"); + when(ctx.getAttribute("identity-url")).thenReturn("test_url"); + + when(dbService.getCapabilitiesData(ctx)).thenReturn(null); + + when(dbService.getDependencyInfo(ctx)).thenReturn(dependencyInfoPayload()); + + Transaction transaction = inputParamsCollector.collectInputParams(ctx); + + Assert.assertEquals( + "{\"input\":{\"request-info\":{\"action\":\"some-request-action\",\"payload\":\"some-payload\",\"action-level\":\"some-action-level\",\"action-identifier\":{\"vnf-id\":\"some-vnf-id\",\"vserver-id\":\"some-vserver-id\",\"vnfc-name\":\"some-vnfc-name\"}},\"inventory-info\":{\"vnf-info\":{\"vnf-id\":\"some-vnf-id\",\"identity-url\":\"test_url\",\"vm\":[]}},\"capabilities\":{\"vnf\":[],\"vm\":{},\"vnfc\":[],\"vf-module\":[]}}}", + transaction.getPayload()); + Assert.assertEquals("POST", transaction.getExecutionRPC()); + Assert.assertEquals("seq-generator-uid", transaction.getuId()); + Assert.assertEquals("some-pswd", transaction.getPswd()); + Assert.assertEquals("exec-endpoint", transaction.getExecutionEndPoint()); + } + + private String dependencyInfoPayload() throws JsonProcessingException { + Vnfcs vnfcs = new Vnfcs(); + vnfcs.setVnfcType("some-type"); + vnfcs.setResilience("some-resilience"); + vnfcs.setMandatory("some-mandatory"); + Map<String, List<Vnfcs>> input = new HashMap<>(); + List<Vnfcs> list = new ArrayList<>(); + list.add(vnfcs); + list.add(vnfcs); + input.put("vnfcs", list); + + return new ObjectMapper().writeValueAsString(input); + } } diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java index 022f31742..aad6dcec0 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/InventoryInfoExtractorTest.java @@ -3,7 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,167 +32,169 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class InventoryInfoExtractorTest { - private SvcLogicContext ctx; - private InventoryInfoExtractor inventoryInfoExtractor; - - @Before - public void setUp() { - inventoryInfoExtractor = new InventoryInfoExtractor(); - ctx = mock(SvcLogicContext.class); - } - - @Test - public void full_config() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals( - "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, " + - "identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, " + - "vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-1, vnfcName=some-vnfc-name-1]]]]]", - inventoryInfo.toString()); - } - - @Test - public void full_config__with_zero__vnfc_count() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals( - "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, " - + "vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, " - + "vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0]], " - + "Vm [vserverId=some-id-1, vmId=null, vnfc=null]]]]", - inventoryInfo.toString()); - } - - @Test - public void full_config__with_zero__vm_count() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals("InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, " - + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", - inventoryInfo.toString()); - } - - @Test - public void full_config__with_empty__vm_count() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(""); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals( - "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, " - + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", - inventoryInfo.toString()); - } - - @Test - public void full_config__with_null__vm_count() throws Exception { - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); - when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); - when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(null); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); - - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); - when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); - - String vnfId = "some-vnf-id"; - InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); - - Assert.assertEquals( - "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, " - + "vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", - inventoryInfo.toString()); - } - - @Test - public void testGetIdentityUrl_from_payload() throws Exception{ - InventoryInfoExtractor info = new InventoryInfoExtractor(); - when(ctx.getAttribute("identity-url")).thenReturn("some_url"); - VnfInfo vnfInfo = new VnfInfo(); - String url=info.getIdentityUrl(ctx, vnfInfo, "123"); - System.out.println(info.toString()); - Assert.assertEquals(url, "some_url"); - } - - @Test - public void testGetIdentityUrl_from_Inventory() throws Exception{ - InventoryInfoExtractor info = new InventoryInfoExtractor(); - when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some_url_from_inventory"); - VnfInfo vnfInfo = new VnfInfo(); - String url=info.getIdentityUrl(ctx, vnfInfo, "123"); - System.out.println(info.toString()); - Assert.assertEquals(url, "some_url_from_inventory"); - } + private SvcLogicContext ctx; + private InventoryInfoExtractor inventoryInfoExtractor; + + @Before + public void setUp() { + inventoryInfoExtractor = new InventoryInfoExtractor(); + ctx = mock(SvcLogicContext.class); + } + + @Test + public void full_config() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0, vnfcFunctionCode=some-vnfc-function-code-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-1, vnfcName=some-vnfc-name-1, vnfcFunctionCode=some-vnfc-function-code-1]]]]]", + inventoryInfo.toString()); + // System.out.println("New inventory info"+inventoryInfo.toString()); + } + + @Test + public void full_config__with_zero__vnfc_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=[Vm [vserverId=some-id-0, vmId=null, vnfc=Vnfcslist [vnfcType=some-vnfc-type-0, vnfcName=some-vnfc-name-0, vnfcFunctionCode=some-vnfc-function-code-0]], Vm [vserverId=some-id-1, vmId=null, vnfc=null]]]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_zero__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_empty__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(""); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", + inventoryInfo.toString()); + } + + @Test + public void full_config__with_null__vm_count() throws Exception { + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name")).thenReturn("some-vnf-name"); + when(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type")).thenReturn("some-vnf-type"); + when(ctx.getAttribute("tmp.vnfInfo.vm-count")).thenReturn(null); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some-url"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vserver-id")).thenReturn("some-id-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-count")).thenReturn("2"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-name")).thenReturn("some-vnfc-name-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-type")).thenReturn("some-vnfc-type-0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[0].vnfc-function-code")).thenReturn("some-vnfc-function-code-0"); + + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vserver-id")).thenReturn("some-id-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-count")).thenReturn("0"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-name")).thenReturn("some-vnfc-name-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-type")).thenReturn("some-vnfc-type-1"); + when(ctx.getAttribute("tmp.vnfInfo.vm[1].vnfc-function-code")).thenReturn("some-vnfc-function-code-1"); + + String vnfId = "some-vnf-id"; + InventoryInfo inventoryInfo = inventoryInfoExtractor.getInventoryInfo(ctx, vnfId); + + Assert.assertEquals( + "InventoryInfo [vnfInfo=VnfInfo [vnfId=some-vnf-id, vnfName=some-vnf-name, vnfType=some-vnf-type, identityUrl=some-url, vm=null]]", + inventoryInfo.toString()); + } + + @Test + public void testGetIdentityUrl_from_payload() throws Exception { + InventoryInfoExtractor info = new InventoryInfoExtractor(); + when(ctx.getAttribute("identity-url")).thenReturn("some_url"); + VnfInfo vnfInfo = new VnfInfo(); + String url = info.getIdentityUrl(ctx, vnfInfo, "123"); + System.out.println(info.toString()); + Assert.assertEquals(url, "some_url"); + } + + @Test + public void testGetIdentityUrl_from_Inventory() throws Exception { + InventoryInfoExtractor info = new InventoryInfoExtractor(); + when(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url")).thenReturn("some_url_from_inventory"); + VnfInfo vnfInfo = new VnfInfo(); + String url = info.getIdentityUrl(ctx, vnfInfo, "123"); + System.out.println(info.toString()); + Assert.assertEquals(url, "some_url_from_inventory"); + } } |