diff --git a/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_01.robot b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_01.robot new file mode 100644 index 0000000000000000000000000000000000000000..065e4771e2716c0a229c0d8452480b25c924e928 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_01.robot @@ -0,0 +1,34 @@ +*** Settings *** +Documentation Check that you can retrieve a context source registration subscription +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Suite Setup Setup Initial Context Source Registration Subscription +Suite Teardown Delete Created Context Source Registration Subscription + +*** Variable *** +${subscription_id_prefix}= urn:ngsi-ld:Subscription: +${subscription_payload_file_path}= csourceSubscriptions/subscription-sample.jsonld + +*** Test Case *** +Retrieve Context Source Registration Subscription + [Documentation] Check that you can retrieve a context source registration subscription + [Tags] mandatory + + Retrieve Context Source Registration Subscription ${subscription_id} context=${ngsild_test_suite_context} + + Check Response Status Code Set To 200 + Check Response Body Containing Subscription element ${subscription_payload_file_path} ${subscription_id} + +*** Keywords *** +Setup Initial Context Source Registration Subscription + ${subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${subscription_payload}= Load Test Sample ${subscription_payload_file_path} ${subscription_id} + + Create Context Source Registration Subscription ${subscription_payload} + + Set Suite Variable ${subscription_id} + +Delete Created Context Source Registration Subscription + Delete Context Source Registration Subscription ${subscription_id} diff --git a/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_02.robot b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_02.robot new file mode 100644 index 0000000000000000000000000000000000000000..f256820e81f8ca6409d16d89683a19d572e637c4 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_02.robot @@ -0,0 +1,16 @@ +*** Settings *** +Documentation Check that you cannot retrieve a context source registration subscription with an invalid URI, an error of type BadRequestData shall be raised +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Test Case *** +Retrieve Context Source Registration Subscription With An Invalid Id + [Documentation] Check that you cannot retrieve a context source registration subscription with an invalid URI, an error of type BadRequestData shall be raised + [Tags] mandatory + + Retrieve Context Source Registration Subscription invalidUri + + Check Response Status Code Set To 400 + Check Response Body Containing ProblemDetails Element Containing Type Element set to ${response} ${ERROR_TYPE_BAD_REQUEST_DATA} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response} diff --git a/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_03.robot b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_03.robot new file mode 100644 index 0000000000000000000000000000000000000000..d48f640aa497d60b4782c3e4ccff06e875406200 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_03.robot @@ -0,0 +1,16 @@ +*** Settings *** +Documentation Check that you cannot retrieve an unknown context source registration subscription, an error of type ResourceNotFound shall be raised +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Test Case *** +Retrieve Unknown Context Source Registration Subscription + [Documentation] Check that you cannot retrieve an unknown context source registration subscription, an error of type ResourceNotFound shall be raised + [Tags] mandatory + + Retrieve Context Source Registration Subscription urn:ngsi-ld:Subscription:unknowSubscription + + Check Response Status Code Set To 404 + Check Response Body Containing ProblemDetails Element Containing Type Element set to ${response} ${ERROR_TYPE_RESOURCE_NOT_FOUND} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response} diff --git a/libraries/assertionUtils.py b/libraries/assertionUtils.py index 87a56863b6d7e5ee42c8434754027d284a094dc2..fb7e614ed976b8262948c97e103e842cb09fe77a 100644 --- a/libraries/assertionUtils.py +++ b/libraries/assertionUtils.py @@ -4,8 +4,8 @@ def compare_dictionaries_ignoring_keys(dict1, dict2, exclude_regex_paths): """Function exposed as a keyword to compare two dictionaries :param dict1: actual dictionary :param dict2: expected dictionary - :param exclude_regex_paths: regex path of keys to be ignored + :param exclude_regex_paths: list of regex paths of keys to be ignored """ - res = DeepDiff(dict1, dict2, exclude_regex_paths=[exclude_regex_paths], ignore_order=True) + res = DeepDiff(dict1, dict2, exclude_regex_paths=exclude_regex_paths, ignore_order=True) print(res) return not res diff --git a/resources/ApiUtils.resource b/resources/ApiUtils.resource index ca87fce190fece970b92240fb87e8ddcf8e7636a..9925f19f293b778b44b091b397ec11267d4c9764 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -410,9 +410,11 @@ Update Context Source Registration Subscription Set Test Variable ${response} Retrieve Context Source Registration Subscription - [Arguments] ${subscription_id} + [Arguments] ${subscription_id} ${context}=${EMPTY} - ${response}= GET ${CONTEXT_SOURCE_REGISTRATION_SUBSCRIPTION_ENDPOINT_PATH}/${subscription_id} + &{headers}= Create Dictionary + Run Keyword If '${context}'!='' Set To Dictionary ${headers} Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json" + ${response}= GET ${CONTEXT_SOURCE_REGISTRATION_SUBSCRIPTION_ENDPOINT_PATH}/${subscription_id} headers=${headers} Output request Output response diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 415a2d02e7d98fefd358005d6fc999142c7df854..25c5f6fcb3636752edffbf6233cd8be39c2b5cf4 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -4,6 +4,8 @@ Library ${EXECDIR}/libraries/assertionUtils.py *** Variable *** ${instance_id_regex_expr}= root\\[.*\\]\\['instanceId'\\] ${notification_timestamps_regex_expr}= root\\['last.*'\\] +${context_regex_expr}= root\\['@context'\\] +${status_regex_expr}= root\\['status'\\] *** Keywords *** Check Response Status Code @@ -36,13 +38,21 @@ Check Response Body Content ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response_body} ${entity_payload} ${instance_id_regex_expr} Should Be True ${comparaison_result} msg=Entity Comparaison Failed +# Since Http headers names are case-insensitive (from Http specification) +# We check both Location and location headers Check Response Headers Containing URI set to [Arguments] ${expected_path} ${expected_entity_id} ${response} - Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['location']} ignore_order=True + Run Keyword If 'Location' in ${response['headers']} Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['Location']} ignore_order=True + Run Keyword If 'location' in ${response['headers']} Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['location']} ignore_order=True + +# Since Http headers names are case-insensitive (from Http specification) +# We check both Location and location headers Check Response Headers ID Not Empty [Arguments] ${response} - ${id}= Fetch From Right ${response['headers']['location']} / + + ${location_header}= Set Variable If 'Location' in ${response['headers']} ${response['headers']['Location']} ${response['headers']['location']} + ${id}= Fetch From Right ${location_header} / Should Not Be Empty ${id} [return] ${id} @@ -104,6 +114,14 @@ Check Response Body Containing List Containing EntityTemporal elements ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response['body']} ${temporal_entities_representation_payload} ${instance_id_regex_expr} Should Be True ${comparaison_result} msg=EntityTemporal List Comparaison Failed +Check Response Body Containing Subscription element + [Arguments] ${expectation_filename} ${subscription_id} + ${subscription_payload}= Load Json From File ${EXECDIR}/data/${expectation_filename} + ${subscription}= Update Value To Json ${subscription_payload} $..id ${subscription_id} + ${ignored_keys}= Create List ${status_regex_expr} ${context_regex_expr} + ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response['body']} ${subscription} ${ignored_keys} + Should Be True ${comparaison_result} msg=Subscription Comparaison Failed + Check Response Body Type When Using Session Request [Arguments] ${response} ${type} Should Be Equal ${response['type']} ${type}