@Test public void testAccept() { given(environmentDtoEvent.getData()).willReturn(environmentDeletionDto); given(environmentDeletionDto.getEnvironmentDto()).willReturn(environmentDto); given(environmentDto.getResourceCrn()).willReturn(TEST_CRN); given(environmentService.findEnvironmentById(any())).willReturn(Optional.of(new Environment())); doNothing().when(umsClient).notifyResourceDeleted(TEST_CRN, Optional.empty()); doNothing().when(eventSender).sendEvent(any(EnvDeleteEvent.class), any()); underTest.accept(environmentDtoEvent); verify(environmentService, times(1)).findEnvironmentById(any()); verify(umsClient, times(1)).notifyResourceDeleted(TEST_CRN, Optional.empty()); verify(eventSender, times(1)).sendEvent(any(EnvDeleteEvent.class), any()); }
@Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); String environmentCrn = null; try { environmentCrn = environmentDto.getResourceCrn(); AtomicReference<String> resourceCrn = new AtomicReference<>(null); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> { resourceCrn.set(environment.getResourceCrn()); }); if (StringUtils.isBlank(environmentCrn)) { environmentCrn = resourceCrn.get(); } virtualGroupService.cleanupVirtualGroups(Crn.fromString(environmentCrn).getAccountId(), environmentCrn); umsClient.notifyResourceDeleted(environmentCrn, MDCUtils.getRequestId()); } catch (Exception e) { LOGGER.warn("UMS delete event failed (this event is not critical)", e); } EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentCrn) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(FINISH_ENV_DELETE_EVENT.selector()) .build(); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); }
EnvironmentUMSResourceDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); String environmentCrn = null; try { environmentCrn = environmentDto.getResourceCrn(); AtomicReference<String> resourceCrn = new AtomicReference<>(null); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> { resourceCrn.set(environment.getResourceCrn()); }); if (StringUtils.isBlank(environmentCrn)) { environmentCrn = resourceCrn.get(); } virtualGroupService.cleanupVirtualGroups(Crn.fromString(environmentCrn).getAccountId(), environmentCrn); umsClient.notifyResourceDeleted(environmentCrn, MDCUtils.getRequestId()); } catch (Exception e) { LOGGER.warn("UMS delete event failed (this event is not critical)", e); } EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentCrn) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(FINISH_ENV_DELETE_EVENT.selector()) .build(); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } }
EnvironmentUMSResourceDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); String environmentCrn = null; try { environmentCrn = environmentDto.getResourceCrn(); AtomicReference<String> resourceCrn = new AtomicReference<>(null); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> { resourceCrn.set(environment.getResourceCrn()); }); if (StringUtils.isBlank(environmentCrn)) { environmentCrn = resourceCrn.get(); } virtualGroupService.cleanupVirtualGroups(Crn.fromString(environmentCrn).getAccountId(), environmentCrn); umsClient.notifyResourceDeleted(environmentCrn, MDCUtils.getRequestId()); } catch (Exception e) { LOGGER.warn("UMS delete event failed (this event is not critical)", e); } EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentCrn) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(FINISH_ENV_DELETE_EVENT.selector()) .build(); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } protected  EnvironmentUMSResourceDeleteHandler(EventSender eventSender,
            EnvironmentService environmentService, GrpcUmsClient umsClient, VirtualGroupService virtualGroupService); }
EnvironmentUMSResourceDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); String environmentCrn = null; try { environmentCrn = environmentDto.getResourceCrn(); AtomicReference<String> resourceCrn = new AtomicReference<>(null); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> { resourceCrn.set(environment.getResourceCrn()); }); if (StringUtils.isBlank(environmentCrn)) { environmentCrn = resourceCrn.get(); } virtualGroupService.cleanupVirtualGroups(Crn.fromString(environmentCrn).getAccountId(), environmentCrn); umsClient.notifyResourceDeleted(environmentCrn, MDCUtils.getRequestId()); } catch (Exception e) { LOGGER.warn("UMS delete event failed (this event is not critical)", e); } EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentCrn) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(FINISH_ENV_DELETE_EVENT.selector()) .build(); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } protected  EnvironmentUMSResourceDeleteHandler(EventSender eventSender,
            EnvironmentService environmentService, GrpcUmsClient umsClient, VirtualGroupService virtualGroupService); @Override String selector(); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); }
EnvironmentUMSResourceDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); String environmentCrn = null; try { environmentCrn = environmentDto.getResourceCrn(); AtomicReference<String> resourceCrn = new AtomicReference<>(null); environmentService.findEnvironmentById(environmentDto.getId()) .ifPresent(environment -> { resourceCrn.set(environment.getResourceCrn()); }); if (StringUtils.isBlank(environmentCrn)) { environmentCrn = resourceCrn.get(); } virtualGroupService.cleanupVirtualGroups(Crn.fromString(environmentCrn).getAccountId(), environmentCrn); umsClient.notifyResourceDeleted(environmentCrn, MDCUtils.getRequestId()); } catch (Exception e) { LOGGER.warn("UMS delete event failed (this event is not critical)", e); } EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder() .withResourceId(environmentDto.getResourceId()) .withResourceName(environmentDto.getName()) .withResourceCrn(environmentCrn) .withForceDelete(environmentDeletionDto.isForceDelete()) .withSelector(FINISH_ENV_DELETE_EVENT.selector()) .build(); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } protected  EnvironmentUMSResourceDeleteHandler(EventSender eventSender,
            EnvironmentService environmentService, GrpcUmsClient umsClient, VirtualGroupService virtualGroupService); @Override String selector(); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent);  }