Skip to content

Commit 470c571

Browse files
committed
[Fix #1002] Adding test
Signed-off-by: fjtirado <ftirados@redhat.com>
1 parent 61cd3ca commit 470c571

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

impl/core/src/main/java/io/serverlessworkflow/impl/executors/CallFunctionExecutor.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,31 @@
1616
package io.serverlessworkflow.impl.executors;
1717

1818
import io.serverlessworkflow.api.types.CallFunction;
19+
import io.serverlessworkflow.api.types.FunctionArguments;
1920
import io.serverlessworkflow.api.types.Task;
2021
import io.serverlessworkflow.api.types.TaskBase;
2122
import io.serverlessworkflow.impl.WorkflowDefinition;
2223
import io.serverlessworkflow.impl.WorkflowMutablePosition;
24+
import io.serverlessworkflow.impl.WorkflowUtils;
25+
import io.serverlessworkflow.impl.WorkflowValueResolver;
26+
import java.util.Map;
2327
import java.util.Optional;
2428

2529
public class CallFunctionExecutor implements CallableTaskBuilder<CallFunction> {
2630

2731
private TaskExecutorBuilder<? extends TaskBase> executorBuilder;
32+
private WorkflowValueResolver<Map<String, Object>> args;
2833

2934
@Override
3035
public void init(
3136
CallFunction task, WorkflowDefinition definition, WorkflowMutablePosition position) {
3237
String functionName = task.getCall();
38+
FunctionArguments functionArgs = task.getWith();
39+
args =
40+
functionArgs != null
41+
? WorkflowUtils.buildMapResolver(
42+
definition.application(), functionArgs.getAdditionalProperties())
43+
: (w, t, m) -> Map.of();
3344
Task function = null;
3445
if (definition.workflow().getUse() != null
3546
&& definition.workflow().getUse().getFunctions() != null
@@ -53,6 +64,12 @@ public boolean accept(Class<? extends TaskBase> clazz) {
5364
@Override
5465
public CallableTask build() {
5566
TaskExecutor<? extends TaskBase> executor = executorBuilder.build();
56-
return (w, t, m) -> executor.apply(w, Optional.of(t), m).thenApply(o -> o.output());
67+
return (w, t, m) ->
68+
executor
69+
.apply(
70+
w,
71+
Optional.of(t),
72+
w.definition().application().modelFactory().fromAny(args.apply(w, t, m)))
73+
.thenApply(o -> o.output());
5774
}
5875
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,19 @@ void testTimeout() throws IOException {
121121
.orElseThrow();
122122
assertThat(result.get("message")).isEqualTo("Viva er Beti Balompie");
123123
}
124+
125+
@Test
126+
void testCustomFunction() {
127+
assertThatThrownBy(
128+
() ->
129+
app.workflowDefinition(
130+
readWorkflowFromClasspath(
131+
"workflows-samples/call-custom-function-inline.yaml"))
132+
.instance(Map.of())
133+
.start()
134+
.join())
135+
.hasCauseInstanceOf(WorkflowException.class)
136+
.extracting(w -> ((WorkflowException) w.getCause()).getWorkflowError().status())
137+
.isEqualTo(404);
138+
}
124139
}

impl/test/src/test/resources/workflows-samples/call-custom-function-inline.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
document:
22
dsl: '1.0.1'
3-
namespace: samples
3+
namespace: test
44
name: call-custom-function-inline
55
version: '0.1.0'
66
use:
@@ -12,7 +12,7 @@ use:
1212
type: object
1313
properties:
1414
petId:
15-
type: string
15+
type: integer
1616
required: [ petId ]
1717
call: http
1818
with:

0 commit comments

Comments
 (0)