From 66c5b8018e1fdb269c798be8eef0efad4d07639d Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Tue, 21 Nov 2023 20:42:34 +0100 Subject: [PATCH 1/2] feat(subscription): add simple test for entity type selection --- .../046_16_01.robot | 61 +++++++++++++++++++ .../046_16_02.robot | 56 +++++++++++++++++ ...on-building-entities-type-selection.jsonld | 18 ++++++ .../Subscription/046_16_01.json | 39 ++++++++++++ .../Subscription/046_16_02.json | 39 ++++++++++++ .../test_ContextInformation_Subscription.py | 14 +++++ 6 files changed, 227 insertions(+) create mode 100644 TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot create mode 100644 TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot create mode 100644 data/subscriptions/subscription-building-entities-type-selection.jsonld create mode 100644 doc/files/ContextInformation/Subscription/046_16_01.json create mode 100644 doc/files/ContextInformation/Subscription/046_16_02.json diff --git a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot new file mode 100644 index 00000000..437b266c --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot @@ -0,0 +1,61 @@ +*** Settings *** +Documentation If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query. + +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-building-entities-type-selection.jsonld +${building_id_prefix}= urn:ngsi-ld:Building: +${notification_server_send_url}= http://${notification_server_host}:${notification_server_port}/notify +${entity_building_filepath}= building-simple-attributes-sample.jsonld +${content_type}= application/ld+json + + +*** Test Cases *** +046_16_01 Check that a notification is sent with entity matching the entity type selection + [Documentation] If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query. + [Tags] sub-notification 5_8_6 since_v1.5.1 + + ${entity_id}= Generate Random Entity Id ${building_id_prefix} + ${response}= Create Entity Selecting Content Type + ... ${entity_building_filepath} + ... ${entity_id} + ... ${content_type} + Set Suite Variable ${entity_id} + + ${notification} ${headers}= Wait for notification timeout=${5} + + Should be Equal ${subscription_id} ${notification}[subscriptionId] + Dictionary Should Contain Key ${notification} data + Should Not Be Empty ${notification}[data] Notification data should not be empty + Should be Equal ${entity_id} ${notification}[data][0][id] + + +*** Keywords *** +Setup Initial Subscription + ${subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${subscription_payload}= Load Subscription Sample With Reachable Endpoint + ... ${subscription_payload_file_path} + ... ${subscription_id} + ... ${notification_server_send_url} + Create Subscription From Subscription Payload ${subscription_payload} ${CONTENT_TYPE_LD_JSON} + Set Suite Variable ${subscription_id} + +Before Test + Start Local Server ${notification_server_host} ${notification_server_port} + Sleep 1s + Setup Initial Subscription + +After Test + Delete Subscription ${subscription_id} + Delete Entity by Id ${entity_id} + Stop Local Server diff --git a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot new file mode 100644 index 00000000..23a4f99a --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot @@ -0,0 +1,56 @@ +*** Settings *** +Documentation If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query. + +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-building-entities-type-selection.jsonld +${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: +${notification_server_send_url}= http://${notification_server_host}:${notification_server_port}/notify +${entity_vehicle_filepath}= vehicle-simple-attributes-sample.jsonld +${content_type}= application/ld+json + + +*** Test Cases *** +046_16_02 Check that a notification is not sent if the entity type does not match the entity type selection + [Documentation] If a subscription defines an entity type selection query, a notification shall not be sent if the entity type does not match the query + [Tags] sub-notification 5_8_6 since_v1.5.1 + + ${vehicle_id}= Generate Random Entity Id ${vehicle_id_prefix} + ${response}= Create Entity Selecting Content Type + ... ${entity_vehicle_filepath} + ... ${vehicle_id} + ... ${content_type} + Set Suite Variable ${vehicle_id} + + Wait for no notification + + +*** Keywords *** +Setup Initial Subscription + ${subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${subscription_payload}= Load Subscription Sample With Reachable Endpoint + ... ${subscription_payload_file_path} + ... ${subscription_id} + ... ${notification_server_send_url} + Create Subscription From Subscription Payload ${subscription_payload} ${CONTENT_TYPE_LD_JSON} + Set Suite Variable ${subscription_id} + +Before Test + Start Local Server ${notification_server_host} ${notification_server_port} + Sleep 1s + Setup Initial Subscription + +After Test + Delete Subscription ${subscription_id} + Delete Entity by Id ${vehicle_id} + Stop Local Server diff --git a/data/subscriptions/subscription-building-entities-type-selection.jsonld b/data/subscriptions/subscription-building-entities-type-selection.jsonld new file mode 100644 index 00000000..90156142 --- /dev/null +++ b/data/subscriptions/subscription-building-entities-type-selection.jsonld @@ -0,0 +1,18 @@ +{ + "id":"urn:ngsi-ld:Subscription:randomUUID", + "type":"Subscription", + "entities":[ + { + "type":"(Building|Tower)" + } + ], + "notificationTrigger": ["entityCreated"], + "notification":{ + "endpoint":{ + "uri":"http://my.endpoint.org/notify" + } + }, + "@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_16_01.json b/doc/files/ContextInformation/Subscription/046_16_01.json new file mode 100644 index 00000000..8a070dac --- /dev/null +++ b/doc/files/ContextInformation/Subscription/046_16_01.json @@ -0,0 +1,39 @@ +{ + "tp_id": "TP/NGSI-LD/CI/SUB/046_16_01", + "test_objective": "If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.", + "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.8.6", + "config_id": "", + "parent_release": "v1.3.1", + "clauses": [ + "5.8.6" + ], + "pics_selection": "", + "keywords": [ + "Before Test", + "After Test" + ], + "teardown": "After Test", + "initial_condition": "with {\n the SUT containing an initial state\n}", + "test_cases": [ + { + "name": "046_16_01 Check that a notification is sent with entity matching the entity type selection", + "permutation_tp_id": "TP/NGSI-LD/CI/SUB/046_16_01", + "doc": "If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.", + "tags": [ + "5_8_6", + "since_v1.5.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 '5' seconds and\n Notification received Notification data: '${notification}[subscriptionId]' equal to '${subscription_id}' and\n Notification received Notification data: '${notification}[data][0][id]' equal to '${entity_id}' and\n Notification received The dictionary `${notification}' should contain the key 'data' and\n Notification received The variable `${notification}[data]' should not be '${EMPTY}'\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entities/'\n method set to 'POST'\n Request Header['Content-Type'] set to 'application/ld+json' and\n payload defined in file: 'building-simple-attributes-sample.jsonld'\n}", + "http_verb": "POST", + "endpoint": "entities/" + } + ], + "permutations": [], + "robotpath": "ContextInformation/Subscription/SubscriptionNotificationBehaviour", + "robotfile": "046_16_01" +} \ No newline at end of file diff --git a/doc/files/ContextInformation/Subscription/046_16_02.json b/doc/files/ContextInformation/Subscription/046_16_02.json new file mode 100644 index 00000000..970cf96b --- /dev/null +++ b/doc/files/ContextInformation/Subscription/046_16_02.json @@ -0,0 +1,39 @@ +{ + "tp_id": "TP/NGSI-LD/CI/SUB/046_16_02", + "test_objective": "If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.", + "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.8.6", + "config_id": "", + "parent_release": "v1.3.1", + "clauses": [ + "5.8.6" + ], + "pics_selection": "", + "keywords": [ + "Before Test", + "After Test" + ], + "teardown": "After Test", + "initial_condition": "with {\n the SUT containing an initial state\n}", + "test_cases": [ + { + "name": "046_16_02 Check that a notification is not sent if the entity type does not match the entity type selection", + "permutation_tp_id": "TP/NGSI-LD/CI/SUB/046_16_02", + "doc": "If a subscription defines an entity type selection query, a notification shall not be sent if the entity type does not match the query", + "tags": [ + "5_8_6", + "since_v1.5.1", + "sub-notification" + ], + "setup": null, + "teardown": null, + "template": null, + "then": "then {\n the client at '${endpoint}' receives a valid Notification containing:\n Notification received Waiting for no Notification data and\n Query Parameter: timeout set to '5'\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entities/'\n method set to 'POST'\n Request Header['Content-Type'] set to 'application/ld+json' and\n payload defined in file: 'vehicle-simple-attributes-sample.jsonld'\n}", + "http_verb": "POST", + "endpoint": "entities/" + } + ], + "permutations": [], + "robotpath": "ContextInformation/Subscription/SubscriptionNotificationBehaviour", + "robotfile": "046_16_02" +} \ No newline at end of file diff --git a/doc/tests/test_ContextInformation_Subscription.py b/doc/tests/test_ContextInformation_Subscription.py index 097a4a0a..404842ac 100644 --- a/doc/tests/test_ContextInformation_Subscription.py +++ b/doc/tests/test_ContextInformation_Subscription.py @@ -203,6 +203,20 @@ class TestCISubscription(TestCase): self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_046_16_01(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_16_01.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_046_16_01.json' + + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + + def test_046_16_02(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot' + 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' + + 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 From 457bc236263534fa88be463f0768de5d31832a68 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sat, 23 Mar 2024 10:04:57 +0100 Subject: [PATCH 2/2] chore: robotidy and update generated doc --- .../SubscriptionNotificationBehaviour/046_16_01.robot | 2 +- .../SubscriptionNotificationBehaviour/046_16_02.robot | 2 +- doc/files/ContextInformation/Subscription/046_16_01.json | 5 +++-- doc/files/ContextInformation/Subscription/046_16_02.json | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot index 437b266c..1fc0f388 100644 --- a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot @@ -23,7 +23,7 @@ ${content_type}= application/ld+json *** Test Cases *** 046_16_01 Check that a notification is sent with entity matching the entity type selection [Documentation] If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query. - [Tags] sub-notification 5_8_6 since_v1.5.1 + [Tags] sub-notification 5_8_6 since_v1.5.1 ${entity_id}= Generate Random Entity Id ${building_id_prefix} ${response}= Create Entity Selecting Content Type diff --git a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot index 23a4f99a..b07e3496 100644 --- a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot @@ -23,7 +23,7 @@ ${content_type}= application/ld+json *** Test Cases *** 046_16_02 Check that a notification is not sent if the entity type does not match the entity type selection [Documentation] If a subscription defines an entity type selection query, a notification shall not be sent if the entity type does not match the query - [Tags] sub-notification 5_8_6 since_v1.5.1 + [Tags] sub-notification 5_8_6 since_v1.5.1 ${vehicle_id}= Generate Random Entity Id ${vehicle_id_prefix} ${response}= Create Entity Selecting Content Type diff --git a/doc/files/ContextInformation/Subscription/046_16_01.json b/doc/files/ContextInformation/Subscription/046_16_01.json index 8a070dac..89d9df44 100644 --- a/doc/files/ContextInformation/Subscription/046_16_01.json +++ b/doc/files/ContextInformation/Subscription/046_16_01.json @@ -1,14 +1,15 @@ { "tp_id": "TP/NGSI-LD/CI/SUB/046_16_01", "test_objective": "If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.", - "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.8.6", + "reference": "ETSI GS CIM 009 V1.5.1 [], clause 5.8.6", "config_id": "", - "parent_release": "v1.3.1", + "parent_release": "v1.5.1", "clauses": [ "5.8.6" ], "pics_selection": "", "keywords": [ + "Setup Initial Subscription", "Before Test", "After Test" ], diff --git a/doc/files/ContextInformation/Subscription/046_16_02.json b/doc/files/ContextInformation/Subscription/046_16_02.json index 970cf96b..507da9a5 100644 --- a/doc/files/ContextInformation/Subscription/046_16_02.json +++ b/doc/files/ContextInformation/Subscription/046_16_02.json @@ -1,14 +1,15 @@ { "tp_id": "TP/NGSI-LD/CI/SUB/046_16_02", "test_objective": "If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.", - "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.8.6", + "reference": "ETSI GS CIM 009 V1.5.1 [], clause 5.8.6", "config_id": "", - "parent_release": "v1.3.1", + "parent_release": "v1.5.1", "clauses": [ "5.8.6" ], "pics_selection": "", "keywords": [ + "Setup Initial Subscription", "Before Test", "After Test" ], -- GitLab