Skip to content

Commit c89dc1f

Browse files
authored
Merge pull request #501 from fjtirado/Fix_#500
[Fix #500] Fixing set behaviour
2 parents 22a1c68 + acb632a commit c89dc1f

File tree

5 files changed

+26
-68
lines changed

5 files changed

+26
-68
lines changed

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.serverlessworkflow.impl.WorkflowDefinition;
2222
import io.serverlessworkflow.impl.expressions.ExpressionUtils;
2323
import io.serverlessworkflow.impl.json.JsonUtils;
24-
import io.serverlessworkflow.impl.json.MergeUtils;
2524
import java.util.Map;
2625

2726
public class SetExecutor extends AbstractTaskExecutor<SetTask> {
@@ -38,10 +37,8 @@ protected SetExecutor(SetTask task, WorkflowDefinition definition) {
3837
@Override
3938
protected void internalExecute(WorkflowContext workflow, TaskContext<SetTask> taskContext) {
4039
taskContext.rawOutput(
41-
MergeUtils.merge(
42-
JsonUtils.fromValue(
43-
ExpressionUtils.evaluateExpressionMap(
44-
toBeSet, workflow, taskContext, taskContext.input())),
45-
taskContext.input()));
40+
JsonUtils.fromValue(
41+
ExpressionUtils.evaluateExpressionMap(
42+
toBeSet, workflow, taskContext, taskContext.input())));
4643
}
4744
}

impl/core/src/test/java/io/serverlessworkflow/impl/WorkflowDefinitionTest.java

+6-28
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.serverlessworkflow.impl;
1717

1818
import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
19+
import static io.serverlessworkflow.api.WorkflowReader.validation;
1920
import static org.assertj.core.api.Assertions.assertThat;
2021
import static org.assertj.core.api.Assertions.catchThrowableOfType;
2122

@@ -52,58 +53,35 @@ static void init() {
5253
@MethodSource("provideParameters")
5354
void testWorkflowExecution(String fileName, Consumer<WorkflowDefinition> assertions)
5455
throws IOException {
55-
assertions.accept(appl.workflowDefinition(readWorkflowFromClasspath(fileName)));
56+
assertions.accept(appl.workflowDefinition(readWorkflowFromClasspath(validation(), fileName)));
5657
}
5758

5859
private static Stream<Arguments> provideParameters() {
5960
return Stream.of(
6061
args(
6162
"switch-then-string.yaml",
6263
Map.of("orderType", "electronic"),
63-
o ->
64-
assertThat(o.output())
65-
.isEqualTo(
66-
Map.of(
67-
"orderType", "electronic", "validate", true, "status", "fulfilled"))),
64+
o -> assertThat(o.output()).isEqualTo(Map.of("validate", true, "status", "fulfilled"))),
6865
args(
6966
"switch-then-string.yaml",
7067
Map.of("orderType", "physical"),
7168
o ->
7269
assertThat(o.output())
73-
.isEqualTo(
74-
Map.of(
75-
"orderType",
76-
"physical",
77-
"inventory",
78-
"clear",
79-
"items",
80-
1,
81-
"address",
82-
"Elmer St"))),
70+
.isEqualTo(Map.of("inventory", "clear", "items", 1, "address", "Elmer St"))),
8371
args(
8472
"switch-then-string.yaml",
8573
Map.of("orderType", "unknown"),
8674
o ->
8775
assertThat(o.output())
88-
.isEqualTo(
89-
Map.of(
90-
"orderType",
91-
"unknown",
92-
"log",
93-
"warn",
94-
"message",
95-
"something's wrong"))),
76+
.isEqualTo(Map.of("log", "warn", "message", "something's wrong"))),
9677
args(
9778
"for-sum.yaml",
9879
Map.of("input", Arrays.asList(1, 2, 3)),
9980
o -> assertThat(o.output()).isEqualTo(6)),
10081
args(
10182
"for-collect.yaml",
10283
Map.of("input", Arrays.asList(1, 2, 3)),
103-
o ->
104-
assertThat(o.output())
105-
.isEqualTo(
106-
Map.of("input", Arrays.asList(1, 2, 3), "output", Arrays.asList(2, 4, 6)))),
84+
o -> assertThat(o.output()).isEqualTo(Map.of("output", Arrays.asList(2, 4, 6)))),
10785
args(
10886
"simple-expression.yaml",
10987
Map.of("input", Arrays.asList(1, 2, 3)),

impl/core/src/test/resources/for-collect.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ do:
1313
from: '{input: .input, output: []}'
1414
do:
1515
- sumIndex:
16-
output:
17-
as: .output+=[$number+$index+1]
16+
set:
17+
output: ${.output+[$number+$index+1]}

impl/core/src/test/resources/for-sum.yaml

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ document:
44
name: for-sum-example
55
version: '0.1.0'
66
do:
7-
- initCounter:
8-
set:
9-
counter: 0
107
- sumAll:
118
for:
129
each: number
1310
in: .input
1411
do:
1512
- accumulate:
16-
output:
17-
as: .counter+=$number
18-
output:
19-
as: .counter
13+
set:
14+
counter: ${.counter+$number}
15+
output:
16+
as: .counter

impl/core/src/test/resources/switch-then-string.yaml

+11-25
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,17 @@ do:
1515
- default:
1616
then: handleUnknownOrderType
1717
- processElectronicOrder:
18-
do:
19-
- validatePayment:
20-
set:
21-
validate: true
22-
- fulfillOrder:
23-
set:
24-
status: fulfilled
25-
then: exit
18+
set:
19+
validate: true
20+
status: fulfilled
21+
then: exit
2622
- processPhysicalOrder:
27-
do:
28-
- checkInventory:
29-
set:
30-
inventory: clear
31-
- packItems:
32-
set:
33-
items: 1
34-
- scheduleShipping:
35-
set:
36-
address: Elmer St
23+
set:
24+
inventory: clear
25+
items: 1
26+
address: Elmer St
3727
then: exit
3828
- handleUnknownOrderType:
39-
do:
40-
- logWarning:
41-
set:
42-
log: warn
43-
- notifyAdmin:
44-
set:
45-
message: something's wrong
29+
set:
30+
log: warn
31+
message: something's wrong

0 commit comments

Comments
 (0)