From c9d2929af56571e6787d8c2b3921eb0a3af630c0 Mon Sep 17 00:00:00 2001 From: Houcem Kacem Date: Wed, 17 Mar 2021 12:24:02 +0100 Subject: [PATCH] feat: add tcs for query subscriptions --- .../QuerySubscriptions/031_01.robot | 45 +++++++++++++++ .../QuerySubscriptions/031_02.robot | 50 ++++++++++++++++ .../subscriptions-031-01-expectation.json | 57 +++++++++++++++++++ ...bscription-watchedAttributes-sample.jsonld | 20 +++++++ resources/ApiUtils.resource | 12 ++-- 5 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_01.robot create mode 100644 TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_02.robot create mode 100644 data/subscriptions/expectations/subscriptions-031-01-expectation.json create mode 100644 data/subscriptions/subscription-watchedAttributes-sample.jsonld diff --git a/TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_01.robot b/TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_01.robot new file mode 100644 index 00000000..4507b2df --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_01.robot @@ -0,0 +1,45 @@ +*** Settings *** +Documentation Check that you can query a list of subscriptions +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Suite Setup Setup Initial Subscriptions +Suite Teardown Delete Initial Subscriptions + +*** Variable *** +${subscription_id_prefix}= urn:ngsi-ld:Subscription: +${first_subscription_payload_file_path}= subscriptions/subscription-sample.jsonld +${second_subscription_payload_file_path}= subscriptions/subscription-watchedAttributes-sample.jsonld +${third_subscription_payload_file_path}= subscriptions/subscription-inactive-sample.jsonld +${expectation_file_path}= subscriptions/expectations/subscriptions-031-01-expectation.json + +*** Test Case *** +Query Subscriptions + [Documentation] Check that you can query a list of subscriptions + [Tags] mandatory + + Query Subscriptions context=${ngsild_test_suite_context} + + @{subscription_ids}= Create List ${first_subscription_id} ${second_subscription_id} ${third_subscription_id} + Check Response Status Code Set To 200 + Check Response Body Containing List Containing Subscription elements ${expectation_file_path} ${subscription_ids} + +*** Keywords *** +Setup Initial Subscriptions + ${first_subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${second_subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${third_subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + + Create Subscription ${first_subscription_id} ${first_subscription_payload_file_path} ${CONTENT_TYPE_LD_JSON} + Create Subscription ${second_subscription_id} ${second_subscription_payload_file_path} ${CONTENT_TYPE_LD_JSON} + Create Subscription ${third_subscription_id} ${third_subscription_payload_file_path} ${CONTENT_TYPE_LD_JSON} + + Set Suite Variable ${first_subscription_id} + Set Suite Variable ${second_subscription_id} + Set Suite Variable ${third_subscription_id} + +Delete Initial Subscriptions + Delete Subscription ${first_subscription_id} + Delete Subscription ${second_subscription_id} + Delete Subscription ${third_subscription_id} diff --git a/TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_02.robot b/TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_02.robot new file mode 100644 index 00000000..15078a31 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_02.robot @@ -0,0 +1,50 @@ +*** Settings *** +Documentation Check that you can query a list of subscriptions: Pagination logic shall be in place +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Template Query Subscriptions With Limit And Page Parameters +Suite Setup Setup Initial Subscriptions +Suite Teardown Delete Initial Subscriptions + +*** Variable *** +${subscription_id_prefix}= urn:ngsi-ld:Subscription: +${first_subscription_payload_file_path}= subscriptions/subscription-sample.jsonld +${second_subscription_payload_file_path}= subscriptions/subscription-watchedAttributes-sample.jsonld +${third_subscription_payload_file_path}= subscriptions/subscription-inactive-sample.jsonld + +*** Test Cases *** LIMIT PAGE EXPECTED_SUBSCRIPTION_NUMBER PREV_LINK NEXT_LINK +Query Second Subscription ${1} ${2} ${1} ;rel="prev";type="application/ld+json" ;rel="next";type="application/ld+json" +Query Last Subscription ${2} ${2} ${1} ;rel="prev";type="application/ld+json" ${EMPTY} +Query All Subscriptions ${15} ${1} ${3} ${EMPTY} ${EMPTY} + +*** Keywords *** +Query Subscriptions With Limit And Page Parameters + [Arguments] ${limit} ${page} ${expectation_subscription_number} ${prev_link} ${next_link} + [Documentation] Check that you can query a list of subscriptions: Pagination logic shall be in place + [Tags] mandatory + + Query Subscriptions context=${ngsild_test_suite_context} limit=${limit} page=${page} + + Check Response Status Code Set To 200 + Check Response Body Containing Number Of Entities Subscription ${expectation_subscription_number} + Check Pagination Prev And Next Headers ${prev_link} ${next_link} + +Setup Initial Subscriptions + ${first_subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${second_subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${third_subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + + Create Subscription ${first_subscription_id} ${first_subscription_payload_file_path} ${CONTENT_TYPE_LD_JSON} + Create Subscription ${second_subscription_id} ${second_subscription_payload_file_path} ${CONTENT_TYPE_LD_JSON} + Create Subscription ${third_subscription_id} ${third_subscription_payload_file_path} ${CONTENT_TYPE_LD_JSON} + + Set Suite Variable ${first_subscription_id} + Set Suite Variable ${second_subscription_id} + Set Suite Variable ${third_subscription_id} + +Delete Initial Subscriptions + Delete Subscription ${first_subscription_id} + Delete Subscription ${second_subscription_id} + Delete Subscription ${third_subscription_id} diff --git a/data/subscriptions/expectations/subscriptions-031-01-expectation.json b/data/subscriptions/expectations/subscriptions-031-01-expectation.json new file mode 100644 index 00000000..cd952e1f --- /dev/null +++ b/data/subscriptions/expectations/subscriptions-031-01-expectation.json @@ -0,0 +1,57 @@ +[ + { + "id":"urn:ngsi-ld:Subscription:randomUUID", + "type":"Subscription", + "entities":[ + { + "type":"Building" + } + ], + "notification":{ + "format":"keyValues", + "endpoint":{ + "uri":"http://my.endpoint.org/notify", + "accept":"application/json" + } + }, + "status": "active" + }, + { + "id":"urn:ngsi-ld:Subscription:randomUUID", + "type":"Subscription", + "watchedAttributes":[ + "name", + "subCategory" + ], + "entities":[ + { + "type":"Building" + } + ], + "notification":{ + "format":"keyValues", + "endpoint":{ + "uri":"http://my.endpoint.org/notify", + "accept":"application/json" + } + }, + "status": "active" + }, + { + "id":"urn:ngsi-ld:Subscription:randomUUID", + "type":"Subscription", + "entities":[ + { + "type":"Building" + } + ], + "notification":{ + "format":"keyValues", + "endpoint":{ + "uri":"http://my.endpoint.org/notify", + "accept":"application/json" + } + }, + "status": "paused" + } +] \ No newline at end of file diff --git a/data/subscriptions/subscription-watchedAttributes-sample.jsonld b/data/subscriptions/subscription-watchedAttributes-sample.jsonld new file mode 100644 index 00000000..de343a44 --- /dev/null +++ b/data/subscriptions/subscription-watchedAttributes-sample.jsonld @@ -0,0 +1,20 @@ +{ + "id":"urn:ngsi-ld:Subscription:randomUUID", + "type":"Subscription", + "watchedAttributes": ["name", "subCategory"], + "entities":[ + { + "type":"Building" + } + ], + "notification":{ + "format":"keyValues", + "endpoint":{ + "uri":"http://my.endpoint.org/notify", + "accept":"application/json" + } + }, + "@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" + ] +} \ No newline at end of file diff --git a/resources/ApiUtils.resource b/resources/ApiUtils.resource index 3a024e6e..51895df3 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -693,16 +693,20 @@ Delete Subscription [return] ${response} Query Subscriptions - [Arguments] ${limit}=${EMPTY} ${accept}=${EMPTY} + [Arguments] ${context}=${EMPTY} ${limit}=${EMPTY} ${page}=${EMPTY} ${accept}=${EMPTY} + &{headers}= Create Dictionary &{params}= Create Dictionary - Run Keyword If '${accept}'!='' Set To Dictionary ${headers} Accept ${accept} + Run Keyword If '${context}'!='' Set To Dictionary ${headers} Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json" Run Keyword If '${limit}'!='' Set To Dictionary ${params} limit=${limit} + Run Keyword If '${page}'!='' Set To Dictionary ${params} page=${page} + Run Keyword If '${accept}'!='' Set To Dictionary ${headers} Accept ${accept} - ${response}= GET ${SUBSCRIPTION_ENDPOINT_PATH} headers=${headers} query=${params} + ${response}= GET ${SUBSCRIPTION_ENDPOINT_PATH} headers=${headers} query=${params} Output request Output response - [return] ${response} + + Set Test Variable ${response} Retrieve Subscription [Arguments] ${id} ${accept}=${EMPTY} ${context}=${EMPTY} -- GitLab