diff options
author | jananib <janani.b@huawei.com> | 2020-05-15 22:06:53 +0530 |
---|---|---|
committer | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2020-05-20 13:22:15 +0000 |
commit | 6c13a6a736ef4d71bad9b709eb986db811b3eb08 (patch) | |
tree | 7912d8dab3aa7c97435b2f9c633a71c9f6f798cf /bpmn | |
parent | 8f6932185e2914dff70084b76b6f9b72971089df (diff) |
Allowing user-params to be empty
Ignore empty user-params
Change-Id: Ia57c94424db69bbd2d207e5df2549ab452724ded
Issue-ID: SO-2896
Signed-off-by: jananib <janani.b@huawei.com>
Diffstat (limited to 'bpmn')
4 files changed, 67 insertions, 9 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java index c2874fe23d..478b65c349 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java @@ -104,9 +104,10 @@ public class VfModuleCDSRequestProvider implements CDSRequestProvider { final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams(); - - configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest, - modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule); + if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { + configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest, + modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule); + } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e); } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java index 7425d09721..6251eb6fad 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java @@ -93,9 +93,10 @@ public class VnfCDSRequestProvider implements CDSRequestProvider { final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams(); - - configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest, - modelCustomizationUuid); + if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { + configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest, + modelCustomizationUuid); + } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e); } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java index 9c3ce60400..06defaa84c 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java @@ -44,6 +44,7 @@ import org.onap.so.serviceinstancebeans.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.LinkedList; import java.util.Map; @RunWith(MockitoJUnitRunner.Silent.class) @@ -202,4 +203,10 @@ public abstract class AbstractVnfCDSRequestProviderTest { executeBuildingBlock.setBuildingBlock(buildingBlock); buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock); } + + protected void setScopeAndActionWithoutUserParams(String scope, String action) { + buildingBlockExecution.getGeneralBuildingBlock().getRequestContext().getRequestParameters() + .setUserParams(new LinkedList<>()); + setScopeAndAction(scope, action); + } } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java index 2ca09d9ab3..f224ebf21e 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java @@ -25,8 +25,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.client.exception.PayloadGenerationException; +import org.onap.so.serviceinstancebeans.Service; +import org.springframework.beans.factory.annotation.Autowired; +import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -34,11 +40,19 @@ import static org.mockito.Mockito.*; public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest { + @Autowired + private ObjectMapper objectMapper; + + @Spy + protected ExtractServiceFromUserParameters extractServiceFromUserParameters; + + @Spy + @InjectMocks + protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule; + @InjectMocks private VfModuleCDSRequestProvider vfModuleCDSRequestProvider; - @Mock - protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule; @Test public void testRequestPayloadForConfigDeployVfModule() throws Exception { @@ -52,7 +66,8 @@ public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProvide ResourceKey.GENERIC_VNF_ID); doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution, ResourceKey.VF_MODULE_ID); - doNothing().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), + doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); + doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), anyString()); // when @@ -76,5 +91,39 @@ public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProvide assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID); } + @Test + public void testRequestPayloadForConfigDeployVfModuleWithoutUserParams() throws Exception { + // given + setScopeAndActionWithoutUserParams(VF_SCOPE, DEPLOY_ACTION); + ServiceInstance serviceInstance = createServiceInstance(); + + doReturn(serviceInstance).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.SERVICE_INSTANCE_ID); + doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.GENERIC_VNF_ID); + doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.VF_MODULE_ID); + doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); + doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), + anyString()); + + vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution); + String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get(); + // verify + ObjectMapper mapper = new ObjectMapper(); + JsonNode payloadJson = mapper.readTree(payload); + JsonNode requestNode = payloadJson.findValue("configDeploy-request"); + JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties"); + + assertNotNull(payload); + assertTrue(verfiyJsonFromString(payload)); + assertThat(requestNode.get("resolution-key").asText()).isEqualTo(VF_MODULE_NAME); + assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(propertiesNode.get("vf-module-id").asText()).isEqualTo(VF_MODULE_ID); + assertThat(propertiesNode.get("vf-module-name").asText()).isEqualTo(VF_MODULE_NAME); + assertThat(propertiesNode.get("vf-module-customization-uuid").asText()).isEqualTo(VF_MODULE_CUSTOMIZATION_UUID); + assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID); + assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID); + } } |