private void addInputOutputMappingToTask(YamlTask task, ServiceTaskBuilder serviceTaskBuilder) { final String outputBehaviorString = task.getOutputBehavior(); final ZeebeOutputBehavior outputBehavior; try { outputBehavior = ZeebeOutputBehavior.valueOf(outputBehaviorString.toLowerCase()); } catch (IllegalArgumentException e) { throw new RuntimeException( String.format( "Expected output behavior to be one of %s, but actual output behavior was '%s'", outputBehaviorString, Arrays.toString(ZeebeOutputBehavior.values()))); } serviceTaskBuilder.zeebeOutputBehavior(outputBehavior); for (YamlMapping inputMapping : task.getInputs()) { serviceTaskBuilder.zeebeInput(inputMapping.getSource(), inputMapping.getTarget()); } for (YamlMapping outputMapping : task.getOutputs()) { serviceTaskBuilder.zeebeOutput(outputMapping.getSource(), outputMapping.getTarget()); } } }
@Test public void shouldCreateIncidentForOutputMappingAndNoTaskCompletePayload() { // given testClient.deploy( Bpmn.createExecutableProcess("process") .startEvent() .serviceTask( "failingTask", t -> t.zeebeTaskType("external").zeebeOutput("$.testAttr", "$")) .done()); testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD); // when testClient.completeJobOfType("external"); // then incident is created final Record incidentEvent = testClient.receiveFirstIncidentEvent(IncidentIntent.CREATED); assertThat(incidentEvent.getKey()).isGreaterThan(0); assertIncidentContainErrorDetails(incidentEvent, "No data found for query $.testAttr."); }
@Test public void shouldCreateIncidentForOutputMappingAndNoTaskCompletePayload() { // given testClient.deploy( Bpmn.createExecutableProcess("process") .startEvent() .serviceTask( "failingTask", t -> t.zeebeTaskType("external").zeebeOutput("$.testAttr", "$")) .done()); testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD); // when testClient.completeJobOfType("external"); // then incident is created final Record incidentEvent = testClient.receiveFirstIncidentEvent(IncidentIntent.CREATED); assertThat(incidentEvent.getKey()).isGreaterThan(0); assertIncidentContainErrorDetails(incidentEvent, "No data found for query $.testAttr."); }
private void addInputOutputMappingToTask(YamlTask task, ServiceTaskBuilder serviceTaskBuilder) { final String outputBehaviorString = task.getOutputBehavior(); final ZeebeOutputBehavior outputBehavior; try { outputBehavior = ZeebeOutputBehavior.valueOf(outputBehaviorString.toLowerCase()); } catch (IllegalArgumentException e) { throw new RuntimeException( String.format( "Expected output behavior to be one of %s, but actual output behavior was '%s'", outputBehaviorString, Arrays.toString(ZeebeOutputBehavior.values()))); } serviceTaskBuilder.zeebeOutputBehavior(outputBehavior); for (YamlMapping inputMapping : task.getInputs()) { serviceTaskBuilder.zeebeInput(inputMapping.getSource(), inputMapping.getTarget()); } for (YamlMapping outputMapping : task.getOutputs()) { serviceTaskBuilder.zeebeOutput(outputMapping.getSource(), outputMapping.getTarget()); } } }
@Test public void shouldCreateIncidentForInAndOutputMappingAndNoTaskCompletePayload() { // given testClient.deploy( Bpmn.createExecutableProcess("process") .startEvent() .serviceTask( "failingTask", t -> t.zeebeTaskType("external") .zeebeInput("$.jsonObject", "$") .zeebeOutput("$.foo", "$")) .done()); testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD); // when testClient.completeJobOfType("external"); // then incident is created final Record incidentEvent = testClient.receiveFirstIncidentEvent(IncidentIntent.CREATED); assertThat(incidentEvent.getKey()).isGreaterThan(0); assertIncidentContainErrorDetails(incidentEvent, "No data found for query $.foo."); }
@Test public void shouldCreateIncidentForInAndOutputMappingAndNoTaskCompletePayload() { // given testClient.deploy( Bpmn.createExecutableProcess("process") .startEvent() .serviceTask( "failingTask", t -> t.zeebeTaskType("external") .zeebeInput("$.jsonObject", "$") .zeebeOutput("$.foo", "$")) .done()); testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD); // when testClient.completeJobOfType("external"); // then incident is created final Record incidentEvent = testClient.receiveFirstIncidentEvent(IncidentIntent.CREATED); assertThat(incidentEvent.getKey()).isGreaterThan(0); assertIncidentContainErrorDetails(incidentEvent, "No data found for query $.foo."); }
@Test public void shouldCreateIncidentForInvalidResultOnOutputMapping() { // given testClient.deploy( Bpmn.createExecutableProcess("process") .startEvent() .serviceTask( "failingTask", t -> t.zeebeTaskType("external") .zeebeInput("$.jsonObject", "$") .zeebeOutput("$.testAttr", "$")) .done()); testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD); // when testClient.completeJobOfType( "external", MsgPackUtil.asMsgPackReturnArray("{'testAttr':'test'}")); testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.ELEMENT_ACTIVATED); // then incident is created final Record incidentEvent = testClient.receiveFirstIncidentEvent(IncidentIntent.CREATED); assertThat(incidentEvent.getKey()).isGreaterThan(0); assertIncidentContainErrorDetails(incidentEvent); }
@Test public void shouldCreateIncidentForInvalidResultOnOutputMapping() { // given testClient.deploy( Bpmn.createExecutableProcess("process") .startEvent() .serviceTask( "failingTask", t -> t.zeebeTaskType("external") .zeebeInput("$.jsonObject", "$") .zeebeOutput("$.testAttr", "$")) .done()); testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD); // when testClient.completeJobOfType( "external", MsgPackUtil.asMsgPackReturnArray("{'testAttr':'test'}")); testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.ELEMENT_ACTIVATED); // then incident is created final Record incidentEvent = testClient.receiveFirstIncidentEvent(IncidentIntent.CREATED); assertThat(incidentEvent.getKey()).isGreaterThan(0); assertIncidentContainErrorDetails(incidentEvent); }
Bpmn.createExecutableProcess("process") .startEvent() .serviceTask("service", t -> t.zeebeTaskType("external").zeebeOutput("$.testAttr", "$")) .done());
t.zeebeTaskType("external") .zeebeInput("$.jsonObject", "$") .zeebeOutput("$.foo", "$")) .done());
Bpmn.createExecutableProcess("process") .startEvent() .serviceTask("service", t -> t.zeebeTaskType("external").zeebeOutput("$.testAttr", "$")) .done());
t.zeebeTaskType("external") .zeebeInput("$.jsonObject", "$") .zeebeOutput("$.foo", "$")) .done());
t.zeebeTaskType("external") .zeebeInput("$.jsonObject", "$") .zeebeOutput("$.testAttr", "$")) .done());
t.zeebeTaskType("external") .zeebeInput("$.jsonObject", "$") .zeebeOutput("$.testAttr", "$")) .done());
@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()) .hasScopeKey(workflowInstanceKey) .hasName("y") .hasValue("2"); }
@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"); }
@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()) .hasScopeKey(workflowInstanceKey) .hasName("y") .hasValue("1"); }
@Test public void shouldNotCompleteInstanceAfterIncidentIsRaisedOnActivity() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .serviceTask("task-2", t -> t.zeebeTaskType("task-2").zeebeOutput("$.result", "$.r")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-2"); final Record<IncidentRecordValue> incident = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); testClient.completeJobOfType("task-1"); testClient.updatePayload(incident.getValue().getElementInstanceKey(), "{'result':'123'}"); testClient.resolveIncident(incident.getKey()); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldNotCompleteInstanceAfterIncidentIsRaisedOnActivity() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .serviceTask("task-2", t -> t.zeebeTaskType("task-2").zeebeOutput("$.result", "$.r")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-2"); final Record<IncidentRecordValue> incident = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); testClient.completeJobOfType("task-1"); testClient.updatePayload(incident.getValue().getElementInstanceKey(), "{'result':'123'}"); testClient.resolveIncident(incident.getKey()); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.ELEMENT_COMPLETED); }