Search in sources :

Example 1 with ProcessInstanceRecordValue

use of io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue in project zeebe-process-test by camunda.

the class ProcessInstanceAssert method isWaitingExactlyAtElements.

/**
 * Verifies the expectation that the process instance is currently waiting at the specified
 * elements, and not at any other element.
 *
 * @param elementIdsVarArg The ids of the elements
 * @return this {@link ProcessInstanceAssert}
 */
public ProcessInstanceAssert isWaitingExactlyAtElements(final String... elementIdsVarArg) {
    final List<String> elementIds = Arrays.asList(elementIdsVarArg);
    final Set<String> elementsInWaitState = getElementsInWaitState();
    final List<String> wrongfullyWaitingElementIds = new ArrayList<>();
    final List<String> wrongfullyNotWaitingElementIds = new ArrayList<>();
    StreamFilter.processInstance(recordStream).withProcessInstanceKey(actual).withRejectionType(RejectionType.NULL_VAL).withoutBpmnElementType(BpmnElementType.PROCESS).withIntent(ProcessInstanceIntent.ELEMENT_ACTIVATED).stream().map(Record::getValue).map(ProcessInstanceRecordValue::getElementId).distinct().forEach(id -> {
        final boolean shouldBeWaitingAtElement = elementIds.contains(id);
        final boolean isWaitingAtElement = elementsInWaitState.contains(id);
        if (shouldBeWaitingAtElement && !isWaitingAtElement) {
            wrongfullyNotWaitingElementIds.add(id);
        } else if (!shouldBeWaitingAtElement && isWaitingAtElement) {
            wrongfullyWaitingElementIds.add(id);
        }
    });
    final SoftAssertions softly = new SoftAssertions();
    softly.assertThat(wrongfullyWaitingElementIds.isEmpty()).withFailMessage("Process with key %s is waiting at element(s) with id(s) %s", actual, String.join(", ", wrongfullyWaitingElementIds)).isTrue();
    softly.assertThat(wrongfullyNotWaitingElementIds.isEmpty()).withFailMessage("Process with key %s is not waiting at element(s) with id(s) %s", actual, String.join(", ", wrongfullyNotWaitingElementIds)).isTrue();
    softly.assertAll();
    return this;
}
Also used : ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) SoftAssertions(org.assertj.core.api.SoftAssertions) ArrayList(java.util.ArrayList)

Example 2 with ProcessInstanceRecordValue

use of io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue in project zeebe-exporter-protobuf by camunda-community-hub.

the class RecordTransformTest method shouldTransformWorkflowInstance.

@Test
public void shouldTransformWorkflowInstance() {
    // given
    final ProcessInstanceRecordValue workflowInstanceRecordValue = mockProcessInstanceRecordValue();
    final Record<ProcessInstanceRecordValue> mockedRecord = mockRecord(workflowInstanceRecordValue, ValueType.PROCESS_INSTANCE, ProcessInstanceIntent.ELEMENT_ACTIVATED);
    // when
    final Schema.ProcessInstanceRecord workflowInstance = (Schema.ProcessInstanceRecord) RecordTransformer.toProtobufMessage(mockedRecord);
    // then
    assertMetadata(workflowInstance.getMetadata(), "PROCESS_INSTANCE", "ELEMENT_ACTIVATED");
    assertThat(workflowInstance.getBpmnProcessId()).isEqualTo("process");
    assertThat(workflowInstance.getElementId()).isEqualTo("startEvent");
    assertThat(workflowInstance.getProcessDefinitionKey()).isEqualTo(4L);
    assertThat(workflowInstance.getVersion()).isEqualTo(1);
    assertThat(workflowInstance.getProcessInstanceKey()).isEqualTo(1L);
    assertThat(workflowInstance.getFlowScopeKey()).isEqualTo(-1L);
    assertThat(workflowInstance.getBpmnElementType()).isEqualTo("START_EVENT");
    assertThat(workflowInstance.getParentProcessInstanceKey()).isEqualTo(-1L);
    assertThat(workflowInstance.getParentElementInstanceKey()).isEqualTo(-1L);
}
Also used : ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) Test(org.junit.Test)

Example 3 with ProcessInstanceRecordValue

use of io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue in project zeebe-exporter-protobuf by camunda-community-hub.

the class RecordTransformTest method mockProcessInstanceRecordValue.

private ProcessInstanceRecordValue mockProcessInstanceRecordValue() {
    final ProcessInstanceRecordValue workflowInstanceRecordValue = mock(ProcessInstanceRecordValue.class);
    when(workflowInstanceRecordValue.getProcessInstanceKey()).thenReturn(1L);
    when(workflowInstanceRecordValue.getBpmnProcessId()).thenReturn("process");
    when(workflowInstanceRecordValue.getElementId()).thenReturn("startEvent");
    when(workflowInstanceRecordValue.getFlowScopeKey()).thenReturn(-1L);
    when(workflowInstanceRecordValue.getVersion()).thenReturn(1);
    when(workflowInstanceRecordValue.getProcessDefinitionKey()).thenReturn(4L);
    when(workflowInstanceRecordValue.getBpmnElementType()).thenReturn(BpmnElementType.START_EVENT);
    when(workflowInstanceRecordValue.getParentProcessInstanceKey()).thenReturn(-1L);
    when(workflowInstanceRecordValue.getParentElementInstanceKey()).thenReturn(-1L);
    return workflowInstanceRecordValue;
}
Also used : ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue)

Example 4 with ProcessInstanceRecordValue

use of io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue in project zeebe by camunda.

the class MessageCorrelationTest method shouldCorrelateFirstPublishedMessage.

@Test
public void shouldCorrelateFirstPublishedMessage() {
    // given
    engine.deployment().withXmlResource(SINGLE_MESSAGE_PROCESS).deploy();
    final PublishMessageClient messageClient = engine.message().withName("message").withCorrelationKey("order-123");
    messageClient.withVariables(asMsgPack("nr", 1)).publish();
    messageClient.withVariables(asMsgPack("nr", 2)).publish();
    // when
    final long processInstanceKey = engine.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable("key", "order-123").create();
    // then
    final Record<ProcessInstanceRecordValue> event = RecordingExporter.processInstanceRecords().withElementType(BpmnElementType.PROCESS).withIntent(ProcessInstanceIntent.ELEMENT_COMPLETED).getFirst();
    final Map<String, String> variables = ProcessInstances.getCurrentVariables(processInstanceKey, event.getPosition());
    assertThat(variables).containsOnly(entry("key", "\"order-123\""), entry("nr", "1"));
}
Also used : PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) Test(org.junit.Test)

Example 5 with ProcessInstanceRecordValue

use of io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue in project zeebe by camunda.

the class MappingIncidentTest method shouldResolveIncidentForInputMappingFailure.

@Test
public void shouldResolveIncidentForInputMappingFailure() {
    // given
    ENGINE.deployment().withXmlResource(PROCESS_INPUT_MAPPING).deploy();
    final long processInstanceKey = ENGINE.processInstance().ofBpmnProcessId("process").create();
    final Record<ProcessInstanceRecordValue> failureEvent = RecordingExporter.processInstanceRecords().withElementId("failingTask").withIntent(ProcessInstanceIntent.ELEMENT_ACTIVATING).withProcessInstanceKey(processInstanceKey).getFirst();
    final Record<IncidentRecordValue> incidentEvent = RecordingExporter.incidentRecords().withIntent(IncidentIntent.CREATED).withProcessInstanceKey(processInstanceKey).getFirst();
    // when
    ENGINE.variables().ofScope(failureEvent.getValue().getFlowScopeKey()).withDocument(VARIABLES).update();
    final Record<IncidentRecordValue> incidentResolvedEvent = ENGINE.incident().ofInstance(processInstanceKey).withKey(incidentEvent.getKey()).resolve();
    // then
    final Record<ProcessInstanceRecordValue> followUpEvent = RecordingExporter.processInstanceRecords().withElementId("failingTask").withIntent(ProcessInstanceIntent.ELEMENT_ACTIVATED).withProcessInstanceKey(processInstanceKey).getFirst();
    final Record incidentResolveCommand = RecordingExporter.incidentRecords().withIntent(RESOLVE).withRecordKey(incidentEvent.getKey()).getFirst();
    assertThat(incidentResolvedEvent.getKey()).isEqualTo(incidentEvent.getKey());
    assertThat(incidentResolveCommand.getPosition()).isEqualTo(followUpEvent.getSourceRecordPosition());
    assertThat(incidentResolveCommand.getPosition()).isEqualTo(incidentResolvedEvent.getSourceRecordPosition());
    Assertions.assertThat(incidentResolvedEvent.getValue()).hasErrorType(ErrorType.IO_MAPPING_ERROR).hasBpmnProcessId("process").hasProcessInstanceKey(processInstanceKey).hasElementId("failingTask").hasElementInstanceKey(failureEvent.getKey()).hasVariableScopeKey(failureEvent.getKey());
    assertThat(incidentEvent.getValue().getErrorMessage()).contains("no variable found for name 'foo'");
}
Also used : ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) Record(io.camunda.zeebe.protocol.record.Record) Test(org.junit.Test)

Aggregations

ProcessInstanceRecordValue (io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue)95 Test (org.junit.Test)79 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)63 Record (io.camunda.zeebe.protocol.record.Record)50 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)44 ProcessInstanceIntent (io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent)44 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)44 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)44 List (java.util.List)41 EngineRule (io.camunda.zeebe.engine.util.EngineRule)36 RecordingExporter (io.camunda.zeebe.test.util.record.RecordingExporter)36 Assertions.tuple (org.assertj.core.api.Assertions.tuple)36 Rule (org.junit.Rule)36 Collectors (java.util.stream.Collectors)35 TimerIntent (io.camunda.zeebe.protocol.record.intent.TimerIntent)20 Duration (java.time.Duration)20 JobIntent (io.camunda.zeebe.protocol.record.intent.JobIntent)17 TimerRecordValue (io.camunda.zeebe.protocol.record.value.TimerRecordValue)17 Map (java.util.Map)17 IncidentRecordValue (io.camunda.zeebe.protocol.record.value.IncidentRecordValue)15