Skip to content

Commit

Permalink
serialize all collections as Json (#26)
Browse files Browse the repository at this point in the history
* serialize all collections as Json

#8

* works on my machine... try camunda 7.15 in github action

* Revert "works on my machine... try camunda 7.15 in github action"

This reverts commit 0d544d2

* minor

* fix - String must not be serialized as Json
  • Loading branch information
Noordsestern authored Jun 15, 2021
1 parent c1ad917 commit c660c94
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
9 changes: 6 additions & 3 deletions CamundaLibrary/CamundaResources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import collections
from collections.abc import Collection

from generic_camunda_client import Configuration, ApiClient, VariableValueDto
from typing import Dict, Any
Expand Down Expand Up @@ -133,9 +133,12 @@ def convert_file_to_dto(path: str) -> VariableValueDto:

@staticmethod
def convert_to_variable_dto(value: Any) -> VariableValueDto:
if isinstance(value, collections.abc.Mapping):
if isinstance(value, str):
return VariableValueDto(value=value)
elif isinstance(value, Collection): # String is also a collection and must be filtered before Collection.
return VariableValueDto(value=json.dumps(value), type='Json')
return VariableValueDto(value=value)
else:
return VariableValueDto(value=value)

@staticmethod
def convert_variable_dto(dto: VariableValueDto) -> Any:
Expand Down
37 changes: 37 additions & 0 deletions tests/robot/ExternalTask/test_dict_vars_to_json.robot
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ Dictionary variable is of type JSON in camunda

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

List variable remains list
# GIVEN
${variables} Process with list variable

# WHEN
${return_variables} Workload is fetched

#THEN
Should Not Be Empty ${return_variables} Fetching failed. Expected workload at topic '${EXISTING_TOPIC}'

#AND
Should Be Equal ${return_variables}[map][0] ${variables}[map][0] Dictionary value returned not as expected
Should Be Equal ${return_variables}[map][1] ${variables}[map][1] Dictionary value returned not as expected


List variable is of type JSON in camunda
#GIVEN
${process_instance} Process with list variable is started

${variable_instance} Get Process Instance Variable
... process_instance_id=${process_instance}[id]
... variable_name=map

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


*** Keywords ***
Process with dictionary variable
Expand All @@ -45,6 +70,12 @@ Process with dictionary variable
${process_instance} start process ${PROCESS_DEFINITION_KEY} variables=${variables}
[Return] ${variables}

Process with list variable
${my_dict} Create list 1 2
${variables} Create Dictionary map=${my_dict}
${process_instance} start process ${PROCESS_DEFINITION_KEY} variables=${variables}
[Return] ${variables}

Workload is fetched
${return_variables} fetch workload ${EXISTING_TOPIC}
[Return] ${return_variables}
Expand All @@ -54,3 +85,9 @@ Process with dictionary variable is started
${variables} Create Dictionary map=${my_dict}
${process_instance} start process ${PROCESS_DEFINITION_KEY} variables=${variables}
[Return] ${process_instance}

Process with list variable is started
${my_dict} Create Dictionary a=1 b=2
${variables} Create Dictionary map=${my_dict}
${process_instance} start process ${PROCESS_DEFINITION_KEY} variables=${variables}
[Return] ${process_instance}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ${RESPONSE} ${EMPTY}


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

Expand Down

0 comments on commit c660c94

Please sign in to comment.