|
20 | 20 | import static io.serverlessworkflow.fluent.spec.dsl.DSL.cases; |
21 | 21 | import static io.serverlessworkflow.fluent.spec.dsl.DSL.doTasks; |
22 | 22 | import static io.serverlessworkflow.fluent.spec.dsl.DSL.emit; |
| 23 | +import static io.serverlessworkflow.fluent.spec.dsl.DSL.event; |
23 | 24 | import static io.serverlessworkflow.fluent.spec.dsl.DSL.forEach; |
24 | 25 | import static io.serverlessworkflow.fluent.spec.dsl.DSL.fork; |
25 | 26 | import static io.serverlessworkflow.fluent.spec.dsl.DSL.http; |
@@ -703,4 +704,53 @@ void testDoTaskRunWorkflow() { |
703 | 704 | RunTaskConfiguration.ProcessReturnType.NONE, runTask.getRun().getRunWorkflow().getReturn()); |
704 | 705 | assertEquals(false, runTask.getRun().getRunWorkflow().isAwait()); |
705 | 706 | } |
| 707 | + |
| 708 | + @Test |
| 709 | + void testListenWithConfigurerBuilder() { |
| 710 | + Workflow wf = |
| 711 | + WorkflowBuilder.workflow("listen-with-configurer", "test", "0.1.0") |
| 712 | + .tasks( |
| 713 | + doTasks( |
| 714 | + listen( |
| 715 | + "waitForEvent", |
| 716 | + l -> |
| 717 | + l.to() |
| 718 | + .any( |
| 719 | + event().type("com.example.event.A"), |
| 720 | + event().type("com.example.event.B")) |
| 721 | + .until("$.count > 0") |
| 722 | + .forEach( |
| 723 | + "item", |
| 724 | + f -> |
| 725 | + f.tasks( |
| 726 | + set("processed", s -> s.put("eventType", "processed")))) |
| 727 | + .apply()))) |
| 728 | + .build(); |
| 729 | + |
| 730 | + List<TaskItem> items = wf.getDo(); |
| 731 | + assertNotNull(items, "Do list must not be null"); |
| 732 | + assertEquals(1, items.size(), "There should be one listen task"); |
| 733 | + |
| 734 | + TaskItem item = items.get(0); |
| 735 | + assertEquals("waitForEvent", item.getName(), "TaskItem name should match"); |
| 736 | + ListenTask lt = item.getTask().getListenTask(); |
| 737 | + assertNotNull(lt, "ListenTask should be present"); |
| 738 | + |
| 739 | + // Verify strategy |
| 740 | + var strategy = lt.getListen().getTo().getAnyEventConsumptionStrategy(); |
| 741 | + assertNotNull(strategy, "Any strategy should be set"); |
| 742 | + assertEquals(2, strategy.getAny().size(), "Should have 2 event filters"); |
| 743 | + |
| 744 | + // Verify until condition |
| 745 | + var until = strategy.getUntil(); |
| 746 | + assertNotNull(until, "Until should be set"); |
| 747 | + assertEquals("$.count > 0", until.getAnyEventUntilCondition(), "Until expression should match"); |
| 748 | + |
| 749 | + // Verify foreach |
| 750 | + var foreach = lt.getForeach(); |
| 751 | + assertNotNull(foreach, "Foreach should be set"); |
| 752 | + assertNotNull(foreach.getDo(), "Foreach do tasks should be set"); |
| 753 | + assertEquals(1, foreach.getDo().size(), "Foreach do should have 1 task"); |
| 754 | + assertEquals("processed", foreach.getDo().get(0).getName(), "Foreach task name should match"); |
| 755 | + } |
706 | 756 | } |
0 commit comments