Skip to content

Commit

Permalink
#4 implementation and test case (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noordsestern authored Aug 26, 2021
1 parent d3a96f8 commit 8f1761d
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 10 deletions.
24 changes: 23 additions & 1 deletion CamundaLibrary/CamundaLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,32 @@ def get_fetch_response(self):
return self.FETCH_RESPONSE.to_dict()
return self.FETCH_RESPONSE

@keyword("Drop fetch response")
@keyword("Drop fetch response", tags=['task'])
def drop_fetch_response(self):
self.FETCH_RESPONSE = {}

@keyword("Throw BPMN Error", tags=['task'])
def bpmn_error(self, error_code: str, error_message:str = None, variables: Dict[str, Any] = None, files: Dict = None):
if not self.FETCH_RESPONSE:
logger.warn('No task to complete. Maybe you did not fetch and lock a workitem before?')
else:
with self._shared_resources.api_client as api_client:
api_instance = openapi_client.ExternalTaskApi(api_client)
variables = CamundaResources.convert_dict_to_openapi_variables(variables)
openapi_files = CamundaResources.convert_file_dict_to_openapi_variables(files)
variables.update(openapi_files)
bpmn_error = openapi_client.ExternalTaskBpmnError(worker_id=self.WORKER_ID,
error_message=error_message,
error_code=error_code,
variables=variables)
try:
logger.debug(f"Sending BPMN error for task:\n{bpmn_error}")
api_instance.handle_external_task_bpmn_error(self.FETCH_RESPONSE.id,
external_task_bpmn_error=bpmn_error)
self.drop_fetch_response()
except ApiException as e:
logger.error(f"Exception when calling ExternalTaskApi->handle_external_task_bpmn_error: {e}\n")

@keyword("Complete task", tags=['task'])
def complete(self, result_set: Dict[str, Any] = None, files: Dict = None):
"""
Expand Down
50 changes: 41 additions & 9 deletions tests/bpmn/demo_for_robot.bpmn
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0qiqts0" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0qiqts0" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.9.0">
<bpmn:collaboration id="Collaboration_0p8xj2y">
<bpmn:participant id="Participant_0sda6b4" name="Demo Robot" processRef="demo_for_robot" />
</bpmn:collaboration>
<bpmn:process id="demo_for_robot" name="Demo Prozess für Robot Framework library" isExecutable="true" camunda:versionTag="0.1">
<bpmn:startEvent id="StartEvent_1" name="Trigger received">
<bpmn:outgoing>Flow_0xskn85</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:serviceTask id="Activity_service_1" name="Process element" camunda:type="external" camunda:topic="process_demo_element">
<bpmn:serviceTask id="Activity_process_element" name="Process element" camunda:type="external" camunda:topic="process_demo_element">
<bpmn:incoming>Flow_0xskn85</bpmn:incoming>
<bpmn:outgoing>Flow_1m77rg0</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:userTask id="Activity_user_1" name="Do something manually" camunda:formKey="embedded:deployment:embeddedSampleForm.html">
<bpmn:userTask id="Activity_manual" name="Do something manually" camunda:formKey="embedded:deployment:embeddedSampleForm.html">
<bpmn:incoming>Flow_1m77rg0</bpmn:incoming>
<bpmn:outgoing>Flow_0thahmr</bpmn:outgoing>
</bpmn:userTask>
<bpmn:endEvent id="Event_06qztq3">
<bpmn:incoming>Flow_0thahmr</bpmn:incoming>
<bpmn:incoming>Flow_0uflgxn</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0xskn85" sourceRef="StartEvent_1" targetRef="Activity_service_1" />
<bpmn:sequenceFlow id="Flow_1m77rg0" sourceRef="Activity_service_1" targetRef="Activity_user_1" />
<bpmn:sequenceFlow id="Flow_0thahmr" sourceRef="Activity_user_1" targetRef="Event_06qztq3" />
<bpmn:sequenceFlow id="Flow_0xskn85" sourceRef="StartEvent_1" targetRef="Activity_process_element" />
<bpmn:sequenceFlow id="Flow_1m77rg0" sourceRef="Activity_process_element" targetRef="Activity_manual" />
<bpmn:sequenceFlow id="Flow_0thahmr" sourceRef="Activity_manual" targetRef="Event_06qztq3" />
<bpmn:boundaryEvent id="Event_demo_error" name="An Error occured" attachedToRef="Activity_process_element">
<bpmn:outgoing>Flow_0jgdhq6</bpmn:outgoing>
<bpmn:errorEventDefinition id="ErrorEventDefinition_1kugatc" errorRef="Error_19xhp28" camunda:errorCodeVariable="error_code" camunda:errorMessageVariable="error_message" />
</bpmn:boundaryEvent>
<bpmn:sequenceFlow id="Flow_0jgdhq6" sourceRef="Event_demo_error" targetRef="Activity_error_handling" />
<bpmn:sequenceFlow id="Flow_0uflgxn" sourceRef="Activity_error_handling" targetRef="Event_06qztq3" />
<bpmn:serviceTask id="Activity_error_handling" name="Do error handling" camunda:type="external" camunda:topic="handle_error">
<bpmn:incoming>Flow_0jgdhq6</bpmn:incoming>
<bpmn:outgoing>Flow_0uflgxn</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
<bpmn:error id="Error_19xhp28" name="demo_error" errorCode="de1" camunda:errorMessage="An error occured during demo" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0p8xj2y">
<bpmndi:BPMNShape id="Participant_0sda6b4_di" bpmnElement="Participant_0sda6b4" isHorizontal="true">
<dc:Bounds x="129" y="57" width="600" height="250" />
<dc:Bounds x="129" y="57" width="661" height="393" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0thahmr_di" bpmnElement="Flow_0thahmr">
<di:waypoint x="560" y="170" />
Expand All @@ -39,21 +51,41 @@
<di:waypoint x="245" y="170" />
<di:waypoint x="300" y="170" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0jgdhq6_di" bpmnElement="Flow_0jgdhq6">
<di:waypoint x="350" y="228" />
<di:waypoint x="350" y="320" />
<di:waypoint x="460" y="320" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0uflgxn_di" bpmnElement="Flow_0uflgxn">
<di:waypoint x="560" y="320" />
<di:waypoint x="591" y="320" />
<di:waypoint x="591" y="170" />
<di:waypoint x="622" y="170" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="209" y="152" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="188" y="195" width="79" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0qv44sp_di" bpmnElement="Activity_service_1">
<bpmndi:BPMNShape id="Activity_0qv44sp_di" bpmnElement="Activity_process_element">
<dc:Bounds x="300" y="130" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1cxrwut_di" bpmnElement="Activity_user_1">
<bpmndi:BPMNShape id="Activity_1cxrwut_di" bpmnElement="Activity_manual">
<dc:Bounds x="460" y="130" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_06qztq3_di" bpmnElement="Event_06qztq3">
<dc:Bounds x="622" y="152" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0de9uw5_di" bpmnElement="Activity_error_handling">
<dc:Bounds x="460" y="280" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1ar6zj2_di" bpmnElement="Event_demo_error">
<dc:Bounds x="332" y="192" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="258" y="247" width="83" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
37 changes: 37 additions & 0 deletions tests/robot/ExternalTask/test_bpmn_error.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*** Settings ***
Library CamundaLibrary ${CAMUNDA_HOST}
Resource ../cleanup.resource
Test Setup Delete all instances from process '${PROCESS_DEFINITION_KEY}'

*** Variables ***
${CAMUNDA_HOST} http://localhost:8080
${PROCESS_DEFINITION_KEY} demo_for_robot
${EXISTING_TOPIC} process_demo_element

*** Variables ***
${CAMUNDA_HOST} http://localhost:8080

*** Test Cases ***
BPMN error without task does not fail
# only throws a warning
throw bpmn error de1

Test 'fetch and lock' for existing topic
[Setup] set camunda url ${CAMUNDA_HOST}
# GIVEN
Start process ${PROCESS_DEFINITION_KEY}
${variables} Create Dictionary text=Manna Manna

# AND
${work_items} fetch workload topic=${existing_topic}

# WHEN
throw bpmn error de1 Alles kaputt variables=${variables}

# THEN
${workload} Fetch Workload handle_error
Should Not Be Empty ${workload}

Should Be Equal As Strings Manna Manna ${workload}[text]
Should Be Equal As Strings de1 ${workload}[error_code]
Should Be Equal As Strings Alles kaputt ${workload}[error_message]

0 comments on commit 8f1761d

Please sign in to comment.