ImageFSM { @OnTransit public void onImageDeleting(@Event ImageDeletingEvent event) { Image image = event.getImage(); String cloudId = image.getCloudId(); Cloud cloud = cloudConfigurationProvider.getCloud(cloudId); if (event.isSync()) { LOG.info("Marking image {} ({}) as deleting", image.getName(), image.getId()); image.setState(ImageState.DELETING); imagesAware.saveImage(image); } else if (imagesAware.imageExists(image.getId())) { if (operationProcessor.supply(cloud, OperationType.DELETE_IMAGE, () -> image)) { LOG.info("Deleting image {} ({})", image.getName(), image.getId()); imagesAware.deleteImage(image.getId()); } else { throw new RuntimeException(String.format("Failed to delete %s", image)); } } else { LOG.error("Can't delete image {} ({}) - not exists", image.getName(), image.getId()); } } @Autowired  ImageFSM(OperationProcessor operationProcessor, ImagesAware imagesAware, CloudConfigurationProvider cloudConfigurationProvider, MailSender mailSender); @BeforeTransit void beforeTransit(@Event ImageEvent imageEvent); @OnTransit void onImageQueued(@Event ImageQueuedEvent event); @OnTransit void onImageSaving(@Event ImageSavingEvent event); @OnTransit void onImageSaved(@Event ImageSavedEvent event); @OnTransit void onImageDeleting(@Event ImageDeletingEvent event); @OnTransit void onImageError(@FromState ImageEvent from, @Event ImageErrorEvent event); @OnException void onUnsupportedOperationException(UnsupportedOperationException e);  }
@Test public void testOnImageDeleting() { Image image = EntityGenerator.getImage(); imagesAware.saveImage(image); String imageId = image.getId(); assertThat(imagesAware.imageExists(imageId), is(true)); fireEvent(ImageDeletingEvent.class, image, false); assertThat(imagesAware.imageExists(imageId), is(false)); }