Skip to content

Commit

Permalink
use common test states
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Fonsell committed Feb 11, 2021
1 parent 2ad9d0e commit ef6af47
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.nflow.engine.service.WorkflowInstanceService;
import io.nflow.engine.workflow.definition.StateExecution;
import io.nflow.engine.workflow.definition.TestDefinition;
import io.nflow.engine.workflow.definition.TestState;
import io.nflow.engine.workflow.definition.TestWorkflow;
import io.nflow.engine.workflow.definition.WorkflowState;
import io.nflow.engine.workflow.instance.QueryWorkflowInstances;
Expand Down Expand Up @@ -289,7 +290,7 @@ public void exceedingMaxRetriesInNonFailureStateGoesToFailureState() {
@Test
public void exceedingMaxRetriesInNonFailureStateGoesToErrorStateWhenNoFailureStateIsDefined() {
handleRetryMaxRetriesExceeded(TestDefinition.START_1, TestDefinition.START_2);
assertThat(execution.getNextState(), is(equalTo(TestWorkflow.ERROR.name())));
assertThat(execution.getNextState(), is(equalTo(TestState.ERROR.name())));
assertThat(execution.getNextActivation(), is(notNullValue()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ public void onlyOneFailureStateCanBeDefined() {

static class TestWorkflow2 extends TestWorkflow {
public void permitDifferentFailure() {
permit(TestWorkflow.PROCESS, TestWorkflow.DONE);
permit(TestWorkflow.PROCESS, TestWorkflow.DONE, TestWorkflow.FAILED);
permit(TestWorkflow.PROCESS, TestWorkflow.ERROR, TestWorkflow.ERROR);
permit(TestState.PROCESS, TestState.DONE);
permit(TestState.PROCESS, TestState.DONE, TestWorkflow.FAILED);
permit(TestState.PROCESS, TestState.ERROR, TestState.ERROR);
}

public void permitSameFailure() {
permit(TestWorkflow.PROCESS, TestWorkflow.DONE);
permit(TestWorkflow.PROCESS, TestWorkflow.DONE, TestWorkflow.FAILED);
permit(TestWorkflow.PROCESS, TestWorkflow.ERROR, TestWorkflow.FAILED);
permit(TestState.PROCESS, TestState.DONE);
permit(TestState.PROCESS, TestState.DONE, TestWorkflow.FAILED);
permit(TestState.PROCESS, TestState.ERROR, TestWorkflow.FAILED);
}
}

static class TestWorkflow3 extends TestWorkflow {
public NextAction done(@SuppressWarnings("unused") StateExecution execution) {
return stopInState(TestWorkflow.DONE, "Done");
return stopInState(TestState.DONE, "Done");
}
}

static class TestWorkflow4 extends AbstractWorkflowDefinition {

protected TestWorkflow4() {
super("test", TestWorkflow.BEGIN, TestWorkflow.ERROR);
super("test", TestState.BEGIN, TestState.ERROR);
}

public void begin(@SuppressWarnings("unused") StateExecution execution) {
Expand All @@ -79,7 +79,7 @@ public void begin(@SuppressWarnings("unused") StateExecution execution) {
@Test
public void isAllowedNextActionReturnsFalseForIllegalStateChange() {
WorkflowInstance instance = new WorkflowInstance.Builder().setState("begin").build();
NextAction nextAction = moveToState(TestWorkflow.PROCESS, "reason");
NextAction nextAction = moveToState(TestState.PROCESS, "reason");
assertThat(workflow.isAllowedNextAction(instance, nextAction), is(false));
}

Expand All @@ -93,7 +93,7 @@ public void isAllowedNextActionReturnsTrueForMovingToFailureState() {
@Test
public void isAllowedNextActionReturnsTrueForMovingToErrorState() {
WorkflowInstance instance = new WorkflowInstance.Builder().setState("process").build();
NextAction nextAction = moveToState(TestWorkflow.ERROR, "reason");
NextAction nextAction = moveToState(TestState.ERROR, "reason");
assertThat(workflow.isAllowedNextAction(instance, nextAction), is(true));
}

Expand All @@ -107,7 +107,7 @@ public void isAllowedNextActionReturnsTrueForRetry() {
@Test
public void isAllowedNextActionReturnsTrueForPermittedStateChange() {
WorkflowInstance instance = new WorkflowInstance.Builder().setState("begin").build();
NextAction nextAction = moveToState(TestWorkflow.DONE, "reason");
NextAction nextAction = moveToState(TestState.DONE, "reason");
assertThat(workflow.isAllowedNextAction(instance, nextAction), is(true));
}

Expand All @@ -132,7 +132,7 @@ public void settersAndGettersWork() {
wf.setDescription("description");
assertThat(wf.getName(), is("name"));
assertThat(wf.getDescription(), is("description"));
assertThat(wf.getInitialState(), is(TestWorkflow.BEGIN));
assertThat(wf.getInitialState(), is(TestState.BEGIN));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package io.nflow.engine.workflow.definition;

import static io.nflow.engine.workflow.definition.NextAction.stopInState;
import static io.nflow.engine.workflow.definition.TestState.BEGIN;
import static io.nflow.engine.workflow.definition.TestState.DONE;
import static io.nflow.engine.workflow.definition.TestState.ERROR;

import io.nflow.engine.workflow.curated.SimpleState;

public class TestWorkflow extends AbstractWorkflowDefinition {

public static final WorkflowState BEGIN = new SimpleState("begin", WorkflowStateType.start);
public static final WorkflowState START_WITHOUT_FAILURE = new SimpleState("startWithoutFailure", WorkflowStateType.start);
public static final WorkflowState PROCESS = new SimpleState("process");
public static final WorkflowState DONE = new SimpleState("done", WorkflowStateType.end);
public static final WorkflowState FAILED = new SimpleState("failed", WorkflowStateType.end);
public static final WorkflowState ERROR = new SimpleState("error", WorkflowStateType.manual);

public TestWorkflow() {
super("test", BEGIN, ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ public void errorTransitionDelayIsBetweenMinAndMaxDelay() {
@Test
public void getMaxSubsequentStateExecutionsReturns100ByDefault() {
WorkflowSettings s = new WorkflowSettings.Builder().build();
assertThat(s.getMaxSubsequentStateExecutions(TestWorkflow.BEGIN), is(equalTo(100)));
assertThat(s.getMaxSubsequentStateExecutions(TestState.BEGIN), is(equalTo(100)));
}

@Test
public void getMaxSubsequentStateExecutionsReturnsValueDefinedForTheState() {
int executionsDefault = 200;
int executionsForBegin = 300;
WorkflowSettings s = new WorkflowSettings.Builder().setMaxSubsequentStateExecutions(executionsDefault)
.setMaxSubsequentStateExecutions(TestWorkflow.BEGIN, executionsForBegin).build();
assertThat(s.getMaxSubsequentStateExecutions(TestWorkflow.BEGIN), is(equalTo(executionsForBegin)));
.setMaxSubsequentStateExecutions(TestState.BEGIN, executionsForBegin).build();
assertThat(s.getMaxSubsequentStateExecutions(TestState.BEGIN), is(equalTo(executionsForBegin)));
}

@Test
public void getMaxSubsequentStateExecutionsReturnsGivenDefaultValueWhenNotDefinedForState() {
int executionsDefault = 200;
WorkflowSettings s = new WorkflowSettings.Builder().setMaxSubsequentStateExecutions(executionsDefault).build();
assertThat(s.getMaxSubsequentStateExecutions(TestWorkflow.BEGIN), is(equalTo(executionsDefault)));
assertThat(s.getMaxSubsequentStateExecutions(TestState.BEGIN), is(equalTo(executionsDefault)));
}

@Test
Expand Down

0 comments on commit ef6af47

Please sign in to comment.