-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(engine): implement test for #9143
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...t/java/io/camunda/zeebe/engine/processing/bpmn/behavior/OutputCollectionBehaviorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under | ||
* one or more contributor license agreements. See the NOTICE file distributed | ||
* with this work for additional information regarding copyright ownership. | ||
* Licensed under the Zeebe Community License 1.1. You may not use this file | ||
* except in compliance with the Zeebe Community License 1.1. | ||
*/ | ||
package io.camunda.zeebe.engine.processing.bpmn.behavior; | ||
|
||
import static io.camunda.zeebe.util.buffer.BufferUtil.cloneBuffer; | ||
import static io.camunda.zeebe.util.buffer.BufferUtil.wrapString; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.camunda.zeebe.el.Expression; | ||
import io.camunda.zeebe.el.impl.StaticExpression; | ||
import io.camunda.zeebe.engine.processing.bpmn.BpmnElementContext; | ||
import io.camunda.zeebe.engine.processing.common.ExpressionProcessor; | ||
import io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableLoopCharacteristics; | ||
import io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMultiInstanceBody; | ||
import io.camunda.zeebe.msgpack.spec.MsgPackWriter; | ||
import io.camunda.zeebe.util.Either; | ||
import java.util.Optional; | ||
import org.agrona.DirectBuffer; | ||
import org.agrona.ExpandableArrayBuffer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Answers; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class OutputCollectionBehaviorTest { | ||
|
||
@Test // regression test for #9143 | ||
void shouldRaiseIncidentWhenOverwritingOutputCollectionWithLessElements() { | ||
// given | ||
final var collectionWithSize1 = createCollection(1); | ||
final var elementToAdd = wrapString("element to add"); | ||
final var indexThatIsOutOfBounds = 2; | ||
final var outputElementsExpression = new StaticExpression("OUTPUT_COLLECTION"); | ||
final var outputElementName = wrapString("OUTPUT_ELEMENT"); | ||
final var loopCharacteristics = | ||
createLoopCharacteristics(outputElementName, outputElementsExpression); | ||
|
||
final var mockStateBehavior = mock(BpmnStateBehavior.class, Answers.RETURNS_DEEP_STUBS); | ||
when(mockStateBehavior.getLocalVariable(any(), eq(outputElementName))) | ||
.thenReturn(collectionWithSize1); | ||
|
||
final var mockExpressionProcessor = mock(ExpressionProcessor.class); | ||
when(mockExpressionProcessor.evaluateAnyExpression(eq(outputElementsExpression), anyLong())) | ||
.thenReturn(Either.right(elementToAdd)); | ||
|
||
final var mockElement = mock(ExecutableMultiInstanceBody.class); | ||
when(mockElement.getLoopCharacteristics()).thenReturn(loopCharacteristics); | ||
|
||
final var mockChildContext = mock(BpmnElementContext.class); | ||
when(mockStateBehavior.getElementInstance(mockChildContext).getMultiInstanceLoopCounter()) | ||
.thenReturn(indexThatIsOutOfBounds); | ||
|
||
final var sut = new OutputCollectionBehavior(mockStateBehavior, mockExpressionProcessor); | ||
|
||
// when | ||
final var result = sut.updateOutputCollection(mockElement, mockChildContext, null); | ||
|
||
// then | ||
assertThat(result.isLeft()).isTrue(); | ||
|
||
// final var failure = result.getLeft(); | ||
// TODO ass assertions on failure | ||
} | ||
|
||
private ExecutableLoopCharacteristics createLoopCharacteristics( | ||
final DirectBuffer outputElementName, final Expression outputElementExpression) { | ||
return new ExecutableLoopCharacteristics( | ||
false, | ||
Optional.empty(), | ||
null, | ||
Optional.empty(), | ||
Optional.of(outputElementName), | ||
Optional.of(outputElementExpression)); | ||
} | ||
|
||
private DirectBuffer createCollection(final int size) { | ||
final var writer = new MsgPackWriter(); | ||
final var buffer = new ExpandableArrayBuffer(); | ||
|
||
writer.wrap(buffer, 0); | ||
|
||
// initialize the array with nil | ||
writer.writeArrayHeader(size); | ||
for (var i = 0; i < size; i++) { | ||
writer.writeNil(); | ||
} | ||
|
||
final var length = writer.getOffset(); | ||
|
||
return cloneBuffer(buffer, 0, length); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
engine/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mock-maker-inline |