@Test public void shouldDetachChildEnvironmentIfParentExists() throws Exception { EnvironmentDto environmentDto = new EnvironmentDto(); environmentDto.setId(CHILD_ENVIRONMENT_ID); EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto .builder() .withEnvironmentDto(environmentDto) .withForceDelete(true) .withId(CHILD_ENVIRONMENT_ID) .build(); when(environmentService.findEnvironmentById(CHILD_ENVIRONMENT_ID)).thenReturn(of(anEnvironmentWithParent(CHILD_ENVIRONMENT_ID))); when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(of(new DescribeFreeIpaResponse())); victim.accept(new Event<>(environmentDeletionDto)); ArgumentCaptor<DetachChildEnvironmentRequest> detachChildEnvironmentRequestArgumentCaptor = ArgumentCaptor.forClass(DetachChildEnvironmentRequest.class); verify(freeIpaService).detachChildEnvironment(detachChildEnvironmentRequestArgumentCaptor.capture()); verifyNoMoreInteractions(freeIpaService); verify(eventSender).sendEvent(any(BaseNamedFlowEvent.class), any(Event.Headers.class)); verify(dnsV1Endpoint).deleteDnsZoneBySubnet(eq(PARENT_ENVIRONMENT_CRN), any()); assertEquals(PARENT_ENVIRONMENT_CRN, detachChildEnvironmentRequestArgumentCaptor.getValue().getParentEnvironmentCrn()); assertEquals(ENVIRONMENT_CRN, detachChildEnvironmentRequestArgumentCaptor.getValue().getChildEnvironmentCrn()); }
@Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); Environment environment = environmentService.findEnvironmentById(environmentDto.getId()).orElse(null); try { if (shouldRemoveFreeIpa(environment)) { if (Objects.nonNull(environment.getParentEnvironment())) { detachChildEnvironmentFromFreeIpa(environment); } else { deleteFreeIpa(environment, environmentDeletionDto.isForceDelete()); } } eventSender().sendEvent(getNextStepObject(environmentDeletionDto), environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } }
FreeIpaDeletionHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); Environment environment = environmentService.findEnvironmentById(environmentDto.getId()).orElse(null); try { if (shouldRemoveFreeIpa(environment)) { if (Objects.nonNull(environment.getParentEnvironment())) { detachChildEnvironmentFromFreeIpa(environment); } else { deleteFreeIpa(environment, environmentDeletionDto.isForceDelete()); } } eventSender().sendEvent(getNextStepObject(environmentDeletionDto), environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } }
FreeIpaDeletionHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); Environment environment = environmentService.findEnvironmentById(environmentDto.getId()).orElse(null); try { if (shouldRemoveFreeIpa(environment)) { if (Objects.nonNull(environment.getParentEnvironment())) { detachChildEnvironmentFromFreeIpa(environment); } else { deleteFreeIpa(environment, environmentDeletionDto.isForceDelete()); } } eventSender().sendEvent(getNextStepObject(environmentDeletionDto), environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  FreeIpaDeletionHandler(
            EventSender eventSender,
            EnvironmentService environmentService,
            FreeIpaService freeIpaService,
            PollingService<FreeIpaPollerObject> freeIpaPollingService,
            DnsV1Endpoint dnsV1Endpoint); }
FreeIpaDeletionHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); Environment environment = environmentService.findEnvironmentById(environmentDto.getId()).orElse(null); try { if (shouldRemoveFreeIpa(environment)) { if (Objects.nonNull(environment.getParentEnvironment())) { detachChildEnvironmentFromFreeIpa(environment); } else { deleteFreeIpa(environment, environmentDeletionDto.isForceDelete()); } } eventSender().sendEvent(getNextStepObject(environmentDeletionDto), environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  FreeIpaDeletionHandler(
            EventSender eventSender,
            EnvironmentService environmentService,
            FreeIpaService freeIpaService,
            PollingService<FreeIpaPollerObject> freeIpaPollingService,
            DnsV1Endpoint dnsV1Endpoint); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); @Override String selector(); }
FreeIpaDeletionHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); Environment environment = environmentService.findEnvironmentById(environmentDto.getId()).orElse(null); try { if (shouldRemoveFreeIpa(environment)) { if (Objects.nonNull(environment.getParentEnvironment())) { detachChildEnvironmentFromFreeIpa(environment); } else { deleteFreeIpa(environment, environmentDeletionDto.isForceDelete()); } } eventSender().sendEvent(getNextStepObject(environmentDeletionDto), environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  FreeIpaDeletionHandler(
            EventSender eventSender,
            EnvironmentService environmentService,
            FreeIpaService freeIpaService,
            PollingService<FreeIpaPollerObject> freeIpaPollingService,
            DnsV1Endpoint dnsV1Endpoint); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); @Override String selector();  }