From 0694ef8767152d32d4fa2e0f99e8cf26c2755cd6 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sun, 13 Apr 2025 12:34:54 +0200 Subject: [PATCH] feat: check 207 when appending attribute with noOverwrite and existing attribute --- .../UpdateBatchOfEntities/005_02.robot | 4 ++-- .../AppendEntityAttributes/010_04.robot | 20 ++++++++++++++----- doc/analysis/checks.py | 13 ++++++++++++ .../ContextInformation/Provision/005_02.json | 16 ++++++++------- .../ContextInformation/Provision/010_04.json | 11 +++++----- resources/AssertionUtils.resource | 19 ++++++++++++++++++ resources/JsonUtils.resource | 6 ++++++ 7 files changed, 70 insertions(+), 19 deletions(-) diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_02.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_02.robot index 97f8ebdb3..c580c5c1e 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_02.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_02.robot @@ -19,13 +19,13 @@ ${entity_payload_filename}= building-simple-attributes.jsonld *** Test Cases *** FILENAME UPDATE_FRAGMENT_FILENAME EXPECTED_STATUS 005_02_01 EntityWithExistingAttributes [Tags] be-update 5_6_9 - building-simple-attributes.jsonld fragmentEntities/empty-fragment.json 204 + building-simple-attributes.jsonld fragmentEntities/empty-fragment.json 207 005_02_02 EntityWithNewAttribute [Tags] be-update 5_6_9 building-relationship.jsonld fragmentEntities/locatedAt-fragment.json 204 005_02_03 EntityWithNewAndExistingAttribute [Tags] be-update 5_6_9 - building-location-attribute.jsonld fragmentEntities/location-fragment.json 204 + building-location-attribute.jsonld fragmentEntities/location-fragment.json 207 *** Keywords *** diff --git a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/AppendEntityAttributes/010_04.robot b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/AppendEntityAttributes/010_04.robot index 564840ba6..35d2e2feb 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/AppendEntityAttributes/010_04.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/AppendEntityAttributes/010_04.robot @@ -1,5 +1,5 @@ *** Settings *** -Documentation Check that one can append entity attributes +Documentation Check that one can append entity attributes with noOverwrite option Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource @@ -12,20 +12,22 @@ Test Template Append Attributes With Params *** Variables *** -${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: -${filename}= vehicle-speed-two-datasetid.jsonld +${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: +${filename}= vehicle-speed-two-datasetid.jsonld +${existing_attribute_name}= https://ngsi-ld-test-suite/context#speed +${non_existing_attribute_name}= https://uri.etsi.org/ngsi-ld/default-context/attribute_to_be_added *** Test Cases *** STATUS_CODE FRAGMENT_FILENAME EXPECTATION_FILENAME 010_04_01 Append entity attributes and ignore existing multi-attribute instance - 204 vehicle-attribute-to-add-fragment.jsonld vehicle-speed-appended.jsonld + 207 vehicle-attribute-to-add-fragment.jsonld vehicle-speed-appended.jsonld 010_04_02 Append entity attributes with a new multi-attribute instance 204 vehicle-speed-different-datasetid-fragment.jsonld vehicle-speed-different-datasetid.jsonld *** Keywords *** Append Attributes With Params - [Documentation] Check that one can append entity attributes + [Documentation] Check that one can append entity attributes with noOverwrite option [Tags] ea-append 5_6_3 [Arguments] ${status_code} ${fragment_filename} ${expectation_filename} ${response}= Append Entity Attributes With Parameters @@ -34,6 +36,14 @@ Append Attributes With Params ... ${CONTENT_TYPE_LD_JSON} ... noOverwrite Check Response Status Code ${status_code} ${response.status_code} + IF ${status_code} == 207 + @{expected_successful_attributes_names}= Create List ${non_existing_attribute_name} + @{expected_failed_attributes_names}= Create List ${existing_attribute_name} + &{expected_update_result}= Create Update Result + ... ${expected_successful_attributes_names} + ... ${expected_failed_attributes_names} + Check Response Body Containing Update Result ${expected_update_result} ${response.json()} + END ${entity_expectation_payload}= Load Test Sample entities/expectations/${expectation_filename} ${entity_id} ${response1}= Retrieve Entity by Id diff --git a/doc/analysis/checks.py b/doc/analysis/checks.py index e91aa77e8..8f2482025 100644 --- a/doc/analysis/checks.py +++ b/doc/analysis/checks.py @@ -92,6 +92,8 @@ class Checks: Checks.check_notificationparams, 'Check Response Body Containing Batch Operation Result': Checks.check_response_body_containing_batch_operation_result, + 'Check Response Body Containing Update Result': + Checks.check_response_body_containing_update_result, 'Wait for notification': Checks.wait_for_notification, 'Wait for no notification': @@ -307,6 +309,10 @@ class Checks: 'params': ['operation'], 'position': [0] }, + 'Check Response Body Containing Update Result': { + 'params': ['expected_update_result'], + 'position': [0] + }, 'Should be Equal': { 'params': ['expected_value', 'obtained_value'], 'position': [0, 1] @@ -1106,6 +1112,13 @@ class Checks: else: raise Exception(f'ERROR, Expected operation parameter but received: {kwargs}') + @staticmethod + def check_response_body_containing_update_result(kwargs: list) -> str: + if "expected_update_result" in kwargs: + return f"Response body containing update result set to '{kwargs['expected_update_result']}'" + else: + raise Exception(f'ERROR, Expected expected_update_result parameter but received: {kwargs}') + @staticmethod def check_response_body_content(kwargs: list) -> str: expected_parameters = ['expectation_filename', 'response_body', 'additional_ignored_path'] diff --git a/doc/files/ContextInformation/Provision/005_02.json b/doc/files/ContextInformation/Provision/005_02.json index aef00418b..17835a865 100644 --- a/doc/files/ContextInformation/Provision/005_02.json +++ b/doc/files/ContextInformation/Provision/005_02.json @@ -1,6 +1,6 @@ { "tp_id": "TP/NGSI-LD/CI/Prov/BE/005_02", - "test_objective": "Check that you can update a batch of entities with noOverwrite option", + "test_objective": "Check that one can update a batch of entities with noOverwrite option", "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.6.9", "config_id": "", "parent_release": "v1.3.1", @@ -19,7 +19,7 @@ { "name": "005_02_01 EntityWithExistingAttributes", "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/005_02_01", - "doc": "Check that you can update a batch of entities with noOverwrite option", + "doc": "Check that one can update a batch of entities with noOverwrite option", "tags": [ "5_6_9", "be-update" @@ -27,7 +27,7 @@ "setup": "Setup Initial Entities", "teardown": "Delete Initial Entities", "template": "Batch Update Entity With NoOverwrite Option Scenarios", - "then": "then {\n the SUT sends a valid Response for the operations:\n Batch Update Entities with Response Status Code set to 204 and\n Query Entities with Updated Entities set to '${updated_entities}' valid entities\n}", + "then": "then {\n the SUT sends a valid Response for the operations:\n Batch Update Entities with Response Status Code set to 207 and\n Query Entities with Updated Entities set to '${updated_entities}' valid entities\n}", "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entityOperations/update?${params_as_string}'\n method set to 'POST'\n Request batch update operation over entity from filename '@{entities_to_be_updated}' with overwrite_option set to '${EMPTY}' and Content-Type set to 'application/ld+json'\n}", "http_verb": "POST", "endpoint": "entityOperations/update?${params_as_string}" @@ -35,7 +35,7 @@ { "name": "005_02_02 EntityWithNewAttribute", "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/005_02_02", - "doc": "Check that you can update a batch of entities with noOverwrite option", + "doc": "Check that one can update a batch of entities with noOverwrite option", "tags": [ "5_6_9", "be-update" @@ -51,7 +51,7 @@ { "name": "005_02_03 EntityWithNewAndExistingAttribute", "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/005_02_03", - "doc": "Check that you can update a batch of entities with noOverwrite option", + "doc": "Check that one can update a batch of entities with noOverwrite option", "tags": [ "5_6_9", "be-update" @@ -59,13 +59,15 @@ "setup": "Setup Initial Entities", "teardown": "Delete Initial Entities", "template": "Batch Update Entity With NoOverwrite Option Scenarios", - "then": "then {\n the SUT sends a valid Response for the operations:\n Batch Update Entities with Response Status Code set to 204 and\n Query Entities with Updated Entities set to '${updated_entities}' valid entities\n}", + "then": "then {\n the SUT sends a valid Response for the operations:\n Batch Update Entities with Response Status Code set to 207 and\n Query Entities with Updated Entities set to '${updated_entities}' valid entities\n}", "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entityOperations/update?${params_as_string}'\n method set to 'POST'\n Request batch update operation over entity from filename '@{entities_to_be_updated}' with overwrite_option set to '${EMPTY}' and Content-Type set to 'application/ld+json'\n}", "http_verb": "POST", "endpoint": "entityOperations/update?${params_as_string}" } ], - "permutations": [], + "permutations": [ + "then" + ], "robotpath": "ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities", "robotfile": "005_02" } \ No newline at end of file diff --git a/doc/files/ContextInformation/Provision/010_04.json b/doc/files/ContextInformation/Provision/010_04.json index 0a03a635c..a63c89d45 100644 --- a/doc/files/ContextInformation/Provision/010_04.json +++ b/doc/files/ContextInformation/Provision/010_04.json @@ -1,6 +1,6 @@ { "tp_id": "TP/NGSI-LD/CI/Prov/EA/010_04", - "test_objective": "Check that you can append entity attributes", + "test_objective": "Check that one can append entity attributes with noOverwrite option", "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.6.3", "config_id": "", "parent_release": "v1.3.1", @@ -19,7 +19,7 @@ { "name": "010_04_01 Append entity attributes and ignore existing multi-attribute instance", "permutation_tp_id": "TP/NGSI-LD/CI/Prov/EA/010_04_01", - "doc": "Check that you can append entity attributes", + "doc": "Check that one can append entity attributes with noOverwrite option", "tags": [ "ea-append", "5_6_3" @@ -27,7 +27,7 @@ "setup": "Create Initial Entity", "teardown": "Delete Initial Entity", "template": "Append Attributes With Params", - "then": "then {\n the SUT sends a valid Response for the operations:\n Append Entity Attributes With Parameters with Response Status Code set to 204 and\n Retrieve Entity by Id with Check Updated Entity and\n Query Parameter: 'updated_resource' set to 'entity_expectation_payload' and\n Query Parameter: 'response_body' set to 'response1.json()' and\n Query Parameter: 'ignored_keys' set to 'ignored_attributes'\n}", + "then": "then {\n the SUT sends a valid Response for the operations:\n Append Entity Attributes With Parameters with Response Status Code set to 207 and\n Append Entity Attributes With Parameters with Response body containing update result set to '${expected_update_result}' and\n Retrieve Entity by Id with Check Updated Entity and\n Query Parameter: 'updated_resource' set to 'entity_expectation_payload' and\n Query Parameter: 'response_body' set to 'response1.json()' and\n Query Parameter: 'ignored_keys' set to 'ignored_attributes'\n}", "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entities/{id}/attrs?options=${options}'\n method set to 'POST'\n Append entity attributes with parameters: and\n Query Parameter: id set to '${entity_id}' and\n Query Parameter: fragment_filename set to 'vehicle-attribute-to-add-fragment.jsonld' and\n Query Parameter: content_type set to 'application/ld+json' and\n Query Parameter: options set to 'noOverwrite'\n}", "http_verb": "POST", "endpoint": "entities/{id}/attrs?options=${options}" @@ -35,7 +35,7 @@ { "name": "010_04_02 Append entity attributes with a new multi-attribute instance", "permutation_tp_id": "TP/NGSI-LD/CI/Prov/EA/010_04_02", - "doc": "Check that you can append entity attributes", + "doc": "Check that one can append entity attributes with noOverwrite option", "tags": [ "ea-append", "5_6_3" @@ -43,13 +43,14 @@ "setup": "Create Initial Entity", "teardown": "Delete Initial Entity", "template": "Append Attributes With Params", - "then": "then {\n the SUT sends a valid Response for the operations:\n Append Entity Attributes With Parameters with Response Status Code set to 204 and\n Retrieve Entity by Id with Check Updated Entity and\n Query Parameter: 'updated_resource' set to 'entity_expectation_payload' and\n Query Parameter: 'response_body' set to 'response1.json()' and\n Query Parameter: 'ignored_keys' set to 'ignored_attributes'\n}", + "then": "then {\n the SUT sends a valid Response for the operations:\n Append Entity Attributes With Parameters with Response Status Code set to 204 and\n Append Entity Attributes With Parameters with Response body containing update result set to '${expected_update_result}' and\n Retrieve Entity by Id with Check Updated Entity and\n Query Parameter: 'updated_resource' set to 'entity_expectation_payload' and\n Query Parameter: 'response_body' set to 'response1.json()' and\n Query Parameter: 'ignored_keys' set to 'ignored_attributes'\n}", "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entities/{id}/attrs?options=${options}'\n method set to 'POST'\n Append entity attributes with parameters: and\n Query Parameter: id set to '${entity_id}' and\n Query Parameter: fragment_filename set to 'vehicle-speed-different-datasetid-fragment.jsonld' and\n Query Parameter: content_type set to 'application/ld+json' and\n Query Parameter: options set to 'noOverwrite'\n}", "http_verb": "POST", "endpoint": "entities/{id}/attrs?options=${options}" } ], "permutations": [ + "then", "when" ], "robotpath": "ContextInformation/Provision/EntityAttributes/AppendEntityAttributes", diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 70b84d919..11fffabc0 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -141,6 +141,25 @@ Check Response Body Containing Batch Operation Result Should Not Be Empty ${response_error['error']} END +Check Response Body Containing Update Result + [Arguments] ${expected_update_result} ${response_body} + @{expected_successful_attributes_names}= Get From Dictionary ${expected_update_result} updated + @{expected_failed_attributes_names}= Get From Dictionary ${expected_update_result} notUpdated + ${expected_failed_attributes_names_length}= Get Length ${expected_failed_attributes_names} + + @{response_errors}= Get From Dictionary ${response_body} notUpdated + ${response_errors_length}= Get Length ${response_errors} + + Lists Should Be Equal + ... ${expected_successful_attributes_names} + ... ${response_body['updated']} + ... ignore_order=True + Should be Equal as Integers ${expected_failed_attributes_names_length} ${response_errors_length} + FOR ${response_error} IN @{response_errors} + List Should Contain Value ${expected_failed_attributes_names} ${response_error['attributeName']} + Should Not Be Empty ${response_error['reason']} + END + Check Response Body Containing Entity element [Arguments] ${expectation_filename} ${entity_id} ${response_body} ${ignore_core_context_version}=False ${entity_payload}= Load JSON From File ${EXECDIR}/data/entities/expectations/${expectation_filename} diff --git a/resources/JsonUtils.resource b/resources/JsonUtils.resource index 3e3d80148..10f4d2759 100644 --- a/resources/JsonUtils.resource +++ b/resources/JsonUtils.resource @@ -83,6 +83,12 @@ Create Batch Operation Result &{batch_operation_result}= Create Dictionary success=${success} errors=${errors} RETURN &{batch_operation_result} +Create Update Result + [Arguments] ${updated} ${notUpdated} + + &{update_result}= Create Dictionary updated=${updated} notUpdated=${notUpdated} + RETURN &{update_result} + Upsert Element In Entity [Arguments] ${initial_entity} ${fragment} ${jsonPath}=$ -- GitLab