From 7f95c93ab040d35146ab9f5b6328e725d1c5739c Mon Sep 17 00:00:00 2001 From: Vishesh Ruparelia Date: Sat, 5 Aug 2023 15:01:57 +0530 Subject: [PATCH] add missing support for contextAttributes in ProduceEvent Signed-off-by: Vishesh Ruparelia --- api/src/main/resources/schema/produce/produceevent.json | 5 +++++ .../serverlessworkflow/api/test/MarkupToWorkflowTest.java | 7 +++++++ api/src/test/resources/features/transitions.json | 6 +++++- api/src/test/resources/features/transitions.yml | 3 +++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/api/src/main/resources/schema/produce/produceevent.json b/api/src/main/resources/schema/produce/produceevent.json index b5bb7d5f..f094824e 100644 --- a/api/src/main/resources/schema/produce/produceevent.json +++ b/api/src/main/resources/schema/produce/produceevent.json @@ -10,6 +10,11 @@ "data": { "type": "string", "description": "Workflow expression which selects parts of the states data output to become the data of the produced event" + }, + "contextAttributes": { + "type": "object", + "description": "Add additional event extension context attributes", + "existingJavaType": "java.util.Map" } }, "required": [ diff --git a/api/src/test/java/io/serverlessworkflow/api/test/MarkupToWorkflowTest.java b/api/src/test/java/io/serverlessworkflow/api/test/MarkupToWorkflowTest.java index fed3dc97..992bdd3a 100644 --- a/api/src/test/java/io/serverlessworkflow/api/test/MarkupToWorkflowTest.java +++ b/api/src/test/java/io/serverlessworkflow/api/test/MarkupToWorkflowTest.java @@ -40,6 +40,8 @@ import io.serverlessworkflow.api.timeouts.WorkflowExecTimeout; import io.serverlessworkflow.api.workflow.*; import java.util.List; +import java.util.Map; + import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -260,6 +262,11 @@ public void testTransitions(String workflowLocation) { assertEquals("RejectApplication", cond2.getTransition().getNextState()); assertNotNull(cond2.getTransition().getProduceEvents()); assertEquals(1, cond2.getTransition().getProduceEvents().size()); + assertNotNull(cond2.getTransition().getProduceEvents().get(0).getContextAttributes()); + Map contextAttributes = cond2.getTransition().getProduceEvents().get(0).getContextAttributes(); + assertEquals(2, contextAttributes.size()); + assertEquals("IN", contextAttributes.get("order_location")); + assertEquals("online", contextAttributes.get("order_type")); assertFalse(cond2.getTransition().isCompensate()); assertNotNull(switchState.getDefaultCondition()); diff --git a/api/src/test/resources/features/transitions.json b/api/src/test/resources/features/transitions.json index cacc94af..ed7b7626 100644 --- a/api/src/test/resources/features/transitions.json +++ b/api/src/test/resources/features/transitions.json @@ -23,7 +23,11 @@ "produceEvents": [ { "eventRef": "provisioningCompleteEvent", - "data": "${ .provisionedOrders }" + "data": "${ .provisionedOrders }", + "contextAttributes": { + "order_location": "IN", + "order_type": "online" + } } ] } diff --git a/api/src/test/resources/features/transitions.yml b/api/src/test/resources/features/transitions.yml index 1b89a85f..3ec34ae4 100644 --- a/api/src/test/resources/features/transitions.yml +++ b/api/src/test/resources/features/transitions.yml @@ -18,6 +18,9 @@ states: produceEvents: - eventRef: provisioningCompleteEvent data: "${ .provisionedOrders }" + contextAttributes: + "order_location": "IN" + "order_type": "online" defaultCondition: transition: nextState: RejectApplication