Skip to content

Commit

Permalink
fix(InboundCorrelationHandler): fix resolveMessageId method
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksiivanov authored and igpetrov committed Oct 9, 2023
1 parent 7d424fd commit 921eb80
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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<String, Object> 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");
}
}
}

0 comments on commit 921eb80

Please sign in to comment.