22
22
23
23
import com .fasterxml .jackson .databind .JsonNode ;
24
24
import com .fasterxml .jackson .databind .node .ArrayNode ;
25
- import com .fasterxml .jackson .databind .node .ObjectNode ;
26
25
import io .serverlessworkflow .impl .json .JsonUtils ;
27
26
import java .io .IOException ;
28
27
import java .time .Instant ;
@@ -59,29 +58,25 @@ private static Stream<Arguments> provideParameters() {
59
58
args (
60
59
"switch-then-string.yaml" ,
61
60
Map .of ("orderType" , "electronic" ),
62
- o ->
63
- assertThat (o .output ().join ())
64
- .isEqualTo (Map .of ("validate" , true , "status" , "fulfilled" ))),
61
+ o -> assertThat (o ).isEqualTo (Map .of ("validate" , true , "status" , "fulfilled" ))),
65
62
args (
66
63
"switch-then-string.yaml" ,
67
64
Map .of ("orderType" , "physical" ),
68
65
o ->
69
- assertThat (o . output (). join () )
66
+ assertThat (o )
70
67
.isEqualTo (Map .of ("inventory" , "clear" , "items" , 1 , "address" , "Elmer St" ))),
71
68
args (
72
69
"switch-then-string.yaml" ,
73
70
Map .of ("orderType" , "unknown" ),
74
- o ->
75
- assertThat (o .output ().join ())
76
- .isEqualTo (Map .of ("log" , "warn" , "message" , "something's wrong" ))),
71
+ o -> assertThat (o ).isEqualTo (Map .of ("log" , "warn" , "message" , "something's wrong" ))),
77
72
args (
78
73
"for-sum.yaml" ,
79
74
Map .of ("input" , Arrays .asList (1 , 2 , 3 )),
80
- o -> assertThat (o . output (). join () ).isEqualTo (6 )),
75
+ o -> assertThat (o ).isEqualTo (6 )),
81
76
args (
82
77
"for-collect.yaml" ,
83
78
Map .of ("input" , Arrays .asList (1 , 2 , 3 )),
84
- o -> assertThat (o . output (). join () ).isEqualTo (Map .of ("output" , Arrays .asList (2 , 4 , 6 )))),
79
+ o -> assertThat (o ).isEqualTo (Map .of ("output" , Arrays .asList (2 , 4 , 6 )))),
85
80
args (
86
81
"simple-expression.yaml" ,
87
82
Map .of ("input" , Arrays .asList (1 , 2 , 3 )),
@@ -97,16 +92,25 @@ private static Stream<Arguments> provideParameters() {
97
92
args (
98
93
"fork.yaml" ,
99
94
Map .of (),
100
- o ->
101
- assertThat (((ObjectNode ) o .outputAsJsonNode ().join ()).get ("patientId" ).asText ())
102
- .isIn ("John" , "Smith" )),
103
- args ("fork-no-compete.yaml" , Map .of (), WorkflowDefinitionTest ::checkNotCompeteOuput ));
95
+ o -> assertThat (((Map <String , Object >) o ).get ("patientId" )).isIn ("John" , "Smith" )),
96
+ argsJson ("fork-no-compete.yaml" , Map .of (), WorkflowDefinitionTest ::checkNotCompeteOuput ));
104
97
}
105
98
106
99
private static Arguments args (
107
- String fileName , Map <String , Object > input , Consumer <WorkflowInstance > instance ) {
100
+ String fileName , Map <String , Object > input , Consumer <Object > instance ) {
101
+ return Arguments .of (
102
+ fileName ,
103
+ (Consumer <WorkflowDefinition >)
104
+ d ->
105
+ instance .accept (
106
+ d .instance (input ).start ().thenApply (JsonUtils ::toJavaValue ).join ()));
107
+ }
108
+
109
+ private static Arguments argsJson (
110
+ String fileName , Map <String , Object > input , Consumer <JsonNode > instance ) {
108
111
return Arguments .of (
109
- fileName , (Consumer <WorkflowDefinition >) d -> instance .accept (d .execute (input )));
112
+ fileName ,
113
+ (Consumer <WorkflowDefinition >) d -> instance .accept (d .instance (input ).start ().join ()));
110
114
}
111
115
112
116
private static <T extends Throwable > Arguments args (
@@ -117,8 +121,7 @@ private static <T extends Throwable> Arguments args(
117
121
d ->
118
122
checkWorkflowException (
119
123
catchThrowableOfType (
120
- CompletionException .class ,
121
- () -> d .execute (Map .of ()).outputAsJsonNode ().join ()),
124
+ CompletionException .class , () -> d .instance (Map .of ()).start ().join ()),
122
125
consumer ,
123
126
clazz ));
124
127
}
@@ -129,8 +132,7 @@ private static <T extends Throwable> void checkWorkflowException(
129
132
consumer .accept (clazz .cast (ex .getCause ()));
130
133
}
131
134
132
- private static void checkNotCompeteOuput (WorkflowInstance instance ) {
133
- JsonNode out = instance .outputAsJsonNode ().join ();
135
+ private static void checkNotCompeteOuput (JsonNode out ) {
134
136
assertThat (out ).isInstanceOf (ArrayNode .class );
135
137
assertThat (out ).hasSize (2 );
136
138
ArrayNode array = (ArrayNode ) out ;
@@ -156,8 +158,8 @@ private static void checkWorkflowException(WorkflowException ex) {
156
158
assertThat (ex .getWorflowError ().instance ()).isEqualTo ("do/0/notImplemented" );
157
159
}
158
160
159
- private static void checkSpecialKeywords (WorkflowInstance obj ) {
160
- Map <String , Object > result = (Map <String , Object >) obj . output (). join () ;
161
+ private static void checkSpecialKeywords (Object obj ) {
162
+ Map <String , Object > result = (Map <String , Object >) obj ;
161
163
assertThat (Instant .ofEpochMilli ((long ) result .get ("startedAt" )))
162
164
.isAfterOrEqualTo (before )
163
165
.isBeforeOrEqualTo (Instant .now ());
0 commit comments