@Test void delete() { when(stackService.findAllByEnvironmentCrnAndAccountId(eq(ENVIRONMENT_CRN), eq(ACCOUNT_ID))).thenReturn(Collections.singletonList(stack)); when(flowLogService.findAllByResourceIdAndFinalizedIsFalseOrderByCreatedDesc(STACK_ID)).thenReturn(List.of()); underTest.delete(ENVIRONMENT_CRN, ACCOUNT_ID, false); verify(stackService, times(1)).findAllByEnvironmentCrnAndAccountId(eq(ENVIRONMENT_CRN), eq(ACCOUNT_ID)); ArgumentCaptor<TerminationEvent> terminationEventArgumentCaptor = ArgumentCaptor.forClass(TerminationEvent.class); verify(flowManager, times(1)).notify(eq(TERMINATION_EVENT.event()), terminationEventArgumentCaptor.capture()); verify(flowCancelService).cancelTooOldTerminationFlowForResource(stack.getId(), stack.getName()); verify(freeipaJobService).unschedule(stack); assertAll( () -> assertEquals(TERMINATION_EVENT.event(), terminationEventArgumentCaptor.getValue().selector()), () -> assertEquals(STACK_ID, terminationEventArgumentCaptor.getValue().getResourceId()), () -> assertFalse(terminationEventArgumentCaptor.getValue().getForced()) ); }
public void delete(String environmentCrn, String accountId, boolean forced) { List<Stack> stacks = stackService.findAllByEnvironmentCrnAndAccountId(environmentCrn, accountId); if (stacks.isEmpty()) { throw new NotFoundException("No FreeIpa found in environment"); } stacks.forEach(stack -> validateDeletion(stack, accountId)); stacks.forEach(stack -> unscheduleAndTriggerTerminate(stack, forced)); }
FreeIpaDeletionService { public void delete(String environmentCrn, String accountId, boolean forced) { List<Stack> stacks = stackService.findAllByEnvironmentCrnAndAccountId(environmentCrn, accountId); if (stacks.isEmpty()) { throw new NotFoundException("No FreeIpa found in environment"); } stacks.forEach(stack -> validateDeletion(stack, accountId)); stacks.forEach(stack -> unscheduleAndTriggerTerminate(stack, forced)); } }
FreeIpaDeletionService { public void delete(String environmentCrn, String accountId, boolean forced) { List<Stack> stacks = stackService.findAllByEnvironmentCrnAndAccountId(environmentCrn, accountId); if (stacks.isEmpty()) { throw new NotFoundException("No FreeIpa found in environment"); } stacks.forEach(stack -> validateDeletion(stack, accountId)); stacks.forEach(stack -> unscheduleAndTriggerTerminate(stack, forced)); }  }
FreeIpaDeletionService { public void delete(String environmentCrn, String accountId, boolean forced) { List<Stack> stacks = stackService.findAllByEnvironmentCrnAndAccountId(environmentCrn, accountId); if (stacks.isEmpty()) { throw new NotFoundException("No FreeIpa found in environment"); } stacks.forEach(stack -> validateDeletion(stack, accountId)); stacks.forEach(stack -> unscheduleAndTriggerTerminate(stack, forced)); }  void delete(String environmentCrn, String accountId, boolean forced); }
FreeIpaDeletionService { public void delete(String environmentCrn, String accountId, boolean forced) { List<Stack> stacks = stackService.findAllByEnvironmentCrnAndAccountId(environmentCrn, accountId); if (stacks.isEmpty()) { throw new NotFoundException("No FreeIpa found in environment"); } stacks.forEach(stack -> validateDeletion(stack, accountId)); stacks.forEach(stack -> unscheduleAndTriggerTerminate(stack, forced)); }  void delete(String environmentCrn, String accountId, boolean forced);  }