ImageFSM { @OnTransit public void onImageSaving(@Event ImageSavingEvent event) { Image image = event.getImage(); String cloudId = image.getCloudId(); Cloud cloud = cloudConfigurationProvider.getCloud(cloudId); if (event.isSync()) { LOG.info("Marking image {} ({}) as saving", image.getName(), image.getId()); image.setState(ImageState.SAVING); imagesAware.saveImage(image); } else { LOG.info("Adding image {} ({})", image.getName(), image.getId()); Optional<Image> updatedImageCandidate = operationProcessor.process(cloud, OperationType.ADD_IMAGE, () -> image); if (!updatedImageCandidate.isPresent()) { throw new RuntimeException(String.format("Failed to add %s", image)); } Image updatedImage = updatedImageCandidate.get(); updatedImage.setState(ImageState.SAVING); String temporaryImageId = event.getTemporaryImageId(); if (temporaryImageId != null && imagesAware.imageExists(temporaryImageId)) { imagesAware.deleteImage(temporaryImageId); } imagesAware.saveImage(updatedImage); } } @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 testOnImageSaving() { testOnImageSyncEvent(ImageSavingEvent.class, SAVING); }