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 18, 2020
1 parent 2127c9e commit 966d836
Show file tree
Hide file tree
Showing 12 changed files with 371 additions and 50 deletions.
57 changes: 57 additions & 0 deletions TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
*** Settings ***
Library RequestsLibrary
Library OperatingSystem
Library TAF/testCaseModules/keywords/setup/edgex.py
Library TAF/testCaseModules/keywords/setup/startup_checker.py
Library TAF/testCaseModules/keywords/consul/consul.py
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot

*** Keywords ***
Setup Suite for App Service
[Arguments] ${appServiceUrl}
Setup Suite
Set Suite Variable ${url} ${appServiceUrl}
Deploy services app-service-${edgex_profile}
Check app-service is available
Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token

Check app-service is available
${port}= Split String ${url} :
Check service is available ${port}[2] /api/v2/ping

Suite Teardown for App Service
Suite Teardown
Remove services app-service-${edgex_profile}
Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Remove Token

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' 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}
... ELSE Run Keywords Set test variable ${secrets_path} ${secrets_data}[path]
... AND Set test variable ${secrets_key} ${secrets_data}[secrets][0][key]
... AND Set test variable ${secrets_value} ${secrets_data}[secrets][0][value]



56 changes: 45 additions & 11 deletions TAF/testCaseModules/keywords/common/commonKeywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,19 @@ 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}]

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 +125,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}


36 changes: 36 additions & 0 deletions TAF/testData/app-service/secrets_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Empty Path": {
"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"
}
]
}
}
37 changes: 37 additions & 0 deletions TAF/testData/app-service/trigger_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"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",
"origin": 1540855006469,
"readings": [
{
"id": "5bd794de0e36080001f53eac",
"origin": 1540855006469,
"device": "Random-Float-Device",
"name": "RandomValue_Float64",
"value": "QAFk2HxRUOo="
}
]
}
}
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'
}
31 changes: 23 additions & 8 deletions TAF/testScenarios/functionalTest/V2-API/app-service/info/GET.robot
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Suite Setup Run Keywords Setup Suite AND Deploy App Service
Suite Teardown Run Keywords Suite Teardown AND Remove App Service
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Suite Setup Setup Suite for App Service ${AppServiceUrl_blackbox}
Suite Teardown Suite Teardown for App Service
Default Tags v2-api

*** 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
And apiVersion Should be ${api_version}

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
And apiVersion Should be ${api_version}

InfoGET003 - Query metrics
When Query Metrics
Then Should Return Status Code "200" And Metrics
Then Should Return Status Code "200" And metrics
And apiVersion Should be ${api_version}

InfoGET004 - Query config
When Query Config
Then Should Return Status Code "200" And Config
Then Should Return Status Code "200" And config
And apiVersion Should be ${api_version}

**** Keywords ***
Should Return SDK Version
Should contain "sdk_version"

apiVersion Should be ${api_version}
Should contain "apiVersion"
Should be true '${content}[apiVersion]' == '${api_version}'
Original file line number Diff line number Diff line change
@@ -1,36 +1,68 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Suite Setup Run Keywords Setup Suite AND Deploy App Service
Suite Teardown Run Keywords Suite Teardown AND Remove App Service
Library Process
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Suite Setup Setup Suite for App Service Secrets
Suite Teardown Suite Teardown for App Service
Default Tags v2-api

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

*** Test Cases ***
SecretsPOST001 - Stores secrets to the secret client
When Store Secret Data
When Store Secret Data With Empty Path
Then Run Keyword if $SECURITY_SERVICE_NEEDED == 'true'
... Should Return Status Code "201"
... Run keywords Should Return Status Code "201"
... AND Secrets Should be Stored
... ELSE Should Return Status Code "500"

SecretsPOST002 - Stores secrets to the secret client With Path
SecretsPOST002 - Stores secrets to the secret client with Path
When Store Secret Data With Path
Then Run Keyword if $SECURITY_SERVICE_NEEDED == 'true'
... Should Return Status Code "201"
... Run keywords Should Return Status Code "201"
... AND Secrets Should be Stored
... ELSE Should Return Status Code "500"

ErrSecretsPOST001 - Stores secrets to the secret client fails (missing key)
When Store Secret Data With Missing Key
Then Run Keyword if $SECURITY_SERVICE_NEEDED == 'true'
... Should Return Status Code "400"
Then Should Return Status Code "400"

ErrSecretsPOST002 - Stores secrets to the secret client fails (missing value)
When Store Secret Data With Missing Value
Then Run Keyword if $SECURITY_SERVICE_NEEDED == 'true'
... Should Return Status Code "400"
Then Should Return Status Code "400"

ErrSecretsPOST003 - Stores secrets to the secret client fails (security not enabled)
When Store Secret Data With Path
Then Run Keyword if $SECURITY_SERVICE_NEEDED == 'false'
... Should Return Status Code "500"
... Should Return Status Code "500"
... ELSE Should Return Status Code "201"

*** Keywords ***
Setup Suite for App Service Secrets
Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Run Keywords
#EDGEX_SECURITY_SECRET_STORE: "true"
... Set Suite Variable ${edgex_profile} http-export-secrets
... AND Setup Suite for App Service http://${BASE_URL}:48098
#EDGEX_SECURITY_SECRET_STORE: "false"
... ELSE Run keywords Set Suite Variable ${edgex_profile} http-export
... AND Setup Suite for App Service http://${BASE_URL}:48096

Get AppService Token
${command}= Set Variable docker exec app-service-${edgex_profile} cat /tmp/edgex/secrets/appservice-${edgex_profile}/secrets-token.json
${result} = Run Process ${command} shell=yes output_encoding=UTF-8
${result_string}= Evaluate json.loads('''${result.stdout}''') json
Set Test Variable ${token} ${result_string}[auth][client_token]

Secrets Should be Stored
Get AppService Token
Create Session GetSecrets url=https://${BASE_URL}:8200 disable_warnings=true
${headers}= Create Dictionary X-Vault-Token ${token}
${resp}= Get request GetSecrets /v1/secret/edgex/appservice-${edgex_profile}/${secrets_path} headers=${headers}
Set Response to Test Variables ${resp}
Run keyword if ${response} != 200 log to console ${content}
Should Contain ${content}[data] ${secrets_key} ${secrets_value}


Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Suite Setup Run Keywords Setup Suite AND Deploy App Service
Suite Teardown Run Keywords Suite Teardown AND Remove App Service
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/app-service/AppServiceAPI.robot
Library TAF/testCaseModules/keywords/consul/consul.py
Suite Setup Setup Suite for App Service ${AppServiceUrl_blackbox}
Suite Teardown Suite Teardown for App Service
Default Tags v2-api

*** 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)
When Trigger Function Pipeline With Unprocessable Entity
Given Set Functions FilterByDeviceName, TransformToXML, SetOutputData
And Accept raw data true
When Trigger Function Pipeline With Invalid Data
Then Should Return Status Code "422"
[Teardown] Accept raw data false

*** Keywords ***
Accept raw data
[arguments] ${bool}
${path}= Set variable /v1/kv/edgex/appservices/1.0/AppService-${edgex_profile}/Writable/Pipeline/UseTargetTypeOfByteArray
Modify consul config ${path} ${bool}
sleep 1

Loading

0 comments on commit 966d836

Please sign in to comment.