@Test public void shouldRejectDeploymentIfUsedInvalidMessage() throws IOException { // given final BpmnModelInstance process = Bpmn.createExecutableProcess().startEvent().intermediateCatchEvent("invalidmessage").done(); // when final ExecuteCommandResponse resp = apiRule.partitionClient().deployWithResponse(process); // then assertThat(resp.getRecordType()).isEqualTo(RecordType.COMMAND_REJECTION); }
@Test public void shouldRejectDeploymentIfUsedInvalidMessage() throws IOException { // given final BpmnModelInstance process = Bpmn.createExecutableProcess().startEvent().intermediateCatchEvent("invalidmessage").done(); // when final ExecuteCommandResponse resp = apiRule.partitionClient().deployWithResponse(process); // then assertThat(resp.getRecordType()).isEqualTo(RecordType.COMMAND_REJECTION); }
@Override BpmnModelInstance modelInstance() { return Bpmn.createExecutableProcess(processId()) .startEvent() .intermediateCatchEvent(elementId()) .timerWithDuration("PT0.01S") .done(); } },
@Test public void shouldTriggerTimerWithNegativeDuration() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("-PT1H")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); }
@Override BpmnModelInstance modelInstance() { return Bpmn.createExecutableProcess(processId()) .startEvent() .intermediateCatchEvent(elementId()) .timerWithDuration("PT0.01S") .done(); } },
@Test public void shouldTriggerTimerWithZeroDuration() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT0S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); }
@Test public void shouldTriggerTimerWithZeroDuration() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT0S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); }
@Test public void shouldTriggerTimerWithNegativeDuration() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("-PT1H")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); }
@Override BpmnModelInstance modelInstance() { return Bpmn.createExecutableProcess(processId()) .startEvent() .intermediateCatchEvent(elementId()) .message(b -> b.name(messageName()).zeebeCorrelationKey("$.id")) .done(); }
@Override BpmnModelInstance modelInstance() { return Bpmn.createExecutableProcess(processId()) .startEvent() .intermediateCatchEvent(elementId()) .message(b -> b.name(messageName()).zeebeCorrelationKey("$.id")) .done(); }
@Test public void shouldCancelIntermediateCatchEvent() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("catch-event") .message(b -> b.name("msg").zeebeCorrelationKey("$.id")) .done()); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("id", "123")); testClient.receiveElementInState("catch-event", WorkflowInstanceIntent.EVENT_ACTIVATED); final ExecuteCommandResponse response = cancelWorkflowInstance(workflowInstanceKey); // then assertThat(response.getIntent()).isEqualTo(WorkflowInstanceIntent.ELEMENT_TERMINATING); final Record<WorkflowInstanceRecordValue> terminatedEvent = testClient.receiveElementInState(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_TERMINATED); assertWorkflowInstanceRecord(workflowInstanceKey, PROCESS_ID, terminatedEvent); }
@Test public void shouldCancelIntermediateCatchEvent() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("catch-event") .message(b -> b.name("msg").zeebeCorrelationKey("$.id")) .done()); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("id", "123")); testClient.receiveElementInState("catch-event", WorkflowInstanceIntent.ELEMENT_ACTIVATED); final ExecuteCommandResponse response = cancelWorkflowInstance(workflowInstanceKey); // then assertThat(response.getIntent()).isEqualTo(WorkflowInstanceIntent.ELEMENT_TERMINATING); final Record<WorkflowInstanceRecordValue> terminatedEvent = testClient.receiveElementInState(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_TERMINATED); assertWorkflowInstanceRecord(workflowInstanceKey, PROCESS_ID, terminatedEvent); }
@Test public void testLifeCycle() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT0S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()) .isTrue(); assertThat(RecordingExporter.workflowInstanceRecords().withElementId("timer").limit(5)) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.EVENT_ACTIVATING, WorkflowInstanceIntent.EVENT_ACTIVATED, WorkflowInstanceIntent.EVENT_OCCURRED, WorkflowInstanceIntent.EVENT_TRIGGERING, WorkflowInstanceIntent.EVENT_TRIGGERED); assertThat(RecordingExporter.timerRecords().limit(4)) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( TimerIntent.CREATE, TimerIntent.CREATED, TimerIntent.TRIGGER, TimerIntent.TRIGGERED); }
@Test public void testLifeCycle() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT0S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withElementId(PROCESS_ID) .exists()) .isTrue(); assertThat(RecordingExporter.workflowInstanceRecords().withElementId("timer").limit(5)) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.ELEMENT_ACTIVATING, WorkflowInstanceIntent.ELEMENT_ACTIVATED, WorkflowInstanceIntent.EVENT_OCCURRED, WorkflowInstanceIntent.ELEMENT_COMPLETING, WorkflowInstanceIntent.ELEMENT_COMPLETED); assertThat(RecordingExporter.timerRecords().limit(4)) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( TimerIntent.CREATE, TimerIntent.CREATED, TimerIntent.TRIGGER, TimerIntent.TRIGGERED); }
@Before public void setUp() { streamProcessor = streamProcessorRule.getStreamProcessor(); // given streamProcessorRule.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT10S")) .endEvent() .done()); streamProcessor.blockAfterTimerEvent(r -> r.getMetadata().getIntent() == TimerIntent.CREATED); streamProcessorRule.createWorkflowInstance(PROCESS_ID); waitUntil(() -> streamProcessor.isBlocked()); }
@Before public void setUp() { streamProcessor = streamProcessorRule.getStreamProcessor(); // given streamProcessorRule.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT10S")) .endEvent() .done()); streamProcessor.blockAfterTimerEvent(r -> r.getMetadata().getIntent() == TimerIntent.CREATED); streamProcessorRule.createWorkflowInstance(PROCESS_ID); waitUntil(() -> streamProcessor.isBlocked()); }
@Test public void shouldCreateTimer() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT10S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("timer") .getFirst(); // then final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); Assertions.assertThat(createdEvent.getValue()).hasElementInstanceKey(activatedEvent.getKey()); assertThat(createdEvent.getValue().getDueDate()) .isGreaterThan(brokerRule.getClock().getCurrentTimeInMillis()); }
@Test public void shouldCreateTimer() { // given final BpmnModelInstance workflow = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .intermediateCatchEvent("timer", c -> c.timerWithDuration("PT10S")) .endEvent() .done(); testClient.deploy(workflow); testClient.createWorkflowInstance(PROCESS_ID); // when final Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_ACTIVATED) .withElementId("timer") .getFirst(); // then final Record<TimerRecordValue> createdEvent = RecordingExporter.timerRecords(TimerIntent.CREATED).getFirst(); Assertions.assertThat(createdEvent.getValue()).hasElementInstanceKey(activatedEvent.getKey()); assertThat(createdEvent.getValue().getDueDate()) .isGreaterThan(brokerRule.getClock().getCurrentTimeInMillis()); }
@Test public void shouldUpdatePayloadWhenCatchEventIsEntered() { // given testClient.deploy( Bpmn.createExecutableProcess("wf") .startEvent() .intermediateCatchEvent("catch-event") .message(b -> b.name("msg").zeebeCorrelationKey("$.id")) .done()); testClient.createWorkflowInstance("wf", asMsgPack("id", "123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.ELEMENT_ACTIVATED); // when updatePayload( catchEventEntered.getKey(), MsgPackUtil.asMsgPackReturnArray("{'id':'123', 'x': 1}")); testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.PAYLOAD_UPDATED); testClient.publishMessage("msg", "123", asMsgPack("y", 2)); // then final Record<WorkflowInstanceRecordValue> catchEventOccurred = testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.ELEMENT_COMPLETED); assertWorkflowInstancePayload(catchEventOccurred, "{'id':'123', 'x': 1, 'y': 2}"); }
@Test public void shouldUpdatePayloadWhenCatchEventIsEntered() { // given testClient.deploy( Bpmn.createExecutableProcess("wf") .startEvent() .intermediateCatchEvent("catch-event") .message(b -> b.name("msg").zeebeCorrelationKey("$.id")) .done()); testClient.createWorkflowInstance("wf", asMsgPack("id", "123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveFirstWorkflowInstanceEvent( WorkflowInstanceIntent.ELEMENT_ACTIVATED, BpmnElementType.INTERMEDIATE_CATCH_EVENT); // when updatePayload( catchEventEntered.getKey(), MsgPackUtil.asMsgPackReturnArray("{'id':'123', 'x': 1}")); testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.PAYLOAD_UPDATED); testClient.publishMessage("msg", "123", asMsgPack("y", 2)); // then final Record<WorkflowInstanceRecordValue> catchEventOccurred = testClient.receiveFirstWorkflowInstanceEvent( WorkflowInstanceIntent.ELEMENT_COMPLETED, BpmnElementType.INTERMEDIATE_CATCH_EVENT); assertWorkflowInstancePayload(catchEventOccurred, "{'id':'123', 'x': 1, 'y': 2}"); }