diff --git a/impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunWorkflowExecutorBuilder.java b/impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunWorkflowExecutorBuilder.java index 71208c43c..e716f1e4b 100644 --- a/impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunWorkflowExecutorBuilder.java +++ b/impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunWorkflowExecutorBuilder.java @@ -18,19 +18,22 @@ import io.serverlessworkflow.api.types.RunTaskConfiguration; import io.serverlessworkflow.api.types.RunWorkflow; import io.serverlessworkflow.api.types.SubflowConfiguration; +import io.serverlessworkflow.api.types.SubflowInput; import io.serverlessworkflow.impl.WorkflowDefinition; import io.serverlessworkflow.impl.WorkflowDefinitionId; import io.serverlessworkflow.impl.WorkflowUtils; +import java.util.Map; public class RunWorkflowExecutorBuilder implements RunnableTaskBuilder { public CallableTask build(RunWorkflow taskConfiguration, WorkflowDefinition definition) { SubflowConfiguration workflowConfig = taskConfiguration.getWorkflow(); + SubflowInput input = workflowConfig.getInput(); return new RunWorkflowExecutor( new WorkflowDefinitionId( workflowConfig.getNamespace(), workflowConfig.getName(), workflowConfig.getVersion()), WorkflowUtils.buildMapResolver( - definition.application(), workflowConfig.getInput().getAdditionalProperties())); + definition.application(), input != null ? input.getAdditionalProperties() : Map.of())); } @Override diff --git a/impl/test/src/test/java/io/serverlessworkflow/impl/test/SubWorkflowTest.java b/impl/test/src/test/java/io/serverlessworkflow/impl/test/SubWorkflowTest.java index dd783335c..3a14ceccf 100644 --- a/impl/test/src/test/java/io/serverlessworkflow/impl/test/SubWorkflowTest.java +++ b/impl/test/src/test/java/io/serverlessworkflow/impl/test/SubWorkflowTest.java @@ -25,7 +25,7 @@ import io.serverlessworkflow.fluent.spec.dsl.DSL; import io.serverlessworkflow.impl.WorkflowApplication; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SubWorkflowTest { @@ -114,7 +114,7 @@ public void readContextAndSetTest() throws Exception { assertThat(updated.get("password"), is(equalTo("test_tested"))); assertThat( result.get("detail"), - is(equalTo("The workflow set-into-context:1.0.0 updated user in context"))); + is(equalTo("The workflow read-set-into-context:1.0.0 updated user in context"))); } } @@ -147,10 +147,7 @@ public void runSubWorkflowFromDslTest() throws Exception { Workflow parent = WorkflowBuilder.workflow("parentFlow", "org.acme", "1.0.0") - .tasks( - DSL.subflow( - DSL.workflow("org.acme", "childFlow", "1.0.0") - .input(Map.of("id", 42, "region", "us-east")))) + .tasks(DSL.subflow(DSL.workflow("org.acme", "childFlow", "1.0.0"))) .build(); try (WorkflowApplication app = WorkflowApplication.builder().build()) { @@ -161,4 +158,32 @@ public void runSubWorkflowFromDslTest() throws Exception { assertThat(result.get("greeting"), is(equalTo("helloWorld"))); } } + + @Test + public void runSubWorkflowsFromDslTest() throws Exception { + Workflow child = + WorkflowBuilder.workflow("childFlow", "org.acme", "1.0.0") + .tasks(d -> d.set("update", s -> s.put("counter", 1).put("greeting", "helloWorld"))) + .build(); + + Workflow update = + WorkflowBuilder.workflow("updateFlow", "org.acme", "1.0.0") + .tasks(d -> d.set("update", s -> s.expr("$input+{counter:.counter+1}"))) + .build(); + + Workflow parent = + WorkflowBuilder.workflow("parentFlow", "org.acme", "1.0.0") + .tasks(DSL.subflow(DSL.workflow("org.acme", "childFlow", "1.0.0"))) + .tasks(DSL.subflow(DSL.workflow("org.acme", "updateFlow", "1.0.0"))) + .build(); + + try (WorkflowApplication app = WorkflowApplication.builder().build()) { + app.workflowDefinition(child); + app.workflowDefinition(update); + Map result = + app.workflowDefinition(parent).instance(Map.of()).start().join().asMap().orElseThrow(); + assertThat(result.get("counter"), is(equalTo(2))); + assertThat(result.get("greeting"), is(equalTo("helloWorld"))); + } + } } diff --git a/impl/test/src/test/resources/workflows-samples/sub-workflow/output-export-and-set-sub-workflow-child.yaml b/impl/test/src/test/resources/workflows-samples/sub-workflow/output-export-and-set-sub-workflow-child.yaml index 4ca614c1a..ac905ca93 100644 --- a/impl/test/src/test/resources/workflows-samples/sub-workflow/output-export-and-set-sub-workflow-child.yaml +++ b/impl/test/src/test/resources/workflows-samples/sub-workflow/output-export-and-set-sub-workflow-child.yaml @@ -1,6 +1,6 @@ document: dsl: '1.0.0' - namespace: default + namespace: test name: set-into-context version: '1.0.0' diff --git a/impl/test/src/test/resources/workflows-samples/sub-workflow/output-export-and-set-sub-workflow-parent.yaml b/impl/test/src/test/resources/workflows-samples/sub-workflow/output-export-and-set-sub-workflow-parent.yaml index 025163f69..6398634e4 100644 --- a/impl/test/src/test/resources/workflows-samples/sub-workflow/output-export-and-set-sub-workflow-parent.yaml +++ b/impl/test/src/test/resources/workflows-samples/sub-workflow/output-export-and-set-sub-workflow-parent.yaml @@ -1,15 +1,13 @@ document: dsl: '1.0.0' - namespace: default - name: parent + namespace: test + name: set-context-parent version: '1.0.0' do: - sayHello: run: workflow: - namespace: default + namespace: test name: set-into-context - version: '1.0.0' - input: - foo: bar \ No newline at end of file + version: '1.0.0' \ No newline at end of file diff --git a/impl/test/src/test/resources/workflows-samples/sub-workflow/read-context-and-set-sub-workflow-child.yaml b/impl/test/src/test/resources/workflows-samples/sub-workflow/read-context-and-set-sub-workflow-child.yaml index 962f3dc24..c7c04b589 100644 --- a/impl/test/src/test/resources/workflows-samples/sub-workflow/read-context-and-set-sub-workflow-child.yaml +++ b/impl/test/src/test/resources/workflows-samples/sub-workflow/read-context-and-set-sub-workflow-child.yaml @@ -1,7 +1,7 @@ document: dsl: '1.0.0' - namespace: default - name: set-into-context + namespace: test + name: read-set-into-context version: '1.0.0' do: diff --git a/impl/test/src/test/resources/workflows-samples/sub-workflow/read-context-and-set-sub-workflow-parent.yaml b/impl/test/src/test/resources/workflows-samples/sub-workflow/read-context-and-set-sub-workflow-parent.yaml index 025163f69..56487a177 100644 --- a/impl/test/src/test/resources/workflows-samples/sub-workflow/read-context-and-set-sub-workflow-parent.yaml +++ b/impl/test/src/test/resources/workflows-samples/sub-workflow/read-context-and-set-sub-workflow-parent.yaml @@ -1,6 +1,6 @@ document: dsl: '1.0.0' - namespace: default + namespace: test name: parent version: '1.0.0' @@ -8,8 +8,6 @@ do: - sayHello: run: workflow: - namespace: default - name: set-into-context - version: '1.0.0' - input: - foo: bar \ No newline at end of file + namespace: test + name: read-set-into-context + version: '1.0.0' \ No newline at end of file diff --git a/impl/test/src/test/resources/workflows-samples/sub-workflow/sub-workflow-child.yaml b/impl/test/src/test/resources/workflows-samples/sub-workflow/sub-workflow-child.yaml index 7400150a2..3719122d2 100644 --- a/impl/test/src/test/resources/workflows-samples/sub-workflow/sub-workflow-child.yaml +++ b/impl/test/src/test/resources/workflows-samples/sub-workflow/sub-workflow-child.yaml @@ -1,7 +1,7 @@ document: dsl: '1.0.0' - namespace: default - name: set-into-context + namespace: test + name: hello-world-child version: '1.0.0' do: diff --git a/impl/test/src/test/resources/workflows-samples/sub-workflow/sub-workflow-parent.yaml b/impl/test/src/test/resources/workflows-samples/sub-workflow/sub-workflow-parent.yaml index 025163f69..d44938815 100644 --- a/impl/test/src/test/resources/workflows-samples/sub-workflow/sub-workflow-parent.yaml +++ b/impl/test/src/test/resources/workflows-samples/sub-workflow/sub-workflow-parent.yaml @@ -1,15 +1,13 @@ document: dsl: '1.0.0' - namespace: default - name: parent + namespace: test + name: hello-world-parent version: '1.0.0' do: - sayHello: run: workflow: - namespace: default - name: set-into-context + namespace: test + name: hello-world-child version: '1.0.0' - input: - foo: bar \ No newline at end of file