2222
2323import com .fasterxml .jackson .databind .JsonNode ;
2424import com .fasterxml .jackson .databind .node .ArrayNode ;
25- import com .fasterxml .jackson .databind .node .ObjectNode ;
2625import io .serverlessworkflow .impl .json .JsonUtils ;
2726import java .io .IOException ;
2827import java .time .Instant ;
@@ -59,29 +58,25 @@ private static Stream<Arguments> provideParameters() {
5958 args (
6059 "switch-then-string.yaml" ,
6160 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" ))),
6562 args (
6663 "switch-then-string.yaml" ,
6764 Map .of ("orderType" , "physical" ),
6865 o ->
69- assertThat (o . output (). join () )
66+ assertThat (o )
7067 .isEqualTo (Map .of ("inventory" , "clear" , "items" , 1 , "address" , "Elmer St" ))),
7168 args (
7269 "switch-then-string.yaml" ,
7370 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" ))),
7772 args (
7873 "for-sum.yaml" ,
7974 Map .of ("input" , Arrays .asList (1 , 2 , 3 )),
80- o -> assertThat (o . output (). join () ).isEqualTo (6 )),
75+ o -> assertThat (o ).isEqualTo (6 )),
8176 args (
8277 "for-collect.yaml" ,
8378 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 )))),
8580 args (
8681 "simple-expression.yaml" ,
8782 Map .of ("input" , Arrays .asList (1 , 2 , 3 )),
@@ -97,16 +92,25 @@ private static Stream<Arguments> provideParameters() {
9792 args (
9893 "fork.yaml" ,
9994 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 ));
10497 }
10598
10699 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 ) {
108111 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 ()));
110114 }
111115
112116 private static <T extends Throwable > Arguments args (
@@ -117,8 +121,7 @@ private static <T extends Throwable> Arguments args(
117121 d ->
118122 checkWorkflowException (
119123 catchThrowableOfType (
120- CompletionException .class ,
121- () -> d .execute (Map .of ()).outputAsJsonNode ().join ()),
124+ CompletionException .class , () -> d .instance (Map .of ()).start ().join ()),
122125 consumer ,
123126 clazz ));
124127 }
@@ -129,8 +132,7 @@ private static <T extends Throwable> void checkWorkflowException(
129132 consumer .accept (clazz .cast (ex .getCause ()));
130133 }
131134
132- private static void checkNotCompeteOuput (WorkflowInstance instance ) {
133- JsonNode out = instance .outputAsJsonNode ().join ();
135+ private static void checkNotCompeteOuput (JsonNode out ) {
134136 assertThat (out ).isInstanceOf (ArrayNode .class );
135137 assertThat (out ).hasSize (2 );
136138 ArrayNode array = (ArrayNode ) out ;
@@ -156,8 +158,8 @@ private static void checkWorkflowException(WorkflowException ex) {
156158 assertThat (ex .getWorflowError ().instance ()).isEqualTo ("do/0/notImplemented" );
157159 }
158160
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 ;
161163 assertThat (Instant .ofEpochMilli ((long ) result .get ("startedAt" )))
162164 .isAfterOrEqualTo (before )
163165 .isBeforeOrEqualTo (Instant .now ());
0 commit comments