Skip to content

Commit

Permalink
junit5: fix WorkflowDefinitionUpdateTest
Browse files Browse the repository at this point in the history
When running WorkflowDefinitionUpdateTest API returned
unexpected workflow definitions.

Spring component scan picked up a workflow that
test was expecting not to be present. For some reason this didn't
happen with H2 profile.

Modify the test to use a new workflow which is not used
by any other test and that is not component scanned.
  • Loading branch information
jsyrjala committed Mar 7, 2019
1 parent d7769ee commit 076c5aa
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.nflow.tests.demo.workflow;

import io.nflow.engine.workflow.definition.*;
import org.springframework.stereotype.Component;

import static io.nflow.engine.workflow.definition.NextAction.moveToState;
import static io.nflow.engine.workflow.definition.NextAction.stopInState;
import static io.nflow.engine.workflow.definition.WorkflowStateType.*;

public class Demo2Workflow extends WorkflowDefinition<Demo2Workflow.State> {

public static final String DEMO2_WORKFLOW_TYPE = "demo2";

public static enum State implements WorkflowState {
begin(start), process(normal), done(end), error(manual);

private WorkflowStateType type;

private State(WorkflowStateType type) {
this.type = type;
}

@Override
public WorkflowStateType getType() {
return type;
}

@Override
public String getDescription() {
return name();
}
}

public Demo2Workflow() {
super(DEMO2_WORKFLOW_TYPE, State.begin, State.error);
setDescription("Simple demo workflow: start -> process -> end");
permit(State.begin, State.process);
permit(State.process, State.done);
}

public NextAction begin(@SuppressWarnings("unused") StateExecution execution) {
return moveToState(State.process, "Go to process state");
}

public NextAction process(@SuppressWarnings("unused") StateExecution execution) {
return stopInState(State.done, "Go to done state");
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
package io.nflow.tests;

import static io.nflow.tests.demo.workflow.Demo2Workflow.DEMO2_WORKFLOW_TYPE;
import static io.nflow.tests.demo.workflow.DemoWorkflow.DEMO_WORKFLOW_TYPE;
import static io.nflow.tests.demo.workflow.StateWorkflow.STATE_WORKFLOW_TYPE;
import static org.junit.jupiter.api.Assertions.fail;

import io.nflow.tests.demo.workflow.Demo2Workflow;
import io.nflow.tests.extension.NflowServerConfig;
import io.nflow.tests.extension.NflowServerExtension;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;

import io.nflow.rest.v1.msg.ListWorkflowDefinitionResponse;
import io.nflow.tests.demo.workflow.DemoWorkflow;
import io.nflow.tests.demo.workflow.StateWorkflow;

import java.util.Arrays;
import java.util.stream.Collectors;

@ExtendWith(NflowServerExtension.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class WorkflowDefinitionUpdateTest extends AbstractNflowTest {

public static NflowServerConfig server = new NflowServerConfig.Builder().springContextClass(FirstConfiguration.class)
.prop("nflow.db.h2.url", "jdbc:h2:mem:workflowdefinitionupdatetest;TRACE_LEVEL_FILE=4;DB_CLOSE_DELAY=-1").build();
private static Logger logger = LoggerFactory.getLogger(WorkflowDefinitionUpdateTest.class);
public static NflowServerConfig server = new NflowServerConfig.Builder()
.springContextClass(FirstConfiguration.class)
.prop("nflow.db.h2.url", "jdbc:h2:mem:workflowdefinitionupdatetest;TRACE_LEVEL_FILE=4;DB_CLOSE_DELAY=-1")
.build();

public WorkflowDefinitionUpdateTest() {
super(server);
Expand All @@ -37,8 +44,8 @@ public DemoWorkflow demoWorkflow() {

static class SecondConfiguration {
@Bean
public StateWorkflow stateWorkflow() {
return new StateWorkflow();
public Demo2Workflow demo2Workflow() {
return new Demo2Workflow();
}
}

Expand All @@ -47,7 +54,7 @@ public StateWorkflow stateWorkflow() {
public void demoWorkflowDefinitionIsReturned() {
ListWorkflowDefinitionResponse[] definitions = getWorkflowDefinitions();
assertWorkflowDefinitionExists(DEMO_WORKFLOW_TYPE, definitions, true);
assertWorkflowDefinitionExists(STATE_WORKFLOW_TYPE, definitions, false);
assertWorkflowDefinitionExists(DEMO2_WORKFLOW_TYPE, definitions, false);
}

@Test
Expand All @@ -72,7 +79,7 @@ public void restartServerWithDifferentConfiguration() throws Exception {
public void bothDefinitionsAreReturned() {
ListWorkflowDefinitionResponse[] definitions = getWorkflowDefinitions();
assertWorkflowDefinitionExists(DEMO_WORKFLOW_TYPE, definitions, true);
assertWorkflowDefinitionExists(STATE_WORKFLOW_TYPE, definitions, true);
assertWorkflowDefinitionExists(DEMO2_WORKFLOW_TYPE, definitions, true);
}

private void assertWorkflowDefinitionExists(String type, ListWorkflowDefinitionResponse[] definitions, boolean shouldExist) {
Expand Down

0 comments on commit 076c5aa

Please sign in to comment.