diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
10 files changed, 195 insertions, 32 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java index e5df3d3f35..f1fd23fe82 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java @@ -65,6 +65,7 @@ import org.onap.so.client.sniro.beans.ServiceInfo; import org.onap.so.client.sniro.beans.SniroManagerRequest; import org.onap.so.client.sniro.beans.SubscriberInfo; import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -160,14 +161,15 @@ public class SniroHomingV2 { logger.trace("Completed Sniro Homing Call Sniro"); } catch (BpmnError e) { logger.error(EXCEPTION_OCCURRED, e); - exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage()); + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage(), + TargetEntity.SNIRO); } catch (BadResponseException e) { logger.error(EXCEPTION_OCCURRED, e); - exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage()); + exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage(), TargetEntity.SNIRO); } catch (Exception e) { logger.error(EXCEPTION_OCCURRED, e); exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, - "Internal Error - occurred while preparing sniro request: " + e.getMessage()); + "Internal Error - occurred while preparing sniro request: " + e.getMessage(), TargetEntity.SO); } } @@ -211,14 +213,16 @@ public class SniroHomingV2 { logger.trace("Completed Sniro Homing Process Solution"); } catch (BpmnError e) { logger.error(EXCEPTION_OCCURRED, e); - exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage()); + exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage(), + TargetEntity.SNIRO); } catch (BadResponseException e) { logger.error(EXCEPTION_OCCURRED, e); - exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage()); + exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage(), TargetEntity.SNIRO); } catch (Exception e) { logger.error(EXCEPTION_OCCURRED, e); exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, - "Internal Error - occurred while processing sniro asynchronous response: " + e.getMessage()); + "Internal Error - occurred while processing sniro asynchronous response: " + e.getMessage(), + TargetEntity.SO); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java index 859db11037..e9d33f46ab 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java @@ -38,6 +38,7 @@ import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.NetworkAdapterResources; +import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -93,7 +94,7 @@ public class NetworkAdapterRestV1 { throw new Exception("No Network Request was created. networkAdapterRequest was null."); } } catch (Exception ex) { - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); } } @@ -138,7 +139,7 @@ public class NetworkAdapterRestV1 { } } catch (Exception e) { logger.error("Error in Openstack Adapter callback", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), TargetEntity.OPENSTACK); } } @@ -151,7 +152,7 @@ public class NetworkAdapterRestV1 { public void handleTimeOutException(DelegateExecution execution) { exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, - "Error timed out waiting on Openstack Async-Response"); + "Error timed out waiting on Openstack Async-Response", TargetEntity.SO); } public void handleSyncError(DelegateExecution execution) { @@ -159,6 +160,6 @@ public class NetworkAdapterRestV1 { String responseString = (String) execution.getVariable(NETWORK_SYNC_RESPONSE); String errorMessage = "Error with Openstack Adapter Sync Request: StatusCode = " + statusCode + " Response = " + responseString; - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, errorMessage); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, errorMessage, TargetEntity.OPENSTACK); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java index fcc67d0ef7..9bbe94a077 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java @@ -29,8 +29,10 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.SDNCVnfResources; +import org.onap.so.utils.TargetEntity; import org.onap.so.client.orchestration.SDNCVfModuleResources; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +41,8 @@ import org.springframework.stereotype.Component; @Component public class SDNCQueryTasks { - + private static final Logger logger = LoggerFactory.getLogger(SDNCQueryTasks.class); + private static final String NO_RESPONSE_FROM_SDNC = "Error did not receive a response from SDNC."; public static final String SDNCQUERY_RESPONSE = "SDNCQueryResponse_"; @Autowired private SDNCVnfResources sdncVnfResources; @@ -63,8 +66,14 @@ public class SDNCQueryTasks { } String response = sdncVnfResources.queryVnf(genericVnf); execution.setVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId(), response); + } catch (BadResponseException ex) { + if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SDNC); + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); + } } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); } } @@ -88,6 +97,12 @@ public class SDNCQueryTasks { throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value"); } + } catch (BadResponseException ex) { + if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SDNC); + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); + } } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } @@ -109,10 +124,16 @@ public class SDNCQueryTasks { // If we see a bb object not found exception for something that is not a vf module id, then we should throw // the error as normal if (!ResourceKey.VF_MODULE_ID.equals(bbException.getResourceKey())) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, bbException); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, bbException, TargetEntity.SO); + } + } catch (BadResponseException ex) { + if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SDNC); + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); } } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, TargetEntity.SO); } } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java index cb761f4110..03714db943 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasks.java @@ -37,6 +37,7 @@ import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCRequest; +import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -79,17 +80,19 @@ public class SDNCRequestTasks { } catch (PathNotFoundException e) { logger.error("Error Parsing SDNC Response. Could not find read final ack indicator from JSON.", e); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, - "Recieved invalid response from SDNC, unable to read message content."); + "Recieved invalid response from SDNC, unable to read message content.", TargetEntity.SO); } catch (MapperException e) { logger.error("Failed to map SDNC object to JSON prior to POST.", e); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, - "Failed to map SDNC object to JSON prior to POST."); + "Failed to map SDNC object to JSON prior to POST.", TargetEntity.SO); } catch (BadResponseException e) { logger.error("Did not receive a successful response from SDNC.", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getLocalizedMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getLocalizedMessage(), + TargetEntity.SDNC); } catch (HttpClientErrorException e) { logger.error("HttpClientErrorException: 404 Not Found, Failed to contact SDNC", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "SDNC cannot be contacted."); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "SDNC cannot be contacted.", + TargetEntity.SO); } } @@ -120,16 +123,17 @@ public class SDNCRequestTasks { } } catch (SDNCErrorResponseException e) { logger.error("SDNC error response - " + e.getMessage()); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), TargetEntity.SDNC); } catch (Exception e) { - logger.error("Error procesing SDNC callback", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error procesing SDNC callback"); + logger.error("Error processing SDNC callback", e); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error processing SDNC callback", + TargetEntity.SO); } } public void handleTimeOutException(DelegateExecution execution) { exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, - "Error timed out waiting on SDNC Async-Response"); + "Error timed out waiting on SDNC Async-Response", TargetEntity.SO); } protected boolean convertIndicatorToBoolean(String finalMessageIndicator) { @@ -149,5 +153,4 @@ public class SDNCRequestTasks { } return result; } - } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java index 67dc9fec26..2d3f5de616 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java @@ -26,6 +26,7 @@ import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.bpmn.core.WorkflowException; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.constants.Status; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; import org.slf4j.Logger; @@ -37,6 +38,7 @@ import org.springframework.stereotype.Component; public class WorkflowActionBBFailure { private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBFailure.class); + public static final String ROLLBACK_TARGET_STATE = "rollbackTargetState"; @Autowired private RequestsDbClient requestDbclient; @Autowired @@ -89,6 +91,8 @@ public class WorkflowActionBBFailure { rollbackErrorMsg = "Rollback has been completed successfully."; request.setRollbackStatusMessage(rollbackErrorMsg); execution.setVariable("RollbackErrorMessage", rollbackErrorMsg); + String rollbackTargetState = (String) execution.getVariable(ROLLBACK_TARGET_STATE); + request.setRequestStatus(rollbackTargetState); } else if (isRollbackFailure) { Optional<String> rollbackErrorMsgOp = retrieveErrorMessage(execution); if (rollbackErrorMsgOp.isPresent()) { @@ -98,6 +102,7 @@ public class WorkflowActionBBFailure { } request.setRollbackStatusMessage(rollbackErrorMsg); execution.setVariable("RollbackErrorMessage", rollbackErrorMsg); + request.setRequestStatus(Status.FAILED.toString()); } else { Optional<String> errorMsgOp = retrieveErrorMessage(execution); if (errorMsgOp.isPresent()) { @@ -107,6 +112,12 @@ public class WorkflowActionBBFailure { } request.setStatusMessage(errorMsg); execution.setVariable("ErrorMessage", errorMsg); + String handlingCode = (String) execution.getVariable("handlingCode"); + if ("Abort".equalsIgnoreCase(handlingCode)) { + request.setRequestStatus(Status.ABORTED.toString()); + } else { + request.setRequestStatus(Status.FAILED.toString()); + } } if (ebb != null && ebb.getBuildingBlock() != null) { String flowStatus = ""; @@ -120,7 +131,6 @@ public class WorkflowActionBBFailure { } request.setProgress(Long.valueOf(100)); - request.setRequestStatus("FAILED"); request.setLastModifiedBy("CamundaBPMN"); request.setEndTime(new Timestamp(System.currentTimeMillis())); requestDbclient.updateInfraActiveRequests(request); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index 44152fcaf4..a17556f091 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -312,7 +312,6 @@ public class WorkflowActionBBTasks { } workflowActionBBFailure.updateRequestErrorStatusMessage(execution); - if (rollbackFlows.isEmpty()) execution.setVariable("isRollbackNeeded", false); else diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java index d0cee42178..8aea2d2650 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java @@ -39,12 +39,14 @@ import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.exception.MapperException; +import org.onap.so.utils.TargetEntity; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -110,8 +112,9 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { delegateExecution.setVariable("networkAdapterRequest", updateNetworkRequest); delegateExecution.setVariable("NetworkAResponse_MESSAGE", updateNetworkResponse.toXmlString()); - doThrow(new BpmnError("MSOWorkflowException")).when(exceptionBuilder) - .buildAndThrowWorkflowException(any(DelegateExecution.class), anyInt(), any(String.class)); + doThrow(new BpmnError("MSOWorkflowException")).when(exceptionBuilder).buildAndThrowWorkflowException( + any(DelegateExecution.class), anyInt(), any(String.class), any(TargetEntity.class)); + try { networkAdapterRestV1Tasks.processCallback(delegateExecution); } catch (BpmnError be) { @@ -119,6 +122,6 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { } assertNull(delegateExecution.getVariable("updateNetworkResponse")); verify(exceptionBuilder, times(1)).buildAndThrowWorkflowException(any(DelegateExecution.class), eq(7000), - eq("test error message")); + eq("test error message"), eq(TargetEntity.OPENSTACK)); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java index 3ea8474b24..0ba9237aaf 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasksTest.java @@ -43,6 +43,9 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.BadResponseException; +import org.onap.so.utils.TargetEntities; +import org.onap.so.utils.TargetEntity; public class SDNCQueryTasksTest extends BaseTaskTest { @InjectMocks @@ -61,8 +64,8 @@ public class SDNCQueryTasksTest extends BaseTaskTest { genericVnf = setGenericVnf(); vfModule = setVfModule(); - doThrow(new BpmnError("BPMN Error")).when(exceptionUtil) - .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); + doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException( + any(BuildingBlockExecution.class), eq(7000), any(Exception.class), any(TargetEntities.class)); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) .thenReturn(serviceInstance); @@ -88,6 +91,28 @@ public class SDNCQueryTasksTest extends BaseTaskTest { } @Test + public void queryVfModuleBadResponseExceptionTest() throws Exception { + BadResponseException exception = new BadResponseException("Error received from SDNC"); + doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVfModule(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SDNC); + } + + @Test + public void queryVfModuleResponseExceptionNoResponseTest() throws Exception { + BadResponseException exception = new BadResponseException("Error did not receive a response from SDNC."); + doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVfModule(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SO); + } + + @Test public void queryVnfTest() throws Exception { String sdncQueryResponse = "response"; @@ -101,6 +126,28 @@ public class SDNCQueryTasksTest extends BaseTaskTest { } @Test + public void queryVnfBadResponseExceptionTest() throws Exception { + BadResponseException exception = new BadResponseException("Error received from SDNC"); + doThrow(exception).when(sdncVnfResources).queryVnf(genericVnf); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVnf(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SDNC); + } + + @Test + public void queryVnfBadResponseExceptionNoResponseTest() throws Exception { + BadResponseException exception = new BadResponseException("Error did not receive a response from SDNC."); + doThrow(exception).when(sdncVnfResources).queryVnf(genericVnf); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVnf(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SO); + } + + @Test public void queryVfModuleForVolumeGroupTest() throws Exception { String sdncQueryResponse = "response"; vfModule.setSelflink("vfModuleSelfLink"); @@ -115,6 +162,28 @@ public class SDNCQueryTasksTest extends BaseTaskTest { } @Test + public void queryVfModuleForVolumeGroupBadResponseExceptionTest() throws Exception { + BadResponseException exception = new BadResponseException("Error received from SDNC"); + doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVfModuleForVolumeGroup(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SDNC); + } + + @Test + public void queryVfModuleForVolumeGroupBadResponseExceptionNoResponseTest() throws Exception { + BadResponseException exception = new BadResponseException("Error did not receive a response from SDNC."); + doThrow(exception).when(sdncVfModuleResources).queryVfModule(vfModule); + + expectedException.expect(BpmnError.class); + sdncQueryTasks.queryVfModuleForVolumeGroup(execution); + + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(execution, 700, exception, TargetEntity.SO); + } + + @Test public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception { expectedException.expect(BpmnError.class); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java index 6a94b357e0..0fc33fe5ce 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCRequestTasksTest.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.infrastructure.sdnc.tasks; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import java.io.IOException; @@ -48,6 +49,7 @@ import org.onap.so.client.exception.MapperException; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sdnc.beans.SDNCRequest; import org.onap.so.client.sdnc.endpoint.SDNCTopology; +import org.onap.so.utils.TargetEntity; import org.w3c.dom.Document; import org.xml.sax.InputSource; import com.fasterxml.jackson.core.JsonParseException; @@ -66,7 +68,6 @@ public class SDNCRequestTasksTest extends SDNCRequestTasks { @Mock SDNCClient sdncClient; - @Spy private ExceptionBuilder exceptionBuilder; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java index 12f34eaddf..2d48d02774 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java @@ -41,6 +41,7 @@ import org.mockito.Spy; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.core.WorkflowException; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.constants.Status; import org.onap.so.db.request.beans.InfraActiveRequests; public class WorkflowActionBBFailureTest extends BaseTaskTest { @@ -102,6 +103,24 @@ public class WorkflowActionBBFailureTest extends BaseTaskTest { workflowActionBBFailure.updateRequestStatusToFailed(execution); String errorMsg = (String) execution.getVariable("ErrorMessage"); assertEquals("error in test case", errorMsg); + assertEquals(Status.FAILED.toString(), req.getRequestStatus()); + } + + @Test + public void updateRequestStatusToAborted() { + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", false); + execution.setVariable("isRollback", false); + execution.setVariable("handlingCode", "Abort"); + InfraActiveRequests req = new InfraActiveRequests(); + WorkflowException wfe = new WorkflowException("processKey123", 1, "error in test case"); + execution.setVariable("WorkflowException", wfe); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("ErrorMessage"); + assertEquals("error in test case", errorMsg); + assertEquals(Status.ABORTED.toString(), req.getRequestStatus()); } @Test @@ -117,19 +136,52 @@ public class WorkflowActionBBFailureTest extends BaseTaskTest { workflowActionBBFailure.updateRequestStatusToFailed(execution); String errorMsg = (String) execution.getVariable("RollbackErrorMessage"); assertEquals("error in rollback", errorMsg); + assertEquals(Status.FAILED.toString(), req.getRequestStatus()); + } + + @Test + public void updateRequestStatusToRolledback() { + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", true); + execution.setVariable("isRollback", true); + execution.setVariable("rollbackTargetState", "ROLLED_BACK"); + InfraActiveRequests req = new InfraActiveRequests(); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("RollbackErrorMessage"); + assertEquals("Rollback has been completed successfully.", errorMsg); + assertEquals(Status.ROLLED_BACK.toString(), req.getRequestStatus()); + } + + @Test + public void updateRequestStatusToRolledbackToAssigned() { + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", true); + execution.setVariable("isRollback", true); + execution.setVariable("rollbackTargetState", "ROLLED_BACK_TO_ASSIGNED"); + InfraActiveRequests req = new InfraActiveRequests(); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("RollbackErrorMessage"); + assertEquals("Rollback has been completed successfully.", errorMsg); + assertEquals(Status.ROLLED_BACK_TO_ASSIGNED.toString(), req.getRequestStatus()); } @Test - public void updateRequestStatusToFailedRollbackCompleted() { + public void updateRequestStatusToRolledbackToCreated() { execution.setVariable("mso-request-id", "123"); execution.setVariable("isRollbackComplete", true); execution.setVariable("isRollback", true); + execution.setVariable("rollbackTargetState", "ROLLED_BACK_TO_CREATED"); InfraActiveRequests req = new InfraActiveRequests(); doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); workflowActionBBFailure.updateRequestStatusToFailed(execution); String errorMsg = (String) execution.getVariable("RollbackErrorMessage"); assertEquals("Rollback has been completed successfully.", errorMsg); + assertEquals(Status.ROLLED_BACK_TO_CREATED.toString(), req.getRequestStatus()); } @Test |