Skip to content

Commit

Permalink
Fix incorrect computation of all available correlation keys
Browse files Browse the repository at this point in the history
Use a new approach based on https://simonhessner.de/calculate-power-set-set-of-all-subsets-in-python-without-recursion/
to generate the power set for the correlation keys
  • Loading branch information
filiphr committed Jan 23, 2024
1 parent 57a1ed4 commit 630a6c7
Show file tree
Hide file tree
Showing 5 changed files with 1,183 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setEventRegistry(EventRegistry eventRegistry) {
}

public void triggerTestEvent() {
triggerTestEvent(null);
triggerTestEvent((String) null);
}

public void triggerTestEvent(String customerId) {
Expand All @@ -108,6 +108,10 @@ public void triggerOrderTestEvent(String orderId) {

public void triggerTestEvent(String customerId, String orderId) {
ObjectNode eventNode = createTestEventNode(customerId, orderId);
triggerTestEvent(eventNode);
}

public void triggerTestEvent(ObjectNode eventNode) {
try {
eventRegistry.eventReceived(inboundChannelModel, objectMapper.writeValueAsString(eventNode));
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.test.Deployment;
import org.flowable.eventregistry.api.model.EventPayloadTypes;
import org.flowable.eventsubscription.api.EventSubscription;
import org.flowable.task.api.Task;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.node.ObjectNode;

public class BpmnEventRegistryConsumerTest extends AbstractBpmnEventRegistryConsumerTest {

@Test
Expand Down Expand Up @@ -122,6 +125,191 @@ public void testBoundaryEventListenerWithPayload() {
assertThat(eventSubscription).isNull();
}

@Test
@Deployment
public void testBoundaryEventWith3CorrelationsAllCombinations() {
// The BPMN has boundary events for each combination, the correlation matches a new task will be created
getEventRepositoryService().createEventModelBuilder()
.key("customer")
.resourceName("customer.event")
.correlationParameter("id", EventPayloadTypes.STRING)
.correlationParameter("first", EventPayloadTypes.STRING)
.correlationParameter("last", EventPayloadTypes.STRING)
.deploy();

ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("multiCorrelationProcess")
.variable("customerId", "1234")
.variable("customerFirstName", "John")
.variable("customerLastName", "Doe")
.start();

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder("User task");

ObjectNode event = processEngineConfiguration.getObjectMapper().createObjectNode()
.put("type", "customer")
.put("id", "1235")
.put("first", "Jane")
.put("last", "Doele");
inboundEventChannelAdapter.triggerTestEvent(event);

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder("User task");

event = processEngineConfiguration.getObjectMapper().createObjectNode()
.put("type", "customer")
.put("id", "1234")
.put("first", "John")
.put("last", "Doe");
inboundEventChannelAdapter.triggerTestEvent(event);

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder(
"User task",
"Customer ID Task",
"Customer ID and First Name Task",
"Customer ID and Last Name Task",
"Customer ID, First Name and Last Name Task",
"First Name Task",
"First Name and Last Name Task",
"Last Name Task"
);
}

@Test
@Deployment
public void testBoundaryEventWith4CorrelationsAllCombinations() {
// The BPMN has boundary events for each combination, the correlation matches a new task will be created
getEventRepositoryService().createEventModelBuilder()
.key("testEvent")
.resourceName("test.event")
.correlationParameter("id", EventPayloadTypes.STRING)
.correlationParameter("orderId", EventPayloadTypes.STRING)
.correlationParameter("firstName", EventPayloadTypes.STRING)
.correlationParameter("lastName", EventPayloadTypes.STRING)
.deploy();

ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("multiCorrelationProcess")
.variable("customerId", "customer-1")
.variable("orderId", "order-1")
.variable("firstName", "John")
.variable("lastName", "Doe")
.start();

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder("User task");

ObjectNode event = processEngineConfiguration.getObjectMapper().createObjectNode()
.put("type", "testEvent")
.put("id", "customer-2")
.put("orderId", "order-2")
.put("firstName", "Jane")
.put("lastName", "Doele");
inboundEventChannelAdapter.triggerTestEvent(event);

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder("User task");

event = processEngineConfiguration.getObjectMapper().createObjectNode()
.put("type", "testEvent")
.put("id", "customer-1")
.put("orderId", "order-1")
.put("firstName", "John")
.put("lastName", "Doe");
inboundEventChannelAdapter.triggerTestEvent(event);

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder(
"User task",
"ID",
"Order ID",
"First Name",
"Last Name",
"ID and Order ID",
"ID and First Name",
"ID and Last Name",
"Order ID and First Name",
"Order ID and Last Name",
"First Name and Last Name",
"ID, Order ID and First Name",
"ID, Order ID and Last Name",
"ID, First Name and Last Name",
"Order ID, First Name and Last Name",
"ID, Order ID, First Name and Last Name"
);
}

@Test
@Deployment(resources = "org/flowable/engine/test/eventregistry/BpmnEventRegistryConsumerTest.testBoundaryEventWith4CorrelationsAllCombinations.bpmn20.xml")
public void testBoundaryEventWith4CorrelationsSubsetOfCombinations() {
// The BPMN has boundary events for each combination, the correlation matches a new task will be created
// In this test we are going to match a subset of the tasks
getEventRepositoryService().createEventModelBuilder()
.key("testEvent")
.resourceName("test.event")
.correlationParameter("id", EventPayloadTypes.STRING)
.correlationParameter("orderId", EventPayloadTypes.STRING)
.correlationParameter("firstName", EventPayloadTypes.STRING)
.correlationParameter("lastName", EventPayloadTypes.STRING)
.deploy();

ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
.processDefinitionKey("multiCorrelationProcess")
.variable("customerId", "customer-1")
.variable("orderId", "order-1")
.variable("firstName", "John")
.variable("lastName", "Doe")
.start();

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder("User task");

ObjectNode event = processEngineConfiguration.getObjectMapper().createObjectNode()
.put("type", "testEvent")
.put("id", "customer-2")
.put("orderId", "order-1")
.put("firstName", "Jane")
.put("lastName", "Doe");
inboundEventChannelAdapter.triggerTestEvent(event);

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder(
"User task",
"Order ID",
"Last Name",
"Order ID and Last Name"
);

event = processEngineConfiguration.getObjectMapper().createObjectNode()
.put("type", "testEvent")
.put("id", "customer-2")
.put("orderId", "order-2")
.put("firstName", "John")
.put("lastName", "Smith");
inboundEventChannelAdapter.triggerTestEvent(event);

assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).list())
.extracting(Task::getName)
.containsExactlyInAnyOrder(
"User task",
"Order ID",
"Last Name",
"Order ID and Last Name",
// The first name is from the John Smith trigger
"First Name"
);
}

@Test
@Deployment
public void testReceiveEventTaskNoCorrelation() {
Expand Down
Loading

0 comments on commit 630a6c7

Please sign in to comment.