From f39b2854f5fabf8df9b118eede7969128ad267fd Mon Sep 17 00:00:00 2001 From: mwfpope Date: Fri, 14 Sep 2018 22:51:11 -0700 Subject: [PATCH] Fix a bug in WorkflowTest.java The WorkflowTest rule does not use the DataConverter that is specified in the Workflow annotation. Instead, it always uses the JsonDataConverter. This means that if you try to use your own DataConverter with the WorkflowTest rule, your tests will fail if the JsonDataConverter can't deserialize something that your custom DataConverter serialized. This change creates an overloaded constructor that will allow developers to construct the WorkflowTest rule with their custom DataConverter implementation. --- .../simpleworkflow/flow/junit/WorkflowTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/amazonaws/services/simpleworkflow/flow/junit/WorkflowTest.java b/src/main/java/com/amazonaws/services/simpleworkflow/flow/junit/WorkflowTest.java index b515946..625a1b4 100644 --- a/src/main/java/com/amazonaws/services/simpleworkflow/flow/junit/WorkflowTest.java +++ b/src/main/java/com/amazonaws/services/simpleworkflow/flow/junit/WorkflowTest.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.Map.Entry; +import com.amazonaws.services.simpleworkflow.flow.DataConverter; import com.amazonaws.services.simpleworkflow.flow.JsonDataConverter; import com.amazonaws.services.simpleworkflow.flow.test.TestDecisionContext; import com.amazonaws.services.simpleworkflow.flow.test.TestLambdaFunctionClient; @@ -45,13 +46,20 @@ public class WorkflowTest extends WorkflowTestBase { private Map workers = new HashMap(); + private DataConverter dataConverter; + public WorkflowTest() { + this(new JsonDataConverter); + } + + public WorkflowTest(DataConverter dataConverter) { super(new TestDecisionContext(new TestPOJOActivityImplementationGenericActivityClient(), new TestPOJOWorkflowImplementationGenericWorkflowClient(), new TestWorkflowClock(), new TestWorkflowContext(), new TestLambdaFunctionClient())); activityClient = (TestPOJOActivityImplementationGenericActivityClient) decisionContext.getActivityClient(); workflowClient = (TestPOJOWorkflowImplementationGenericWorkflowClient) decisionContext.getWorkflowClient(); lambdaFunctionClient = (TestLambdaFunctionClient) decisionContext.getLambdaFunctionClient(); + this.dataConverter = dataConverter; } public void addActivitiesImplementation(Object activitiesImplementation) { @@ -84,7 +92,7 @@ public void addWorkflowImplementationType(Class workflowImplementationType) { public void addWorkflowImplementationType(Class workflowImplementationType, Object[] constructorArgs) { try { - workflowClient.addWorkflowImplementationType(workflowImplementationType, new JsonDataConverter(), constructorArgs, null); + workflowClient.addWorkflowImplementationType(workflowImplementationType, dataConverter, constructorArgs, null); } catch (Exception e) { throw new IllegalArgumentException("Invalid workflow type: " + workflowImplementationType, e);