From 49cf8e245ed07555b222ac0b6a4e5577b4c64ea3 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Tue, 16 Apr 2024 10:34:22 +0200 Subject: [PATCH 1/2] feat: add tests for multi-typing in batch operations --- .../UpdateBatchOfEntities/005_05.robot | 59 +++++++++++++++++++ .../UpsertBatchOfEntities/004_08.robot | 52 ++++++++++++++++ .../building-minimal-with-new-type.jsonld | 7 +++ .../building-minimal-with-new-types.jsonld | 7 +++ .../building-two-types-fragment.jsonld | 3 + .../ContextInformation/Provision/004_08.json | 41 +++++++++++++ .../ContextInformation/Provision/005_05.json | 41 +++++++++++++ .../test_ContextInformation_Provision.py | 14 +++++ 8 files changed, 224 insertions(+) create mode 100644 TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_05.robot create mode 100644 TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_08.robot create mode 100644 data/entities/building-minimal-with-new-type.jsonld create mode 100644 data/entities/building-minimal-with-new-types.jsonld create mode 100644 data/entities/fragmentEntities/building-two-types-fragment.jsonld create mode 100644 doc/files/ContextInformation/Provision/004_08.json create mode 100644 doc/files/ContextInformation/Provision/005_05.json diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_05.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_05.robot new file mode 100644 index 00000000..bab8ffbd --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_05.robot @@ -0,0 +1,59 @@ +*** Settings *** +Documentation Check that you can update types of entities in a batch update operation + +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Setup Setup Initial Entities +Test Teardown Delete Initial Entities +Test Template Batch Update Entity Scenarios + + +*** Variables *** +${building_id_prefix}= urn:ngsi-ld:Building: +${entity_payload_filename}= building-minimal-sample.jsonld + + +*** Test Cases *** FILENAME UPDATE_FRAGMENT_FILENAME +005_05_01 EntityWithNewType + [Tags] be-update 5_6_9 4_16 + building-minimal-with-new-type.jsonld fragmentEntities/building-two-types-fragment.jsonld + + +*** Keywords *** +Batch Update Entity Scenarios + [Documentation] Check that you can update types of entities in a batch update operation + [Arguments] ${filename} ${update_fragment_filename} + ${first_entity}= Load Entity ${filename} ${first_entity_id} + ${second_entity}= Load Entity ${filename} ${second_entity_id} + @{entities_ids_to_be_updated}= Create List ${first_entity_id} ${second_entity_id} + @{entities_to_be_updated}= Create List ${first_entity} ${second_entity} + ${response}= Batch Update Entities @{entities_to_be_updated} + Check Response Status Code 204 ${response.status_code} + ${first_created_entity}= Load Test Sample entities/${entity_payload_filename} ${first_entity_id} + ${second_created_entity}= Load Test Sample entities/${entity_payload_filename} ${second_entity_id} + ${update_fragment}= Load Test Sample entities/${update_fragment_filename} + ${first_updated_entity}= Upsert Element In Entity ${first_created_entity} ${update_fragment} + ${second_updated_entity}= Upsert Element In Entity ${second_created_entity} ${update_fragment} + @{updated_entities}= Create List ${first_updated_entity} ${second_updated_entity} + ${expected_entities_ids}= Catenate SEPARATOR=, @{entities_ids_to_be_updated} + ${response1}= Query Entities + ... entity_ids=${expected_entities_ids} + ... entity_types=Building + ... context=${ngsild_test_suite_context} + ... accept=${CONTENT_TYPE_LD_JSON} + Check Updated Resources Set To ${updated_entities} ${response1.json()} + +Setup Initial Entities + ${first_entity_id}= Generate Random Entity Id ${building_id_prefix} + ${second_entity_id}= Generate Random Entity Id ${building_id_prefix} + Create Entity ${entity_payload_filename} ${first_entity_id} + Create Entity ${entity_payload_filename} ${second_entity_id} + Set Test Variable ${first_entity_id} + Set Test Variable ${second_entity_id} + +Delete Initial Entities + @{entities_ids_to_be_deleted}= Create List ${first_entity_id} ${second_entity_id} + Batch Delete Entities entities_ids_to_be_deleted=@{entities_ids_to_be_deleted} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_08.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_08.robot new file mode 100644 index 00000000..655f495a --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_08.robot @@ -0,0 +1,52 @@ +*** Settings *** +Documentation Check that you can upsert a batch of existing entities with new types and they will be replaced + +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Setup Setup Initial Entities +Test Teardown Delete Initial Entities +Test Template Batch Upsert Existing Entities Scenarios + + +*** Variables *** +${building_id_prefix}= urn:ngsi-ld:Building: + + +*** Test Cases *** FILENAME +004_08_01 EntityWithNewTypes + [Tags] be-upsert 5_6_8 4_16 + building-minimal-with-new-types.jsonld + + +*** Keywords *** +Batch Upsert Existing Entities Scenarios + [Documentation] Check that you can upsert a batch of existing entities with new types + [Arguments] ${filename} + ${first_existing_entity}= Load Entity ${filename} ${first_existing_entity_id} + ${second_existing_entity}= Load Entity ${filename} ${second_existing_entity_id} + @{entities_to_be_upserted}= Create List ${first_existing_entity} ${second_existing_entity} + ${response}= Batch Upsert Entities @{entities_to_be_upserted} + Check Response Status Code 204 ${response.status_code} + @{upserted_entities_ids}= Create List ${first_existing_entity_id} ${second_existing_entity_id} + ${expected_updated_entities_ids}= Catenate SEPARATOR=, @{upserted_entities_ids} + ${response1}= Query Entities + ... entity_ids=${expected_updated_entities_ids} + ... entity_types=Building + ... context=${ngsild_test_suite_context} + ... accept=${CONTENT_TYPE_LD_JSON} + Check Updated Resources Set To ${entities_to_be_upserted} ${response1.json()} + +Setup Initial Entities + ${first_existing_entity_id}= Generate Random Entity Id ${building_id_prefix} + ${second_existing_entity_id}= Generate Random Entity Id ${building_id_prefix} + Create Entity building-minimal-sample.jsonld ${first_existing_entity_id} + Create Entity building-minimal-sample.jsonld ${second_existing_entity_id} + Set Test Variable ${first_existing_entity_id} + Set Test Variable ${second_existing_entity_id} + +Delete Initial Entities + @{entities_ids_to_be_deleted}= Create List ${first_existing_entity_id} ${second_existing_entity_id} + Batch Delete Entities entities_ids_to_be_deleted=@{entities_ids_to_be_deleted} diff --git a/data/entities/building-minimal-with-new-type.jsonld b/data/entities/building-minimal-with-new-type.jsonld new file mode 100644 index 00000000..ad8142cc --- /dev/null +++ b/data/entities/building-minimal-with-new-type.jsonld @@ -0,0 +1,7 @@ +{ + "id": "urn:ngsi-ld:Building:randomUUID", + "type": "Vehicle", + "@context": [ + "https://easy-global-market.github.io/ngsild-api-data-models/ngsildTestSuite/ngsildTestSuiteV1.8-compound.jsonld" + ] +} diff --git a/data/entities/building-minimal-with-new-types.jsonld b/data/entities/building-minimal-with-new-types.jsonld new file mode 100644 index 00000000..9c632c57 --- /dev/null +++ b/data/entities/building-minimal-with-new-types.jsonld @@ -0,0 +1,7 @@ +{ + "id": "urn:ngsi-ld:Building:randomUUID", + "type": ["Building" ,"Vehicle"], + "@context": [ + "https://easy-global-market.github.io/ngsild-api-data-models/ngsildTestSuite/ngsildTestSuiteV1.8-compound.jsonld" + ] +} diff --git a/data/entities/fragmentEntities/building-two-types-fragment.jsonld b/data/entities/fragmentEntities/building-two-types-fragment.jsonld new file mode 100644 index 00000000..34237f84 --- /dev/null +++ b/data/entities/fragmentEntities/building-two-types-fragment.jsonld @@ -0,0 +1,3 @@ +{ + "type": ["Building", "Vehicle"] +} \ No newline at end of file diff --git a/doc/files/ContextInformation/Provision/004_08.json b/doc/files/ContextInformation/Provision/004_08.json new file mode 100644 index 00000000..ea8975d7 --- /dev/null +++ b/doc/files/ContextInformation/Provision/004_08.json @@ -0,0 +1,41 @@ +{ + "tp_id": "TP/NGSI-LD/CI/Prov/BE/004_08", + "test_objective": "Check that you can upsert a batch of existing entities with new types and they will be replaced", + "reference": "ETSI GS CIM 009 V1.3.1 [], clauses 4.16, 5.6.8", + "config_id": "", + "parent_release": "v1.3.1", + "clauses": [ + "4.16", + "5.6.8" + ], + "pics_selection": "", + "keywords": [ + "Batch Upsert Existing Entities Scenarios", + "Setup Initial Entities", + "Delete Initial Entities" + ], + "teardown": "None", + "initial_condition": "with {\n the SUT being in the \"initial state\" and\n and containing a list of entities\n}", + "test_cases": [ + { + "name": "004_08_01 EntityWithNewTypes", + "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_08_01", + "doc": "Check that you can upsert a batch of existing entities with new types", + "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": [], + "robotpath": "ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities", + "robotfile": "004_08" +} \ No newline at end of file diff --git a/doc/files/ContextInformation/Provision/005_05.json b/doc/files/ContextInformation/Provision/005_05.json new file mode 100644 index 00000000..1920bb69 --- /dev/null +++ b/doc/files/ContextInformation/Provision/005_05.json @@ -0,0 +1,41 @@ +{ + "tp_id": "TP/NGSI-LD/CI/Prov/BE/005_05", + "test_objective": "Check that you can update types of entities in a batch update operation", + "reference": "ETSI GS CIM 009 V1.3.1 [], clauses 4.16, 5.6.9", + "config_id": "", + "parent_release": "v1.3.1", + "clauses": [ + "4.16", + "5.6.9" + ], + "pics_selection": "", + "keywords": [ + "Batch Update Entity Scenarios", + "Setup Initial Entities", + "Delete Initial Entities" + ], + "teardown": "None", + "initial_condition": "with {\n the SUT being in the \"initial state\" and\n and containing a list of entities\n}", + "test_cases": [ + { + "name": "005_05_01 EntityWithNewType", + "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/005_05_01", + "doc": "Check that you can update types of entities in a batch update operation", + "tags": [ + "4_16", + "5_6_9", + "be-update" + ], + "setup": "Setup Initial Entities", + "teardown": "Delete Initial Entities", + "template": "Batch Update Entity 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}", + "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": [], + "robotpath": "ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities", + "robotfile": "005_05" +} \ No newline at end of file diff --git a/doc/tests/test_ContextInformation_Provision.py b/doc/tests/test_ContextInformation_Provision.py index e9970bd6..679e9ed6 100644 --- a/doc/tests/test_ContextInformation_Provision.py +++ b/doc/tests/test_ContextInformation_Provision.py @@ -168,6 +168,13 @@ class TestCIProvision(TestCase): self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_005_05(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_05.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/005_05.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_005_05.json' + + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_004_01(self): robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_01.robot' expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/004_01.json' @@ -217,6 +224,13 @@ class TestCIProvision(TestCase): self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_004_08(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_08.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/004_08.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_004_08.json' + + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_001_01(self): robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_01.robot' expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/001_01.json' -- GitLab From 1934a0f090299b85ef306c3514e85b0f7f340155 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Mon, 22 Jul 2024 15:16:43 +0200 Subject: [PATCH 2/2] fix: use test suite context from ETSI --- data/entities/building-minimal-with-new-type.jsonld | 2 +- data/entities/building-minimal-with-new-types.jsonld | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/entities/building-minimal-with-new-type.jsonld b/data/entities/building-minimal-with-new-type.jsonld index ad8142cc..f039cafa 100644 --- a/data/entities/building-minimal-with-new-type.jsonld +++ b/data/entities/building-minimal-with-new-type.jsonld @@ -2,6 +2,6 @@ "id": "urn:ngsi-ld:Building:randomUUID", "type": "Vehicle", "@context": [ - "https://easy-global-market.github.io/ngsild-api-data-models/ngsildTestSuite/ngsildTestSuiteV1.8-compound.jsonld" + "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld" ] } diff --git a/data/entities/building-minimal-with-new-types.jsonld b/data/entities/building-minimal-with-new-types.jsonld index 9c632c57..608bbcc7 100644 --- a/data/entities/building-minimal-with-new-types.jsonld +++ b/data/entities/building-minimal-with-new-types.jsonld @@ -2,6 +2,6 @@ "id": "urn:ngsi-ld:Building:randomUUID", "type": ["Building" ,"Vehicle"], "@context": [ - "https://easy-global-market.github.io/ngsild-api-data-models/ngsildTestSuite/ngsildTestSuiteV1.8-compound.jsonld" + "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld" ] } -- GitLab