-
Notifications
You must be signed in to change notification settings - Fork 50
Add then to the Java DSL #1190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+236
−1
Merged
Add then to the Java DSL #1190
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
impl/test/src/test/java/io/serverlessworkflow/impl/test/WorkflowThenTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.impl.test; | ||
|
|
||
| import static io.serverlessworkflow.fluent.func.dsl.FuncDSL.consume; | ||
| import static io.serverlessworkflow.fluent.func.dsl.FuncDSL.function; | ||
|
|
||
| import io.serverlessworkflow.api.types.FlowDirectiveEnum; | ||
| import io.serverlessworkflow.api.types.Workflow; | ||
| import io.serverlessworkflow.fluent.func.FuncWorkflowBuilder; | ||
| import io.serverlessworkflow.impl.WorkflowApplication; | ||
| import io.serverlessworkflow.impl.WorkflowDefinition; | ||
| import io.serverlessworkflow.impl.WorkflowModel; | ||
| import java.util.Arrays; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class WorkflowThenTest { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(WorkflowThenTest.class); | ||
|
|
||
| @Test | ||
| void consume_then_skips_next_task_and_jumps_to_target() { | ||
|
|
||
| Workflow wf = | ||
| FuncWorkflowBuilder.workflow("intelligent-newsletter") | ||
| .tasks( | ||
| consume("sendNewsletter", input -> log.debug("Consuming: {}", input), Object.class) | ||
| .then("otherTask"), | ||
| function("nextTask", v -> "nextTask: " + v, String.class), | ||
| function("otherTask", v -> "otherTask: " + v, String.class)) | ||
| .build(); | ||
|
|
||
| try (WorkflowApplication app = WorkflowApplication.builder().build()) { | ||
| WorkflowDefinition def = app.workflowDefinition(wf); | ||
| WorkflowModel model = def.instance("hello newsletter").start().join(); | ||
|
|
||
| String output = model.asText().orElseThrow(); | ||
| Assertions.assertEquals("otherTask: hello newsletter", output); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void function_then_skips_next_task_and_jumps_to_target() { | ||
|
|
||
| Workflow wf = | ||
| FuncWorkflowBuilder.workflow("intelligent-newsletter") | ||
| .tasks( | ||
| function("arrayFromString", input -> input.split(","), String.class) | ||
| .then("otherTask"), | ||
| function("nextTask", arr -> "nextTask: " + Arrays.toString(arr), String[].class), | ||
| function("otherTask", arr -> "otherTask: " + Arrays.toString(arr), String[].class)) | ||
| .build(); | ||
|
|
||
| try (WorkflowApplication app = WorkflowApplication.builder().build()) { | ||
| WorkflowDefinition def = app.workflowDefinition(wf); | ||
| String output = def.instance("hello,from,cncf").start().join().asText().orElseThrow(); | ||
|
|
||
| Assertions.assertEquals("otherTask: [hello, from, cncf]", output); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void function_then_end_directive_stops_workflow_execution() { | ||
|
|
||
| Workflow wf = | ||
| FuncWorkflowBuilder.workflow("intelligent-newsletter") | ||
| .tasks( | ||
| function("uppercase", String::toUpperCase, String.class) | ||
| .then(FlowDirectiveEnum.END), | ||
| function("lowercase", String::toLowerCase, String.class)) | ||
| .build(); | ||
|
|
||
| try (WorkflowApplication app = WorkflowApplication.builder().build()) { | ||
| WorkflowDefinition def = app.workflowDefinition(wf); | ||
| String output = | ||
| def.instance("Hello Alice, Hello Bob, Hello Everyone!") | ||
| .start() | ||
| .join() | ||
| .asText() | ||
| .orElseThrow(); | ||
|
|
||
| Assertions.assertEquals("HELLO ALICE, HELLO BOB, HELLO EVERYONE!", output); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.