### Question:
CreateInventoryTask extends ExternalTaskUtils { public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) { mdcSetup.setupMDC(externalTask); boolean inventoryException = false; String externalTaskId = externalTask.getId(); CloudInformation cloudInformation = externalTask.getVariable("cloudInformation"); boolean success = true; if (cloudInformation != null) { Integer retryCount = externalTask.getRetries(); try { logger.info("Executing External Task Create Inventory, Retry Number: {} \n {}", retryCount, cloudInformation.toString()); createInventory.heatbridge(cloudInformation); } catch (Exception e) { logger.error("Error during inventory of stack", e); success = false; } mdcSetup.setElapsedTime(); if (success) { externalTaskService.complete(externalTask); mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.COMPLETE.toString()); logger.debug("The External Task Id: {} Successful", externalTaskId); logger.info(ONAPLogConstants.Markers.EXIT, "Exiting"); mdcSetup.clearClientMDCs(); } else { if (retryCount == null) { logger.error("The External Task Id: {} Failed, Setting Retries to Default Start Value: {}", externalTaskId, getRetrySequence().length); externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, getRetrySequence().length, 10000); } else if (retryCount != null && retryCount - 1 == 0) { externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE); mdcSetup.setResponseCode(ONAPLogConstants.ResponseStatus.ERROR.toString()); logger.error("The External Task Id: {} Failed, All Retries Exhausted", externalTaskId); logger.info(ONAPLogConstants.Markers.EXIT, "Exiting"); } else { logger.error("The External Task Id: {} Failed, Decrementing Retries: {} , Retry Delay: ", externalTaskId, retryCount - 1, calculateRetryDelay(retryCount)); externalTaskService.handleFailure(externalTask, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI, retryCount - 1, calculateRetryDelay(retryCount)); } logger.error("The External Task Id: {} Failed", externalTaskId); } } else { logger.error("The External Task Id: {} Failed, No Cloud Information Provided", externalTaskId); externalTaskService.handleBpmnError(externalTask, AAI_INVENTORY_FAILURE); } } CreateInventoryTask(); void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService); @Autowired
    public AuditMDCSetup mdcSetup; }### Answer:
@Test public void test_Runtime_Parse_Exception() { doReturn(null).when(externalTask).getVariable("auditInventoryResult"); inventoryTask.executeExternalTask(externalTask, externalTaskService); Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); }
@Test public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException { AAIObjectAuditList object = new AAIObjectAuditList(); AAIObjectAudit e = new AAIObjectAudit(); e.setDoesObjectExist(true); object.getAuditList().add(e); GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult"); inventoryTask.executeExternalTask(externalTask, externalTaskService); Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); }