Skip to content

Commit dc2223b

Browse files
committed
Adding listen to all test
Signed-off-by: Francisco Javier Tirado Sarti <ftirados@redhat.com>
1 parent 5d6a4b5 commit dc2223b

File tree

3 files changed

+52
-19
lines changed

3 files changed

+52
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private EventRegistrationBuilderCollection anyEvents(AnyEventConsumptionStrategy
8080
}
8181

8282
private EventRegistrationBuilderCollection oneEvent(OneEventConsumptionStrategy oneStrategy) {
83-
return new EventRegistrationBuilderCollection(List.of(from(oneStrategy.getOne())), false);
83+
return new EventRegistrationBuilderCollection(List.of(from(oneStrategy.getOne())), true);
8484
}
8585

8686
protected ListenExecutorBuilder(

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

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.fasterxml.jackson.databind.JsonNode;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import com.fasterxml.jackson.databind.node.ArrayNode;
2223
import com.fasterxml.jackson.databind.node.ObjectNode;
2324
import io.serverlessworkflow.api.WorkflowReader;
2425
import io.serverlessworkflow.impl.json.JsonUtils;
@@ -27,7 +28,6 @@
2728
import java.util.concurrent.CompletableFuture;
2829
import java.util.stream.Stream;
2930
import org.junit.jupiter.api.BeforeAll;
30-
import org.junit.jupiter.api.Test;
3131
import org.junit.jupiter.params.ParameterizedTest;
3232
import org.junit.jupiter.params.provider.Arguments;
3333
import org.junit.jupiter.params.provider.MethodSource;
@@ -58,15 +58,16 @@ void testEventListened(String listen, String emit, JsonNode expectedResult, Obje
5858
assertThat(waitingInstance.outputAsJsonNode()).isEqualTo(expectedResult);
5959
}
6060

61-
@Test
62-
void testUntilConsumed() throws IOException {
61+
@ParameterizedTest
62+
@MethodSource("eventsListenerParameters")
63+
void testEventsListened(String listen, String emit1, String emit2, JsonNode expectedResult)
64+
throws IOException {
6365
WorkflowDefinition listenDefinition =
64-
appl.workflowDefinition(
65-
WorkflowReader.readWorkflowFromClasspath("listen-to-any-until-consumed.yaml"));
66+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath(listen));
6667
WorkflowDefinition emitDoctorDefinition =
67-
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("emit-doctor.yaml"));
68+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath(emit1));
6869
WorkflowDefinition emitOutDefinition =
69-
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("emit-out.yaml"));
70+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath(emit2));
7071
WorkflowInstance waitingInstance = listenDefinition.instance(Map.of());
7172
CompletableFuture<JsonNode> future = waitingInstance.start();
7273
assertThat(waitingInstance.status()).isEqualTo(WorkflowStatus.RUNNING);
@@ -77,16 +78,30 @@ void testUntilConsumed() throws IOException {
7778
emitOutDefinition.instance(Map.of()).start().join();
7879
assertThat(future).isCompleted();
7980
assertThat(waitingInstance.status()).isEqualTo(WorkflowStatus.COMPLETED);
80-
assertThat(waitingInstance.outputAsJsonNode()).isEqualTo(temperature());
81+
assertThat(waitingInstance.outputAsJsonNode()).isEqualTo(expectedResult);
8182
}
8283

8384
private static Stream<Arguments> eventListenerParameters() {
8485
return Stream.of(
85-
Arguments.of("listen-to-any.yaml", "emit.yaml", cruellaDeVil(), Map.of()),
86+
Arguments.of("listen-to-any.yaml", "emit.yaml", array(cruellaDeVil()), Map.of()),
8687
Arguments.of(
8788
"listen-to-any-filter.yaml", "emit-doctor.yaml", doctor(), Map.of("temperature", 39)));
8889
}
8990

91+
private static Stream<Arguments> eventsListenerParameters() {
92+
return Stream.of(
93+
Arguments.of(
94+
"listen-to-all.yaml",
95+
"emit-doctor.yaml",
96+
"emit.yaml",
97+
array(temperature(), cruellaDeVil())),
98+
Arguments.of(
99+
"listen-to-any-until-consumed.yaml",
100+
"emit-doctor.yaml",
101+
"emit-out.yaml",
102+
array(temperature())));
103+
}
104+
90105
private static JsonNode cruellaDeVil() {
91106
ObjectMapper mapper = JsonUtils.mapper();
92107
ObjectNode node = mapper.createObjectNode();
@@ -97,21 +112,24 @@ private static JsonNode cruellaDeVil() {
97112
mapper
98113
.createArrayNode()
99114
.add(mapper.createObjectNode().put("breed", "dalmatian").put("quantity", 101)));
100-
return mapper.createArrayNode().add(node);
115+
return node;
101116
}
102117

103118
private static JsonNode doctor() {
104-
ObjectMapper mapper = JsonUtils.mapper();
105-
ObjectNode node = mapper.createObjectNode();
106-
node.put("temperature", 39);
119+
ObjectNode node = temperature();
107120
node.put("isSick", true);
108-
return mapper.createArrayNode().add(node);
121+
return array(node);
109122
}
110123

111-
private static JsonNode temperature() {
112-
ObjectMapper mapper = JsonUtils.mapper();
113-
ObjectNode node = mapper.createObjectNode();
124+
private static ObjectNode temperature() {
125+
ObjectNode node = JsonUtils.mapper().createObjectNode();
114126
node.put("temperature", 39);
115-
return mapper.createArrayNode().add(node);
127+
return node;
128+
}
129+
130+
private static JsonNode array(JsonNode... jsonNodes) {
131+
ArrayNode arrayNode = JsonUtils.mapper().createArrayNode();
132+
for (JsonNode node : jsonNodes) arrayNode.add(node);
133+
return arrayNode;
116134
}
117135
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: test
4+
name: listen-to-all
5+
version: '0.1.0'
6+
do:
7+
- callDoctor:
8+
listen:
9+
to:
10+
all:
11+
- with:
12+
type: com.fake-hospital.vitals.measurements.temperature
13+
data: ${ .temperature > 38 }
14+
- with:
15+
type: com.petstore.order.placed.v1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy