Skip to content

Commit

Permalink
Implement app service V2 API test cases
Browse files Browse the repository at this point in the history
Fix edgexfoundry#155

Signed-off-by: Ginny Guan <[email protected]>
  • Loading branch information
jinlinGuan committed Sep 8, 2020
1 parent fca51c6 commit e387dee
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 33 deletions.
41 changes: 41 additions & 0 deletions TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
*** Settings ***
Library RequestsLibrary
Library OperatingSystem
Library TAF/testCaseModules/keywords/setup/edgex.py
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot

*** Keywords ***
Deploy App Service
Deploy services app-service-${edgex_profile}

Remove App Service
Remove services app-service-${edgex_profile}

Set functions ${functions}
${path}= Set variable /v1/kv/edgex/appservices/1.0/AppService-${edgex_profile}/Writable/Pipeline/ExecutionOrder
Modify consul config ${path} ${functions}
sleep 1

Trigger Function Pipeline With ${data}
${trigger_data}= Run keyword if '${data}' != 'Invalid Data' and '${data}' != 'Unprocessable Entity'
... set variable Valid Data ELSE set variable ${data}
${trigger_data}= Load data file "app-service/trigger_data.json" and get variable "${trigger_data}"
Run keyword if '${data}' == 'No Matching DeviceName'
... Run keywords set to dictionary ${trigger_data} device="DeiveNotMatch"
... AND set to dictionary ${trigger_data}[readings][0] device="DeviceNotMatch"
Create Session Trigger url=${url} disable_warnings=true
${headers}= Create Dictionary Authorization=Bearer ${jwt_token}
${resp}= Post request Trigger api/${api_version}/trigger json=${trigger_data} headers=${headers}
Set Response to Test Variables ${resp}
Run keyword if ${response} != 200 log to console ${content}

Store Secret Data With ${data}
${secrets_data}= Load data file "app-service/secrets_data.json" and get variable "${data}"
Create Session Secrets url=${url} disable_warnings=true
${headers}= Create Dictionary Authorization=Bearer ${jwt_token}
${resp}= Post request Secrets api/${api_version}/secrets json=${secrets_data} headers=${headers}
Set Response to Test Variables ${resp}
Run keyword if ${response} != 201 log to console ${content}



57 changes: 46 additions & 11 deletions TAF/testCaseModules/keywords/common/commonKeywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ Get random "${value}" from "${list}"
${random_value}= convert to string ${random}[${value}]
[Return] ${random_value}

Should return status code "200"
Should be true ${response} == 200
Should return status code "${status_code}"
Should be true ${response} == ${status_code}

Should return status code "400"
Should be true ${response} == 400
Should return Content-Type "${content_type}"
Should be true '${headers}' == '${content_type}'

Should return status code "404"
Should be true ${response} == 404
Should contain "${element}"
Should Not be empty ${content}[${element}]
log to console ${content}[${element}]

Should return status code "423"
Should be true ${response} == 423

Should return status code "500"
Should be true ${response} == 500
Should Return Status Code "${status_code}" And ${element}
Should return status code "${status_code}"
Should return Content-Type "application/json"
Should contain "${element}"

Get current milliseconds epoch time
${current_epoch_time}= Get current epoch time
Expand Down Expand Up @@ -126,3 +126,38 @@ Load data file "${json_file}" and get variable "${use_variable}"
${json_string}= Evaluate json.loads('''${json_data}''') json
[Return] ${json_string}[${use_variable}]

Set Response to Test Variables
[Arguments] ${resp}
Set test variable ${response} ${resp.status_code}
${headers}= Run keyword if 'Content-Type' in ${resp.headers} Set variable ${resp.headers}[Content-Type]
... ELSE Set variable None
${content}= Run Keyword If '${headers}' == 'application/json' Evaluate json.loads('''${resp.content}''') json
... ELSE Set variable ${resp.content}
Set test variable ${headers} ${headers}
Set test variable ${content} ${content}

Query Ping
${headers}= Create Dictionary Authorization=Bearer ${jwt_token}
Create Session Ping url=${url} disable_warnings=true
${resp}= Get request Ping api/${api_version}/ping headers=${headers}
Set Response to Test Variables ${resp}

Query Config
${headers}= Create Dictionary Authorization=Bearer ${jwt_token}
Create Session Config url=${url} disable_warnings=true
${resp}= Get request Config api/${api_version}/config headers=${headers}
Set Response to Test Variables ${resp}

Query Version
${headers}= Create Dictionary Authorization=Bearer ${jwt_token}
Create Session Ping url=${url} disable_warnings=true
${resp}= Get request Ping api/${api_version}/version headers=${headers}
Set Response to Test Variables ${resp}

Query Metrics
${headers}= Create Dictionary Authorization=Bearer ${jwt_token}
Create Session Ping url=${url} disable_warnings=true
${resp}= Get request Ping api/${api_version}/metrics headers=${headers}
Set Response to Test Variables ${resp}


35 changes: 35 additions & 0 deletions TAF/testData/app-service/secrets_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"No Path": {
"secrets" : [
{
"key" : "MySecretKey",
"value" : "MySecretValue"
}
]
},
"Path": {
"path" : "MyPath",
"secrets" : [
{
"key" : "MySecretKey",
"value" : "MySecretValue"
}
]
},
"Missing Key": {
"path" : "MyPath",
"secrets" : [
{
"value" : "MySecretValue"
}
]
},
"Missing Value": {
"path" : "MyPath",
"secrets" : [
{
"key" : "MySecretKey"
}
]
}
}
53 changes: 53 additions & 0 deletions TAF/testData/app-service/trigger_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"Valid Data": {
"id": "5bd794de0e36080001f53eab",
"pushed": 0,
"device": "Random-Float-Device",
"created": 1540855006481,
"modified": 0,
"origin": 1540855006469,
"schedule": null,
"event": null,
"readings": [
{
"id": "5bd794de0e36080001f53eac",
"pushed": 0,
"created": 1540855006481,
"origin": 1540855006469,
"modified": 0,
"device": "Random-Float-Device",
"name": "RandomValue_Float64",
"value": "QAFk2HxRUOo="
}
]
},
"Invalid Data": {
"id": "5bd794de0e36080001f53eab",
"device": "Random-Float-Device",
"origin": 1540855006469,
"readings": [
{
"id": "5bd794de0e36080001f53eac",
"origin": 1540855006469,
"device": "Random-Float-Device",
"name": "RandomValue_Float64",
"value": "invalid value"
}
]
},
"Unprocessable Entity": {
"id": "5bd794de0e36080001f53eab",
"device": "Random-Float-Device",
"origin": 1540855006469,
"readings": [
{
"id": "5bd794de0e36080001f53eac",
"origin": 1540855006469,
"device": "Random-Float-Device",
"name": "RandomValue_Float64",
"value": "QAFk2HxRUOo="
}
],
"addition": 123
}
}
13 changes: 13 additions & 0 deletions TAF/testData/app-service/trigger_response_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
trigger_content={
"XML String": '<Event><ID>5bd794de0e36080001f53eab</ID><Pushed>0</Pushed><Device>Random-Float-Device</Device>'
'<Created>1540855006481</Created><Modified>0</Modified><Origin>1540855006469</Origin><Readings>'
'<Id>5bd794de0e36080001f53eac</Id><Pushed>0</Pushed><Created>1540855006481</Created><Origin>1540855006469</Origin>'
'<Modified>0</Modified><Device>Random-Float-Device</Device><Name>RandomValue_Float64</Name><Value>QAFk2HxRUOo=</Value>'
'<ValueType></ValueType><FloatEncoding></FloatEncoding><BinaryValue></BinaryValue><MediaType></MediaType></Readings></Event>',
"JSON String": '{"id":"5bd794de0e36080001f53eab","device":"Random-Float-Device","created":1540855006481,"origin":1540855006469,'
'"readings":[{"id":"5bd794de0e36080001f53eac","created":1540855006481,"origin":1540855006469,'
'"device":"Random-Float-Device","name":"RandomValue_Float64","value":"QAFk2HxRUOo="}]}',
"JSON-GZIP String": 'H4sIAAAAAAAA/5SOwYrCMBiE32XOKfzdJtk2sIeFpext2YJeRCRtfkuwTaDWIkjfXdSDeFE8zjfDzJzgHQxU7T4L6Zg405QTUbpVGdsaAo4n3zAMKhtc7JOyi3ZMfm5UoBnYjuxgUiUpV4pIyzwViINvfXjAuhAY2Dof2j3M6vl08373i6fB9ndzabsDb64JLSEwXTQM/r/L3cfvsVr8xS/M6/kcAAD//766olAgAQAA',
"JSON-ZLIB String": 'eJyUjsGKwjAYhN9lzin83SbZNrCHhaXsbdmCXkQkbX5LsE2g1iJI313Ug3hRPM43w8yc4B0MVO0+C+mYONOUE1G6VRnbGgKOJ98wDCobXOyTsot2TH5uVKAZ2I7sYFIlKVeKSMs8FYiDb314wLoQGNg6H9o9zOr5dPN+94unwfZ3c2m7A2+uCS0hMF00DP6/y93H77Fa/MUvzOv5HAAA//9QTVQF',
"JSON-ZLIB-AES String": '7E/CbWn7FhxheP2OgLT1OFCquTKtVXGVDLqjX8EWL8vlnYEhRIKII2KA9MJQlXx5pxXzMkA8dYW5uXDpm4UbKqVVpi7QqQoYPJ4tBo0D7LIT4NJpRwg5qAXQ0FaZtEPvO6tpK1KA1wWMrnj9uXCa2zphifSxDRG+W2Hbm/Hc2GItheZI+yS2+2nbuANVOhtBeYblT31B1rr4wPX4wCxwzil2SVSLRclR3eLy/fiokzv3s423em5TsN34SsG5R9JcsEPZtAt9tTWhw2k8vY8osJd1ZWOq1S0s3+Hkscp2mO9d+NUBZD+MbMwUPTrdfCCkh9pTCQIBs5OSkGxIb2JVHCzutX+kC6MJnE+KfmHKezfF+AlgzHKZ5rScPrkbnO7Cp5aJ6Aarw0dhog97y/Q2K/CsE5A9W1L/bgIP1W/EgZm94rtDFqGnzGP8FihHSeLn'
}
21 changes: 15 additions & 6 deletions TAF/testScenarios/functionalTest/V2-API/app-service/info/GET.robot
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Suite Setup Run Keywords Setup Suite AND Deploy App Service
... AND Set Suite Variable ${url} ${AppServiceUrl_blackbox}
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Keywords Suite Teardown AND Remove App Service
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Remove Token

*** Variables ***
${SUITE} App-Service GET Testcases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/app-service-get.log
${edgex_profile} blackbox-tests
${AppServiceUrl_blackbox} http://${BASE_URL}:48095
${api_version} v2

*** Test Cases ***
InfoGET001 - Query ping
When Query Ping
Then Should Return Status Code "200" And Timestamp
Then Should Return Status Code "200" And timestamp

InfoGET002 - Query version
When Query Version
Then Should Return Status Code "200" And Version
And Should Return SDK Version
Then Should Return Status Code "200" And version
And Should Return SDK Version

InfoGET003 - Query metrics
When Query Metrics
Then Should Return Status Code "200" And Metrics
Then Should Return Status Code "200" And metrics

InfoGET004 - Query config
When Query Config
Then Should Return Status Code "200" And Config
Then Should Return Status Code "200" And config

**** Keywords ***
Should Return SDK Version
Should contain "sdk_version"
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Suite Setup Run Keywords Setup Suite AND Deploy App Service
... AND Set Suite Variable ${url} ${AppServiceUrl_http}
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Keywords Suite Teardown AND Remove App Service
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Remove Token

*** Variables ***
${SUITE} App-Service Secrets POST Testcases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/app-service-secrets.log
${edgex_profile} http-export
${AppServiceUrl_http} http://${BASE_URL}:48096
${api_version} v2

*** Test Cases ***
SecretsPOST001 - Stores secrets to the secret client
When Store Secret Data
When Store Secret Data With No Path
Then Run Keyword if $SECURITY_SERVICE_NEEDED == 'true'
... Should Return Status Code "201"

Expand All @@ -33,4 +39,4 @@ ErrSecretsPOST003 - Stores secrets to the secret client fails (security not enab
When Store Secret Data With Path
Then Run Keyword if $SECURITY_SERVICE_NEEDED == 'false'
... Should Return Status Code "500"

Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Library TAF/testCaseModules/keywords/consul/consul.py
Suite Setup Run Keywords Setup Suite AND Deploy App Service
... AND Set Suite Variable ${url} ${AppServiceUrl_blackbox}
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Keywords Suite Teardown AND Remove App Service
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Remove Token

*** Variables ***
${SUITE} App-Service Trigger POST Negative Testcases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/app-service-trigger-negative.log
${edgex_profile} blackbox-tests
${AppServiceUrl_blackbox} http://${BASE_URL}:48095
${api_version} v2

*** Test Cases ***
ErrTriggerPOST001 - Trigger pipeline fails (Invalid Data)
Given Set functions FilterByDeviceName, TransformToXML, SetOutputData
When Trigger Function Pipeline With Invalid Data
Then Should Return Status Code "400"

ErrTriggerPOST002 - Trigger pipeline fails (Unprocessable Entity)
Given Set functions FilterByDeviceName, TransformToXML, SetOutputData
When Trigger Function Pipeline With Unprocessable Entity
Then Should Return Status Code "422"
Original file line number Diff line number Diff line change
@@ -1,44 +1,61 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Library TAF/testCaseModules/keywords/consul/consul.py
Variables TAF/testData/app-service/trigger_response_content.py
Suite Setup Run Keywords Setup Suite AND Deploy App Service
... AND Set Suite Variable ${url} ${AppServiceUrl_blackbox}
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Keywords Suite Teardown AND Remove App Service
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Remove Token

*** Variables ***
${SUITE} App-Service Trigger POST Positive Testcases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/app-service-trigger-positive.log
${edgex_profile} blackbox-tests
${AppServiceUrl_blackbox} http://${BASE_URL}:48095
${api_version} v2

*** Test Cases ***
TriggerPOST001 - Trigger pipeline (no match)
Given Set functions FilterByDeviceName, TransformToXML, SetOutputData
When Trigger Function Pipeline With No Matching DeviceName
Then Should Return Status Code "200"
And Body Should Match Empty
And Body Should Match Empty

TriggerPOST002 - Trigger pipeline (XML)
Given Set functions FilterByDeviceName, TransformToXML, SetOutputData
When Trigger Function Pipeline With Matching DeviceName
Then Should Return Status Code "200"
And Body Should Match XML String
And Body Should Match XML String

TriggerPOST003 - Trigger pipeline (JSON)
Given Set TransformToJSON
Given Set functions FilterByDeviceName, TransformToJSON, SetOutputData
When Trigger Function Pipeline With Matching DeviceName
Then Should Return Status Code "200"
And Body Should Match JSON String
And Body Should Match JSON String

TriggerPOST004 - Trigger pipeline (JSON-GZIP)
Given Set CompressWithGZIP
Given Set functions FilterByDeviceName, TransformToJSON, CompressWithGZIP, SetOutputData
When Trigger Function Pipeline With Matching DeviceName
Then Should Return Status Code "200"
And Body Should Match JSON String
And Body Should Match JSON-GZIP String

TriggerPOST005 - Trigger pipeline (JSON-ZLIB)
Given Set CompressWithZLIB
Given Set functions FilterByDeviceName, TransformToJSON, CompressWithZLIB, SetOutputData
When Trigger Function Pipeline With Matching DeviceName
Then Should Return Status Code "200"
And Body Should Match JSON String
And Body Should Match JSON-ZLIB String

TriggerPOST006 - Trigger pipeline (JSON-ZLIB-AES)
Given Set EncryptWithAES
Given Set functions FilterByDeviceName, TransformToXML, CompressWithZLIB, EncryptWithAES, SetOutputData
When Trigger Function Pipeline With Matching DeviceName
Then Should Return Status Code "200"
And Body Should Match JSON String
And Body Should Match JSON-ZLIB-AES String

*** Keywords ***
Body Should Match ${type}
${length}= Get Length ${content}
Run keyword if '${type}' == 'Empty' Should be true ${length}==0
... ELSE Should be true '${content}' == '${trigger_content["${type}"]}'

Loading

0 comments on commit e387dee

Please sign in to comment.