Skip to content

Commit

Permalink
feat: Implement tests for Units of Measure(UoM) (#703)
Browse files Browse the repository at this point in the history
Signed-off-by: Cherry Wang <[email protected]>

Signed-off-by: Cherry Wang <[email protected]>
  • Loading branch information
cherrycl authored Sep 2, 2022
1 parent 462a5ff commit a8729ca
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 143 deletions.
4 changes: 0 additions & 4 deletions TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ Suite Teardown for App Service
Set Functions ${functions}
${path}= Set variable /v1/kv/edgex/appservices/${CONSUL_CONFIG_VERSION}/app-functional-tests/Writable/Pipeline/ExecutionOrder
Update Service Configuration On Consul ${path} ${functions}
sleep 1

Set Transform Type ${type}
${path}= Set variable /v1/kv/edgex/appservices/${CONSUL_CONFIG_VERSION}/app-functional-tests/Writable/Pipeline/Functions/Transform/Parameters/Type
Update Service Configuration On Consul ${path} ${type}
sleep 1

Set Compress Algorithm ${algorithm}
${path}= Set variable /v1/kv/edgex/appservices/${CONSUL_CONFIG_VERSION}/app-functional-tests/Writable/Pipeline/Functions/Compress/Parameters/Algorithm
Update Service Configuration On Consul ${path} ${algorithm}
sleep 1

Set Encrypt Algorithm ${algorithm}
${path}= Set variable /v1/kv/edgex/appservices/${CONSUL_CONFIG_VERSION}/app-functional-tests/Writable/Pipeline/Functions/Encrypt/Parameters/Algorithm
Update Service Configuration On Consul ${path} ${algorithm}
sleep 1

Trigger Function Pipeline With ${data}
${trigger_data}= Run keyword if '${data}' != 'Invalid Data' set variable Valid Data
Expand Down
2 changes: 1 addition & 1 deletion TAF/testCaseModules/keywords/common/commonKeywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Update Service Configuration On Consul
${url} Set Variable http://${BASE_URL}:${REGISTRY_PORT}
Create Session Consul url=${url} disable_warnings=true
${resp}= PUT On Session Consul ${path} data=${value} headers=${headers} expected_status=200
Sleep 1s # Waiting for the configuration updating

Get Consul Token
${command} Set Variable cat /tmp/edgex/secrets/consul-acl-token/bootstrap_token.json
Expand All @@ -263,7 +264,6 @@ Set Telemetry ${config}=${value} For ${service_name} On Consul
${telemetry_path} Set Variable /v1/kv/edgex/${service_layer}/${CONSUL_CONFIG_VERSION}/${service_name}/Writable/Telemetry
${path} Set Variable ${telemetry_path}/${config}
Update Service Configuration On Consul ${path} ${value}
Sleep 500ms # Waiting for the configuration available

Run Redis Subscriber Progress And Output
[Arguments] ${topic} ${keyword}
Expand Down
83 changes: 70 additions & 13 deletions TAF/testCaseModules/keywords/core-metadata/coreMetadataAPI.robot
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ${deviceResourceUri} /api/${API_VERSION}/deviceresource
${deviceUri} /api/${API_VERSION}/device
${provisionWatcherUri} /api/${API_VERSION}/provisionwatcher
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/coreMetadataAPI.log
${uomValidationPath} /v1/kv/edgex/core/${CONSUL_CONFIG_VERSION}/core-metadata/Writable/UoM/Validation

*** Keywords ***
# Device Profile
Expand Down Expand Up @@ -510,28 +511,25 @@ Delete Profile Files
Remove File ${WORK_DIR}/TAF/testData/core-metadata/deviceprofile/${file}

# Device profile > resource
Generate a device profile and Add multiple Resources on device profile
Create A Device Profile And Generate Multiple Resources Entity
Set Test Variable ${test_profile} Test-Profile-1
Generate a device profile sample ${test_profile}
Create Device Profile ${deviceProfile}
${resource_data}= Get File ${WORK_DIR}/TAF/testData/core-metadata/resource_profile.json encoding=UTF-8
${json_string}= Evaluate json.loads(r'''${resource_data}''') json
Generate resource ${json_string}
Generate multiple deviceResources

Add multiple Resources on multiple device profile
${resource_data}= Get File ${WORK_DIR}/TAF/testData/core-metadata/resource_profile.json encoding=UTF-8
${json_string}= Evaluate json.loads(r'''${resource_data}''') json
Generate resource ${json_string}
Generate multiple deviceResources
Set To Dictionary ${resourceProfile}[1] profileName=Test-Profile-2
Set To Dictionary ${resourceProfile}[2] profileName=Test-Profile-3

Generate resource
[Arguments] ${data_list}
${len} Get Length ${data_list}
Generate multiple deviceResources
${resource_data}= Get File ${WORK_DIR}/TAF/testData/core-metadata/resource_profile.json encoding=UTF-8
${json_string}= Evaluate json.loads(r'''${resource_data}''') json
${len} Get Length ${json_string}
FOR ${INDEX} IN RANGE ${len}
Set To Dictionary ${data_list}[${INDEX}] apiVersion=${API_VERSION}
Set To Dictionary ${json_string}[${INDEX}] apiVersion=${API_VERSION}
END
Set Test Variable ${resourceProfile} ${data_list}
Set Test Variable ${resourceProfile} ${json_string}

Create New resource ${entity}
Create Session Core Metadata url=${coreMetadataUrl} disable_warnings=true
Expand Down Expand Up @@ -755,4 +753,63 @@ Create A Provision Watcher Sample With Associated Test-Device-Service And ${devi
Set ProfileChange.${config}=${value} For Core-Metadata On Consul
${path}= Set Variable /v1/kv/edgex/core/${CONSUL_CONFIG_VERSION}/core-metadata/Writable/ProfileChange/${config}
Update Service Configuration On Consul ${path} ${value}
Sleep 1s # Waiting for the configuration updating

## UoM
Query UoM
${headers}= Create Dictionary Authorization=Bearer ${jwt_token}
Create Session Metrics url=${coreMetadataUrl} disable_warnings=true
${resp}= GET On Session Metrics api/${API_VERSION}/uom headers=${headers} expected_status=200
Set Response to Test Variables ${resp}

Retrieve Valid Units Value
Query UoM
${units} Create List
${units_key} Get Dictionary Keys ${content}[uom][units]
FOR ${ITEM} IN @{units_key}
FOR ${INDEX} IN RANGE len(${content}[uom][units][${ITEM}][values])
Append To List ${units} ${content}[uom][units][${ITEM}][values][${INDEX}]
END
END
Set Test Variable ${uom_units} ${units}

Set Profile Units Value To ${valid}
Run Keyword If "${valid}" == "valid" Retrieve Valid Units Value
FOR ${INDEX} IN RANGE len(${deviceProfile}[0][profile][deviceResources])
${unit} Run Keyword If "${valid}" == "valid" Evaluate random.choice(@{uom_units}) random
... ELSE Set Variable invalid
Set To Dictionary ${deviceProfile}[0][profile][deviceResources][${INDEX}][properties] units=${unit}
END
Set Test Variable ${deviceProfile} ${deviceProfile}

Create A Profile ${file} With ${valid} Units Value
Generate a device profile sample ${file}
Set Profile Units Value To ${valid}
Create Device Profile ${deviceProfile}

Update Units Value In Profile ${file} To ${valid}
Run Keyword If "${valid}" == "valid" Retrieve Valid Units Value
${content} Get File ${WORK_DIR}/TAF/testData/core-metadata/deviceprofile/${file}.yaml
${matches} Get Regexp Matches ${content} units: \"(.*?)\"
FOR ${ITEM} IN @{matches}
${variables}= Get variables
${existed} Run Keyword And Return Status Should be true "\${replaced}" in $variables
${data} Run Keyword If ${existed} == True Set Variable ${replaced}
... ELSE Set Variable ${content}
${unit} Run Keyword If "${valid}" == "valid" Evaluate random.choice(@{uom_units}) random
... ELSE Set Variable invalid
${replaced} Replace String ${data} ${ITEM} units: "${unit}" count=1
END
Create File ${WORK_DIR}/TAF/testData/core-metadata/deviceprofile/NEW-${file}.yaml ${replaced}

Modify Device Profile ${file} With ${valid} Units Value
Update Units Value In Profile ${file} To ${valid}
Upload device profile NEW-${file}.yaml

Create Device Resources Contain ${valid} Units Value
Run Keyword If "${valid}" == "valid" Retrieve Valid Units Value
FOR ${INDEX} IN RANGE len(${resourceProfile})
${unit} Run Keyword If "${valid}" == "valid" Evaluate random.choice(@{uom_units}) random
... ELSE Set Variable invalid
Set To Dictionary ${resourceProfile}[${INDEX}][resource][properties] units=${unit}
END
Create New resource ${resourceProfile}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ Accept raw data
[Arguments] ${bool}
${path}= Set variable /v1/kv/edgex/appservices/${CONSUL_CONFIG_VERSION}/app-functional-tests/Writable/Pipeline/UseTargetTypeOfByteArray
Update Service Configuration On Consul ${path} ${bool}
sleep 1

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ ErrEventGET005 - Query events by start/end time fails (Start>End)
ErrEventGET006 - Query event fails when persistData is false
${path}= Set Variable /v1/kv/edgex/core/${CONSUL_CONFIG_VERSION}/core-data/Writable/PersistData
Given Update Service Configuration On Consul ${path} false
And Sleep 1s # Waiting for the configuration updating
And Generate Event Sample Event Device-Test-001 Profile-Test-001 Command-Test-001 Simple Reading
And Create Event With Device-Test-001 And Profile-Test-001 And Command-Test-001
When Query Event By Event Id "${id}"
Expand All @@ -59,4 +58,3 @@ ErrEventGET006 - Query event fails when persistData is false
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
[Teardown] Run Keywords Delete All Events By Age
... AND Update Service Configuration On Consul ${path} true
... AND Sleep 1s # Waiting for the configuration updating
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,3 @@ ErrProfileResourcePATCH003 - Update deviceResource with isHidden validation erro
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
[Teardown] Delete Device Profile By Name ${test_profile}

ErrProfileResourcePATCH004 - Update resources which contain invalid Units value
[Tags] Skipped
Given Set UoM Validation to True
And Generate Device Profile
When Update Resource with Invalid Units Value
Then Should Return Status Code "207"
And Should Return Content-Type "application/json"
And Item Index All Should Contain Status Code "500"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Resource Should Not Be Updated
[Teardown] Run Keywords Set UoM Validation to False
... AND Delete Device Profile
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ ProfileResourcePATCH002 - Update multiple resources on multiple device profiles
And Resource DeviceValue_FLOAT32_R in Profile Test-Profile-3 Should Be Updated
[Teardown] Delete Multiple Device Profiles By Names Test-Profile-1 Test-Profile-2 Test-Profile-3

ProfileResourcePATCH003 - Update resources which contain valid Units value
[Tags] Skipped
Given Create Device Profile
And Set UoM Validation to True
When Update Resource with Valid Units Value
Then Should Return Status Code "207"
And Should Return Content-Type "application/json"
And Item Index All Should Contain Status Code "200"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Resource Should Be Updated
[Teardown] Run Keywords Set UoM Validation to False
... AND Delete Device Profile

*** Keywords ***
Generate multiple resource sample for updating
${resource_1}= Create Dictionary name=DeviceValue_Boolean_RW description=Dcp_ABC isHidden=${false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ${SUITE} Core Metadata Device Profile POST Deviceresource Negative Test
*** Test Cases ***
ErrProfileResourcePOST001 - Add deviceResource with Non-existent device profile name
# non-existent profile name
Given Generate deviceResource
Given Generate multiple deviceResources
And Set To Dictionary ${resourceProfile}[0] profileName=non-existent
When Create New resource ${resourceProfile}
Then Should Return Status Code "207"
Expand All @@ -21,7 +21,7 @@ ErrProfileResourcePOST001 - Add deviceResource with Non-existent device profile

ErrProfileResourcePOST002 - Add deviceResource with Empty profile name
# empty profile name
Given Generate deviceResource
Given Generate multiple deviceResources
And Set To Dictionary ${resourceProfile}[0] profileName=${EMPTY}
When Create New resource ${resourceProfile}
Then Should Return Status Code "400"
Expand All @@ -30,7 +30,7 @@ ErrProfileResourcePOST002 - Add deviceResource with Empty profile name

ErrProfileResourcePOST003 - Add deviceResource with duplicate Resource name
# 2 deviceResource with same resource name
Given Generate a device profile and Add multiple Resources on device profile
Given Create A Device Profile And Generate Multiple Resources Entity
And Create New resource ${resourceProfile}
When Create New resource ${resourceProfile}
Then Should Return Status Code "207"
Expand All @@ -42,7 +42,7 @@ ErrProfileResourcePOST003 - Add deviceResource with duplicate Resource name
ErrProfileResourcePOST004 - Add deviceResource with Empty Resource Name
# deviceResources > deviceResource without name
# Contains valid profile body
Given Generate a device profile and Add multiple Resources on device profile
Given Create A Device Profile And Generate Multiple Resources Entity
And Set To Dictionary ${resourceProfile}[0][resource] name=${EMPTY}
When Create New resource ${resourceProfile}
Then Should Return Status Code "400"
Expand All @@ -53,7 +53,7 @@ ErrProfileResourcePOST004 - Add deviceResource with Empty Resource Name
ErrProfileResourcePOST005 - Add deviceResource with Empty valueType
# deviceResources > ResourceProperties without valueType
# Contains valid profile body
Given Generate a device profile and Add multiple Resources on device profile
Given Create A Device Profile And Generate Multiple Resources Entity
And Set To Dictionary ${resourceProfile}[0][resource][properties] valueType=${Empty}
When Create New resource ${resourceProfile}
Then Should Return Status Code "400"
Expand All @@ -64,7 +64,7 @@ ErrProfileResourcePOST005 - Add deviceResource with Empty valueType
ErrProfileResourcePOST006 - Add deviceResource with valueType validation error
# deviceResources > deviceResource invalid valueType
# Contains valid profile body
Given Generate a device profile and Add multiple Resources on device profile
Given Create A Device Profile And Generate Multiple Resources Entity
And Set To Dictionary ${resourceProfile}[0][resource][properties] valueType=invalid
When Create New resource ${resourceProfile}
Then Should Return Status Code "400"
Expand All @@ -75,7 +75,7 @@ ErrProfileResourcePOST006 - Add deviceResource with valueType validation error
ErrProfileResourcePOST007 - Add deviceResource with Empty readWrite
# deviceResources > ResourceProperties without readWrite
# Contains valid profile body
Given Generate a device profile and Add multiple Resources on device profile
Given Create A Device Profile And Generate Multiple Resources Entity
And Set To Dictionary ${resourceProfile}[0][resource][properties] readWrite=${Empty}
When Create New resource ${resourceProfile}
Then Should Return Status Code "400"
Expand All @@ -86,28 +86,34 @@ ErrProfileResourcePOST007 - Add deviceResource with Empty readWrite
ErrProfileResourcePOST008 - Add deviceResource with readWrite validation error
# deviceResources > ResourceProperties invalid readWrite
# Contains valid profile body
Given Generate a device profile and Add multiple Resources on device profile
Given Create A Device Profile And Generate Multiple Resources Entity
And Set To Dictionary ${resourceProfile}[0][resource][properties] readWrite=invalid
When Create New resource ${resourceProfile}
Then Should Return Status Code "400"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
[Teardown] Delete device profile by name ${test_profile}

ErrProfileResourcePOST008 - Add deviceResource with invalid units value
[Tags] Skipped
Given Set UoM Validation to True
And Create A Device Profile
When Create Device Resource with Invalid Units Value
Then Should Return Status Code "500"
ErrProfileResourcePOST009 - Add deviceResource with invalid units value
Given Create A Device Profile And Generate Multiple Resources Entity
And Update Service Configuration On Consul ${uomValidationPath} true
When Create Device Resources Contain invalid Units Value
Then Should Return Status Code "207"
And Should Return Content-Type "application/json"
And Item Index All Should Contain Status Code "500"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And The Resource Should Not Be Added
[Teardown] Run Keywords Set UoM Validation to False
... AND Delete Device Profile
And Resources Should Not Be Added in ${test_profile}
[Teardown] Run Keywords Update Service Configuration On Consul ${uomValidationPath} false
... AND Delete Device Profile By Name ${test_profile}

*** Keywords ***
Generate deviceResource
${resource_data}= Get File ${WORK_DIR}/TAF/testData/core-metadata/resource_profile.json encoding=UTF-8
${json_string}= Evaluate json.loads(r'''${resource_data}''') json
Generate resource ${json_string}
Resources Should Not Be Added in ${profile_name}
Query device profile by name ${profile_name}
${resource_name_list} Create List
FOR ${resource} IN @{content}[profile][deviceResources]
Append To List ${resource_name_list} ${resource}[name]
END
# Validate
FOR ${INDEX} IN RANGE len(${resourceProfile})
List Should Not Contain Value ${resource_name_list} ${resourceProfile}[${INDEX}][resource][name]
END
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ ErrProfilePOSTUpload008 - Create device profile by upload file with deviceComman
[Teardown] Delete Profile Files NEW-Test-Profile-2.yaml

ErrProfilePOSTUpload009 - Create device profile by upload file with invalid units property
[Tags] Skipped
Given Set UoM Validation to True
When Upload Device Prfoile and the File Contains Invalid Units Value
Given Update Service Configuration On Consul ${uomValidationPath} true
When Modify Device Profile Test-Profile-4 With invalid Units Value
Then Should Return Status Code "500"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
[Teardown] Run Keywords Set UoM Validation to False
[Teardown] Update Service Configuration On Consul ${uomValidationPath} false
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ ErrProfilePOST008 - Create device profile with deviceCommands deviceResources va
And Response Time Should Be Less Than "${default_response_time_threshold}"ms

ErrProfilePOST009 - Create device profile with invalid units value
[Tags] Skipped
Given Set UoM Validation to True
When Create Device Profile Which Contains Invalid Units Value
Given Update Service Configuration On Consul ${uomValidationPath} true
When Create A Profile Test-Profile-1 With invalid Units Value
Then Should Return Status Code "207"
And Should Return Content-Type "application/json"
And Item Index All Should Contain Status Code "500"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
[Teardown] Set UoM Validation to False
[Teardown] Update Service Configuration On Consul ${uomValidationPath} false
Loading

0 comments on commit a8729ca

Please sign in to comment.