@Test void testWhenFreeIpaDescribeTellsFreeIpaIsNotStartableThenExceptionComesAndNoStartEventHappens() { when(mockFreeIpaService.describe(MOCK_ENV_CRN)).thenReturn(Optional.of(mockDescribeFreeIpaResponse)); when(mockDescribeFreeIpaResponse.getStatus()).thenReturn(Status.DELETED_ON_PROVIDER_SIDE); underTest.accept(mockEnvironmentDtoEvent); verify(mockEventSender, never()).sendEvent(any(EnvStartEvent.class), any()); verify(mockFreeIpaPollerService, never()).startAttachedFreeipaInstances(any(), any()); ArgumentCaptor<EnvStartFailedEvent> startFailedEventCaptor = ArgumentCaptor.forClass(EnvStartFailedEvent.class); verify(mockEventSender, times(1)).sendEvent(startFailedEventCaptor.capture(), eq(mockEventHeaders)); EnvStartFailedEvent envStartFailedEvent = startFailedEventCaptor.getValue(); assertThat(envStartFailedEvent.getEnvironmentDto()).isEqualTo(mockEnvironmentDto); assertThat(envStartFailedEvent.getEnvironmentStatus()).isEqualTo(EnvironmentStatus.START_FREEIPA_FAILED); }
@Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStartable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a valid state to start! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.startAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent() .withSelector(EnvStartStateSelectors.ENV_START_DATALAKE_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStartEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } }
StartFreeIpaHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStartable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a valid state to start! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.startAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent() .withSelector(EnvStartStateSelectors.ENV_START_DATALAKE_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStartEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } }
StartFreeIpaHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStartable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a valid state to start! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.startAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent() .withSelector(EnvStartStateSelectors.ENV_START_DATALAKE_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStartEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  StartFreeIpaHandler(EventSender eventSender, FreeIpaPollerService freeIpaPollerService, FreeIpaService freeIpaService); }
StartFreeIpaHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStartable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a valid state to start! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.startAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent() .withSelector(EnvStartStateSelectors.ENV_START_DATALAKE_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStartEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  StartFreeIpaHandler(EventSender eventSender, FreeIpaPollerService freeIpaPollerService, FreeIpaService freeIpaService); @Override String selector(); @Override void accept(Event<EnvironmentDto> environmentDtoEvent); }
StartFreeIpaHandler extends EventSenderAwareHandler<EnvironmentDto> { @Override public void accept(Event<EnvironmentDto> environmentDtoEvent) { EnvironmentDto environmentDto = environmentDtoEvent.getData(); try { freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> { if (freeIpa.getStatus() != null && !freeIpa.getStatus().isStartable()) { throw new FreeIpaOperationFailedException("FreeIPA is not in a valid state to start! Current state is: " + freeIpa.getStatus().name()); } }); freeIpaPollerService.startAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn()); EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent() .withSelector(EnvStartStateSelectors.ENV_START_DATALAKE_EVENT.selector()) .withResourceId(environmentDto.getId()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(envStartEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_FREEIPA_FAILED); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } protected  StartFreeIpaHandler(EventSender eventSender, FreeIpaPollerService freeIpaPollerService, FreeIpaService freeIpaService); @Override String selector(); @Override void accept(Event<EnvironmentDto> environmentDtoEvent);  }