@Test public void shouldCreateVariableByWorkflowInstanceCreation() { // given testClient.deploy(WORKFLOW); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, "{'x':1}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.CREATED).getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("x") .hasValue("1"); }
@Test public void shouldWriteVariableCreatedEvent() { // given testClient.deploy(WORKFLOW); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, payload); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.CREATED).getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("x") .hasValue(expectedValue); } }
@Test public void shouldUpdateVariableByUpdatePayload() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, "{'x':1}"); // when testClient.updatePayload(workflowInstanceKey, "{'x':2}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.UPDATED).getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("x") .hasValue("2"); }
@Test public void shouldCreateVariableByUpdatePayload() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // when testClient.updatePayload(workflowInstanceKey, "{'x':1}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.CREATED).getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("x") .hasValue("1"); }
@Test public void shouldMergeMessagePayloadByDefault() { // given deployWorkflowWithMapping(e -> {}); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, "{'key': 'order-66'}"); // when testClient.publishMessage("message", "order-66", "{'foo': 'bar'}"); // then final Record<VariableRecordValue> variableEvent = RecordingExporter.variableRecords().withName("foo").getFirst(); Assertions.assertThat(variableEvent.getValue()) .hasValue("\"bar\"") .hasScopeInstanceKey(workflowInstanceKey); }
@Test public void shouldCreateVariableByJobCompletion() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("test", "{'x':1}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.CREATED).getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("x") .hasValue("1"); }
@Test public void shouldUpdateVariableByJobCompletion() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, "{'x':1}"); // when testClient.completeJobOfType("test", "{'x':2}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.UPDATED).getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("x") .hasValue("2"); }
@Test public void shouldMapMessagePayloadIntoInstancePayload() { // given deployWorkflowWithMapping(e -> e.zeebeOutput("$.foo", "$.message")); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, "{'key': 'order-66'}"); // when testClient.publishMessage("message", "order-66", "{'foo': 'bar'}"); // then final Record<VariableRecordValue> variableEvent = RecordingExporter.variableRecords().withName("message").getFirst(); Assertions.assertThat(variableEvent.getValue()) .hasValue("\"bar\"") .hasScopeInstanceKey(workflowInstanceKey); }
@Test public void shouldMergeMessagePayload() { // given deployWorkflowWithMapping(e -> e.zeebeOutputBehavior(ZeebeOutputBehavior.merge)); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, "{'key': 'order-66'}"); // when testClient.publishMessage("message", "order-66", "{'foo': 'bar'}"); // then final Record<VariableRecordValue> variableEvent = RecordingExporter.variableRecords().withName("foo").getFirst(); Assertions.assertThat(variableEvent.getValue()) .hasValue("\"bar\"") .hasScopeInstanceKey(workflowInstanceKey); }
@Test public void shouldUpdateVariableByOutputMapping() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("task", t -> t.zeebeTaskType("test").zeebeOutput("$.x", "$.y")) .endEvent() .done()); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, "{'y':1}"); // when testClient.completeJobOfType("test", "{'x':2}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.UPDATED).getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("y") .hasValue("2"); }
@Test public void shouldCreateVariableByOutputMapping() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("task", t -> t.zeebeTaskType("test").zeebeOutput("$.x", "$.y")) .endEvent() .done()); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("test", "{'x':1}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.CREATED).withName("y").getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("y") .hasValue("1"); }