Skip to content

Commit 412f1a1

Browse files
committed
refactor SubWorkflowTest
1 parent de80b45 commit 412f1a1

1 file changed

Lines changed: 32 additions & 42 deletions

File tree

impl/test/src/test/java/io/serverlessworkflow/impl/test/SubWorkflowTest.java

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
package io.serverlessworkflow.impl.test;
1717

1818
import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
19-
import static org.junit.Assert.assertEquals;
19+
import static org.hamcrest.MatcherAssert.assertThat;
20+
import static org.hamcrest.Matchers.equalTo;
21+
import static org.hamcrest.Matchers.is;
2022

2123
import io.serverlessworkflow.api.types.Workflow;
2224
import io.serverlessworkflow.fluent.spec.WorkflowBuilder;
2325
import io.serverlessworkflow.fluent.spec.dsl.DSL;
2426
import io.serverlessworkflow.impl.WorkflowApplication;
25-
import java.io.IOException;
2627
import java.util.Map;
2728
import org.junit.Test;
2829

@@ -31,7 +32,7 @@ public class SubWorkflowTest {
3132
private static final String WORKFLOW_TEST_PATH = "workflows-samples/sub-workflow/";
3233

3334
@Test
34-
public void setTest() throws IOException {
35+
public void setTest() throws Exception {
3536
Workflow workflowParent =
3637
readWorkflowFromClasspath(WORKFLOW_TEST_PATH + "sub-workflow-parent.yaml");
3738
Workflow workflowChild =
@@ -43,18 +44,16 @@ public void setTest() throws IOException {
4344
app.workflowDefinition(workflowParent)
4445
.instance(Map.of())
4546
.start()
46-
.get()
47+
.join()
4748
.asMap()
4849
.orElseThrow();
49-
assertEquals("1", result.get("counter").toString());
50-
assertEquals("helloWorld", result.get("greeting").toString());
51-
} catch (Exception e) {
52-
throw new RuntimeException("Workflow execution failed", e);
50+
assertThat(result.get("counter"), equalTo(1));
51+
assertThat(result.get("greeting"), equalTo("helloWorld"));
5352
}
5453
}
5554

5655
@Test
57-
public void setBlankInputTest() throws IOException {
56+
public void setBlankInputTest() throws Exception {
5857
Workflow workflowParent =
5958
readWorkflowFromClasspath(WORKFLOW_TEST_PATH + "sub-workflow-parent.yaml");
6059
Workflow workflowChild =
@@ -66,18 +65,16 @@ public void setBlankInputTest() throws IOException {
6665
app.workflowDefinition(workflowParent)
6766
.instance(Map.of())
6867
.start()
69-
.get()
68+
.join()
7069
.asMap()
7170
.orElseThrow();
72-
assertEquals("1", result.get("counter").toString());
73-
assertEquals("helloWorld", result.get("greeting").toString());
74-
} catch (Exception e) {
75-
throw new RuntimeException("Workflow execution failed", e);
71+
assertThat(result.get("counter"), is(equalTo(1)));
72+
assertThat(result.get("greeting"), is(equalTo("helloWorld")));
7673
}
7774
}
7875

7976
@Test
80-
public void setStringInputTest() throws IOException {
77+
public void setStringInputTest() throws Exception {
8178
Workflow workflowParent =
8279
readWorkflowFromClasspath(WORKFLOW_TEST_PATH + "sub-workflow-parent.yaml");
8380
Workflow workflowChild =
@@ -89,18 +86,16 @@ public void setStringInputTest() throws IOException {
8986
app.workflowDefinition(workflowParent)
9087
.instance("Tested")
9188
.start()
92-
.get()
89+
.join()
9390
.asMap()
9491
.orElseThrow();
95-
assertEquals("1", result.get("counter").toString());
96-
assertEquals("helloWorld", result.get("greeting").toString());
97-
} catch (Exception e) {
98-
throw new RuntimeException("Workflow execution failed", e);
92+
assertThat(result.get("counter"), is(equalTo(1)));
93+
assertThat(result.get("greeting"), is(equalTo("helloWorld")));
9994
}
10095
}
10196

10297
@Test
103-
public void readContextAndSetTest() throws IOException {
98+
public void readContextAndSetTest() throws Exception {
10499
Workflow workflowParent =
105100
readWorkflowFromClasspath(
106101
WORKFLOW_TEST_PATH + "read-context-and-set-sub-workflow-parent.yaml");
@@ -112,20 +107,19 @@ public void readContextAndSetTest() throws IOException {
112107
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
113108
app.workflowDefinition(workflowChild);
114109
Map<String, Object> result =
115-
app.workflowDefinition(workflowParent).instance(map).start().get().asMap().orElseThrow();
110+
app.workflowDefinition(workflowParent).instance(map).start().join().asMap().orElseThrow();
116111
Map<String, String> updated = (Map<String, String>) result.get("updated");
117-
assertEquals("userId_1_tested", updated.get("userId"));
118-
assertEquals("test_tested", updated.get("username"));
119-
assertEquals("test_tested", updated.get("password"));
120-
assertEquals(
121-
"The workflow set-into-context:1.0.0 updated user in context", result.get("detail"));
122-
} catch (Exception e) {
123-
throw new RuntimeException("Workflow execution failed", e);
112+
assertThat(updated.get("userId"), is(equalTo("userId_1_tested")));
113+
assertThat(updated.get("username"), is(equalTo("test_tested")));
114+
assertThat(updated.get("password"), is(equalTo("test_tested")));
115+
assertThat(
116+
result.get("detail"),
117+
is(equalTo("The workflow set-into-context:1.0.0 updated user in context")));
124118
}
125119
}
126120

127121
@Test
128-
public void outputExportContextAndSetTest() throws IOException {
122+
public void outputExportContextAndSetTest() throws Exception {
129123
Workflow workflowParent =
130124
readWorkflowFromClasspath(
131125
WORKFLOW_TEST_PATH + "output-export-and-set-sub-workflow-parent.yaml");
@@ -137,17 +131,15 @@ public void outputExportContextAndSetTest() throws IOException {
137131
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
138132
app.workflowDefinition(workflowChild);
139133
Map<String, Object> result =
140-
app.workflowDefinition(workflowParent).instance(map).start().get().asMap().orElseThrow();
141-
assertEquals("userId_1_tested", result.get("userId"));
142-
assertEquals("test_tested", result.get("username"));
143-
assertEquals("test_tested", result.get("password"));
144-
} catch (Exception e) {
145-
throw new RuntimeException("Workflow execution failed", e);
134+
app.workflowDefinition(workflowParent).instance(map).start().join().asMap().orElseThrow();
135+
assertThat(result.get("userId"), is(equalTo("userId_1_tested")));
136+
assertThat(result.get("username"), is(equalTo("test_tested")));
137+
assertThat(result.get("password"), is(equalTo("test_tested")));
146138
}
147139
}
148140

149141
@Test
150-
public void runSubWorkflowFromDslTest() {
142+
public void runSubWorkflowFromDslTest() throws Exception {
151143
Workflow child =
152144
WorkflowBuilder.workflow("childFlow", "org.acme", "1.0.0")
153145
.tasks(d -> d.set("update", s -> s.put("counter", 1).put("greeting", "helloWorld")))
@@ -164,11 +156,9 @@ public void runSubWorkflowFromDslTest() {
164156
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
165157
app.workflowDefinition(child);
166158
Map<String, Object> result =
167-
app.workflowDefinition(parent).instance(Map.of()).start().get().asMap().orElseThrow();
168-
assertEquals("1", result.get("counter").toString());
169-
assertEquals("helloWorld", result.get("greeting").toString());
170-
} catch (Exception e) {
171-
throw new RuntimeException("Workflow execution failed", e);
159+
app.workflowDefinition(parent).instance(Map.of()).start().join().asMap().orElseThrow();
160+
assertThat(result.get("counter"), is(equalTo(1)));
161+
assertThat(result.get("greeting"), is(equalTo("helloWorld")));
172162
}
173163
}
174164
}

0 commit comments

Comments
 (0)