diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
2 files changed, 134 insertions, 39 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java index 340b2776a4..0b1c5b0f5e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java @@ -20,6 +20,13 @@ package org.onap.so.bpmn.infrastructure.service.level; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; @@ -27,23 +34,16 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelPreparation; import org.onap.so.client.exception.ExceptionBuilder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import static org.assertj.core.api.Assertions.assertThat; +import org.onap.so.db.catalog.beans.Workflow; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {ServiceLevelPreparation.class, ExceptionBuilder.class}) -public class ServiceLevelPreparationTest { +public class ServiceLevelPreparationTest extends BaseTaskTest { private static final String TEST_PNF_SCOPE = "pnf"; private static final String TEST_PROCESS_KEY = "testProcessKey"; @@ -52,42 +52,29 @@ public class ServiceLevelPreparationTest { private static final String RESOURCE_TYPE = "resourceType"; private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; private static final String PNF_NAME = "pnfName"; - private static final List<String> PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, - ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + private static final String HEALTH_CHECK_OPERATION = "ResourceHealthCheck"; + private static final String PNF_HEALTH_CHECK_WORKFLOW = "PNFHealthCheck"; + private static final Map<String, List<String>> HEALTH_CHECK_PARAMS_MAP = Map.of(TEST_PNF_SCOPE, + Arrays.asList(SERVICE_INSTANCE_ID, RESOURCE_TYPE, BPMN_REQUEST, PNF_NAME), "vnf", Collections.emptyList()); + + private List<Workflow> workflowList = new ArrayList<>(); - private Map<String, String> pnfHealthCheckTestParams = new HashMap<>(); + @Rule + public ExpectedException thrown = ExpectedException.none(); - @Autowired + @InjectMocks private ServiceLevelPreparation serviceLevelPrepare; - @Autowired + @InjectMocks + @Spy private ExceptionBuilder exceptionBuilder; - @Rule - public ExpectedException thrown = ExpectedException.none(); - private DelegateExecution execution = new DelegateExecutionFake(); private DelegateExecution invalidExecution = new DelegateExecutionFake(); @Before public void setUpPnfUpgradeTest() { - pnfHealthCheckTestParams.put("TEST_SERVICE_MODEL_INFO", "d4c6855e-3be2-5dtu-9390-c999a38829bc"); - pnfHealthCheckTestParams.put("TEST_SERVICE_INSTANCE_NAME", "test_service_id"); - pnfHealthCheckTestParams.put("TEST_PNF_CORRELATION_ID", "pnfCorrelationId"); - pnfHealthCheckTestParams.put("TEST_MODEL_UUID", "6bc0b04d-1873-4721-b53d-6615225b2a28"); - pnfHealthCheckTestParams.put("TEST_PNF_UUID", "c93g70d9-8de3-57f1-7de1-f5690ac2b005"); - pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_NAME", "serviceUpgrade"); - pnfHealthCheckTestParams.put("TEST_PRC_BLUEPRINT_VERSION", "1.0.2"); - pnfHealthCheckTestParams.put("TEST_PRC_CUSTOMIZATION_UUID", "PRC_customizationUuid"); - pnfHealthCheckTestParams.put("TEST_RESOURCE_CUSTOMIZATION_UUID_PARAM", "9acb3a83-8a52-412c-9a45-901764938144"); - pnfHealthCheckTestParams.put("TEST_PRC_INSTANCE_NAME", "Demo_pnf"); - pnfHealthCheckTestParams.put("TEST_PRC_CONTROLLER_ACTOR", "cds"); - pnfHealthCheckTestParams.put("TEST_REQUEST_PAYLOAD", "test_payload"); - - for (String param : PNF_HEALTH_CHECK_PARAMS) { - execution.setVariable(param, pnfHealthCheckTestParams.get("TEST_" + param)); - } execution.setVariable(RESOURCE_TYPE, TEST_PNF_SCOPE); execution.setVariable(TEST_PROCESS_KEY, PROCESS_KEY_VALUE); execution.setVariable(BPMN_REQUEST, "bpmnRequestValue"); @@ -95,14 +82,22 @@ public class ServiceLevelPreparationTest { execution.setVariable(PNF_NAME, "PnfDemo"); invalidExecution.setVariables(execution.getVariables()); + + Workflow pnfWorkflow = new Workflow(); + pnfWorkflow.setName(PNF_HEALTH_CHECK_WORKFLOW); + pnfWorkflow.setOperationName(HEALTH_CHECK_OPERATION); + pnfWorkflow.setResourceTarget(TEST_PNF_SCOPE); + workflowList.add(pnfWorkflow); + + when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(workflowList); } @Test public void executePnfUpgradeSuccessTest() throws Exception { serviceLevelPrepare.execute(execution); // Expect the pnf health check workflow to be set in to execution if validation is successful - assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.WORKFLOW_TO_INVOKE))) - .isEqualTo("GenericPnfHealthCheck"); + assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE))) + .isEqualTo("PNFHealthCheck"); } @Test @@ -110,7 +105,8 @@ public class ServiceLevelPreparationTest { invalidExecution.removeVariable(BPMN_REQUEST); // BPMN exception is thrown in case of validation failure or invalid execution thrown.expect(BpmnError.class); - serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE, PNF_HEALTH_CHECK_PARAMS); + serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE, + HEALTH_CHECK_PARAMS_MAP.get(TEST_PNF_SCOPE)); } @Test @@ -129,6 +125,32 @@ public class ServiceLevelPreparationTest { } + @Test + public void validateDefaultWorkflowIsSetWithoutDBData() throws Exception { + // Mock empty workflow list in db response + when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(new ArrayList<Workflow>()); + serviceLevelPrepare.execute(execution); + // Expect default workflow gets assigned when workflow name not found in db. + assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE))) + .isEqualTo(ServiceLevelConstants.DEFAULT_HEALTH_CHECK_WORKFLOWS.get(TEST_PNF_SCOPE)); + } + + @Test + public void validateWorkflowSetFromDb() throws Exception { + Workflow vnfWorkflow = new Workflow(); + vnfWorkflow.setName("VNFHealthCheck"); + vnfWorkflow.setOperationName(HEALTH_CHECK_OPERATION); + vnfWorkflow.setResourceTarget("vnf"); + workflowList.add(vnfWorkflow); + // Mock db response with multiple worklfows mapped with same operation name + when(catalogDbClient.findWorkflowByOperationName(HEALTH_CHECK_OPERATION)).thenReturn(workflowList); + serviceLevelPrepare.execute(execution); + + // Expect right workflow gets assigned from db based on the controller scope. + assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE))) + .isEqualTo(PNF_HEALTH_CHECK_WORKFLOW); + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 407a844c4e..c1970ec32c 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -1601,6 +1601,79 @@ public class WorkflowActionTest extends BaseTaskTest { } @Test + public void getConfigBuildingBlocksNullConfigurationTest() throws Exception { + String gAction = "deleteInstance"; + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES); + + WorkflowType resourceType = WorkflowType.VFMODULE; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = + new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("vnfId", "1234"); + execution.setVariable("vfModuleId", "vfModuleId1234"); + execution.setVariable("requestUri", + "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules"); + ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); + RequestDetails requestDetails = sIRequest.getRequestDetails(); + String requestAction = "deleteInstance"; + String requestId = "9c944122-d161-4280-8594-48c06a9d96d5"; + boolean aLaCarte = true; + String apiVersion = "7"; + String vnfType = "vnfType"; + String key = "00d15ebb-c80e-43c1-80f0-90c40dde70b0"; + String resourceId = "d1d35800-783d-42d3-82f6-d654c5054a6e"; + Resource resourceKey = new Resource(resourceType, key, aLaCarte); + WorkflowResourceIds workflowResourceIds = SPY_workflowAction.populateResourceIdsFromApiHandler(execution); + + List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", + "UnassignVfModuleBB", "DeleteFabricConfigurationBB"); + + ConfigBuildingBlocksDataObject dataObj = new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest) + .setOrchFlows(orchFlows).setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion) + .setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte).setVnfType(vnfType) + .setWorkflowResourceIds(workflowResourceIds).setRequestDetails(requestDetails).setExecution(execution); + + org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf(); + vnf.setVnfId("vnf0"); + vnf.setModelCustomizationId("modelCustomizationId"); + when(bbSetupUtils.getAAIGenericVnf(any())).thenReturn(vnf); + + org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule(); + vfModule.setModelCustomizationId("modelCustomizationId"); + + /* this is a test case where configuration for vnfc is null */ + org.onap.aai.domain.yang.Configuration config1 = null; + org.onap.aai.domain.yang.Configuration config2 = new org.onap.aai.domain.yang.Configuration(); + config2.setConfigurationId("config2"); + + List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>(); + org.onap.aai.domain.yang.Vnfc vnfc1 = new org.onap.aai.domain.yang.Vnfc(); + vnfc1.setVnfcName("zauk53avetd02svm001"); + org.onap.aai.domain.yang.Vnfc vnfc2 = new org.onap.aai.domain.yang.Vnfc(); + vnfc2.setVnfcName("zauk53avetd02tvm001"); + vnfcs.add(vnfc1); + vnfcs.add(vnfc2); + + when(bbSetupUtils.getAAIVfModule(any(), any())).thenReturn(vfModule); + doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(any(), any(), + eq(org.onap.aai.domain.yang.Vnfc.class), eq(AAIObjectType.VNFC)); + doReturn(config1).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc1), + eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION)); + doReturn(config2).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc2), + eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION)); + + List<ExecuteBuildingBlock> results = SPY_workflowAction.getConfigBuildingBlocks(dataObj); + + assertFalse(results.isEmpty()); + assertEquals(1, results.size()); + assertEquals("config2", results.get(0).getWorkflowResourceIds().getConfigurationId()); + assertEquals("zauk53avetd02tvm001", results.get(0).getConfigurationResourceKeys().getVnfcName()); + } + + @Test public void selectExecutionListALaCarteVfModuleNoFabricDeleteTest() throws Exception { String gAction = "deleteInstance"; String resource = "VfModule"; |