Skip to content

Commit 9204603

Browse files
committed
add test FuncDoTaskTest, testDoTaskRaiseAndTryCatch
Signed-off-by: Matheus André <matheusandr2@gmail.com>
1 parent 7689b6d commit 9204603

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.fluent.test;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import io.serverlessworkflow.fluent.func.FuncWorkflowBuilder;
21+
import io.serverlessworkflow.impl.WorkflowApplication;
22+
import io.serverlessworkflow.impl.WorkflowInstance;
23+
import io.serverlessworkflow.impl.WorkflowModel;
24+
import io.serverlessworkflow.impl.WorkflowStatus;
25+
import java.net.URI;
26+
import java.util.Map;
27+
import java.util.concurrent.CompletableFuture;
28+
import org.junit.jupiter.api.Test;
29+
30+
public class FuncDoTaskTest {
31+
32+
@Test
33+
void testDoTaskRaiseAndTryCatch() throws Exception {
34+
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
35+
36+
var workflow =
37+
FuncWorkflowBuilder.workflow("test-do-task")
38+
.tasks(
39+
doTask ->
40+
doTask.tryCatch(
41+
"try-catch-task",
42+
tryBuilder ->
43+
tryBuilder
44+
.tryHandler(
45+
tryBlock ->
46+
tryBlock.raise(
47+
"raise-error-task",
48+
raiseBlock ->
49+
raiseBlock.error(
50+
error ->
51+
error
52+
.type(
53+
URI.create(
54+
"http://example.com/error"))
55+
.status(500))))
56+
.catchHandler(
57+
catchBlock ->
58+
catchBlock
59+
.errorsWith(
60+
errs -> errs.type("http://example.com/error"))
61+
.doTasks(
62+
catchTasks ->
63+
catchTasks.set(
64+
"catchHandled",
65+
setBlock ->
66+
setBlock.expr(
67+
Map.of("handled", true)))))))
68+
.build();
69+
70+
WorkflowInstance instance = app.workflowDefinition(workflow).instance(Map.of());
71+
72+
CompletableFuture<WorkflowModel> future = instance.start();
73+
WorkflowModel result = future.join();
74+
75+
assertThat(instance.status()).isEqualTo(WorkflowStatus.COMPLETED);
76+
assertThat(result.as(Map.class).orElseThrow())
77+
.containsEntry("handled", true)
78+
.containsKey("handled");
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)