### Question:
WorkflowServiceImpl implements IWorkflowService { @Override public StartWorkflowResponse startWorkflow(StartWorkflowRequest request, DpsHeaders headers) { log.debug("Start Workflow with payload - {}", request); validationService.validateStartWorkflowRequest(request); String userId = headers.getUserEmail(); String strategyName = ingestionStrategyService.determineStrategy(request.getWorkflowType(), request.getDataType(), userId); String workflowId = UUID.randomUUID().toString(); String airflowRunId = UUID.randomUUID().toString(); submitIngestService.submitIngest(strategyName, request.getContext()); workflowStatusRepository.saveWorkflowStatus(WorkflowStatus.builder() .workflowId(workflowId) .airflowRunId(airflowRunId) .workflowStatusType(WorkflowStatusType.SUBMITTED) .build()); return StartWorkflowResponse.builder().workflowId(workflowId).build(); }  @Override StartWorkflowResponse startWorkflow(StartWorkflowRequest request, DpsHeaders headers);  }### Answer:
@Test void shouldStartWorkflow() { HashMap<String, Object> context = new HashMap<>(); context.put("key", "value"); StartWorkflowRequest request = StartWorkflowRequest.builder() .workflowType(WorkflowType.INGEST) .dataType(DATA_TYPE) .context(context).build(); DpsHeaders headers = getMessageHeaders(); given(ingestionStrategyService .determineStrategy(eq(WorkflowType.INGEST), eq(DATA_TYPE), isNull())) .willReturn(DAG_NAME); StartWorkflowResponse startWorkflowResponse = workflowService .startWorkflow(request, headers); then(startWorkflowResponse.getWorkflowId()).isNotNull(); InOrder inOrder = Mockito.inOrder(validationService, ingestionStrategyService, submitIngestService, workflowStatusRepository); inOrder.verify(validationService).validateStartWorkflowRequest(request); inOrder.verify(ingestionStrategyService) .determineStrategy(eq(WorkflowType.INGEST), eq(DATA_TYPE), isNull()); inOrder.verify(submitIngestService).submitIngest(eq(DAG_NAME), eq(context)); inOrder.verify(workflowStatusRepository).saveWorkflowStatus(workflowStatusCaptor.capture()); inOrder.verifyNoMoreInteractions(); then(workflowStatusCaptor.getValue()).satisfies(status -> { then(status.getAirflowRunId()).isNotNull(); then(status.getWorkflowId()).isNotNull(); then(status.getWorkflowStatusType()).isEqualTo(WorkflowStatusType.SUBMITTED); }); }
@Test void shouldNotSaveWorkflowStatusIfSubmitRequestFails() { HashMap<String, Object> context = new HashMap<>(); context.put("key", "value"); StartWorkflowRequest request = StartWorkflowRequest.builder() .workflowType(WorkflowType.INGEST) .dataType(DATA_TYPE) .context(context).build(); DpsHeaders headers = getMessageHeaders(); given(ingestionStrategyService .determineStrategy(eq(WorkflowType.INGEST), eq(DATA_TYPE), isNull())) .willReturn(DAG_NAME); doThrow(new RuntimeException(TEST_EXCEPTION)).when(submitIngestService) .submitIngest(eq( DAG_NAME), eq(context)); Throwable thrown = catchThrowable(() -> workflowService .startWorkflow(request, headers)); then(thrown).isInstanceOf(RuntimeException.class); verify(workflowStatusRepository, never()).saveWorkflowStatus(any()); }