Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.serverlessworkflow.impl.WorkflowDefinition;
import io.serverlessworkflow.impl.expressions.ExpressionUtils;
import io.serverlessworkflow.impl.json.JsonUtils;
import io.serverlessworkflow.impl.json.MergeUtils;
import java.util.Map;

public class SetExecutor extends AbstractTaskExecutor<SetTask> {
Expand All @@ -38,10 +37,8 @@ protected SetExecutor(SetTask task, WorkflowDefinition definition) {
@Override
protected void internalExecute(WorkflowContext workflow, TaskContext<SetTask> taskContext) {
taskContext.rawOutput(
MergeUtils.merge(
JsonUtils.fromValue(
ExpressionUtils.evaluateExpressionMap(
toBeSet, workflow, taskContext, taskContext.input())),
taskContext.input()));
JsonUtils.fromValue(
ExpressionUtils.evaluateExpressionMap(
toBeSet, workflow, taskContext, taskContext.input())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.serverlessworkflow.impl;

import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
import static io.serverlessworkflow.api.WorkflowReader.validation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowableOfType;

Expand Down Expand Up @@ -52,58 +53,35 @@ static void init() {
@MethodSource("provideParameters")
void testWorkflowExecution(String fileName, Consumer<WorkflowDefinition> assertions)
throws IOException {
assertions.accept(appl.workflowDefinition(readWorkflowFromClasspath(fileName)));
assertions.accept(appl.workflowDefinition(readWorkflowFromClasspath(validation(), fileName)));
}

private static Stream<Arguments> provideParameters() {
return Stream.of(
args(
"switch-then-string.yaml",
Map.of("orderType", "electronic"),
o ->
assertThat(o.output())
.isEqualTo(
Map.of(
"orderType", "electronic", "validate", true, "status", "fulfilled"))),
o -> assertThat(o.output()).isEqualTo(Map.of("validate", true, "status", "fulfilled"))),
args(
"switch-then-string.yaml",
Map.of("orderType", "physical"),
o ->
assertThat(o.output())
.isEqualTo(
Map.of(
"orderType",
"physical",
"inventory",
"clear",
"items",
1,
"address",
"Elmer St"))),
.isEqualTo(Map.of("inventory", "clear", "items", 1, "address", "Elmer St"))),
args(
"switch-then-string.yaml",
Map.of("orderType", "unknown"),
o ->
assertThat(o.output())
.isEqualTo(
Map.of(
"orderType",
"unknown",
"log",
"warn",
"message",
"something's wrong"))),
.isEqualTo(Map.of("log", "warn", "message", "something's wrong"))),
args(
"for-sum.yaml",
Map.of("input", Arrays.asList(1, 2, 3)),
o -> assertThat(o.output()).isEqualTo(6)),
args(
"for-collect.yaml",
Map.of("input", Arrays.asList(1, 2, 3)),
o ->
assertThat(o.output())
.isEqualTo(
Map.of("input", Arrays.asList(1, 2, 3), "output", Arrays.asList(2, 4, 6)))),
o -> assertThat(o.output()).isEqualTo(Map.of("output", Arrays.asList(2, 4, 6)))),
args(
"simple-expression.yaml",
Map.of("input", Arrays.asList(1, 2, 3)),
Expand Down
4 changes: 2 additions & 2 deletions impl/core/src/test/resources/for-collect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ do:
from: '{input: .input, output: []}'
do:
- sumIndex:
output:
as: .output+=[$number+$index+1]
set:
output: ${.output+[$number+$index+1]}
11 changes: 4 additions & 7 deletions impl/core/src/test/resources/for-sum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ document:
name: for-sum-example
version: '0.1.0'
do:
- initCounter:
set:
counter: 0
- sumAll:
for:
each: number
in: .input
do:
- accumulate:
output:
as: .counter+=$number
output:
as: .counter
set:
counter: ${.counter+$number}
output:
as: .counter
36 changes: 11 additions & 25 deletions impl/core/src/test/resources/switch-then-string.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,17 @@ do:
- default:
then: handleUnknownOrderType
- processElectronicOrder:
do:
- validatePayment:
set:
validate: true
- fulfillOrder:
set:
status: fulfilled
then: exit
set:
validate: true
status: fulfilled
then: exit
- processPhysicalOrder:
do:
- checkInventory:
set:
inventory: clear
- packItems:
set:
items: 1
- scheduleShipping:
set:
address: Elmer St
set:
inventory: clear
items: 1
address: Elmer St
then: exit
- handleUnknownOrderType:
do:
- logWarning:
set:
log: warn
- notifyAdmin:
set:
message: something's wrong
set:
log: warn
message: something's wrong
Loading