diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/test/java')
7 files changed, 890 insertions, 2 deletions
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java index f558932d33..10844ec652 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtilsTest.java @@ -34,6 +34,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; import org.onap.so.client.exception.ExceptionBuilder; @@ -69,7 +70,7 @@ public class AbstractCDSProcessingBBUtilsTest { } @Test - public void preProcessRequestTest() throws Exception { + public void preProcessRequestDETest() throws Exception { DelegateExecution execution = mock(DelegateExecution.class); when(execution.getVariable("executionObject")).thenReturn(abstractCDSPropertiesBean); @@ -80,7 +81,7 @@ public class AbstractCDSProcessingBBUtilsTest { } @Test - public void sendRequestToCDSClientTest() { + public void sendRequestToCDSClientDETest() { DelegateExecution execution = mock(DelegateExecution.class); when(execution.getVariable("executionServiceInput")).thenReturn(abstractCDSPropertiesBean); @@ -90,4 +91,26 @@ public class AbstractCDSProcessingBBUtilsTest { } + @Test + public void preProcessRequestBBTest() throws Exception { + + BuildingBlockExecution execution = mock(BuildingBlockExecution.class); + when(execution.getVariable("executionObject")).thenReturn(abstractCDSPropertiesBean); + + abstractCDSProcessingBBUtils.constructExecutionServiceInputObject(execution); + verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), anyInt(), + any(Exception.class)); + } + + @Test + public void sendRequestToCDSClientBBTest() { + + BuildingBlockExecution execution = mock(BuildingBlockExecution.class); + when(execution.getVariable("executionServiceInput")).thenReturn(abstractCDSPropertiesBean); + abstractCDSProcessingBBUtils.sendRequestToCDSClient(execution); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), anyInt(), + any(Exception.class)); + + } + } 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 new file mode 100644 index 0000000000..9c3ce60400 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/AbstractVnfCDSRequestProviderTest.java @@ -0,0 +1,205 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.cds; + +import com.google.gson.JsonParser; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.serviceinstancebeans.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RunWith(MockitoJUnitRunner.Silent.class) +public abstract class AbstractVnfCDSRequestProviderTest { + + protected static final String GENERIC_VNF_ID = "vnfId_configVnfTest1"; + protected static final String VF_MODULE_ID = "vf-module-id-1"; + protected static final String VF_MODULE_NAME = "vf-module-name-1"; + protected static final String VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1"; + protected static final String GENERIC_VNF_NAME = "vnf-name-1"; + protected static final String SERVICE_INSTANCE_ID = "serviceInst_configTest"; + protected static final String SERVICE_MODEL_UUID = "b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4"; + protected static final String SERVICE_INSTANCE_NAME = "test-service-instance"; + protected static final String VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4"; + protected static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput"; + protected static final String VNF_SCOPE = "vnf"; + protected static final String SERVICE_SCOPE = "service"; + protected static final String SERVICE_ACTION = "create"; + protected static final String VF_SCOPE = "vfModule"; + protected static final String ASSIGN_ACTION = "configAssign"; + protected static final String DEPLOY_ACTION = "configDeploy"; + protected static final String MSO_REQUEST_ID = "1234"; + protected static final String BUILDING_BLOCK = "buildingBlock"; + protected static final String PUBLIC_NET_ID = "public-net-id"; + protected static final String CLOUD_REGION = "acl-cloud-region"; + + @Mock + protected ExtractPojosForBB extractPojosForBB; + + protected BuildingBlockExecution buildingBlockExecution; + + protected ExecuteBuildingBlock executeBuildingBlock; + + + @Before + public void setUp() { + buildingBlockExecution = createBuildingBlockExecution(); + executeBuildingBlock = new ExecuteBuildingBlock(); + } + + protected BuildingBlockExecution createBuildingBlockExecution() { + DelegateExecution execution = new DelegateExecutionFake(); + execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock()); + return new DelegateExecutionImpl(execution); + } + + protected GeneralBuildingBlock createGeneralBuildingBlock() { + GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock(); + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(createRequestUserParams()); + requestContext.setRequestParameters(requestParameters); + requestContext.setMsoRequestId(MSO_REQUEST_ID); + generalBuildingBlock.setRequestContext(requestContext); + return generalBuildingBlock; + } + + protected ServiceInstance createServiceInstance() { + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceName(SERVICE_INSTANCE_NAME); + serviceInstance.setServiceInstanceId(SERVICE_INSTANCE_ID); + ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance(); + modelInfoServiceInstance.setModelUuid(SERVICE_MODEL_UUID); + serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance); + return serviceInstance; + } + + protected GenericVnf createGenericVnf() { + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(GENERIC_VNF_ID); + genericVnf.setVnfName(GENERIC_VNF_NAME); + genericVnf.setBlueprintName("test"); + genericVnf.setBlueprintVersion("1.0.0"); + ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelCustomizationUuid(VNF_MODEL_CUSTOMIZATION_UUID); + genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf); + return genericVnf; + } + + protected VfModule createVfModule() { + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId(VF_MODULE_ID); + vfModule.setVfModuleName(VF_MODULE_NAME); + ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); + modelInfoVfModule.setModelCustomizationUUID(VF_MODULE_CUSTOMIZATION_UUID); + vfModule.setModelInfoVfModule(modelInfoVfModule); + return vfModule; + } + + protected List<Map<String, Object>> createRequestUserParams() { + List<Map<String, Object>> userParams = new ArrayList<>(); + Map<String, Object> userParamMap = new HashMap<>(); + userParamMap.put("service", getUserParams()); + userParams.add(userParamMap); + return userParams; + } + + protected Service getUserParams() { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfList()); + service.setResources(resources); + return service; + } + + protected List<Vnfs> createVnfList() { + List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>(); + Map<String, String> instanceParam = new HashMap<>(); + instanceParam.put("public_net_id", PUBLIC_NET_ID); + instanceParam.put("acl-cloud-region", CLOUD_REGION); + instanceParamsListSearchedVnf.add(instanceParam); + Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf); + List<Vnfs> vnfList = new ArrayList<>(); + vnfList.add(searchedVnf); + return vnfList; + } + + protected Vnfs createVnf(List<Map<String, String>> instanceParamsList) { + Vnfs vnf = new Vnfs(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_UUID); + vnf.setModelInfo(modelInfo); + vnf.setInstanceParams(instanceParamsList); + + // Set instance parameters and modelinfo for vf-module + VfModules vfModule = new VfModules(); + ModelInfo modelInfoForVfModule = new ModelInfo(); + modelInfoForVfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_UUID); + vfModule.setModelInfo(modelInfoForVfModule); + + List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>(); + Map<String, String> instanceParams = new HashMap<>(); + instanceParams.put("public-net-vf-module-id", PUBLIC_NET_ID); + instanceParams.put("aci-cloud-region-vf-module", CLOUD_REGION); + + instanceParamsListSearchedVfModule.add(instanceParams); + vfModule.setInstanceParams(instanceParamsListSearchedVfModule); + + List<VfModules> vfModules = new ArrayList<>(); + vfModules.add(vfModule); + + vnf.setVfModules(vfModules); + + return vnf; + } + + protected boolean verfiyJsonFromString(String payload) { + JsonParser parser = new JsonParser(); + return parser.parse(payload).isJsonObject(); + } + + protected void setScopeAndAction(String scope, String action) { + BuildingBlock buildingBlock = new BuildingBlock(); + buildingBlock.setBpmnScope(scope); + buildingBlock.setBpmnAction(action); + executeBuildingBlock.setBuildingBlock(buildingBlock); + buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java new file mode 100644 index 0000000000..9baf5dc5bf --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.cds; + +import com.google.gson.JsonObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.Resources; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.VfModules; +import org.onap.so.serviceinstancebeans.Vnfs; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.doReturn; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class ConfigureInstanceParamsForVfModuleTest { + + @InjectMocks + private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule; + + @Mock + private ExtractServiceFromUserParameters extractServiceFromUserParameters; + + private static final String TEST_VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4"; + private static final String TEST_VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce2"; + private static final String TEST_INSTANCE_PARAM_VALUE_1 = "vf-module-1-value"; + private static final String TEST_INSTANCE_PARAM_VALUE_2 = "vf-module-2-value"; + private static final String TEST_INSTANCE_PARAM_KEY_1 = "instance-param-1"; + private static final String TEST_INSTANCE_PARAM_KEY_2 = "instance-param-2"; + + @Test + public void testInstanceParamsForVfModule() throws Exception { + // given + List<Map<String, Object>> userParamsFromRequest = createRequestParameters(); + JsonObject jsonObject = new JsonObject(); + doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); + + // when + configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, userParamsFromRequest, + TEST_VNF_MODEL_CUSTOMIZATION_UUID, TEST_VF_MODULE_CUSTOMIZATION_UUID); + + // verify + assertEquals(TEST_INSTANCE_PARAM_VALUE_1, jsonObject.get(TEST_INSTANCE_PARAM_KEY_1).getAsString()); + assertEquals(TEST_INSTANCE_PARAM_VALUE_2, jsonObject.get(TEST_INSTANCE_PARAM_KEY_2).getAsString()); + } + + private List<Map<String, Object>> createRequestParameters() { + List<Map<String, Object>> userParams = new ArrayList<>(); + Map<String, Object> userParamMap = new HashMap<>(); + userParamMap.put("service", getUserParams()); + userParams.add(userParamMap); + return userParams; + } + + private Service getUserParams() { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfs()); + service.setResources(resources); + return service; + } + + private List<Vnfs> createVnfs() { + Vnfs searchedVnf = createVnf(); + List<Vnfs> vnfList = new ArrayList<>(); + vnfList.add(searchedVnf); + return vnfList; + } + + private Vnfs createVnf() { + Vnfs vnf = new Vnfs(); + ModelInfo modelInfoForVnf = new ModelInfo(); + modelInfoForVnf.setModelCustomizationId(TEST_VNF_MODEL_CUSTOMIZATION_UUID); + vnf.setModelInfo(modelInfoForVnf); + + VfModules vfModule = new VfModules(); + + ModelInfo modelInfoForVfModule = new ModelInfo(); + modelInfoForVfModule.setModelCustomizationId(TEST_VF_MODULE_CUSTOMIZATION_UUID); + + vfModule.setModelInfo(modelInfoForVfModule); + + // Set instance parameters. + List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>(); + Map<String, String> instanceParams = new HashMap<>(); + instanceParams.put("instance-param-1", TEST_INSTANCE_PARAM_VALUE_1); + instanceParams.put("instance-param-2", TEST_INSTANCE_PARAM_VALUE_2); + + instanceParamsListSearchedVfModule.add(instanceParams); + vfModule.setInstanceParams(instanceParamsListSearchedVfModule); + + List<VfModules> vfModules = new ArrayList<>(); + vfModules.add(vfModule); + + vnf.setVfModules(vfModules); + + return vnf; + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java new file mode 100644 index 0000000000..471bdb74fc --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/GeneratePayloadForCdsTest.java @@ -0,0 +1,287 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.so.client.cds; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.JsonParser; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.omg.Messaging.SYNC_WITH_TRANSPORT; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.PayloadGenerationException; +import org.onap.so.serviceinstancebeans.*; +import java.util.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.ThrowableAssert.catchThrowable; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class GeneratePayloadForCdsTest { + private static final String GENERIC_VNF_ID = "vnfId_configVnfTest1"; + private static final String VF_MODULE_ID = "vf-module-id-1"; + private static final String VF_MODULE_NAME = "vf-module-name-1"; + private static final String VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1"; + private static final String GENERIC_VNF_NAME = "vnf-name-1"; + private static final String SERVICE_INSTANCE_ID = "serviceInst_configTest"; + private static final String SERVICE_MODEL_UUID = "b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4"; + private static final String SERVICE_INSTANCE_NAME = "test-service-instance"; + private static final String VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4"; + private static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput"; + private static final String VNF_SCOPE = "vnf"; + private static final String SERVICE_SCOPE = "service"; + private static final String SERVICE_ACTION = "create"; + private static final String VF_SCOPE = "vfModule"; + private static final String ASSIGN_ACTION = "configAssign"; + private static final String DEPLOY_ACTION = "configDeploy"; + private static final String MSO_REQUEST_ID = "1234"; + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String PUBLIC_NET_ID = "public-net-id"; + private static final String CLOUD_REGION = "acl-cloud-region"; + + private BuildingBlockExecution buildingBlockExecution; + private ExecuteBuildingBlock executeBuildingBlock; + + @InjectMocks + private GeneratePayloadForCds configurePayloadForCds; + + @Mock + private VnfCDSRequestProvider vnfCDSRequestProvider; + + @Mock + private VfModuleCDSRequestProvider vfModuleCDSRequestProvider; + + @Mock + private ServiceCDSRequestProvider serviceCDSRequestProvider; + + + @Before + public void setup() { + buildingBlockExecution = createBuildingBlockExecution(); + executeBuildingBlock = new ExecuteBuildingBlock(); + } + + @Test + public void testBuildCdsPropertiesBeanAssignVnf() throws Exception { + // given + final String assignPayload = + "{\"configAssign-request\":{\"resolution-key\":\"vnf-name-1\",\"configAssign-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vnf-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4\",\"acl-cloud-region\":\"acl-cloud-region\",\"public_net_id\":\"public-net-id\"}}}"; + + setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION); + + doReturn(Optional.of(assignPayload)).when(vnfCDSRequestProvider).buildRequestPayload(ASSIGN_ACTION); + + // when + AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution); + + // verify + assertNotNull(propertyBean); + String payload = propertyBean.getRequestObject(); + assertThat(assignPayload.equals(payload)); + assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID)); + assertThat(propertyBean.getOriginatorId().equals("SO")); + assertNotNull(propertyBean.getSubRequestId()); + assertThat(propertyBean.getActionName().equals(ASSIGN_ACTION)); + assertThat(propertyBean.getMode().equalsIgnoreCase("sync")); + } + + @Test + public void testBuildCdsPropertiesBeanDeployVnf() throws Exception { + // given + final String deployPayload = + "{\"configDeploy-request\":{\"resolution-key\":\"vnf-name-1\",\"configDeploy-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vnf-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4\",\"acl-cloud-region\":\"acl-cloud-region\",\"public_net_id\":\"public-net-id\"}}}"; + setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION); + + doReturn(Optional.of(deployPayload)).when(vnfCDSRequestProvider).buildRequestPayload(DEPLOY_ACTION); + + // when + AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution); + + // verify + assertNotNull(propertyBean); + String payload = propertyBean.getRequestObject(); + assertThat(deployPayload.equals(payload)); + assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID)); + assertThat(propertyBean.getOriginatorId().equals("SO")); + assertNotNull(propertyBean.getSubRequestId()); + assertThat(propertyBean.getActionName().equals(DEPLOY_ACTION)); + assertThat(propertyBean.getMode().equalsIgnoreCase("sync")); + } + + @Test + public void testBuildCdsPropertiesBeanCreateService() throws Exception { + // given + final String servicePayload = + "{\"create-request\":{\"resolution-key\":\"test-service-instance\",\"create-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\"}}}"; + setScopeAndAction(SERVICE_SCOPE, SERVICE_ACTION); + doReturn(Optional.of(servicePayload)).when(serviceCDSRequestProvider).buildRequestPayload(SERVICE_ACTION); + + // when + AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution); + + // verify + assertNotNull(propertyBean); + String payload = propertyBean.getRequestObject(); + assertThat(servicePayload.equals(payload)); + assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID)); + assertThat(propertyBean.getOriginatorId().equals("SO")); + assertNotNull(propertyBean.getSubRequestId()); + assertThat(propertyBean.getActionName().equals(SERVICE_ACTION)); + assertThat(propertyBean.getMode().equalsIgnoreCase("sync")); + } + + @Test + public void testBuildCdsPropertiesBeanConfigDeployVfModule() throws Exception { + // given + final String deployVfModulePayload = + "{\"configDeploy-request\":{\"resolution-key\":\"vf-module-name-1\",\"template-prefix\":\"vf-module-name-1configDeploy\",\"configDeploy-properties\":{\"service-instance-id\":\"serviceInst_configTest\",\"service-model-uuid\":\"b45b5780-e5dd-11e9-81b4-2a2ae2dbcce4\",\"vnf-id\":\"vnfId_configVnfTest1\",\"vnf-name\":\"vnf-name-1\",\"vf-module-id\":\"vf-module-id-1\",\"vf-module-name\":\"vf-module-name-1\",\"vf-module-customization-uuid\":\"23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce1\",\"aci-cloud-region-vf-module\":\"acl-cloud-region\",\"public-net-vf-module-id\":\"public-net-id\"}}}"; + setScopeAndAction(VF_SCOPE, DEPLOY_ACTION); + doReturn(Optional.of(deployVfModulePayload)).when(vfModuleCDSRequestProvider) + .buildRequestPayload(DEPLOY_ACTION); + + // when + AbstractCDSPropertiesBean propertyBean = configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution); + + // verify + assertNotNull(propertyBean); + String payload = propertyBean.getRequestObject(); + assertThat(deployVfModulePayload.equals(payload)); + assertThat(propertyBean.getRequestId().equals(MSO_REQUEST_ID)); + assertThat(propertyBean.getOriginatorId().equals("SO")); + assertNotNull(propertyBean.getSubRequestId()); + assertThat(propertyBean.getActionName().equals(DEPLOY_ACTION)); + assertThat(propertyBean.getMode().equalsIgnoreCase("sync")); + } + + @Test + public void testFailureWhenServiceInstanceIsNotPresent() throws Exception { + // given + setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION); + + doThrow(PayloadGenerationException.class).when(serviceCDSRequestProvider).buildRequestPayload(ASSIGN_ACTION); + + // when + final Throwable throwable = + catchThrowable(() -> configurePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution)); + + // verify + assertThat(throwable).isInstanceOf(PayloadGenerationException.class) + .hasMessage("Failed to build payload for CDS"); + } + + private BuildingBlockExecution createBuildingBlockExecution() { + DelegateExecution execution = new DelegateExecutionFake(); + execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock()); + return new DelegateExecutionImpl(execution); + } + + private GeneralBuildingBlock createGeneralBuildingBlock() { + GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock(); + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(createRequestUserParams()); + requestContext.setRequestParameters(requestParameters); + requestContext.setMsoRequestId(MSO_REQUEST_ID); + generalBuildingBlock.setRequestContext(requestContext); + return generalBuildingBlock; + } + + private List<Map<String, Object>> createRequestUserParams() { + List<Map<String, Object>> userParams = new ArrayList<>(); + Map<String, Object> userParamMap = new HashMap<>(); + userParamMap.put("service", getUserParams()); + userParams.add(userParamMap); + return userParams; + } + + private Service getUserParams() { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfList()); + service.setResources(resources); + return service; + } + + private List<Vnfs> createVnfList() { + List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>(); + Map<String, String> instanceParam = new HashMap<>(); + instanceParam.put("public_net_id", PUBLIC_NET_ID); + instanceParam.put("acl-cloud-region", CLOUD_REGION); + instanceParamsListSearchedVnf.add(instanceParam); + Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf); + List<Vnfs> vnfList = new ArrayList<>(); + vnfList.add(searchedVnf); + return vnfList; + } + + private Vnfs createVnf(List<Map<String, String>> instanceParamsList) { + Vnfs vnf = new Vnfs(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_UUID); + vnf.setModelInfo(modelInfo); + vnf.setInstanceParams(instanceParamsList); + + // Set instance parameters and modelinfo for vf-module + VfModules vfModule = new VfModules(); + ModelInfo modelInfoForVfModule = new ModelInfo(); + modelInfoForVfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_UUID); + vfModule.setModelInfo(modelInfoForVfModule); + + List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>(); + Map<String, String> instanceParams = new HashMap<>(); + instanceParams.put("public-net-vf-module-id", PUBLIC_NET_ID); + instanceParams.put("aci-cloud-region-vf-module", CLOUD_REGION); + + instanceParamsListSearchedVfModule.add(instanceParams); + vfModule.setInstanceParams(instanceParamsListSearchedVfModule); + + List<VfModules> vfModules = new ArrayList<>(); + vfModules.add(vfModule); + + vnf.setVfModules(vfModules); + + return vnf; + } + + private void setScopeAndAction(String scope, String action) { + BuildingBlock buildingBlock = new BuildingBlock(); + buildingBlock.setBpmnScope(scope); + buildingBlock.setBpmnAction(action); + executeBuildingBlock.setBuildingBlock(buildingBlock); + buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java new file mode 100644 index 0000000000..70ce3a1eed --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ServiceCDSRequestProviderTest.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.cds; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; + +public class ServiceCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest { + + @InjectMocks + private ServiceCDSRequestProvider serviceCDSRequestProvider; + + @Test + public void testRequestPayloadForCreateService() throws Exception { + // given + setScopeAndAction(SERVICE_SCOPE, SERVICE_ACTION); + ServiceInstance instance = createServiceInstance(); + doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.SERVICE_INSTANCE_ID); + + // when + serviceCDSRequestProvider.setExecutionObject(buildingBlockExecution); + String payload = serviceCDSRequestProvider.buildRequestPayload(SERVICE_ACTION).get(); + + // verify + ObjectMapper mapper = new ObjectMapper(); + JsonNode payloadJson = mapper.readTree(payload); + JsonNode requestNode = payloadJson.findValue("create-request"); + JsonNode propertiesNode = payloadJson.findValue("create-properties"); + + assertNotNull(payload); + assertTrue(verfiyJsonFromString(payload)); + assertThat(requestNode.get("resolution-key").asText()).isEqualTo(SERVICE_INSTANCE_NAME); + assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID); + } +} 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 new file mode 100644 index 0000000000..2ca09d9ab3 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VfModuleCDSRequestProviderTest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.cds; + + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; + +public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest { + + @InjectMocks + private VfModuleCDSRequestProvider vfModuleCDSRequestProvider; + + @Mock + protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule; + + @Test + public void testRequestPayloadForConfigDeployVfModule() throws Exception { + // given + setScopeAndAction(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); + doNothing().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(), + anyString()); + + // when + 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); + } + + +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java new file mode 100644 index 0000000000..7aafd900d4 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/VnfCDSRequestProviderTest.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.cds; + + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.*; + +public class VnfCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest { + + @InjectMocks + private VnfCDSRequestProvider vnfCDSRequestProvider; + + @Mock + protected ConfigureInstanceParamsForVnf configureInstanceParamsForVnf; + + @Test + public void testBuildRequestPayloadAssignActionVnf() throws Exception { + // given + setScopeAndAction(VNF_SCOPE, ASSIGN_ACTION); + ServiceInstance instance = createServiceInstance(); + + doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.SERVICE_INSTANCE_ID); + doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.GENERIC_VNF_ID); + doNothing().when(configureInstanceParamsForVnf).populateInstanceParams(any(), any(), anyString()); + + // when + vnfCDSRequestProvider.setExecutionObject(buildingBlockExecution); + String payload = vnfCDSRequestProvider.buildRequestPayload(ASSIGN_ACTION).get(); + + // verify + ObjectMapper mapper = new ObjectMapper(); + JsonNode payloadJson = mapper.readTree(payload); + JsonNode requestNode = payloadJson.findValue("configAssign-request"); + JsonNode propertiesNode = payloadJson.findValue("configAssign-properties"); + + assertNotNull(payload); + assertTrue(verfiyJsonFromString(payload)); + assertThat(requestNode.get("resolution-key").asText()).isEqualTo(GENERIC_VNF_NAME); + assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID); + assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID); + assertThat(propertiesNode.get("vnf-customization-uuid").asText()).isEqualTo(VNF_MODEL_CUSTOMIZATION_UUID); + } + + @Test + public void testBuildRequestPayloadDeployActionVnf() throws Exception { + // given + setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION); + ServiceInstance instance = createServiceInstance(); + + doReturn(instance).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.SERVICE_INSTANCE_ID); + doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution, + ResourceKey.GENERIC_VNF_ID); + doNothing().when(configureInstanceParamsForVnf).populateInstanceParams(any(), any(), any()); + + // when + vnfCDSRequestProvider.setExecutionObject(buildingBlockExecution); + String payload = vnfCDSRequestProvider.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(GENERIC_VNF_NAME); + assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID); + assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID); + assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID); + assertThat(propertiesNode.get("vnf-customization-uuid").asText()).isEqualTo(VNF_MODEL_CUSTOMIZATION_UUID); + } +} |