Java Code Examples for org.springframework.statemachine.action.Action#execute()
The following examples show how to use
org.springframework.statemachine.action.Action#execute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnvCreationActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
private void testNoEnvironment(Supplier<Action<?, ?>> creationAction, String selector) { Action<?, ?> action = configureAction(creationAction); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.empty()); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentResponseConverter, never()).dtoToSimpleResponse(any(EnvironmentDto.class)); verify(notificationService, never()).send(any(ResourceEvent.class), any(SimpleEnvironmentResponse.class), anyString()); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyCreationActionFailureEvent(selector); }
Example 2
Source File: ExternalDatabaseTerminationActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void externalDatabaseCreationFinishedAction() { TerminateExternalDatabaseResult terminateExternalDatabaseResultPayload = new TerminateExternalDatabaseResult(STACK_ID, EXTERNAL_DATABASE_WAIT_SUCCESS_EVENT.event(), STACK_NAME, STACK_CRN); when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(terminateExternalDatabaseResultPayload); Action<?, ?> action = configureAction(underTest::externalDatabaseTerminationFinishedAction); action.execute(stateContext); verifyNoMoreInteractions(stackUpdaterService); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_TERMINATION_SUCCESSFUL, STACK); assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_TERMINATION_FINISHED_EVENT"); Object capturedPayload = payloadArgumentCaptor.getValue(); assertThat(capturedPayload).isInstanceOf(StackEvent.class); StackEvent stackEvent = (StackEvent) capturedPayload; assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID); }
Example 3
Source File: ExternalDatabaseTerminationActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@ParameterizedTest @ValueSource(booleans = { false, true }) void externalDatabaseTermination(boolean forced) { TerminationEvent terminationEventPayload = new TerminationEvent(ACTION_PAYLOAD_SELECTOR, STACK_ID, forced); when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(terminationEventPayload); Action<?, ?> action = configureAction(underTest::externalDatabaseTermination); action.execute(stateContext); verifyNoMoreInteractions(stackUpdaterService); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); assertThat(selectorArgumentCaptor.getValue()).isEqualTo("TerminateExternalDatabaseRequest"); Object rawPayload = payloadArgumentCaptor.getValue(); assertThat(rawPayload).isInstanceOf(TerminateExternalDatabaseRequest.class); TerminateExternalDatabaseRequest request = (TerminateExternalDatabaseRequest) rawPayload; assertThat(request.isForced()).isEqualTo(forced); }
Example 4
Source File: ExternalDatabaseCreationActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void externalDatabaseCreationFinishedAction() { CreateExternalDatabaseResult createExternalDatabaseResultPayload = new CreateExternalDatabaseResult(STACK_ID, EXTERNAL_DATABASE_WAIT_SUCCESS_EVENT.event(), STACK_NAME, STACK_CRN); when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(createExternalDatabaseResultPayload); Action<?, ?> action = configureAction(underTest::externalDatabaseCreationFinishedAction); action.execute(stateContext); verifyNoMoreInteractions(stackUpdaterService); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_SUCCESSFUL, STACK); assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_CREATION_FINISHED_EVENT"); Object capturedPayload = payloadArgumentCaptor.getValue(); assertThat(capturedPayload).isInstanceOf(StackEvent.class); StackEvent stackEvent = (StackEvent) capturedPayload; assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID); }
Example 5
Source File: EnvClustersDeleteActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void datalakeClustersDeleteAction() { Action<?, ?> action = configureAction(() -> underTest.datalakeClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment)); when(environmentService.save(environment)).thenReturn(savedEnvironment); when(environmentService.getEnvironmentDto(savedEnvironment)).thenReturn(environmentDto); when(environmentResponseConverter.dtoToSimpleResponse(environmentDto)).thenReturn(simpleEnvironmentResponse); action.execute(stateContext); verify(environment).setStatus(EnvironmentStatus.DATALAKE_CLUSTERS_DELETE_IN_PROGRESS); verify(notificationService).send(ResourceEvent.ENVIRONMENT_DATALAKE_CLUSTERS_DELETION_STARTED, simpleEnvironmentResponse, FLOW_TRIGGER_USER_CRN); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyDeleteActionSuccessEvent(DELETE_DATALAKE_CLUSTERS_EVENT); }
Example 6
Source File: EnvClustersDeleteActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void datalakeClustersDeleteActionNoEnvironment() { Action<?, ?> action = configureAction(() -> underTest.datalakeClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.empty()); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentResponseConverter, never()).dtoToSimpleResponse(any(EnvironmentDto.class)); verify(environment, never()).setStatus(any()); verify(notificationService, never()).send(any(ResourceEvent.class), any(SimpleEnvironmentResponse.class), any()); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyDeleteActionSuccessEvent(DELETE_DATALAKE_CLUSTERS_EVENT); }
Example 7
Source File: EnvClustersDeleteActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void datalakeClustersDeleteActionFailure() { Action<?, ?> action = configureAction(() -> underTest.datalakeClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenThrow(new UnsupportedOperationException(MESSAGE)); when(failureEvent.event()).thenReturn(FAILURE_EVENT); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentResponseConverter, never()).dtoToSimpleResponse(any(EnvironmentDto.class)); verify(notificationService, never()).send(any(ResourceEvent.class), any(SimpleEnvironmentResponse.class), anyString()); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyFailureEvent(); }
Example 8
Source File: EnvClustersDeleteActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void datahubClustersDeleteAction() { Action<?, ?> action = configureAction(() -> underTest.datahubClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment)); when(environmentService.save(environment)).thenReturn(savedEnvironment); when(environmentService.getEnvironmentDto(savedEnvironment)).thenReturn(environmentDto); when(environmentResponseConverter.dtoToSimpleResponse(environmentDto)).thenReturn(simpleEnvironmentResponse); action.execute(stateContext); verify(environment).setStatus(EnvironmentStatus.DATAHUB_CLUSTERS_DELETE_IN_PROGRESS); verify(notificationService).send(ResourceEvent.ENVIRONMENT_DATAHUB_CLUSTERS_DELETION_STARTED, simpleEnvironmentResponse, FLOW_TRIGGER_USER_CRN); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyDeleteActionSuccessEvent(DELETE_DATAHUB_CLUSTERS_EVENT); }
Example 9
Source File: EnvClustersDeleteActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void datahubClustersDeleteActionNoEnvironment() { Action<?, ?> action = configureAction(() -> underTest.datahubClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.empty()); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentResponseConverter, never()).dtoToSimpleResponse(any(EnvironmentDto.class)); verify(environment, never()).setStatus(any()); verify(notificationService, never()).send(any(ResourceEvent.class), any(SimpleEnvironmentResponse.class), any()); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyDeleteActionSuccessEvent(DELETE_DATAHUB_CLUSTERS_EVENT); }
Example 10
Source File: EnvClustersDeleteActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test void datahubClustersDeleteActionFailure() { Action<?, ?> action = configureAction(() -> underTest.datahubClustersDeleteAction()); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenThrow(new UnsupportedOperationException(MESSAGE)); when(failureEvent.event()).thenReturn(FAILURE_EVENT); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentResponseConverter, never()).dtoToSimpleResponse(any(EnvironmentDto.class)); verify(notificationService, never()).send(any(ResourceEvent.class), any(SimpleEnvironmentResponse.class), anyString()); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyFailureEvent(); }
Example 11
Source File: EnvDeleteActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
private void testDeleteActionHappyPath(Supplier<Action<?, ?>> deleteAction, String selector, EnvironmentStatus environmentStatus, ResourceEvent eventStarted) { Action<?, ?> action = configureAction(deleteAction); EnvironmentDto environmentDto = mock(EnvironmentDto.class); when(environmentStatusUpdateService.updateEnvironmentStatusAndNotify(any(), any(), any(), any(), any())).thenReturn(environmentDto); action.execute(stateContext); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verify(environmentStatusUpdateService).updateEnvironmentStatusAndNotify(any(), any(), eq(environmentStatus), eq(eventStarted), any()); }
Example 12
Source File: EnvCreationActionsTest.java From cloudbreak with Apache License 2.0 | 6 votes |
private void testFailure(Supplier<Action<?, ?>> creationAction) { Action<?, ?> action = configureAction(creationAction); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenThrow(new UnsupportedOperationException(MESSAGE)); when(failureEvent.event()).thenReturn(FAILURE_EVENT); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentResponseConverter, never()).dtoToSimpleResponse(any(EnvironmentDto.class)); verify(notificationService, never()).send(any(ResourceEvent.class), any(SimpleEnvironmentResponse.class), anyString()); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyFailureEvent(); }
Example 13
Source File: ExternalDatabaseCreationActionsTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test void externalDatabaseCreation() { StackEvent stackEventPayload = new StackEvent(ACTION_PAYLOAD_SELECTOR, STACK_ID); when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(stackEventPayload); Action<?, ?> action = configureAction(underTest::externalDatabaseCreation); action.execute(stateContext); verifyNoMoreInteractions(stackUpdaterService); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); assertThat(selectorArgumentCaptor.getValue()).isEqualTo("CreateExternalDatabaseRequest"); }
Example 14
Source File: EnvDeleteActionsTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private void testNoEnvironment(Supplier<Action<?, ?>> deleteAction, String selector) { Action<?, ?> action = configureAction(deleteAction); action.execute(stateContext); verify(environmentService, never()).save(any(Environment.class)); verify(environmentService, never()).getEnvironmentDto(any(Environment.class)); verify(environmentResponseConverter, never()).dtoToSimpleResponse(any(EnvironmentDto.class)); verify(notificationService, never()).send(any(ResourceEvent.class), any(SimpleEnvironmentResponse.class), anyString()); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); }
Example 15
Source File: ExternalDatabaseCreationActionsTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test void externalDatabaseCreationFailureAction() { RuntimeException expectedException = new RuntimeException(MESSAGE); CreateExternalDatabaseFailed createExternalDatabaseFailedPayload = new CreateExternalDatabaseFailed(STACK_ID, EXTERNAL_DATABASE_CREATION_FAILED_EVENT.event(), STACK_NAME, null, expectedException); when(stackService.getByIdWithClusterInTransaction(any())).thenReturn(STACK); when(runningFlows.get(anyString())).thenReturn(flow); when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(createExternalDatabaseFailedPayload); Action<?, ?> action = configureAction(underTest::externalDatabaseCreationFailureAction); action.execute(stateContext); verify(stackUpdaterService).updateStatus(STACK_ID, DetailedStackStatus.EXTERNAL_DATABASE_CREATION_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FAILED, MESSAGE); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_FAILED, STACK); verify(flow).setFlowFailed(exceptionCaptor.capture()); assertThat(selectorArgumentCaptor.getValue()).isEqualTo("STACK_CREATION_FAILHANDLED"); Object capturedPayload = payloadArgumentCaptor.getValue(); assertThat(capturedPayload).isInstanceOf(StackEvent.class); StackEvent stackEvent = (StackEvent) capturedPayload; assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID); Exception exception = exceptionCaptor.getValue(); assertThat(exception).isEqualTo(expectedException); }
Example 16
Source File: EnvCreationActionsTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private void testCreationActionHappyPath(Supplier<Action<?, ?>> creationAction, String selector, EnvironmentStatus environmentStatus, ResourceEvent eventStarted) { Action<?, ?> action = configureAction(creationAction); Environment environment = mock(Environment.class); when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment)); Environment savedEnvironment = mock(Environment.class); when(environmentService.save(environment)).thenReturn(savedEnvironment); EnvironmentDto environmentDto = mock(EnvironmentDto.class); when(environmentDto.getResourceCrn()).thenReturn(ENVIRONMENT_CRN); when(environmentDto.getName()).thenReturn(ENVIRONMENT_NAME); when(environmentDto.getId()).thenReturn(ENVIRONMENT_ID); when(environmentService.getEnvironmentDto(savedEnvironment)).thenReturn(environmentDto); SimpleEnvironmentResponse response = mock(SimpleEnvironmentResponse.class); when(environmentResponseConverter.dtoToSimpleResponse(environmentDto)).thenReturn(response); action.execute(stateContext); verify(environment).setStatus(environmentStatus); verify(notificationService).send(eventStarted, response, FLOW_TRIGGER_USER_CRN); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verifyCreationActionSuccessEvent(selector); }
Example 17
Source File: ExternalDatabaseTerminationActionsTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test void externalDatabaseCreationFailureAction() { RuntimeException expectedException = new RuntimeException(MESSAGE); TerminateExternalDatabaseFailed terminateExternalDatabaseFailedPayload = new TerminateExternalDatabaseFailed(STACK_ID, EXTERNAL_DATABASE_CREATION_FAILED_EVENT.event(), STACK_NAME, null, expectedException); when(stackService.getByIdWithClusterInTransaction(any())).thenReturn(STACK); when(runningFlows.get(anyString())).thenReturn(flow); when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(terminateExternalDatabaseFailedPayload); Action<?, ?> action = configureAction(underTest::externalDatabaseTerminationFailureAction); action.execute(stateContext); verify(stackUpdaterService).updateStatus(STACK_ID, DetailedStackStatus.DELETE_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_FAILED, MESSAGE); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_TERMINATION_FAILED, STACK); verify(flow).setFlowFailed(exceptionCaptor.capture()); assertThat(selectorArgumentCaptor.getValue()).isEqualTo("TERMINATIONFAILHANDLED"); Object capturedPayload = payloadArgumentCaptor.getValue(); assertThat(capturedPayload).isInstanceOf(StackEvent.class); StackEvent stackEvent = (StackEvent) capturedPayload; assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID); Exception exception = exceptionCaptor.getValue(); assertThat(exception).isEqualTo(expectedException); }