|
16 | 16 | */ |
17 | 17 | package io.serverlessworkflow.api.test; |
18 | 18 |
|
| 19 | +import com.fasterxml.jackson.databind.JsonNode; |
19 | 20 | import io.serverlessworkflow.api.Workflow; |
20 | 21 | import io.serverlessworkflow.api.actions.Action; |
21 | 22 | import io.serverlessworkflow.api.defaultdef.DefaultDefinition; |
|
33 | 34 | import org.junit.jupiter.params.provider.ValueSource; |
34 | 35 |
|
35 | 36 | import java.util.List; |
| 37 | +import java.util.Map; |
36 | 38 |
|
37 | 39 | import static org.junit.jupiter.api.Assertions.*; |
38 | 40 |
|
@@ -230,15 +232,15 @@ public void testFunctionRefs(String workflowLocation) { |
230 | 232 | assertNotNull(action1.getFunctionRef()); |
231 | 233 | FunctionRef functionRef1 = action1.getFunctionRef(); |
232 | 234 | assertEquals("creditCheckFunction", functionRef1.getRefName()); |
233 | | - assertEquals(0, functionRef1.getParameters().size()); |
| 235 | + assertNull(functionRef1.getParameters()); |
234 | 236 |
|
235 | 237 | Action action2 = operationState.getActions().get(1); |
236 | 238 | assertNotNull(action2); |
237 | 239 | assertNotNull(action2.getFunctionRef()); |
238 | 240 | FunctionRef functionRef2 = action2.getFunctionRef(); |
239 | 241 | assertEquals("sendRejectionEmailFunction", functionRef2.getRefName()); |
240 | 242 | assertEquals(1, functionRef2.getParameters().size()); |
241 | | - assertEquals("{{ $.customer }}", functionRef2.getParameters().get("applicant")); |
| 243 | + assertEquals("{{ $.customer }}", functionRef2.getParameters().get("applicant").asText()); |
242 | 244 | } |
243 | 245 |
|
244 | 246 | @ParameterizedTest |
@@ -283,4 +285,64 @@ public void testSubflowStateRepeat(String workflowLocation) { |
283 | 285 | assertEquals(1, subflowState.getRepeat().getStopOnEvents().size()); |
284 | 286 | assertEquals("CarTurnedOffEvent", subflowState.getRepeat().getStopOnEvents().get(0)); |
285 | 287 | } |
| 288 | + |
| 289 | + @ParameterizedTest |
| 290 | + @ValueSource(strings = {"/features/functionrefjsonparams.json", "/features/functionrefjsonparams.yml"}) |
| 291 | + public void testFunctionRefJsonParams(String workflowLocation) { |
| 292 | + Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation)); |
| 293 | + |
| 294 | + assertNotNull(workflow); |
| 295 | + assertNotNull(workflow.getId()); |
| 296 | + assertNotNull(workflow.getName()); |
| 297 | + assertNotNull(workflow.getStates()); |
| 298 | + |
| 299 | + assertNotNull(workflow.getStates()); |
| 300 | + assertTrue(workflow.getStates().size() == 1); |
| 301 | + assertTrue(workflow.getStates().get(0) instanceof OperationState); |
| 302 | + |
| 303 | + OperationState operationState = (OperationState) workflow.getStates().get(0); |
| 304 | + assertNotNull(operationState.getActions()); |
| 305 | + assertEquals(1, operationState.getActions().size()); |
| 306 | + List<Action> actions = operationState.getActions(); |
| 307 | + assertNotNull(actions.get(0).getFunctionRef()); |
| 308 | + assertEquals("addPet", actions.get(0).getFunctionRef().getRefName()); |
| 309 | + |
| 310 | + JsonNode params = actions.get(0).getFunctionRef().getParameters(); |
| 311 | + assertNotNull(params); |
| 312 | + assertEquals(4, params.size()); |
| 313 | + assertEquals(123, params.get("id").intValue()); |
| 314 | + assertEquals("My Address, 123 MyCity, MyCountry", params.get("address").asText()); |
| 315 | + assertEquals("${ .owner.name }", params.get("owner").asText()); |
| 316 | + assertEquals("Pluto", params.get("body").get("name").asText()); |
| 317 | + assertEquals("${ .pet.tagnumber }", params.get("body").get("tag").asText()); |
| 318 | + } |
| 319 | + |
| 320 | + @ParameterizedTest |
| 321 | + @ValueSource(strings = {"/features/functionrefnoparams.json", "/features/functionrefnoparams.yml"}) |
| 322 | + public void testFunctionRefNoParams(String workflowLocation) { |
| 323 | + Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation)); |
| 324 | + |
| 325 | + assertNotNull(workflow); |
| 326 | + assertNotNull(workflow.getId()); |
| 327 | + assertNotNull(workflow.getName()); |
| 328 | + assertNotNull(workflow.getStates()); |
| 329 | + |
| 330 | + assertNotNull(workflow.getStates()); |
| 331 | + assertTrue(workflow.getStates().size() == 1); |
| 332 | + assertTrue(workflow.getStates().get(0) instanceof OperationState); |
| 333 | + |
| 334 | + OperationState operationState = (OperationState) workflow.getStates().get(0); |
| 335 | + assertNotNull(operationState.getActions()); |
| 336 | + assertEquals(2, operationState.getActions().size()); |
| 337 | + List<Action> actions = operationState.getActions(); |
| 338 | + assertNotNull(actions.get(0).getFunctionRef()); |
| 339 | + assertNotNull(actions.get(1).getFunctionRef()); |
| 340 | + assertEquals("addPet", actions.get(0).getFunctionRef().getRefName()); |
| 341 | + assertEquals("addPet", actions.get(1).getFunctionRef().getRefName()); |
| 342 | + |
| 343 | + JsonNode params = actions.get(0).getFunctionRef().getParameters(); |
| 344 | + assertNull(params); |
| 345 | + JsonNode params2 = actions.get(1).getFunctionRef().getParameters(); |
| 346 | + assertNull(params); |
| 347 | + } |
286 | 348 | } |
0 commit comments