diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_03.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_03.robot index 014cf660bc7dbd594a1803698b92ff0a91412917..ac887633f4bc80f6700e802582ef30358249e894 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_03.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_03.robot @@ -25,6 +25,12 @@ ${building_id_prefix}= urn:ngsi-ld:Building: 004_03_03 EntityWithRelationshipsProperties [Tags] be-upsert 5_6_8 building-relationship-of-property.jsonld +004_03_04 EntityWithScope + [Tags] be-upsert 4_18 5_6_8 + building-with-one-scope.jsonld +004_03_05 EntityWithTypes + [Tags] be-upsert 4_16 5_6_8 + building-with-two-types.jsonld *** Keywords *** diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/ReplaceEntity/054_03.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/ReplaceEntity/054_03.robot new file mode 100644 index 0000000000000000000000000000000000000000..19e2b34fcfedf44eb6fc204e82dea65a59ebb998 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/ReplaceEntity/054_03.robot @@ -0,0 +1,52 @@ +*** Settings *** +Documentation Check that one can replace an existing entity and that scopes are replaced + +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource + +Test Setup Setup Initial Entity +Test Teardown Delete Initial Entity + + +*** Variables *** +${building_id_prefix} urn:ngsi-ld:Building: +${entity_filename} building-minimal-with-one-scope.json +${entity_replacement_filename} building-minimal-with-many-scopes.json +${expectation_filename} building-minimal-with-two-scopes.json + + +*** Test Cases *** +054_03_01 Replace an existing entity having scopes + [Documentation] Check that one can replace an existing entity and that scopes are replaced + [Tags] e-replace 4_18 5_6_18 6_5_3_3 since_v1.6.1 + ${response}= Replace Entity + ... entity_id=${entity_id} + ... filename=${entity_replacement_filename} + ... content_type=${CONTENT_TYPE_JSON} + ... context=${ngsild_test_suite_context} + Check Response Status Code 204 ${response.status_code} + + ${response1}= Retrieve Entity by Id + ... id=${entity_id} + ... accept=${CONTENT_TYPE_JSON} + ... context=${ngsild_test_suite_context} + Check Response Body Containing Entity element + ... expectation_filename=${expectation_filename} + ... entity_id=${entity_id} + ... response_body=${response1.json()} + + +*** Keywords *** +Setup Initial Entity + ${entity_id}= Generate Random Entity Id ${building_id_prefix} + Set Test Variable ${entity_id} + ${response}= Create Entity Selecting Content Type + ... ${entity_filename} + ... ${entity_id} + ... ${CONTENT_TYPE_JSON} + ... ${ngsild_test_suite_context} + Check Response Status Code 201 ${response.status_code} + +Delete Initial Entity + Delete Entity by Id ${entity_id} diff --git a/data/entities/building-with-one-scope.jsonld b/data/entities/building-with-one-scope.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..b91cbdf3599141d07db3c50c7960050a2ec9f220 --- /dev/null +++ b/data/entities/building-with-one-scope.jsonld @@ -0,0 +1,8 @@ +{ + "id": "urn:ngsi-ld:Building:randomUUID", + "type": "Building", + "scope": "/Madrid/Gardens/ParqueNorte", + "@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/analysis/requests.py b/doc/analysis/requests.py index 1252c8edde92580707e0d421764ce31a4bba55f3..513d4ae704c9b980aaf67e839fb5fa00d64ecd35 100644 --- a/doc/analysis/requests.py +++ b/doc/analysis/requests.py @@ -102,6 +102,10 @@ class Requests: 'positions': [0], 'params': ['id'] }, + 'Replace Entity': { + 'positions': [0, 1, 2, 3], + 'params': ['entity_id', 'filename', 'content_type', 'context'] + }, 'Replace Entity Selecting Content Type': { 'positions': [0, 1, 2, 3], 'params': ['entity_id', 'entity_fragment', 'content_type', 'context'] @@ -318,6 +322,8 @@ class Requests: Requests.query_entities, 'Delete Entity by Id': Requests.delete_entity_by_id, + 'Replace Entity': + Requests.replace_entity, 'Replace Entity Selecting Content Type': Requests.replace_entity_selecting_content_type, 'Replace Attribute Selecting Content Type': @@ -1364,6 +1370,31 @@ class Requests: if 'id' in kwargs: return f"Delete Entity Request with id set to '{kwargs['id']}'" + @staticmethod + def replace_entity(kwargs) -> str: + expected_parameters = ['entity_id', 'filename', 'content_type', 'context'] + + if 'context' not in kwargs: + kwargs['context'] = '${EMPTY}' + + result = [x for x in kwargs if x not in expected_parameters] + response = "Replace Entity" + for key, value in kwargs.items(): + match key: + case 'entity_id': + response = f"{response} and\n Query Parameter: entity_id set to '{value}'" + case 'filename': + response = f"{response} and\n Query Parameter: filename set to '{value}'" + case 'content_type': + response = f"{response} and\n Query Parameter: content_type set to '{value}'" + case 'context': + response = f"{response} and\n Query Parameter: context set to '{value}'" + case _: + raise Exception(f"ERROR: unexpected attribute {result}, the attributes expected are " + f"{expected_parameters}, but received: {kwargs}") + + return response + @staticmethod def replace_entity_selecting_content_type(kwargs) -> str: expected_parameters = ['entity_id', 'entity_fragment', 'content_type', 'context'] diff --git a/doc/files/ContextInformation/Provision/004_03.json b/doc/files/ContextInformation/Provision/004_03.json index 6e024155fec71e18772886e15447fb795d00e15f..d6ca2d883addfb6f54504588359c2b0d169ab922 100644 --- a/doc/files/ContextInformation/Provision/004_03.json +++ b/doc/files/ContextInformation/Provision/004_03.json @@ -1,10 +1,12 @@ { "tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03", - "test_objective": "Check that you can upsert a batch of existing entities and they will be replaced", - "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.6.8", + "test_objective": "Check that one can upsert a batch of existing entities and they will be replaced", + "reference": "ETSI GS CIM 009 V1.3.1 [], clauses 4.16, 4.18, 5.6.8", "config_id": "", "parent_release": "v1.3.1", "clauses": [ + "4.16", + "4.18", "5.6.8" ], "pics_selection": "", @@ -19,7 +21,7 @@ { "name": "004_03_01 EntityWithSimpleProperties", "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_01", - "doc": "Check that you can upsert a batch of existing entities", + "doc": "Check that one can upsert a batch of existing entities", "tags": [ "5_6_8", "be-upsert" @@ -35,7 +37,7 @@ { "name": "004_03_02 EntityWithSimpleRelationships", "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_02", - "doc": "Check that you can upsert a batch of existing entities", + "doc": "Check that one can upsert a batch of existing entities", "tags": [ "5_6_8", "be-upsert" @@ -51,7 +53,7 @@ { "name": "004_03_03 EntityWithRelationshipsProperties", "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_03", - "doc": "Check that you can upsert a batch of existing entities", + "doc": "Check that one can upsert a batch of existing entities", "tags": [ "5_6_8", "be-upsert" @@ -63,6 +65,40 @@ "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entityOperations/upsert?options=${update_option}'\n method set to 'POST'\n Request batch upsert operation over entity from filename '@{entities_to_be_upserted}' with update_option set to 'replace' and Content-Type set to 'application/ld+json'\n}", "http_verb": "POST", "endpoint": "entityOperations/upsert?options=${update_option}" + }, + { + "name": "004_03_04 EntityWithScope", + "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_04", + "doc": "Check that one can upsert a batch of existing entities", + "tags": [ + "4_18", + "5_6_8", + "be-upsert" + ], + "setup": "Setup Initial Entities", + "teardown": "Delete Initial Entities", + "template": "Batch Upsert Existing Entities Scenarios", + "then": "then {\n the SUT sends a valid Response for the operations:\n Batch Upsert Entities with Response Status Code set to 204 and\n Query Entities with Updated Entities set to '${entities_to_be_upserted}' valid entities\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entityOperations/upsert?options=${update_option}'\n method set to 'POST'\n Request batch upsert operation over entity from filename '@{entities_to_be_upserted}' with update_option set to 'replace' and Content-Type set to 'application/ld+json'\n}", + "http_verb": "POST", + "endpoint": "entityOperations/upsert?options=${update_option}" + }, + { + "name": "004_03_05 EntityWithTypes", + "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_05", + "doc": "Check that one can upsert a batch of existing entities", + "tags": [ + "4_16", + "5_6_8", + "be-upsert" + ], + "setup": "Setup Initial Entities", + "teardown": "Delete Initial Entities", + "template": "Batch Upsert Existing Entities Scenarios", + "then": "then {\n the SUT sends a valid Response for the operations:\n Batch Upsert Entities with Response Status Code set to 204 and\n Query Entities with Updated Entities set to '${entities_to_be_upserted}' valid entities\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entityOperations/upsert?options=${update_option}'\n method set to 'POST'\n Request batch upsert operation over entity from filename '@{entities_to_be_upserted}' with update_option set to 'replace' and Content-Type set to 'application/ld+json'\n}", + "http_verb": "POST", + "endpoint": "entityOperations/upsert?options=${update_option}" } ], "permutations": [], diff --git a/doc/files/ContextInformation/Provision/054_03.json b/doc/files/ContextInformation/Provision/054_03.json new file mode 100644 index 0000000000000000000000000000000000000000..777c0a51617041b5f2de1d314a483658ac09c229 --- /dev/null +++ b/doc/files/ContextInformation/Provision/054_03.json @@ -0,0 +1,43 @@ +{ + "tp_id": "TP/NGSI-LD/CI/Prov/E/054_03", + "test_objective": "Check that one can replace an existing entity and that scopes are replaced", + "reference": "ETSI GS CIM 009 V1.6.1 [], clauses 4.18, 5.6.18, 6.5.3.3", + "config_id": "", + "parent_release": "v1.6.1", + "clauses": [ + "4.18", + "5.6.18", + "6.5.3.3" + ], + "pics_selection": "", + "keywords": [ + "Setup Initial Entity", + "Delete Initial Entity" + ], + "teardown": "None", + "initial_condition": "with {\n the SUT being in the \"initial state\" and\n the SUT containing an initial Entity ${entity} \n with an id set to ${entityId} \n}", + "test_cases": [ + { + "name": "054_03_01 Replace an existing entity having scopes", + "permutation_tp_id": "TP/NGSI-LD/CI/Prov/E/054_03_01", + "doc": "Check that one can replace an existing entity and that scopes are replaced", + "tags": [ + "4_18", + "5_6_18", + "6_5_3_3", + "e-replace", + "since_v1.6.1" + ], + "setup": "Setup Initial Entity", + "teardown": "Delete Initial Entity", + "template": null, + "then": "then {\n the SUT sends a valid Response for the operations:\n Replace Entity with Response Status Code set to 204 and\n Retrieve Entity by Id with Response Body containing en entity element with id set to 'entity_id=${entity_id}' and body content set to 'expectation_filename=${expectation_filename}'\n}", + "when": "when {\n the SUT receives a Request from the client containing:\n URL set to '/ngsi-ld/v1/entities/{entity_id}'\n method set to 'PUT'\n Replace Entity and\n Query Parameter: entity_id set to '${entity_id}' and\n Query Parameter: filename set to '${entity_replacement_filename}' and\n Query Parameter: content_type set to 'application/json' and\n Query Parameter: context set to 'https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld'\n}", + "http_verb": "PUT", + "endpoint": "entities/{entity_id}" + } + ], + "permutations": [], + "robotpath": "ContextInformation/Provision/Entities/ReplaceEntity", + "robotfile": "054_03" +} \ No newline at end of file diff --git a/resources/ApiUtils/ContextInformationProvision.resource b/resources/ApiUtils/ContextInformationProvision.resource index e68f678eb966c03bdcdf2dc38e988975d76356f0..efd7796a46e54da270dc1986d6cf0e4f4796b394 100755 --- a/resources/ApiUtils/ContextInformationProvision.resource +++ b/resources/ApiUtils/ContextInformationProvision.resource @@ -5,6 +5,7 @@ Library RequestsLibrary Library OperatingSystem Library Collections Library JSONLibrary +Resource ${EXECDIR}/resources/JsonUtils.resource *** Variables *** @@ -279,6 +280,29 @@ Update Entity Attributes Output ${response} Update Entity Attributes RETURN ${response} +Replace Entity + [Arguments] + ... ${entity_id} + ... ${filename} + ... ${content_type} + ... ${context}=${EMPTY} + ${entity}= Load Entity + ... entity_file_name=${filename} + ... entity_id=${entity_id} + &{headers}= Create Dictionary Content-Type=${content_type} + IF '${context}'!='' + Set To Dictionary + ... ${headers} + ... Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json" + END + ${response}= PUT + ... url=${url}/${ENTITIES_ENDPOINT_PATH}${entity_id} + ... headers=${headers} + ... json=${entity} + ... expected_status=any + Output ${response} Replace Entity + RETURN ${response} + Replace Entity Selecting Content Type [Arguments] ... ${entity_id}