Skip to content

Commit 37add85

Browse files
committed
test and ajust in classes
Signed-off-by: Matheus André Galvão Da Silva <matheusandr2@gmail.com>
1 parent ab18fc8 commit 37add85

4 files changed

Lines changed: 84 additions & 1 deletion

File tree

experimental/lambda/src/test/java/io/serverless/workflow/impl/executors/func/FuncDSLDataFlowTransformationHelpersTest.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.serverlessworkflow.impl.WorkflowApplication;
2626
import io.serverlessworkflow.impl.WorkflowContextData;
2727
import io.serverlessworkflow.impl.WorkflowDefinition;
28+
import io.serverlessworkflow.impl.WorkflowInstance;
2829
import io.serverlessworkflow.impl.WorkflowModel;
2930
import org.assertj.core.api.SoftAssertions;
3031
import org.junit.jupiter.api.Test;
@@ -160,4 +161,82 @@ void test_input_with_inputFrom_fluent_way() {
160161

161162
softly.assertAll();
162163
}
164+
165+
@Test
166+
void test_output_with_outputAs() {
167+
168+
SoftAssertions softly = new SoftAssertions();
169+
170+
Workflow workflow =
171+
FuncWorkflowBuilder.workflow("enrichOutputWithTaskOutputTest")
172+
.tasks(
173+
function(
174+
"add5",
175+
(Long input) -> {
176+
softly.assertThat(input).isEqualTo(10L);
177+
return input + 5;
178+
},
179+
Long.class)
180+
.outputAs(
181+
(object, workflowContext, taskContextData) -> {
182+
Long taskOutput = output(taskContextData, Long.class);
183+
softly.assertThat(taskOutput).isEqualTo(15L);
184+
Long input = input(workflowContext, Long.class);
185+
softly.assertThat(input).isEqualTo(10L);
186+
return input + taskOutput;
187+
},
188+
Long.class))
189+
.build();
190+
191+
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
192+
WorkflowDefinition def = app.workflowDefinition(workflow);
193+
194+
WorkflowModel model = def.instance(10L).start().join();
195+
Number number = model.asNumber().orElseThrow();
196+
197+
softly.assertThat(number.longValue()).isEqualTo(25L);
198+
}
199+
200+
softly.assertAll();
201+
}
202+
203+
@Test
204+
void test_input_with_exportAs() {
205+
206+
SoftAssertions softly = new SoftAssertions();
207+
208+
Workflow workflow =
209+
FuncWorkflowBuilder.workflow("enrichExportWithInputTest")
210+
.tasks(
211+
function(
212+
"add5",
213+
(Long input) -> {
214+
softly.assertThat(input).isEqualTo(10L);
215+
return input + 5;
216+
},
217+
Long.class)
218+
.exportAs(
219+
(Long object,
220+
WorkflowContextData workflowContext,
221+
TaskContextData taskContextData) -> {
222+
Long taskOutput = output(taskContextData, Long.class);
223+
softly.assertThat(taskOutput).isEqualTo(15L);
224+
Long input = input(workflowContext, Long.class);
225+
softly.assertThat(input).isEqualTo(10L);
226+
return input + taskOutput;
227+
}))
228+
.build();
229+
230+
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
231+
WorkflowDefinition def = app.workflowDefinition(workflow);
232+
233+
WorkflowInstance instance = def.instance(10L);
234+
instance.start().join();
235+
Number number = instance.context().asNumber().orElseThrow();
236+
237+
softly.assertThat(number.longValue()).isEqualTo(25L);
238+
}
239+
240+
softly.assertAll();
241+
}
163242
}

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/BaseTaskItemListBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public abstract class BaseTaskItemListBuilder<SELF extends BaseTaskItemListBuild
4444
protected final String TYPE_TRY = "try";
4545
protected final String TYPE_HTTP = "http";
4646
protected final String TYPE_OPENAPI = "openapi";
47+
protected final String TYPE_WORKFLOW = "workflow";
4748

4849
private final List<TaskItem> list;
4950
private final int offset;

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/TaskItemListBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public TaskItemListBuilder openapi(
147147

148148
@Override
149149
public TaskItemListBuilder workflow(String name, Consumer<WorkflowTaskBuilder> itemsConfigurer) {
150-
name = defaultNameAndRequireConfig(name, itemsConfigurer);
150+
name = defaultNameAndRequireConfig(name, itemsConfigurer, TYPE_WORKFLOW);
151151

152152
final WorkflowTaskBuilder workflowTaskBuilder = new WorkflowTaskBuilder();
153153
itemsConfigurer.accept(workflowTaskBuilder);

fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/dsl/DSLTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ void when_dsl_subflow_workflow_task_with_map_input() {
330330
assertThat(run.getWorkflow().getInput().getAdditionalProperties().get("extra")).isEqualTo(true);
331331
assertThat(run.isAwait()).isTrue();
332332
assertThat(run.getReturn()).isEqualTo(RunTaskConfiguration.ProcessReturnType.NONE);
333+
}
334+
335+
@Test
333336
public void when_call_openapi_with_explicit_name() {
334337
Workflow wf =
335338
WorkflowBuilder.workflow("myFlow", "myNs", "1.2.3")

0 commit comments

Comments
 (0)