diff --git a/connector-runtime/connector-runtime-core/src/main/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandler.java b/connector-runtime/connector-runtime-core/src/main/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandler.java index d0b67cb54c..d9b776e78d 100644 --- a/connector-runtime/connector-runtime-core/src/main/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandler.java +++ b/connector-runtime/connector-runtime-core/src/main/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandler.java @@ -276,7 +276,7 @@ protected Object extractVariables( rawVariables, definition.resultVariable(), definition.resultExpression()); } - private String resolveMessageId(String messageId, String messageIdExpression, Object context) { + private String resolveMessageId(String messageIdExpression, String messageId, Object context) { if (messageId == null) { if (messageIdExpression != null) { return extractMessageId(messageIdExpression, context); diff --git a/connector-runtime/connector-runtime-core/src/test/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandlerTest.java b/connector-runtime/connector-runtime-core/src/test/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandlerTest.java index da7f66a476..761d9c4759 100644 --- a/connector-runtime/connector-runtime-core/src/test/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandlerTest.java +++ b/connector-runtime/connector-runtime-core/src/test/java/io/camunda/connector/runtime/core/inbound/correlation/InboundCorrelationHandlerTest.java @@ -35,6 +35,7 @@ import io.camunda.zeebe.client.ZeebeClient; import java.util.Collections; import java.util.Map; +import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -506,4 +507,57 @@ void resultVarProvided_resultExprProvided_shouldExtractVarsAndCopyAllVarsToResul "otherValue")); } } + + @Nested + class ResolveMessageId { + + @Test + void messageIdIsNull_expressionIsNull_usesRandomUuid() { + // given + var point = new MessageCorrelationPoint("msg1", "=correlationKey", null); + var definition = mock(InboundConnectorDefinitionImpl.class); + when(definition.correlationPoint()).thenReturn(point); + + var dummyCommand = spy(new PublishMessageCommandDummy()); + when(zeebeClient.newPublishMessageCommand()).thenReturn(dummyCommand); + // when + handler.correlate(definition, Collections.emptyMap()); + // then + ArgumentCaptor messageIdCaptor = ArgumentCaptor.forClass(String.class); + verify(dummyCommand).messageId(messageIdCaptor.capture()); + + String resolvedMessageId = messageIdCaptor.getValue(); + assertThat(UUID.fromString(resolvedMessageId)) + .isNotNull(); // If this doesn't throw an exception, it's a UUID. + } + + @Test + void messageIdIsNull_expressionIsProvided_usesExtractedMessageId() { + // given + var point = new MessageCorrelationPoint("msg1", "=correlationKey", "=extractedId"); + var definition = mock(InboundConnectorDefinitionImpl.class); + when(definition.correlationPoint()).thenReturn(point); + var dummyCommand = spy(new PublishMessageCommandDummy()); + when(zeebeClient.newPublishMessageCommand()).thenReturn(dummyCommand); + Map variables = Map.of("extractedId", "resolvedIdValue"); + // when + handler.correlate(definition, variables); + // then + verify(dummyCommand).messageId("resolvedIdValue"); + } + + @Test + void messageIdIsProvided_usesGivenMessageId() { + // given + var point = new MessageCorrelationPoint("msg1", "=correlationKey", null); + var definition = mock(InboundConnectorDefinitionImpl.class); + when(definition.correlationPoint()).thenReturn(point); + var dummyCommand = spy(new PublishMessageCommandDummy()); + when(zeebeClient.newPublishMessageCommand()).thenReturn(dummyCommand); + // when + handler.correlate(definition, Collections.emptyMap(), "providedIdValue"); + // then + verify(dummyCommand).messageId("providedIdValue"); + } + } }