@Test void acceptTestNoEnvironment() { when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.empty()); underTest.accept(environmentDtoEvent); verify(cloudPlatformConnectors, never()).get(any()); verify(cloudPlatformConnectors, never()).get(any(), any()); verify(eventSender).sendEvent(eventArgumentCaptor.capture(), headersArgumentCaptor.capture()); verifyEnvDeleteEvent(); }
@Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { BaseParameters environmentParameters = environment.getParameters(); if (environmentParameters instanceof AwsParameters) { AwsParameters awsParameters = (AwsParameters) environmentParameters; deleteS3GuardTable(environment, awsParameters); } else { LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary."); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so " + "continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } }
S3GuardTableDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { BaseParameters environmentParameters = environment.getParameters(); if (environmentParameters instanceof AwsParameters) { AwsParameters awsParameters = (AwsParameters) environmentParameters; deleteS3GuardTable(environment, awsParameters); } else { LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary."); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so " + "continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } } }
S3GuardTableDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { BaseParameters environmentParameters = environment.getParameters(); if (environmentParameters instanceof AwsParameters) { AwsParameters awsParameters = (AwsParameters) environmentParameters; deleteS3GuardTable(environment, awsParameters); } else { LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary."); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so " + "continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } } protected  S3GuardTableDeleteHandler(EventSender eventSender, EnvironmentService environmentService,
            CloudPlatformConnectors cloudPlatformConnectors, CredentialToCloudCredentialConverter credentialToCloudCredentialConverter); }
S3GuardTableDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { BaseParameters environmentParameters = environment.getParameters(); if (environmentParameters instanceof AwsParameters) { AwsParameters awsParameters = (AwsParameters) environmentParameters; deleteS3GuardTable(environment, awsParameters); } else { LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary."); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so " + "continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } } protected  S3GuardTableDeleteHandler(EventSender eventSender, EnvironmentService environmentService,
            CloudPlatformConnectors cloudPlatformConnectors, CredentialToCloudCredentialConverter credentialToCloudCredentialConverter); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); @Override String selector(); }
S3GuardTableDeleteHandler extends EventSenderAwareHandler<EnvironmentDeletionDto> { @Override public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) { EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData(); EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto(); EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto); try { environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> { BaseParameters environmentParameters = environment.getParameters(); if (environmentParameters instanceof AwsParameters) { AwsParameters awsParameters = (AwsParameters) environmentParameters; deleteS3GuardTable(environment, awsParameters); } else { LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary."); } }); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } catch (Exception e) { if (environmentDeletionDto.isForceDelete()) { LOGGER.warn("The {} was not successful but the environment deletion was requested as force delete so " + "continue the deletion flow", selector()); eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders()); } else { EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder() .withEnvironmentID(environmentDto.getId()) .withException(e) .withResourceCrn(environmentDto.getResourceCrn()) .withResourceName(environmentDto.getName()) .build(); eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders()); } } } protected  S3GuardTableDeleteHandler(EventSender eventSender, EnvironmentService environmentService,
            CloudPlatformConnectors cloudPlatformConnectors, CredentialToCloudCredentialConverter credentialToCloudCredentialConverter); @Override void accept(Event<EnvironmentDeletionDto> environmentDtoEvent); @Override String selector();  }