Skip to content

Commit 78e2f1f

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

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

experimental/lambda/src/main/java/io/serverlessworkflow/impl/executors/func/JavaConsumerCallExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void init(
4242
inputClass = task.inputClass();
4343
}
4444

45-
public CompletableFuture<WorkflowModel> apply(
45+
private CompletableFuture<WorkflowModel> apply(
4646
WorkflowContext workflowContext, TaskContext taskContext, WorkflowModel input) {
4747
T typed = JavaFuncUtils.convertT(input, inputClass);
4848
consumer.accept(typed);

experimental/lambda/src/main/java/io/serverlessworkflow/impl/executors/func/JavaContextFunctionCallExecutor.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ public class JavaContextFunctionCallExecutor<T, V>
3535
private JavaContextFunction<T, V> function;
3636
private Optional<Class<T>> inputClass;
3737

38-
public CompletableFuture<WorkflowModel> apply(
39-
WorkflowContext workflowContext, TaskContext taskContext, WorkflowModel input) {
40-
return CompletableFuture.completedFuture(
41-
workflowContext
42-
.definition()
43-
.application()
44-
.modelFactory()
45-
.fromAny(
46-
input, function.apply(JavaFuncUtils.convertT(input, inputClass), workflowContext)));
47-
}
48-
4938
@Override
5039
public boolean accept(Class<? extends TaskBase> clazz) {
5140
return CallJava.CallJavaContextFunction.class.isAssignableFrom(clazz);
@@ -64,4 +53,15 @@ public void init(
6453
public CallableTask build() {
6554
return this::apply;
6655
}
56+
57+
private CompletableFuture<WorkflowModel> apply(
58+
WorkflowContext workflowContext, TaskContext taskContext, WorkflowModel input) {
59+
return CompletableFuture.completedFuture(
60+
workflowContext
61+
.definition()
62+
.application()
63+
.modelFactory()
64+
.fromAny(
65+
input, function.apply(JavaFuncUtils.convertT(input, inputClass), workflowContext)));
66+
}
6767
}

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)