AbstractWorkflowDefinition extends ModelObject { public boolean isAllowedNextAction(WorkflowInstance instance, NextAction nextAction) { if (nextAction.isRetry()) { return true; } List<String> allowedNextStates = allowedTransitions.get(instance.state); if (allowedNextStates != null && allowedNextStates.contains(nextAction.getNextState().name())) { return true; } if (nextAction.getNextState() == failureTransitions.get(instance.state)) { return true; } return nextAction.getNextState() == getErrorState(); } protected  AbstractWorkflowDefinition(String type, S initialState, S errorState); protected  AbstractWorkflowDefinition(String type, S initialState, S errorState, WorkflowSettings settings); protected  AbstractWorkflowDefinition(String type, S initialState, S errorState, WorkflowSettings settings,
      Map<String, WorkflowStateMethod> stateMethods); String getName(); void setName(String name); String getDescription(); void setDescription(String description); String getType(); S getInitialState(); S getErrorState(); abstract Set<S> getStates(); Map<String, List<String>> getAllowedTransitions(); Map<String, WorkflowState> getFailureTransitions(); WorkflowSettings getSettings(); WorkflowStateMethod getMethod(String stateName); WorkflowState getState(String state); boolean isStartState(String state); boolean isAllowedNextAction(WorkflowInstance instance, NextAction nextAction); Map<Integer, String> getSupportedSignals();  }
@Test public void isAllowedNextActionReturnsFalseForIllegalStateChange() { WorkflowInstance instance = new WorkflowInstance.Builder().setState("begin").build(); NextAction nextAction = moveToState(TestWorkflow.State.process, "reason"); assertThat(workflow.isAllowedNextAction(instance, nextAction), is(false)); }
@Test public void isAllowedNextActionReturnsTrueForMovingToFailureState() { WorkflowInstance instance = new WorkflowInstance.Builder().setState("begin").build(); NextAction nextAction = moveToState(TestWorkflow.State.failed, "reason"); assertThat(workflow.isAllowedNextAction(instance, nextAction), is(true)); }
@Test public void isAllowedNextActionReturnsTrueForMovingToErrorState() { WorkflowInstance instance = new WorkflowInstance.Builder().setState("process").build(); NextAction nextAction = moveToState(TestWorkflow.State.error, "reason"); assertThat(workflow.isAllowedNextAction(instance, nextAction), is(true)); }
@Test public void isAllowedNextActionReturnsTrueForRetry() { WorkflowInstance instance = new WorkflowInstance.Builder().setState("begin").build(); NextAction nextAction = retryAfter(now().plusMinutes(1), "reason"); assertThat(workflow.isAllowedNextAction(instance, nextAction), is(true)); }
@Test public void isAllowedNextActionReturnsTrueForPermittedStateChange() { WorkflowInstance instance = new WorkflowInstance.Builder().setState("begin").build(); NextAction nextAction = moveToState(TestWorkflow.State.done, "reason"); assertThat(workflow.isAllowedNextAction(instance, nextAction), is(true)); }