### Question:
ProvisionerService { public void startStackDeletion(Long id, boolean forced) { SdxCluster sdxCluster = sdxService.getById(id); try { String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn(); ThreadBasedUserCrnProvider.doAsInternalActor(() -> stackV4Endpoint.deleteInternal(0L, sdxCluster.getClusterName(), forced, initiatorUserCrn)); sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.STACK_DELETION_IN_PROGRESS, "Data Lake stack deletion in progress", sdxCluster); } catch (NotFoundException e) { LOGGER.info("Cannot find stack on cloudbreak side {}", sdxCluster.getClusterName()); } catch (WebApplicationException e) { String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e); LOGGER.info("Cannot delete stack {} from cloudbreak: {}", sdxCluster.getStackId(), errorMessage, e); throw new RuntimeException("Cannot delete stack, some error happened on Cloudbreak side: " + errorMessage); } catch (ProcessingException e) { LOGGER.info("Cannot delete stack {} from cloudbreak: {}", sdxCluster.getStackId(), e); throw new RuntimeException("Cannot delete stack, client error happened on Cloudbreak side: " + e.getMessage()); } }  void startStackDeletion(Long id, boolean forced); void waitCloudbreakClusterDeletion(Long id, PollingConfig pollingConfig); void startStackProvisioning(Long id, DetailedEnvironmentResponse environment); StackV4Response waitCloudbreakClusterCreation(Long id, PollingConfig pollingConfig); static final int DELETE_FAILED_RETRY_COUNT; }### Answer:
@Test void startStackDeletionStackNotFound() { long clusterId = CLUSTER_ID.incrementAndGet(); SdxCluster sdxCluster = generateValidSdxCluster(clusterId); when(sdxService.getById(clusterId)).thenReturn(sdxCluster); StackV4Response stackV4Response = new StackV4Response(); stackV4Response.setStatus(Status.CREATE_FAILED); doThrow(new NotFoundException()).when(stackV4Endpoint).deleteInternal(anyLong(), eq(sdxCluster.getClusterName()), eq(Boolean.FALSE), nullable(String.class)); underTest.startStackDeletion(clusterId, false); verify(stackV4Endpoint).deleteInternal(eq(0L), eq(null), eq(false), nullable(String.class)); }
@Test void startForcedStackDeletionStackFound() { long clusterId = CLUSTER_ID.incrementAndGet(); SdxCluster sdxCluster = generateValidSdxCluster(clusterId); when(sdxService.getById(clusterId)).thenReturn(sdxCluster); StackV4Response stackV4Response = new StackV4Response(); stackV4Response.setStatus(Status.CREATE_FAILED); underTest.startStackDeletion(clusterId, true); verify(stackV4Endpoint).deleteInternal(eq(0L), eq(null), eq(true), nullable(String.class)); }
@Test void startStackDeletionButClientError() { long clusterId = CLUSTER_ID.incrementAndGet(); SdxCluster sdxCluster = generateValidSdxCluster(clusterId); when(sdxService.getById(clusterId)).thenReturn(sdxCluster); StackV4Response stackV4Response = new StackV4Response(); stackV4Response.setStatus(Status.CREATE_FAILED); WebApplicationException webApplicationException = new WebApplicationException(); doThrow(webApplicationException).when(stackV4Endpoint).deleteInternal(anyLong(), eq(sdxCluster.getClusterName()), eq(Boolean.FALSE), nullable(String.class)); when(webApplicationExceptionMessageExtractor.getErrorMessage(webApplicationException)).thenReturn("web-error"); RuntimeException actual = Assertions.assertThrows(RuntimeException.class, () -> underTest.startStackDeletion(clusterId, false)); Assertions.assertEquals("Cannot delete stack, some error happened on Cloudbreak side: web-error", actual.getMessage()); verify(stackV4Endpoint).deleteInternal(eq(0L), eq(null), eq(false), nullable(String.class)); }