diff options
author | 2023-01-31 11:13:01 +0000 | |
---|---|---|
committer | 2023-02-13 15:17:17 +0000 | |
commit | fa660d2d8a9b2b6f3190bf5c3c26dcf4fa15c146 (patch) | |
tree | ba1d19ad01465549a272189ba6fe57c5be80cc7b /bpmn/so-bpmn-tasks/src/test/java/org | |
parent | 1a6b1ef83417efbbb8ec7cfe204c105e49e7e1f2 (diff) |
[SO] Pending Create changes for SO-API and BPMN-INFRA to support CNF's through ASD
Issue-ID: SO-4069
Signed-off-by: raviteja.karumuri <raviteja.karumuri@est.tech>
Change-Id: I91e6d2dfc3ce84f7fe496b9b87c2a4ac6f521673
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java/org')
2 files changed, 356 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java new file mode 100644 index 0000000000..f4d8bb8439 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java @@ -0,0 +1,183 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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.bpmn.infrastructure.adapter.cnfm.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT_PARAMETER; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY; +import java.net.URI; +import java.util.Optional; +import java.util.Collections; +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.cnfm.lcm.model.AsInstance; +import org.onap.so.cnfm.lcm.model.CreateAsRequest; +import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; + + +/** + * @author raviteja.kaumuri@est.tech + */ +public class CnfInstantiateTaskTest extends BaseTaskTest { + + private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject"; + private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest"; + private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl"; + private static final String MONITOR_JOB_NAME = "MonitorJobName"; + private static final String MODEL_INSTANCE_NAME = "instanceTest"; + private static final String AS_INSTANCE_ID = "asInstanceid"; + private static final String CLOUD_OWNER = "CloudOwner"; + private static final String LCP_CLOUD_REGION_ID = "RegionOne"; + private static final String CNF_ID = UUID.randomUUID().toString(); + private static final String CNF_NAME = "CNF_NAME"; + private static final String JOB_ID = UUID.randomUUID().toString(); + + @Mock + private CnfmHttpServiceProvider mockedCnfmHttpServiceProvider; + + private final BuildingBlockExecution stubbedExecution = new StubbedBuildingBlockExecution(); + + @Test + public void testCreateCreateASRequest_withValidValues_storesRequestInExecution() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + stubbedExecution.setVariable(INPUT_PARAMETER, + new InputParameter(Collections.emptyMap(), Collections.emptyList())); + + objUnderTest.createCreateAsRequest(stubbedExecution); + + final CreateAsRequest actual = stubbedExecution.getVariable(CREATE_AS_REQUEST_OBJECT); + assertNotNull(actual); + assertEquals(MODEL_INSTANCE_NAME, actual.getAsInstanceName()); + + assertEquals(CLOUD_OWNER, actual.getAdditionalParams().get(CLOUD_OWNER_PARAM_KEY).toString()); + assertEquals(LCP_CLOUD_REGION_ID, actual.getAdditionalParams().get(CLOUD_REGION_PARAM_KEY).toString()); + assertEquals(StubbedBuildingBlockExecution.getTenantId(), + actual.getAdditionalParams().get(TENANT_ID_PARAM_KEY).toString()); + } + + @Test + public void testCreateCreateASRequest_ForBBThrowsException_exceptionBuilderCalled() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + + final BuildingBlockExecution stubbedExecutionNoReqDetails = new StubbedBuildingBlockExecution(); + final ExecuteBuildingBlock executeBuildingBlock = stubbedExecutionNoReqDetails.getVariable("buildingBlock"); + executeBuildingBlock.setRequestDetails(null); + + doThrow(BpmnError.class).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), + eq(2000), anyString(), any()); + objUnderTest.createCreateAsRequest(stubbedExecutionNoReqDetails); + final CreateAsRequest actual = stubbedExecutionNoReqDetails.getVariable(CREATE_AS_REQUEST_OBJECT); + + assertNull(actual); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(2000), anyString(), + any()); + + } + + @Test + public void invokeCnfmWithCreateAsRequest_validValues_storesResponseInExecution() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + stubbedExecution.setVariable(CREATE_AS_REQUEST_OBJECT, new CreateAsRequest()); + + when(mockedCnfmHttpServiceProvider.invokeCreateAsRequest(any(CreateAsRequest.class))) + .thenReturn(getAsInstance()); + + objUnderTest.invokeCnfmWithCreateAsRequest(stubbedExecution); + + assertEquals(JOB_ID, stubbedExecution.getVariable(AS_INSTANCE_ID)); + } + + @Test + public void invokeCnfmWithCreateAsRequest_ForBBThrowsException_exceptionBuilderCalled() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + stubbedExecution.setVariable(CREATE_AS_REQUEST_OBJECT, new CreateAsRequest()); + + when(mockedCnfmHttpServiceProvider.invokeCreateAsRequest(any(CreateAsRequest.class))) + .thenReturn(Optional.empty()); + doThrow(BpmnError.class).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), + eq(2003), anyString(), any()); + + objUnderTest.invokeCnfmWithCreateAsRequest(stubbedExecution); + + assertNull(stubbedExecution.getVariable(AS_INSTANCE_ID)); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(2003), anyString(), + any()); + + } + + @Test + public void testcreateAsInstanceRequest_withValidValues_storesRequestInExecution() throws Exception { + + final CnfInstantiateTask objUnderTest = getCnfInstantiateTask(); + + objUnderTest.createAsInstanceRequest(stubbedExecution); + + final InstantiateAsRequest actual = stubbedExecution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT); + assertNotNull(actual); + assertNotNull(actual.getDeploymentItems()); + } + + private Optional<AsInstance> getAsInstance() { + final AsInstance response = new AsInstance(); + response.setAsInstanceid(JOB_ID); + return Optional.of(response); + } + + private GenericVnf getGenericVnf() { + final GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(CNF_ID); + genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); + genericVnf.setVnfName(CNF_NAME); + return genericVnf; + } + + private ModelInfoGenericVnf getModelInfoGenericVnf() { + final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); + return modelInfoGenericVnf; + } + + private CnfInstantiateTask getCnfInstantiateTask() { + return new CnfInstantiateTask(mockedCnfmHttpServiceProvider, exceptionUtil); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java new file mode 100644 index 0000000000..3b16feda18 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java @@ -0,0 +1,173 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * 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.bpmn.infrastructure.adapter.cnfm.tasks; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.jetbrains.kotlin.codegen.intrinsics.LateinitIsInitialized; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.serviceinstancebeans.CloudConfiguration; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.RequestInfo; +import org.onap.so.serviceinstancebeans.RequestParameters; + +/** + * + * @author Raviteja Karumuri (raviteja.karumuri@est.tech) + * + */ +public class StubbedBuildingBlockExecution implements BuildingBlockExecution { + + private static final String CLOUD_OWNER = "CloudOwner"; + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String LCP_CLOUD_REGION_ID = "RegionOne"; + private static final String MODEL_VERSION_ID = UUID.randomUUID().toString(); + private static final String SERVICE_INSTANCE_ID = UUID.randomUUID().toString(); + private static final String DEPLOYMENT_ID = UUID.randomUUID().toString(); + private static final String SERVICE_INSTANCE_NAME = "test"; + private static final String INSTANCE_NAME = "instanceTest"; + private static final String TENANT_ID = UUID.randomUUID().toString(); + private final Map<String, Serializable> execution = new HashMap<>(); + private final GeneralBuildingBlock generalBuildingBlock; + + StubbedBuildingBlockExecution() { + + generalBuildingBlock = getGeneralBuildingBlockValue(); + setVariable(BUILDING_BLOCK, getExecuteBuildingBlock()); + } + + @Override + public GeneralBuildingBlock getGeneralBuildingBlock() { + return generalBuildingBlock; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T getVariable(final String key) { + return (T) execution.get(key); + } + + @Override + public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { + return null; + } + + @Override + public void setVariable(final String key, final Serializable value) { + execution.put(key, value); + } + + @Override + public Map<ResourceKey, String> getLookupMap() { + return Collections.emptyMap(); + } + + @Override + public String getFlowToBeCalled() { + return null; + } + + @Override + public int getCurrentSequence() { + return 0; + } + + public static String getTenantId() { + return TENANT_ID; + } + + private GeneralBuildingBlock getGeneralBuildingBlockValue() { + final GeneralBuildingBlock buildingBlock = new GeneralBuildingBlock(); + buildingBlock.setServiceInstance(getServiceInstance()); + return buildingBlock; + } + + private ExecuteBuildingBlock getExecuteBuildingBlock() { + ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock(); + executeBuildingBlock.setRequestDetails(getRequestDetails()); + return executeBuildingBlock; + } + + private RequestDetails getRequestDetails() { + RequestDetails requestDetails = new RequestDetails(); + requestDetails.setModelInfo(getModelInfo()); + requestDetails.setCloudConfiguration(getCloudConfiguration()); + requestDetails.setRequestInfo(getRequestInfo()); + requestDetails.setRequestParameters(getRequestParameters()); + return requestDetails; + } + + private ModelInfo getModelInfo() { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId(MODEL_VERSION_ID); + return modelInfo; + } + + private ServiceInstance getServiceInstance() { + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId(SERVICE_INSTANCE_ID); + serviceInstance.setServiceInstanceName(SERVICE_INSTANCE_NAME); + return serviceInstance; + } + + private RequestInfo getRequestInfo() { + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setInstanceName(INSTANCE_NAME); + return requestInfo; + } + + private RequestParameters getRequestParameters() { + Map<String, Object> deploymentItemMap = new HashMap<>(); + deploymentItemMap.put("deploymentItemsId", DEPLOYMENT_ID); + deploymentItemMap.put("lifecycleParameterKeyValues", new Object()); + List<Object> deploymentItems = new ArrayList<>(); + deploymentItems.add(deploymentItemMap); + Map<String, Object> userParamsMap = new HashMap<>(); + userParamsMap.put("deploymentItems", deploymentItems); + userParamsMap.put("namespace", "Namespace"); + List<Map<String, Object>> userParams = new ArrayList<>(); + userParams.add(userParamsMap); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(userParams); + return requestParameters; + } + + private CloudConfiguration getCloudConfiguration() { + final CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setCloudOwner(CLOUD_OWNER); + cloudConfiguration.setLcpCloudRegionId(LCP_CLOUD_REGION_ID); + cloudConfiguration.setTenantId(TENANT_ID); + return cloudConfiguration; + } + +} |