diff --git a/TP/NGSI-LD/ContextInformation/Subscription/CreateSubscription/028_07.robot b/TP/NGSI-LD/ContextInformation/Subscription/CreateSubscription/028_07.robot new file mode 100644 index 0000000000000000000000000000000000000000..1551f9ee3ac7e79a2ecc18fc60839c146e0e0fd1 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/CreateSubscription/028_07.robot @@ -0,0 +1,40 @@ +*** Settings *** +Documentation Check that one cannot create a subscription with invalid or unavailable jsonldContext + +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationSubscription.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Template Create Subscription With Invalid/Unavailable JsonldContext + + +*** Variables *** +${invalid_jsonldContext_subscription_file_path}= subscriptions/subscription-building-with-invalid-jsonldContext.jsonld +${unavailable_jsonldContext_subscription_file_path}= subscriptions/subscription-building-with-unavailable-jsonldContext.jsonld + + +*** Test Cases *** FILE_NAME EXPECTED_ERROR_TYPE EXPECTED_STATUS_CODE +028_07_01 Subscription with invalid jsonldContext + [Tags] sub-create 5_8_1 since_v1.7.1 + ${invalid_jsonldContext_subscription_file_path} ${ERROR_TYPE_BAD_REQUEST_DATA} 400 +028_07_02 Subscription with unavailable jsonldContext + [Tags] sub-create 5_8_1 since_v1.7.1 + ${unavailable_jsonldContext_subscription_file_path} ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE} 503 + + +*** Keywords *** +Create Subscription With Invalid/Unavailable JsonldContext + [Documentation] Check that one cannot create a subscription with invalid or unavailable jsonldContext + [Tags] sub-create 5_8_1 + [Arguments] ${file_name} ${expected_error_type} ${expected_status_code} + ${subscription_id}= Generate Random Subscription Id + Set Suite Variable ${subscription_id} + ${response}= Create Subscription + ... ${subscription_id} + ... ${file_name} + ... ${CONTENT_TYPE_LD_JSON} + Check Response Status Code ${expected_status_code} ${response.status_code} + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${expected_error_type} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} diff --git a/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_20.robot b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_20.robot new file mode 100644 index 0000000000000000000000000000000000000000..42f7697bc7f364a54311fa055d4f35d18ae97a54 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_20.robot @@ -0,0 +1,74 @@ +*** Settings *** +Documentation If a subscription has a jsonldContext member then it should be used when sending notifications. + +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_payload_file_path}= subscriptions/subscription-building-with-jsonldContext.jsonld +${entity_building_filepath}= building-minimal.jsonld +${fragment_filename}= building-name-fragment.jsonld +${notification_server_send_url}= http://${notification_server_host}:${notification_server_port}/notify +${entity_expectation_file_path}= compacted-entity-with-jsonldContext-046-20.jsonld + + +*** Test Cases *** +046_20 Check that jsonldContext member in subscription is used when sending notifcations + [Documentation] If a subscription has a jsonldContext member then it should be used when sending notifications + [Tags] sub-notification 5_8_6 since_v1.7.1 + + ${response}= Update Entity Attributes ${entity_id} ${fragment_filename} ${CONTENT_TYPE_LD_JSON} + + ${notification} ${headers}= Wait for notification timeout=${10} + + Should be Equal ${subscription_id} ${notification}[subscriptionId] + Should be Equal ${entity_id} ${notification}[data][0][id] + + Check Notification Containing Entity Element + ... ${entity_expectation_file_path} + ... ${notification} + + +*** Keywords *** +Before Test + Start Local Server ${notification_server_host} ${notification_server_port} + Add Initial Entity + Sleep 1s + Setup Initial Subscription + +Add Initial Entity + ${entity_id}= Generate Random Building Entity Id + ${create_response}= Create Entity ${entity_building_filepath} ${entity_id} + Check Response Status Code 201 ${create_response.status_code} + Set Suite Variable ${entity_id} + +Setup Initial Subscription + ${subscription_id}= Generate Random Subscription Id + ${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} + ${create_response}= Create Subscription From Subscription Payload + ... ${subscription_payload} + ... ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${create_response.status_code} + Set Suite Variable ${subscription_id} + +After Test + Delete Initial Subscription + Delete Initial Entity + Stop Local Server + +Delete Initial Subscription + Delete Subscription ${subscription_id} + +Delete Initial Entity + Delete Entity by Id ${entity_id} diff --git a/data/subscriptions/expectations/compacted-entity-with-jsonldContext-046-20.jsonld b/data/subscriptions/expectations/compacted-entity-with-jsonldContext-046-20.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..761a6994d07ff56b572feb7819ba771b98dc484a --- /dev/null +++ b/data/subscriptions/expectations/compacted-entity-with-jsonldContext-046-20.jsonld @@ -0,0 +1,10 @@ +{ + "id": "urn:ngsi-ld:Building:randomUUID", + "type": "https://ngsi-ld-test-suite/context#Building", + "https://ngsi-ld-test-suite/context#name": { + "type": "Property", + "value": "Le Tour Eiffel", + "datasetId": "urn:ngsi-ld:Dataset:french-name" + }, + "@context": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld" +} \ No newline at end of file diff --git a/data/subscriptions/subscription-building-with-invalid-jsonldContext.jsonld b/data/subscriptions/subscription-building-with-invalid-jsonldContext.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..a92575554c66ede392d077818645d761ec690e70 --- /dev/null +++ b/data/subscriptions/subscription-building-with-invalid-jsonldContext.jsonld @@ -0,0 +1,20 @@ +{ + "id": "urn:ngsi-ld:Subscription:randomUUID", + "type": "Subscription", + "entities": [ + { + "type": "Building" + } + ], + "notification": { + "format": "normalized", + "endpoint": { + "uri": "http://my.endpoint.org/notify", + "accept": "application/ld+json" + } + }, + "jsonldContext": "unknownContext", + "@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-building-with-jsonldContext.jsonld b/data/subscriptions/subscription-building-with-jsonldContext.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..bfa9e5c4373b2e303d15503711a69cc57736a6c2 --- /dev/null +++ b/data/subscriptions/subscription-building-with-jsonldContext.jsonld @@ -0,0 +1,20 @@ +{ + "id": "urn:ngsi-ld:Subscription:randomUUID", + "type": "Subscription", + "entities": [ + { + "type": "Building" + } + ], + "notification": { + "format": "normalized", + "endpoint": { + "uri": "http://my.endpoint.org/notify", + "accept": "application/ld+json" + } + }, + "jsonldContext": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.8.jsonld", + "@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-building-with-unavailable-jsonldContext.jsonld b/data/subscriptions/subscription-building-with-unavailable-jsonldContext.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..054aceda749e4cc6cc199e2f8dd3d7bf3beee4f9 --- /dev/null +++ b/data/subscriptions/subscription-building-with-unavailable-jsonldContext.jsonld @@ -0,0 +1,20 @@ +{ + "id": "urn:ngsi-ld:Subscription:randomUUID", + "type": "Subscription", + "entities": [ + { + "type": "Building" + } + ], + "notification": { + "format": "normalized", + "endpoint": { + "uri": "http://my.endpoint.org/notify", + "accept": "application/ld+json" + } + }, + "jsonldContext": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-non-existing.jsonld", + "@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/028_07.json b/doc/files/ContextInformation/Subscription/028_07.json new file mode 100644 index 0000000000000000000000000000000000000000..9d945899f5e8f092f72621e6c879c6907ba86e02 --- /dev/null +++ b/doc/files/ContextInformation/Subscription/028_07.json @@ -0,0 +1,58 @@ +{ + "tp_id": "TP/NGSI-LD/CI/SUB/028_07", + "test_objective": "Check that one cannot create a subscription with invalid or unavailable jsonldContext", + "reference": "ETSI GS CIM 009 V1.7.1 [], clause 5.8.1", + "config_id": "", + "parent_release": "v1.7.1", + "clauses": [ + "5.8.1" + ], + "pics_selection": "", + "keywords": [ + "Create Subscription With Invalid/Unavailable JsonldContext" + ], + "teardown": "None", + "initial_condition": "with {\n the SUT containing an initial state\n}", + "test_cases": [ + { + "name": "028_07_01 Subscription with invalid jsonldContext", + "permutation_tp_id": "TP/NGSI-LD/CI/SUB/028_07_01", + "doc": "Check that one cannot create a subscription with invalid or unavailable jsonldContext", + "tags": [ + "5_8_1", + "since_v1.7.1", + "sub-create" + ], + "setup": null, + "teardown": null, + "template": "Create Subscription With Invalid/Unavailable JsonldContext", + "then": "then {\n the SUT sends a valid Response for the operations:\n Create Subscription with Response Status Code set to 400 and\n Create Subscription with Response Body containing the type 'https://uri.etsi.org/ngsi-ld/errors/BadRequestData' and\n Create Subscription with Response body containing 'title' element\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/subscriptions/'\n method set to 'POST'\n Request Header['Content-Type'] set to 'application/ld+json' and\n payload defined in file: 'subscriptions/subscription-building-with-invalid-jsonldContext.jsonld'\n}", + "http_verb": "POST", + "endpoint": "subscriptions/" + }, + { + "name": "028_07_02 Subscription with unavailable jsonldContext", + "permutation_tp_id": "TP/NGSI-LD/CI/SUB/028_07_02", + "doc": "Check that one cannot create a subscription with invalid or unavailable jsonldContext", + "tags": [ + "5_8_1", + "since_v1.7.1", + "sub-create" + ], + "setup": null, + "teardown": null, + "template": "Create Subscription With Invalid/Unavailable JsonldContext", + "then": "then {\n the SUT sends a valid Response for the operations:\n Create Subscription with Response Status Code set to 503 and\n Create Subscription with Response Body containing the type 'https://uri.etsi.org/ngsi-ld/errors/LdContextNotAvailable' and\n Create Subscription with Response body containing 'title' element\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/subscriptions/'\n method set to 'POST'\n Request Header['Content-Type'] set to 'application/ld+json' and\n payload defined in file: 'subscriptions/subscription-building-with-unavailable-jsonldContext.jsonld'\n}", + "http_verb": "POST", + "endpoint": "subscriptions/" + } + ], + "permutations": [ + "then", + "when" + ], + "robotpath": "ContextInformation/Subscription/CreateSubscription", + "robotfile": "028_07" +} \ No newline at end of file diff --git a/doc/files/ContextInformation/Subscription/046_20.json b/doc/files/ContextInformation/Subscription/046_20.json new file mode 100644 index 0000000000000000000000000000000000000000..9fe445cd2565139857d41b5019b98ec354fd4196 --- /dev/null +++ b/doc/files/ContextInformation/Subscription/046_20.json @@ -0,0 +1,43 @@ +{ + "tp_id": "TP/NGSI-LD/CI/SUB/046_20", + "test_objective": "If a subscription has a jsonldContext member then it should be used when sending notifications.", + "reference": "ETSI GS CIM 009 V1.7.1 [], clause 5.8.6", + "config_id": "", + "parent_release": "v1.7.1", + "clauses": [ + "5.8.6" + ], + "pics_selection": "", + "keywords": [ + "Before Test", + "Add Initial Entity", + "Setup Initial Subscription", + "After Test", + "Delete Initial Subscription", + "Delete Initial Entity" + ], + "teardown": "After Test", + "initial_condition": "with {\n the SUT containing an initial state\n}", + "test_cases": [ + { + "name": "046_20 Check that jsonldContext member in subscription is used when sending notifcations", + "permutation_tp_id": "TP/NGSI-LD/CI/SUB/046_20", + "doc": "If a subscription has a jsonldContext member then it should be used when sending notifications", + "tags": [ + "5_8_6", + "since_v1.7.1", + "sub-notification" + ], + "setup": null, + "teardown": null, + "template": null, + "then": "then {\n the SUT sends a valid Response for the operation:\n Notification with Notification containing entity element set to 'compacted-entity-with-jsonldContext-046-20.jsonld'\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 'building-name-fragment.jsonld' 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_20" +} \ No newline at end of file diff --git a/doc/tests/test_ContextInformation_Subscription.py b/doc/tests/test_ContextInformation_Subscription.py index 88e5329d3f2d5895c5f03ddf98803fb32c1ad987..63be7eaf07af7b9d77b655f46701c1289540021a 100644 --- a/doc/tests/test_ContextInformation_Subscription.py +++ b/doc/tests/test_ContextInformation_Subscription.py @@ -84,6 +84,13 @@ class TestCISubscription(TestCase): self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_028_07(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/CreateSubscription/028_07.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/028_07.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_028_07.json' + + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_032_01(self): robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/DeleteSubscription/032_01.robot' expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/032_01.json' @@ -243,6 +250,13 @@ class TestCISubscription(TestCase): self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_046_20(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_20.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_20.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_046_20.json' + + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_046_21_01(self): robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_21_01.robot' expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_21_01.json' diff --git a/resources/ApiUtils/ContextInformationSubscription.resource b/resources/ApiUtils/ContextInformationSubscription.resource index 9a2672f55218ade98a8efc1373890d3ec8aced50..4bd8be4ea8a1fcc5c9845222d4a75169b01bfcdd 100755 --- a/resources/ApiUtils/ContextInformationSubscription.resource +++ b/resources/ApiUtils/ContextInformationSubscription.resource @@ -9,19 +9,20 @@ Resource ${EXECDIR}/resources/ApiUtils/Common.resource *** Variables *** -${SUBSCRIPTION_ENDPOINT_PATH} subscriptions/ +${SUBSCRIPTION_ENDPOINT_PATH} subscriptions/ -${CONTENT_TYPE_JSON} application/json -${CONTENT_TYPE_LD_JSON} application/ld+json +${CONTENT_TYPE_JSON} application/json +${CONTENT_TYPE_LD_JSON} application/ld+json -${SUBSCRIPTION_ID_PREFIX} urn:ngsi-ld:Subscription: +${SUBSCRIPTION_ID_PREFIX} urn:ngsi-ld:Subscription: -${ERROR_TYPE_BAD_REQUEST_DATA} https://uri.etsi.org/ngsi-ld/errors/BadRequestData -${ERROR_TYPE_INVALID_REQUEST} https://uri.etsi.org/ngsi-ld/errors/InvalidRequest -${ERROR_TYPE_RESOURCE_NOT_FOUND} https://uri.etsi.org/ngsi-ld/errors/ResourceNotFound -${ERROR_TYPE_ALREADY_EXISTS} https://uri.etsi.org/ngsi-ld/errors/AlreadyExists +${ERROR_TYPE_BAD_REQUEST_DATA} https://uri.etsi.org/ngsi-ld/errors/BadRequestData +${ERROR_TYPE_INVALID_REQUEST} https://uri.etsi.org/ngsi-ld/errors/InvalidRequest +${ERROR_TYPE_RESOURCE_NOT_FOUND} https://uri.etsi.org/ngsi-ld/errors/ResourceNotFound +${ERROR_TYPE_ALREADY_EXISTS} https://uri.etsi.org/ngsi-ld/errors/AlreadyExists +${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE} https://uri.etsi.org/ngsi-ld/errors/LdContextNotAvailable -${response} ${EMPTY} +${response} ${EMPTY} *** Keywords ***