@Test public void updateImage() { FlowEvent flowEvent = Mockito.mock(FlowEvent.class); when(stateContext.getEvent()).thenReturn(flowEvent); when(flowEvent.name()).thenReturn(EVENT_NAME); ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event(), 1L, statedImage); when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload); when(state.getId()).thenReturn(StackImageUpdateState.UPDATE_IMAGE_STATE); updateImageAction.execute(stateContext); verify(stackImageUpdateService, times(1)).storeNewImageComponent(any(Stack.class), any(StatedImage.class)); verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event()), any(Event.class)); assertTrue(variables.containsKey(AbstractStackImageUpdateAction.ORIGINAL_IMAGE)); }
@Bean(name = "UPDATE_IMAGE_STATE") public AbstractStackImageUpdateAction<?> updateImage() { return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) { @Override protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) { try { variables.put(ORIGINAL_IMAGE, getImageService().getImage(context.getStack().getId())); } catch (CloudbreakImageNotFoundException e) { LOGGER.debug("Image not found", e); throw new CloudbreakServiceException(e.getMessage(), e); } getStackImageUpdateService().storeNewImageComponent(context.getStack(), payload.getImage()); sendEvent(context, new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), context.getStack().getId())); } }; }
StackImageUpdateActions { @Bean(name = "UPDATE_IMAGE_STATE") public AbstractStackImageUpdateAction<?> updateImage() { return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) { @Override protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) { try { variables.put(ORIGINAL_IMAGE, getImageService().getImage(context.getStack().getId())); } catch (CloudbreakImageNotFoundException e) { LOGGER.debug("Image not found", e); throw new CloudbreakServiceException(e.getMessage(), e); } getStackImageUpdateService().storeNewImageComponent(context.getStack(), payload.getImage()); sendEvent(context, new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), context.getStack().getId())); } }; } }
StackImageUpdateActions { @Bean(name = "UPDATE_IMAGE_STATE") public AbstractStackImageUpdateAction<?> updateImage() { return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) { @Override protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) { try { variables.put(ORIGINAL_IMAGE, getImageService().getImage(context.getStack().getId())); } catch (CloudbreakImageNotFoundException e) { LOGGER.debug("Image not found", e); throw new CloudbreakServiceException(e.getMessage(), e); } getStackImageUpdateService().storeNewImageComponent(context.getStack(), payload.getImage()); sendEvent(context, new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), context.getStack().getId())); } }; }  }
StackImageUpdateActions { @Bean(name = "UPDATE_IMAGE_STATE") public AbstractStackImageUpdateAction<?> updateImage() { return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) { @Override protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) { try { variables.put(ORIGINAL_IMAGE, getImageService().getImage(context.getStack().getId())); } catch (CloudbreakImageNotFoundException e) { LOGGER.debug("Image not found", e); throw new CloudbreakServiceException(e.getMessage(), e); } getStackImageUpdateService().storeNewImageComponent(context.getStack(), payload.getImage()); sendEvent(context, new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), context.getStack().getId())); } }; }  @Bean(name = "CHECK_IMAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkImageVersion(); @Bean(name = "CHECK_PACKAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkPackageVersions(); @Bean(name = "UPDATE_IMAGE_STATE") AbstractStackImageUpdateAction<?> updateImage(); @Bean(name = "IMAGE_PREPARE_STATE") AbstractStackImageUpdateAction<?> prepareImageAction(); @Bean(name = "SET_IMAGE_STATE") AbstractStackImageUpdateAction<?> setImageAction(); @Bean(name = "STACK_IMAGE_UPDATE_FINISHED") AbstractStackImageUpdateAction<?> finishAction(); @Bean(name = "STACK_IMAGE_UPDATE_FAILED_STATE") AbstractStackFailureAction<StackImageUpdateState, StackImageUpdateEvent> handleImageUpdateFailure(); }
StackImageUpdateActions { @Bean(name = "UPDATE_IMAGE_STATE") public AbstractStackImageUpdateAction<?> updateImage() { return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) { @Override protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) { try { variables.put(ORIGINAL_IMAGE, getImageService().getImage(context.getStack().getId())); } catch (CloudbreakImageNotFoundException e) { LOGGER.debug("Image not found", e); throw new CloudbreakServiceException(e.getMessage(), e); } getStackImageUpdateService().storeNewImageComponent(context.getStack(), payload.getImage()); sendEvent(context, new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), context.getStack().getId())); } }; }  @Bean(name = "CHECK_IMAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkImageVersion(); @Bean(name = "CHECK_PACKAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkPackageVersions(); @Bean(name = "UPDATE_IMAGE_STATE") AbstractStackImageUpdateAction<?> updateImage(); @Bean(name = "IMAGE_PREPARE_STATE") AbstractStackImageUpdateAction<?> prepareImageAction(); @Bean(name = "SET_IMAGE_STATE") AbstractStackImageUpdateAction<?> setImageAction(); @Bean(name = "STACK_IMAGE_UPDATE_FINISHED") AbstractStackImageUpdateAction<?> finishAction(); @Bean(name = "STACK_IMAGE_UPDATE_FAILED_STATE") AbstractStackFailureAction<StackImageUpdateState, StackImageUpdateEvent> handleImageUpdateFailure();  }