From 815674adf90408c325edf350f9d13fd03e82b4ad Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Tue, 5 Nov 2024 18:40:38 +0100 Subject: [PATCH] feat: check whether notification payload contains system attributes or not depending on sysAttrs value --- .../046_17.robot | 70 +++++++++++++++++++ .../046_18.robot | 70 +++++++++++++++++++ ...ption-with-false-sysAttrs-parameter.jsonld | 20 ++++++ ...iption-with-true-sysAttrs-parameter.jsonld | 20 ++++++ .../Subscription/046_17.json | 42 +++++++++++ .../Subscription/046_18.json | 42 +++++++++++ .../test_ContextInformation_Subscription.py | 12 ++++ 7 files changed, 276 insertions(+) create mode 100644 TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_17.robot create mode 100644 TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_18.robot create mode 100644 data/subscriptions/subscription-with-false-sysAttrs-parameter.jsonld create mode 100644 data/subscriptions/subscription-with-true-sysAttrs-parameter.jsonld create mode 100644 doc/files/ContextInformation/Subscription/046_17.json create mode 100644 doc/files/ContextInformation/Subscription/046_18.json diff --git a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_17.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_17.robot new file mode 100644 index 00000000..faf29843 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_17.robot @@ -0,0 +1,70 @@ +*** Settings *** +Documentation The system generated attributes are included in the response payload body of a notification if sysAttrs parameter is set to true. + +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationSubscription.resource +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource +Resource ${EXECDIR}/resources/NotificationUtils.resource + +Suite Setup Before Test +Suite Teardown After Test + + +*** Variables *** +${subscription_id_prefix} urn:ngsi-ld:Subscription: +${subscription_payload_file_path} subscriptions/subscription-with-true-sysAttrs-parameter.jsonld +${building_id_prefix} urn:ngsi-ld:Building: +${entity_building_filepath} building-simple-attributes.jsonld +${fragment_filename} airQualityLevel-fragment.jsonld +${notification_server_send_url} http://${notification_server_host}:${notification_server_port}/notify + + +*** Test Cases *** +046_17_01 Check that the response payload body contains the system generated attributes if sysAttrs parameter is set to true + [Documentation] The system generated attributes are included in the response payload body of a notification if sysAttrs parameter is set to true. + [Tags] sub-notification 5_8_6 since_v1.6.1 + + ${response}= Update Entity Attributes ${entity_id} ${fragment_filename} ${CONTENT_TYPE_LD_JSON} + + ${notification} ${headers}= Wait for notification timeout=${10} + + ${notification_payload}= Get Request Body + + ${notification}= Evaluate json.loads('''${notification_payload}''') json + + Dictionary Should Contain Key ${notification}[data][0] createdAt + Dictionary Should Contain Key ${notification}[data][0] modifiedAt + + +*** Keywords *** +Before Test + Start Local Server ${notification_server_host} ${notification_server_port} + Setup Initial Subscriptions + +Setup Initial Subscriptions + ${subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${entity_id}= Generate Random Entity Id ${building_id_prefix} + ${subscription_payload}= Load Subscription Sample With Reachable Endpoint + ... ${subscription_payload_file_path} + ... ${subscription_id} + ... ${notification_server_send_url} + ${subscription_payload}= Set Entity Id In Subscription ${subscription_payload} ${entity_id} + Set Suite Variable ${entity_id} + Set Suite Variable ${subscription_id} + + Create Entity ${entity_building_filepath} ${entity_id} + Sleep 1s + Create Subscription From Subscription Payload ${subscription_payload} ${CONTENT_TYPE_LD_JSON} + Sleep 1s + +After Test + Delete Initial Subscriptions + Delete Initial Entity + Stop Local Server + +Delete Initial Subscriptions + Delete Subscription ${subscription_id} + +Delete Initial Entity + Delete Entity by Id ${entity_id} diff --git a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_18.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_18.robot new file mode 100644 index 00000000..a1c6aea5 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_18.robot @@ -0,0 +1,70 @@ +*** Settings *** +Documentation The system generated attributes are not included in the response payload body of a notification if sysAttrs parameter is set to false. + +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationSubscription.resource +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource +Resource ${EXECDIR}/resources/NotificationUtils.resource + +Suite Setup Before Test +Suite Teardown After Test + + +*** Variables *** +${subscription_id_prefix} urn:ngsi-ld:Subscription: +${subscription_payload_file_path} subscriptions/subscription-with-false-sysAttrs-parameter.jsonld +${building_id_prefix} urn:ngsi-ld:Building: +${entity_building_filepath} building-simple-attributes.jsonld +${fragment_filename} airQualityLevel-fragment.jsonld +${notification_server_send_url} http://${notification_server_host}:${notification_server_port}/notify + + +*** Test Cases *** +046_18_01 Check that the response payload body does not contain the system generated attributes if sysAttrs parameter is set to false + [Documentation] The system generated attributes are not included in the response payload body of a notification if sysAttrs parameter is set to false. + [Tags] sub-notification 5_8_6 since_v1.6.1 + + ${response}= Update Entity Attributes ${entity_id} ${fragment_filename} ${CONTENT_TYPE_LD_JSON} + + ${notification} ${headers}= Wait for notification timeout=${10} + + ${notification_payload}= Get Request Body + + ${notification}= Evaluate json.loads('''${notification_payload}''') json + + Dictionary Should Not Contain Key ${notification}[data][0] createdAt + Dictionary Should Not Contain Key ${notification}[data][0] modifiedAt + + +*** Keywords *** +Before Test + Start Local Server ${notification_server_host} ${notification_server_port} + Setup Initial Subscriptions + +Setup Initial Subscriptions + ${subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${entity_id}= Generate Random Entity Id ${building_id_prefix} + ${subscription_payload}= Load Subscription Sample With Reachable Endpoint + ... ${subscription_payload_file_path} + ... ${subscription_id} + ... ${notification_server_send_url} + ${subscription_payload}= Set Entity Id In Subscription ${subscription_payload} ${entity_id} + Set Suite Variable ${entity_id} + Set Suite Variable ${subscription_id} + + Create Entity ${entity_building_filepath} ${entity_id} + Sleep 1s + Create Subscription From Subscription Payload ${subscription_payload} ${CONTENT_TYPE_LD_JSON} + Sleep 1s + +After Test + Delete Initial Subscriptions + Delete Initial Entity + Stop Local Server + +Delete Initial Subscriptions + Delete Subscription ${subscription_id} + +Delete Initial Entity + Delete Entity by Id ${entity_id} diff --git a/data/subscriptions/subscription-with-false-sysAttrs-parameter.jsonld b/data/subscriptions/subscription-with-false-sysAttrs-parameter.jsonld new file mode 100644 index 00000000..899b6182 --- /dev/null +++ b/data/subscriptions/subscription-with-false-sysAttrs-parameter.jsonld @@ -0,0 +1,20 @@ +{ + "id":"urn:ngsi-ld:Subscription:randomUUID", + "type":"Subscription", + "entities":[ + { + "type":"Building" + } + ], + "notification":{ + "format":"keyValues", + "endpoint":{ + "uri":"http://my.endpoint.org/notify", + "accept":"application/json" + }, + "sysAttrs" : false + }, + "@context":[ + "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld" + ] +} \ No newline at end of file diff --git a/data/subscriptions/subscription-with-true-sysAttrs-parameter.jsonld b/data/subscriptions/subscription-with-true-sysAttrs-parameter.jsonld new file mode 100644 index 00000000..5083ad01 --- /dev/null +++ b/data/subscriptions/subscription-with-true-sysAttrs-parameter.jsonld @@ -0,0 +1,20 @@ +{ + "id":"urn:ngsi-ld:Subscription:randomUUID", + "type":"Subscription", + "entities":[ + { + "type":"Building" + } + ], + "notification":{ + "format":"keyValues", + "endpoint":{ + "uri":"http://my.endpoint.org/notify", + "accept":"application/json" + }, + "sysAttrs" : true + }, + "@context":[ + "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld" + ] +} \ No newline at end of file diff --git a/doc/files/ContextInformation/Subscription/046_17.json b/doc/files/ContextInformation/Subscription/046_17.json new file mode 100644 index 00000000..f7e487da --- /dev/null +++ b/doc/files/ContextInformation/Subscription/046_17.json @@ -0,0 +1,42 @@ +{ + "tp_id": "TP/NGSI-LD/CI/SUB/046_17", + "test_objective": "The system generated attributes are included in the response payload body of a notification if sysAttrs parameter is set to true.", + "reference": "ETSI GS CIM 009 V1.6.1 [], clause 5.8.6", + "config_id": "", + "parent_release": "v1.6.1", + "clauses": [ + "5.8.6" + ], + "pics_selection": "", + "keywords": [ + "Before Test", + "Setup Initial Subscriptions", + "After Test", + "Delete Initial Subscriptions", + "Delete Initial Entity" + ], + "teardown": "After Test", + "initial_condition": "with {\n the SUT containing an initial state\n}", + "test_cases": [ + { + "name": "046_17_01 Check that the response payload body contains the system generated attributes if sysAttrs parameter is set to true", + "permutation_tp_id": "TP/NGSI-LD/CI/SUB/046_17_01", + "doc": "The system generated attributes are included in the response payload body of a notification if sysAttrs parameter is set to true.", + "tags": [ + "5_8_6", + "since_v1.6.1", + "sub-notification" + ], + "setup": null, + "teardown": null, + "template": null, + "then": "then {\n the client at '${endpoint}' receives a valid Notification containing:\n Notification received After waiting '10' seconds and\n Notification received The dictionary `${notification}[data][0]' should contain the key 'createdAt' and\n Notification received The dictionary `${notification}[data][0]' should contain the key 'modifiedAt'\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entities/{entityId}/attrs/{attributeId}'\n method set to 'PATCH'\n Update Entity Attributes and\n Query Parameter: id set to '${entity_id}' and\n Query Parameter: fragment_filename set to '${fragment_filename}' and\n Query Parameter: content_type set to 'application/ld+json'\n}", + "http_verb": "PATCH", + "endpoint": "entities/{entityId}/attrs/{attributeId}" + } + ], + "permutations": [], + "robotpath": "ContextInformation/Subscription/SubscriptionNotificationBehaviour", + "robotfile": "046_17" +} \ No newline at end of file diff --git a/doc/files/ContextInformation/Subscription/046_18.json b/doc/files/ContextInformation/Subscription/046_18.json new file mode 100644 index 00000000..d1ce6e83 --- /dev/null +++ b/doc/files/ContextInformation/Subscription/046_18.json @@ -0,0 +1,42 @@ +{ + "tp_id": "TP/NGSI-LD/CI/SUB/046_18", + "test_objective": "The system generated attributes are not included in the response payload body of a notification if sysAttrs parameter is set to false.", + "reference": "ETSI GS CIM 009 V1.6.1 [], clause 5.8.6", + "config_id": "", + "parent_release": "v1.6.1", + "clauses": [ + "5.8.6" + ], + "pics_selection": "", + "keywords": [ + "Before Test", + "Setup Initial Subscriptions", + "After Test", + "Delete Initial Subscriptions", + "Delete Initial Entity" + ], + "teardown": "After Test", + "initial_condition": "with {\n the SUT containing an initial state\n}", + "test_cases": [ + { + "name": "046_18_01 Check that the response payload body does not contain the system generated attributes if sysAttrs parameter is set to false", + "permutation_tp_id": "TP/NGSI-LD/CI/SUB/046_18_01", + "doc": "The system generated attributes are not included in the response payload body of a notification if sysAttrs parameter is set to false.", + "tags": [ + "5_8_6", + "since_v1.6.1", + "sub-notification" + ], + "setup": null, + "teardown": null, + "template": null, + "then": "then {\n the client at '${endpoint}' receives a valid Notification containing:\n Notification received After waiting '10' seconds\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entities/{entityId}/attrs/{attributeId}'\n method set to 'PATCH'\n Update Entity Attributes and\n Query Parameter: id set to '${entity_id}' and\n Query Parameter: fragment_filename set to '${fragment_filename}' and\n Query Parameter: content_type set to 'application/ld+json'\n}", + "http_verb": "PATCH", + "endpoint": "entities/{entityId}/attrs/{attributeId}" + } + ], + "permutations": [], + "robotpath": "ContextInformation/Subscription/SubscriptionNotificationBehaviour", + "robotfile": "046_18" +} \ No newline at end of file diff --git a/doc/tests/test_ContextInformation_Subscription.py b/doc/tests/test_ContextInformation_Subscription.py index 8a550fbd..fdd551bb 100644 --- a/doc/tests/test_ContextInformation_Subscription.py +++ b/doc/tests/test_ContextInformation_Subscription.py @@ -215,6 +215,18 @@ class TestCISubscription(TestCase): expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_16_02.json' difference_file = f'{self.folder_test_suites}/doc/results/out_046_16_02.json' + def test_046_17(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_17.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_17.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_046_17.json' + + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + + def test_046_18(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_18.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_18.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_046_18.json' + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) def test_031_01(self): -- GitLab