From f00a55802e92bb00d1c08d66b2165e7a9851810a Mon Sep 17 00:00:00 2001 From: ranim-n Date: Fri, 23 Feb 2024 11:10:01 +0100 Subject: [PATCH] check whether notification payload contains system attributes or not depending on sysAttrs value --- .../046_16.robot | 70 +++++++++++++++++++ .../046_17.robot | 70 +++++++++++++++++++ ...ith-false-sysAttrs-parameter-sample.jsonld | 20 ++++++ ...with-true-sysAttrs-parameter-sample.jsonld | 20 ++++++ .../test_ContextInformation_Subscription.py | 14 ++++ 5 files changed, 194 insertions(+) create mode 100644 TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16.robot create mode 100644 TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_17.robot create mode 100644 data/subscriptions/subscription-with-false-sysAttrs-parameter-sample.jsonld create mode 100644 data/subscriptions/subscription-with-true-sysAttrs-parameter-sample.jsonld diff --git a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16.robot new file mode 100644 index 00000000..97abcfef --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16.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-sample.jsonld +${building_id_prefix} urn:ngsi-ld:Building: +${entity_building_filepath} building-simple-attributes-sample.jsonld +${fragment_filename} airQualityLevel-fragment.jsonld +${notification_server_send_url} http://${notification_server_host}:${notification_server_port}/notify + + +*** Test Cases *** +046_16_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 + + ${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_17.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_17.robot new file mode 100644 index 00000000..d23e8781 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_17.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-sample.jsonld +${building_id_prefix} urn:ngsi-ld:Building: +${entity_building_filepath} building-simple-attributes-sample.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 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 + + ${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-sample.jsonld b/data/subscriptions/subscription-with-false-sysAttrs-parameter-sample.jsonld new file mode 100644 index 00000000..899b6182 --- /dev/null +++ b/data/subscriptions/subscription-with-false-sysAttrs-parameter-sample.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-sample.jsonld b/data/subscriptions/subscription-with-true-sysAttrs-parameter-sample.jsonld new file mode 100644 index 00000000..5083ad01 --- /dev/null +++ b/data/subscriptions/subscription-with-true-sysAttrs-parameter-sample.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/tests/test_ContextInformation_Subscription.py b/doc/tests/test_ContextInformation_Subscription.py index 215414ca..43275775 100644 --- a/doc/tests/test_ContextInformation_Subscription.py +++ b/doc/tests/test_ContextInformation_Subscription.py @@ -189,6 +189,20 @@ class TestCISubscription(TestCase): self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_046_16(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_16.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_046_16.json' + + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + + 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_031_01(self): robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_01.robot' expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/031_01.json' -- GitLab