From 5558a9d3262cb00b0b831378d3e2a563fe43bea5 Mon Sep 17 00:00:00 2001 From: Cherry Wang Date: Tue, 13 Jul 2021 16:32:34 +0800 Subject: [PATCH] feat: Implement tests for query readings by name and time range Signed-off-by: Cherry Wang --- .../keywords/core-data/coreDataAPI.robot | 17 ++++++++++ .../core-data/reading/GET-negative.robot | 31 +++++++++++++++++ .../core-data/reading/GET-positive.robot | 33 +++++++++++++++---- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/TAF/testCaseModules/keywords/core-data/coreDataAPI.robot b/TAF/testCaseModules/keywords/core-data/coreDataAPI.robot index f3c5507b..ef67b1b5 100644 --- a/TAF/testCaseModules/keywords/core-data/coreDataAPI.robot +++ b/TAF/testCaseModules/keywords/core-data/coreDataAPI.robot @@ -55,6 +55,23 @@ Query readings by start/end time Set Response to Test Variables ${resp} Run Keyword If ${response}!=200 fail ${response}!=200: ${content} +Query readings by resource and start/end time + [Arguments] ${resource} ${start_time} ${end_time} + Create Session Core Data url=${coreDataUrl} disable_warnings=true + ${headers}= Create Dictionary Authorization=Bearer ${jwt_token} + ${resp}= GET On Session Core Data + ... ${coreDataReadingUri}/resourceName/${resource}/start/${start_time}/end/${end_time} + ... headers=${headers} expected_status=any + Set Response to Test Variables ${resp} + +Query readings by resource ${resource} and start ${start_time}/end ${end_time} with ${parameter}=${value} + Create Session Core Data url=${coreDataUrl} disable_warnings=true + ${headers}= Create Dictionary Authorization=Bearer ${jwt_token} + ${resp}= GET On Session Core Data + ... ${coreDataReadingUri}/resourceName/${resource}/start/${start_time}/end/${end_time} + ... params=${parameter}=${value} headers=${headers} expected_status=any + Set Response to Test Variables ${resp} + Query all readings count Create Session Core Data url=${coreDataUrl} disable_warnings=true ${headers}= Create Dictionary Authorization=Bearer ${jwt_token} diff --git a/TAF/testScenarios/functionalTest/V2-API/core-data/reading/GET-negative.robot b/TAF/testScenarios/functionalTest/V2-API/core-data/reading/GET-negative.robot index 04ca5d7a..25773a42 100644 --- a/TAF/testScenarios/functionalTest/V2-API/core-data/reading/GET-negative.robot +++ b/TAF/testScenarios/functionalTest/V2-API/core-data/reading/GET-negative.robot @@ -66,3 +66,34 @@ ErrReadingGET008 - Query readings by start/end time fails (Start>End) And Should Return Content-Type "application/json" And Response Time Should Be Less Than "${default_response_time_threshold}"ms +ErrReadingGET09 - Query readings by rsource and start/end time fails (Invalid Start) + ${end_time}= Get current nanoseconds epoch time + When Query Readings By Resource And Start/End Time Test_Resource InvalidStart ${end_time} + 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 + +ErrReadingGET010 - Query readings by rsource and start/end time fails (Invalid End) + ${start_time}= Get current nanoseconds epoch time + When Query Readings By Resource And Start/End Time Test_Resource ${start_time} InvalidEnd + 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 + +ErrReadingGET011 - Query readings by rsource and start/end time fails (Start>End) + ${start_time}= Get current nanoseconds epoch time + ${end_time}= Get current nanoseconds epoch time + When Query Readings By Resource And Start/End Time Test_Resource ${end_time} ${start_time} + 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 + +ErrReadingGET012 - Query readings by rsource and start/end time with invalid offset range + ${start_time}= Get current nanoseconds epoch time + ${end_time}= Evaluate ${start_time}+100000000 + Given Create Multiple Events + When Query readings by resource Simple-Reading and start ${start_time}/end ${end_time} with offset=10 + Then Should Return Status Code "416" + And Should Return Content-Type "application/json" + And Response Time Should Be Less Than "${default_response_time_threshold}"ms + [Teardown] Delete All Events By Age diff --git a/TAF/testScenarios/functionalTest/V2-API/core-data/reading/GET-positive.robot b/TAF/testScenarios/functionalTest/V2-API/core-data/reading/GET-positive.robot index bf23cb70..c874346e 100644 --- a/TAF/testScenarios/functionalTest/V2-API/core-data/reading/GET-positive.robot +++ b/TAF/testScenarios/functionalTest/V2-API/core-data/reading/GET-positive.robot @@ -61,7 +61,7 @@ ReadingGET006 - Query readings by start/end time Given Create Multiple Events Twice To Get Start/End Time When Query Readings By Start/End Time ${start_time} ${end_time} Then Should Return Status Code "200" - And Readings Should Be Created Between ${start_time} And ${end_time} + And Total 9 Readings Should Be Created Between ${start_time} And ${end_time} And Should Return Content-Type "application/json" And Response Time Should Be Less Than "${default_response_time_threshold}"ms [Teardown] Delete All Events By Age @@ -84,10 +84,29 @@ ReadingGET008 - Query a count of all of readings with specified device by device And Response Time Should Be Less Than "${default_response_time_threshold}"ms [Teardown] Delete All Events By Age +ReadingGET009 - Query readings by resource name and time range + ${resource_name} Set Variable Simple-Reading + Given Create Multiple Events Twice To Get Start/End Time + When Query Readings By Resource And Start/End Time ${resource_name} ${start_time} ${end_time} + Then Should Return Status Code "200" + And All 6 Readings Resource Should be ${resource_name} + And Total 6 Readings Should Be Created Between ${start_time} And ${end_time} + And Should Return Content-Type "application/json" + And Response Time Should Be Less Than "${default_response_time_threshold}"ms + [Teardown] Delete All Events By Age + *** Keywords *** -Readings Should Be Created Between ${start} And ${end} - ${count}= Get Length ${content}[readings] - Should Be Equal As Integers ${count} 9 - FOR ${index} IN RANGE 0 9 - Should Be True ${end} >= ${content}[readings][${index}][origin] >=${start} - END +Total ${number} Readings Should Be Created Between ${start} And ${end} + ${count}= Get Length ${content}[readings] + Should Be Equal As Integers ${count} ${number} + FOR ${index} IN RANGE 0 ${number} + Should Be True ${end} >= ${content}[readings][${index}][origin] >=${start} + END + +All ${number} Readings Resource Should be ${resource_name} + ${count}= Get Length ${content}[readings] + Should Be Equal As Integers ${count} ${number} + FOR ${index} IN RANGE 0 ${number} + Should Be Equal As Strings ${resource_name} ${content}[readings][${index}][resourceName] + END +