Skip to content

Commit

Permalink
get java object from process instance variables - closes #69 (#70)
Browse files Browse the repository at this point in the history
* get java object from process instance variables   - closes #69

* introduce autotype conversion for process instance variables  #69

* typo

* fix test case
  • Loading branch information
Noordsestern authored Mar 16, 2022
1 parent 2185b17 commit 17fd40a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
9 changes: 6 additions & 3 deletions CamundaLibrary/CamundaLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,32 +768,35 @@ def get_activity_instance(self, id: str):
return response.to_dict()

@keyword("Get Process Instance Variable", tags=['process'])
def get_process_instance_variable(self, process_instance_id: str, variable_name: str):
def get_process_instance_variable(self, process_instance_id: str, variable_name: str, auto_type_conversion: bool = True):
"""
Returns the variable with the given name from the process instance with
the given process_instance_id.
Parameters:
- ``process_instance_id``: ID of the target process instance
- ``variable_name``: name of the variable to read
- ``auto_type_conversion``: Converts JSON structures automatically in to python data structures. Default: True. When False, values are not retrieved for JSON variables, but metadata is. Only useful when you want to verify that Camunda holds certain data types.%
== Example ==
| ${variable} | Get Process Instance Variable |
| ... | process_instance_id=fcab43bc-b970-11eb-be75-0242ac110002 |
| ... | variable_name=foo |
See also:
https://docs.camunda.org/manual/7.5/reference/rest/process-instance/variables/get-single-variable/
https://docs.camunda.org/manual/latest/reference/rest/process-instance/variables/get-single-variable/
"""
with self._shared_resources.api_client as api_client:
api_instance: ProcessInstanceApi = openapi_client.ProcessInstanceApi(api_client)

try:
response = api_instance.get_process_instance_variable(
id=process_instance_id, var_name=variable_name)
id=process_instance_id, var_name=variable_name, deserialize_value=not auto_type_conversion)
except ApiException as e:
raise ApiException(f'Failed to get variable {variable_name} from '
f'process instance {process_instance_id}:\n{e}')
if auto_type_conversion:
return CamundaResources.convert_variable_dto(response)
return response

@keyword("Evaluate Decision", tags=['decision'])
Expand Down
2 changes: 2 additions & 0 deletions tests/robot/ExternalTask/test_dict_vars_to_json.robot
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Dictionary variable is of type JSON in camunda
${variable_instance} Get Process Instance Variable
... process_instance_id=${process_instance}[id]
... variable_name=map
... auto_type_conversion=${False}

Should Be Equal Json ${variable_instance.type} Datatype for dictionary was supposed to be Json

Expand All @@ -60,6 +61,7 @@ List variable is of type JSON in camunda
${variable_instance} Get Process Instance Variable
... process_instance_id=${process_instance}[id]
... variable_name=map
... auto_type_conversion=${False}

Should Be Equal Json ${variable_instance.type} Datatype for dictionary was supposed to be Json

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,41 @@ Suite Teardown Clean Up Process Instance
${CAMUNDA_HOST} http://localhost:8080
${PROCESS_INSTANCE_ID} ${EMPTY}
${RESPONSE} ${EMPTY}

${value}

*** Test Cases ***
Get Process Instance Variable
# Given
Process Instance Is Present

# When
Camunda Is Requested For Variable Of The Process Instance
Get Process Instance Variable: String
Given A value bar
Given Process Instance Is Present
When Camunda Is Requested For Variable Of The Process Instance
Then Camunda Answered With Correct Value

Get Process Instance Variable: List
Given A List bar ber bir bor bur
Given Process Instance Is Present
When Camunda Is Requested For Variable Of The Process Instance
Then Camunda Answered With Correct Value

Get Process Instance Variable: Dictionary
Given A List bar=1 ber=2
Given Process Instance Is Present
When Camunda Is Requested For Variable Of The Process Instance
Then Camunda Answered With Correct Value

# Then
Camunda Answered With Correct Value
*** Keywords ***
A Dictionary
[Arguments] &{values}
Set Test Variable ${value} ${values}
A List
[Arguments] @{values}
Set Test Variable ${value} ${values}

A value
[Arguments] ${testvalue}
Set Test Variable ${value} ${testvalue}

*** Keywords ***
Process Instance Is Present
${variable} Create Dictionary foo=bar
${variable} Create Dictionary foo=${value}
${response} Start Process demo_for_robot variables=${variable}
Set Global Variable ${PROCESS_INSTANCE_ID} ${response}[id]

Expand All @@ -36,7 +54,7 @@ Camunda Is Requested For Variable Of The Process Instance

Camunda Answered With Correct Value
Should Be True $RESPONSE Variable could not be read or is empty.
Should Be Equal ${RESPONSE.value} bar
Should Be Equal ${RESPONSE} ${value}

Clean Up Process Instance
Run Keyword If $PROCESS_INSTANCE_ID
Expand Down

0 comments on commit 17fd40a

Please sign in to comment.