From 08993adb72e96f93e70e398cbd9b497224728129 Mon Sep 17 00:00:00 2001 From: Houcem Kacem Date: Wed, 17 Feb 2021 17:11:22 +0100 Subject: [PATCH 1/4] feat: add tp 021_10 --- .../021_10.robot | 36 +++++++++++++++++++ resources/ApiUtils.resource | 3 +- resources/AssertionUtils.resource | 2 +- resources/JsonUtils.resource | 8 +++++ resources/variables.py | 3 +- 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot diff --git a/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot b/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot new file mode 100644 index 00000000..35f5a2eb --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot @@ -0,0 +1,36 @@ +*** Settings *** +Documentation Check that you can query the temporal evolution of entities matching the given NGSI-LD Context Source filter +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Suite Setup Create Initial Context Source Registration +Suite Teardown Delete Initial Context Source Registration + +*** Variable *** +${context_source_registration_id_prefix}= urn:ngsi-ld:ContextSourceRegistration: +${context_source_registration_payload_file_path}= csourceRegistrations/context-source-registration-observationInterval-sample.jsonld + +*** Test Case *** +Query the temporal evolution of entities matching the given NGSI-LD context source filter + [Documentation] Check that you can query the temporal evolution of entities matching the given NGSI-LD Context Source filter + [Tags] mandatory + + @{entity_types_to_be_retrieved}= Create List Building + + Query Temporal Representation Of Entities entity_types=${entity_types_to_be_retrieved} csf=endpoint==${context_source_url} timerel=after timeAt=2020-07-01T12:05:00Z context=${ngsild_test_suite_context} + + Check Response Status Code Set To 200 + Check Response Body Containing Number Of Entities Building ${2} + +*** Keywords *** +Create Initial Context Source Registration + ${context_source_registration_id}= Generate Random Entity Id ${context_source_registration_id_prefix} + ${context_source_registration_payload}= Load Context Source Registration Sample With Reachable Context Source ${context_source_registration_payload_file_path} ${context_source_registration_id} + + Create Context Source Registration ${context_source_registration_payload} + + Set Suite Variable ${context_source_registration_id} + +Delete Initial Context Source Registration + Delete Context Source Registration ${context_source_registration_id} diff --git a/resources/ApiUtils.resource b/resources/ApiUtils.resource index 1a69029a..7a31f554 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -369,7 +369,7 @@ Retrieve Temporal Representation Of Entity Set Test Variable ${response} Query Temporal Representation Of Entities - [Arguments] ${context}=${EMPTY} ${entity_types}=${EMPTY} ${entity_ids}=${EMPTY} ${entity_id_pattern}=${EMPTY} ${ngsild_query}=${EMPTY} ${georel}=${EMPTY} ${geometry}=${EMPTY} ${coordinates}=${EMPTY} ${geoproperty}=${EMPTY} ${timerel}=${EMPTY} ${timeAt}=${EMPTY} ${attrs}=${EMPTY} ${limit}=${EMPTY} ${lastN}=${EMPTY} + [Arguments] ${context}=${EMPTY} ${entity_types}=${EMPTY} ${entity_ids}=${EMPTY} ${entity_id_pattern}=${EMPTY} ${ngsild_query}=${EMPTY} ${csf}=${EMPTY} ${georel}=${EMPTY} ${geometry}=${EMPTY} ${coordinates}=${EMPTY} ${geoproperty}=${EMPTY} ${timerel}=${EMPTY} ${timeAt}=${EMPTY} ${attrs}=${EMPTY} ${limit}=${EMPTY} ${lastN}=${EMPTY} ${entity_types_length} = Get Length ${entity_types} ${entity_ids_length} = Get Length ${entity_ids} ${attrs_length} = Get Length ${attrs} @@ -384,6 +384,7 @@ Query Temporal Representation Of Entities Run Keyword If '${lastN}'!='' Set To Dictionary ${params} lastN=${lastN} Run Keyword If '${entity_id_pattern}'!='' Set To Dictionary ${params} idPattern=${entity_id_pattern} Run Keyword If '${ngsild_query}'!='' Set To Dictionary ${params} q=${ngsild_query} + Run Keyword If '${csf}'!='' Set To Dictionary ${params} csf=${csf} Run Keyword If '${georel}'!='' Set To Dictionary ${params} georel=${georel} Run Keyword If '${geometry}'!='' Set To Dictionary ${params} geometry=${geometry} Run Keyword If '${coordinates}'!='' Set To Dictionary ${params} coordinates=${coordinates} diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 0349eb62..cda0beb8 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -135,7 +135,7 @@ Check Response Body Containing List Containing Subscription elements ${comparison_result}= Compare Dictionaries Ignoring Keys ${response['body']} ${subscription_payload} ${EMPTY} Should Be True ${comparison_result} msg=Subscription Comparison Failed -# Since response body can be a json object if it contains one subscription +# Since response body can be a json object if it contains one element # A check on the response body type is needed Check Response Body Containing Number Of Entities [Arguments] ${expected_entity_type} ${expected_length} diff --git a/resources/JsonUtils.resource b/resources/JsonUtils.resource index c0827f79..297883f4 100644 --- a/resources/JsonUtils.resource +++ b/resources/JsonUtils.resource @@ -34,6 +34,14 @@ Load Subscription Sample With Reachable Endpoint [return] ${subscription} +Load Context Source Registration Sample With Reachable Context Source + [Arguments] ${context_source_registration_file_path} ${context_source_registration_id}=${EMPTY} ${context_source_endpoint_uri}=${context_source_url} + + ${context_source_registration_payload}= Load Test Sample ${context_source_registration_file_path} ${context_source_registration_id} + ${context_source_registration}= Update Value To Json ${context_source_registration_payload} $..endpoint ${context_source_endpoint_uri} + + [return] ${context_source_registration} + Remove Entity Type [Arguments] ${entity} diff --git a/resources/variables.py b/resources/variables.py index 8cbd37d4..a3824774 100644 --- a/resources/variables.py +++ b/resources/variables.py @@ -3,7 +3,8 @@ def get_variables(arg=None): 'url': 'https://broker-ngsi-ld.demeter.ubiwhere.com/ngsi-ld/v1', 'ngsild_test_suite_context': 'https://raw.githubusercontent.com/easy-global-market/ngsild-api-data-models/feature/add-json-ld-context-for-ngsi-ld-test-suite/ngsi-ld-test-suite/ngsi-ld-test-suite-context.jsonld', 'notification_server_host': '0.0.0.0', - 'notification_server_port': 8085 + 'notification_server_port': 8085, + 'context_source_url': 'http://my.csource.org:1026' } return variables \ No newline at end of file -- GitLab From e4585606ce86b44d9d55a6a458d63d72a31f5548 Mon Sep 17 00:00:00 2001 From: Houcem Kacem Date: Wed, 17 Feb 2021 17:14:37 +0100 Subject: [PATCH 2/4] fix: fix csf query --- .../QueryTemporalEvolutionOfEntities/021_10.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot b/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot index 35f5a2eb..2ec1fbca 100644 --- a/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot +++ b/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot @@ -18,7 +18,7 @@ Query the temporal evolution of entities matching the given NGSI-LD context sour @{entity_types_to_be_retrieved}= Create List Building - Query Temporal Representation Of Entities entity_types=${entity_types_to_be_retrieved} csf=endpoint==${context_source_url} timerel=after timeAt=2020-07-01T12:05:00Z context=${ngsild_test_suite_context} + Query Temporal Representation Of Entities entity_types=${entity_types_to_be_retrieved} csf=endpoint=="${context_source_url}" timerel=after timeAt=2020-07-01T12:05:00Z context=${ngsild_test_suite_context} Check Response Status Code Set To 200 Check Response Body Containing Number Of Entities Building ${2} -- GitLab From 8ba370bf12e952f0250c4c18219fe6861cfdef32 Mon Sep 17 00:00:00 2001 From: Houcem Kacem Date: Thu, 18 Feb 2021 15:05:26 +0100 Subject: [PATCH 3/4] feat: mock context source to check request redirection --- .../021_10.robot | 10 +++++++-- resources/JsonUtils.resource | 1 + resources/MockServerUtils.resource | 21 +++++++++++++++++++ resources/variables.py | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 resources/MockServerUtils.resource diff --git a/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot b/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot index 2ec1fbca..ede2080d 100644 --- a/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot +++ b/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot @@ -3,6 +3,7 @@ Documentation Check that you can query the temporal evolution of entities matc Resource ${EXECDIR}/resources/ApiUtils.resource Resource ${EXECDIR}/resources/AssertionUtils.resource Resource ${EXECDIR}/resources/JsonUtils.resource +Resource ${EXECDIR}/resources/MockServerUtils.resource Suite Setup Create Initial Context Source Registration Suite Teardown Delete Initial Context Source Registration @@ -10,6 +11,7 @@ Suite Teardown Delete Initial Context Source Registration *** Variable *** ${context_source_registration_id_prefix}= urn:ngsi-ld:ContextSourceRegistration: ${context_source_registration_payload_file_path}= csourceRegistrations/context-source-registration-observationInterval-sample.jsonld +${context_source_url}= http://${context_source_host}:${context_source_port} *** Test Case *** Query the temporal evolution of entities matching the given NGSI-LD context source filter @@ -20,11 +22,13 @@ Query the temporal evolution of entities matching the given NGSI-LD context sour Query Temporal Representation Of Entities entity_types=${entity_types_to_be_retrieved} csf=endpoint=="${context_source_url}" timerel=after timeAt=2020-07-01T12:05:00Z context=${ngsild_test_suite_context} + Wait for redirected request Check Response Status Code Set To 200 - Check Response Body Containing Number Of Entities Building ${2} - +q *** Keywords *** Create Initial Context Source Registration + Start Context Source Mock Server + ${context_source_registration_id}= Generate Random Entity Id ${context_source_registration_id_prefix} ${context_source_registration_payload}= Load Context Source Registration Sample With Reachable Context Source ${context_source_registration_payload_file_path} ${context_source_registration_id} @@ -33,4 +37,6 @@ Create Initial Context Source Registration Set Suite Variable ${context_source_registration_id} Delete Initial Context Source Registration + Stop Context Source Mock Server + Delete Context Source Registration ${context_source_registration_id} diff --git a/resources/JsonUtils.resource b/resources/JsonUtils.resource index 297883f4..07767d1d 100644 --- a/resources/JsonUtils.resource +++ b/resources/JsonUtils.resource @@ -6,6 +6,7 @@ Library JSONLibrary *** Variable *** ${date_format}= %Y-%m-%dT%H:%M:%SZ ${notification_server_url}= http://${notification_server_host}:${notification_server_port}/notify +${context_source_url}= http://${context_source_host}:${context_source_port} *** Keywords *** Load Entity diff --git a/resources/MockServerUtils.resource b/resources/MockServerUtils.resource new file mode 100644 index 00000000..9aa766e2 --- /dev/null +++ b/resources/MockServerUtils.resource @@ -0,0 +1,21 @@ +*** Settings *** +Documentation Mock http server for context sources +Library HttpCtrl.Server + +*** Keywords *** +Start Context Source Mock Server + #Initialize HTTP Client And Server + Start Server 0.0.0.0 8086 + +Wait for redirected request + [Arguments] ${timeout}=${5} + #HTTP server receives it and checks incoming request for correctness + #.. "Wait For Request" + #.... This call is blocked until HTTP request arrives or timeout. + #.... Further detaills: https://annoviko.github.io/robotframework-httpctrl/server.html#Wait%20For%20Request + Wait For Request ${timeout} + Reply By 200 + +Stop Context Source Mock Server + #Terminate HTTP Server + Stop Server diff --git a/resources/variables.py b/resources/variables.py index a3824774..4890d76b 100644 --- a/resources/variables.py +++ b/resources/variables.py @@ -4,7 +4,8 @@ def get_variables(arg=None): 'ngsild_test_suite_context': 'https://raw.githubusercontent.com/easy-global-market/ngsild-api-data-models/feature/add-json-ld-context-for-ngsi-ld-test-suite/ngsi-ld-test-suite/ngsi-ld-test-suite-context.jsonld', 'notification_server_host': '0.0.0.0', 'notification_server_port': 8085, - 'context_source_url': 'http://my.csource.org:1026' + 'context_source_host': '0.0.0.0', + 'context_source_port': 8086 } return variables \ No newline at end of file -- GitLab From 02b5eed67242faf8685f2dd749c69bde8dabc076 Mon Sep 17 00:00:00 2001 From: Houcem Kacem Date: Thu, 18 Feb 2021 15:06:44 +0100 Subject: [PATCH 4/4] fix: fix code --- .../QueryTemporalEvolutionOfEntities/021_10.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot b/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot index ede2080d..05bdf75f 100644 --- a/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot +++ b/TP/NGSI-LD/ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities/021_10.robot @@ -24,7 +24,7 @@ Query the temporal evolution of entities matching the given NGSI-LD context sour Wait for redirected request Check Response Status Code Set To 200 -q + *** Keywords *** Create Initial Context Source Registration Start Context Source Mock Server -- GitLab