diff --git a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_08.robot b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_08.robot new file mode 100644 index 0000000000000000000000000000000000000000..25d43015b3dba254c8f58756f175813607e8e1a0 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_08.robot @@ -0,0 +1,75 @@ +*** Settings *** +Documentation Query entities with Entity Type Selection Language. + +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource +Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Suite Setup Setup Initial Entities +Suite Teardown Delete Initial Entities +Test Template Query entities using Entity Type Selection Language + + +*** Variables *** +${entity_id_prefix} urn:ngsi-ld:MultiTypes: +${first_entity_filename} building-simple-attributes-sample.jsonld +${second_entity_filename} building-with-different-type-sample.jsonld +${third_entity_filename} building-with-two-types-sample.jsonld +${building_entity_type} Building +${parking_entity_type} Parking +${tourist_destination_entity_type} TouristDestination + + +*** Test Cases *** ENTITY_TYPES_SELECTION EXPECTED_ENTITIES_IDS +019_08_01 query with one type ${building_entity_type} ${first_entity_id},${third_entity_id} +019_08_02 query with the AND operator (${building_entity_type};${tourist_destination_entity_type}) ${third_entity_id} +019_08_03 query with the OR operator ${building_entity_type},${parking_entity_type} ${first_entity_id},${second_entity_id},${third_entity_id} +019_08_04 different query with the OR operator ${parking_entity_type},${tourist_destination_entity_type} ${second_entity_id},${third_entity_id} +019_08_05 query with two operators (${building_entity_type};${parking_entity_type}),${tourist_destination_entity_type} ${third_entity_id} + + +*** Keywords *** +Query entities using Entity Type Selection Language + [Documentation] Query entities with Entity Type Selection Language. + [Tags] e-query 4_17 5_7_2 since_v1.5.1 + [Arguments] ${entity_types_selection} ${expected_entities_ids} + + ${entities_ids}= Split String ${expected_entities_ids} , + @{entities_ids_list}= Create List ${entities_ids} + ${response}= Query Entities + ... entity_types=${entity_types_selection} + ... context=${ngsild_test_suite_context} + + Check Response Status Code 200 ${response.status_code} + Check Response Body Containing Entities URIS set to + ... @{entities_ids_list} + ... ${response.json()} + +Setup Initial Entities + ${first_entity_id}= Generate Random Entity Id ${entity_id_prefix} + Set Suite Variable ${first_entity_id} + ${create_response1}= Create Entity Selecting Content Type + ... ${first_entity_filename} + ... ${first_entity_id} + ... ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${create_response1.status_code} + ${second_entity_id}= Generate Random Entity Id ${entity_id_prefix} + Set Suite Variable ${second_entity_id} + ${create_response2}= Create Entity Selecting Content Type + ... ${second_entity_filename} + ... ${second_entity_id} + ... ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${create_response2.status_code} + ${third_entity_id}= Generate Random Entity Id ${entity_id_prefix} + Set Suite Variable ${third_entity_id} + ${create_response3}= Create Entity Selecting Content Type + ... ${third_entity_filename} + ... ${third_entity_id} + ... ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${create_response3.status_code} + +Delete Initial Entities + Delete Entity by Id ${first_entity_id} + Delete Entity by Id ${second_entity_id} + Delete Entity by Id ${third_entity_id} diff --git a/data/entities/building-with-different-type-sample.jsonld b/data/entities/building-with-different-type-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..88a855f28f45f3a842540f0f2f13b156c17f2ac5 --- /dev/null +++ b/data/entities/building-with-different-type-sample.jsonld @@ -0,0 +1,7 @@ +{ + "id": "urn:ngsi-ld:MultiTypes:randomUUID", + "type": ["Parking" ], + "@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/entities/building-with-two-types-sample.jsonld b/data/entities/building-with-two-types-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..1a7fdcb67984e2f44caa742c0b387da2503a047e --- /dev/null +++ b/data/entities/building-with-two-types-sample.jsonld @@ -0,0 +1,7 @@ +{ + "id": "urn:ngsi-ld:MultiTypes:randomUUID", + "type": ["Building", "TouristDestination" ], + "@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/checks.py b/doc/analysis/checks.py index 3c068c1345e9aecd593edec8ca12411dc3b9c647..89fd93cf5431311a8daf4d8ab93d4611d4143d22 100644 --- a/doc/analysis/checks.py +++ b/doc/analysis/checks.py @@ -8,6 +8,8 @@ class Checks: Checks.check_response_status_code, 'Check Response Body Containing Array Of URIs set to': Checks.check_response_body_containing_array_of_uris_set_to, + 'Check Response Body Containing Entities URIS set to' : + Checks.check_response_body_containing_entities_uris_set_to, 'Check Created Resources Set To': Checks.check_created_resources_set_to, 'Check Response Headers Containing Content-Type set to': @@ -129,6 +131,10 @@ class Checks: 'params': ['expected_entities_ids', 'response_body'], 'position': [0, 1] }, + 'Check Response Body Containing Entities URIS set to': { + 'params': ['expected_entities_ids', 'response_body'], + 'position': [0, 1] + }, 'Check Response Body Containing ProblemDetails Element Containing Type Element set to': { 'params': ['type'], 'position': [1] @@ -439,6 +445,10 @@ class Checks: def check_response_body_containing_array_of_uris_set_to(kwargs: list) -> str: return 'Response Body set to an array of created entities ids' + @staticmethod + def check_response_body_containing_entities_uris_set_to(kwargs: list) -> str: + return 'Response Body contains entities ids' + @staticmethod def check_created_resources_set_to(kwargs: list) -> str: return 'Created resources set to ${entities}' @@ -967,6 +977,7 @@ if __name__ == "__main__": print(data.get_checks(checks='Check Response Status Code', status_code=201)) print(data.get_checks(checks='Check Response Body Containing Array Of URIs set to')) + print(data.get_checks(checks='Check Response Body Containing Entities URIS set to')) print(data.get_checks(checks='Check Created Resources Set To')) print(data.get_checks(checks='Check Response Headers Containing Content-Type set to', content_type='application/json')) diff --git a/doc/files/ContextInformation/Consumption/019_08.json b/doc/files/ContextInformation/Consumption/019_08.json new file mode 100644 index 0000000000000000000000000000000000000000..8838a902fae1744b55f8df4dea444378611bfc14 --- /dev/null +++ b/doc/files/ContextInformation/Consumption/019_08.json @@ -0,0 +1,114 @@ +{ + "tp_id": "TP/NGSI-LD/CI/Cons/E/019_08", + "test_objective": "Query entities with Entity Type Selection Language.", + "reference": "ETSI GS CIM 009 V1.5.1 [], clauses 4.17, 5.7.2", + "config_id": "", + "parent_release": "v1.5.1", + "clauses": [ + "4.17", + "5.7.2" + ], + "pics_selection": "", + "keywords": [ + "Query entities using Entity Type Selection Language", + "Setup Initial Entities", + "Delete Initial Entities" + ], + "teardown": "Delete Initial Entities", + "initial_condition": "with {\n the SUT containing an initial state\n}", + "test_cases": [ + { + "name": "019_08_01 query with one type", + "permutation_tp_id": "TP/NGSI-LD/CI/Cons/E/019_08_01", + "doc": "Query entities with Entity Type Selection Language.", + "tags": [ + "e-query", + "4_17", + "5_7_2", + "since_v1.5.1" + ], + "setup": null, + "teardown": null, + "template": "Query entities using Entity Type Selection Language", + "then": "then {\n the SUT sends a valid Response for the operations:\n Query Entities with Response Status Code set to 200 and\n Query Entities with Response Body contains entities ids\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 'GET'\n Get Entities Request: and\n Query Parameter: entity_types set to '${entity_types_selection}' and\n Query Parameter: Link set to '<$https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\";type=\"application/ld+json\"'\n}", + "http_verb": "GET", + "endpoint": "entities/" + }, + { + "name": "019_08_02 query with the AND operator", + "permutation_tp_id": "TP/NGSI-LD/CI/Cons/E/019_08_02", + "doc": "Query entities with Entity Type Selection Language.", + "tags": [ + "e-query", + "4_17", + "5_7_2", + "since_v1.5.1" + ], + "setup": null, + "teardown": null, + "template": "Query entities using Entity Type Selection Language", + "then": "then {\n the SUT sends a valid Response for the operations:\n Query Entities with Response Status Code set to 200 and\n Query Entities with Response Body contains entities ids\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 'GET'\n Get Entities Request: and\n Query Parameter: entity_types set to '${entity_types_selection}' and\n Query Parameter: Link set to '<$https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\";type=\"application/ld+json\"'\n}", + "http_verb": "GET", + "endpoint": "entities/" + }, + { + "name": "019_08_03 query with the OR operator", + "permutation_tp_id": "TP/NGSI-LD/CI/Cons/E/019_08_03", + "doc": "Query entities with Entity Type Selection Language.", + "tags": [ + "e-query", + "4_17", + "5_7_2", + "since_v1.5.1" + ], + "setup": null, + "teardown": null, + "template": "Query entities using Entity Type Selection Language", + "then": "then {\n the SUT sends a valid Response for the operations:\n Query Entities with Response Status Code set to 200 and\n Query Entities with Response Body contains entities ids\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 'GET'\n Get Entities Request: and\n Query Parameter: entity_types set to '${entity_types_selection}' and\n Query Parameter: Link set to '<$https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\";type=\"application/ld+json\"'\n}", + "http_verb": "GET", + "endpoint": "entities/" + }, + { + "name": "019_08_04 different query with the OR operator", + "permutation_tp_id": "TP/NGSI-LD/CI/Cons/E/019_08_04", + "doc": "Query entities with Entity Type Selection Language.", + "tags": [ + "e-query", + "4_17", + "5_7_2", + "since_v1.5.1" + ], + "setup": null, + "teardown": null, + "template": "Query entities using Entity Type Selection Language", + "then": "then {\n the SUT sends a valid Response for the operations:\n Query Entities with Response Status Code set to 200 and\n Query Entities with Response Body contains entities ids\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 'GET'\n Get Entities Request: and\n Query Parameter: entity_types set to '${entity_types_selection}' and\n Query Parameter: Link set to '<$https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\";type=\"application/ld+json\"'\n}", + "http_verb": "GET", + "endpoint": "entities/" + }, + { + "name": "019_08_05 query with two operators", + "permutation_tp_id": "TP/NGSI-LD/CI/Cons/E/019_08_05", + "doc": "Query entities with Entity Type Selection Language.", + "tags": [ + "e-query", + "4_17", + "5_7_2", + "since_v1.5.1" + ], + "setup": null, + "teardown": null, + "template": "Query entities using Entity Type Selection Language", + "then": "then {\n the SUT sends a valid Response for the operations:\n Query Entities with Response Status Code set to 200 and\n Query Entities with Response Body contains entities ids\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 'GET'\n Get Entities Request: and\n Query Parameter: entity_types set to '${entity_types_selection}' and\n Query Parameter: Link set to '<$https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\";type=\"application/ld+json\"'\n}", + "http_verb": "GET", + "endpoint": "entities/" + } + ], + "permutations": [], + "robotpath": "ContextInformation/Consumption/Entity/QueryEntities", + "robotfile": "019_08" +} \ No newline at end of file diff --git a/doc/tests/test_ContextInformation_Consumption.py b/doc/tests/test_ContextInformation_Consumption.py index 993590cad933a5ed64f23fb8f8ec450653106ba7..a4c28356b361e0e83d558e94184725ad715d4b48 100644 --- a/doc/tests/test_ContextInformation_Consumption.py +++ b/doc/tests/test_ContextInformation_Consumption.py @@ -238,6 +238,13 @@ class TestCIConsumptions(TestCase): self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_019_08(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_08.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Consumption/019_08.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_019_08.json' + + self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_018_01_01(self): robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Consumption/Entity/RetrieveEntity/018_01_01.robot' expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Consumption/018_01_01.json' diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index f3af151f4cc61b6d980a8b9a0b9cf6f2c5e38f84..5d6c646d626ab7fe4b506fa5a2b337ca3db4461d 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -34,6 +34,15 @@ Check Response Body Containing Array Of URIs set to [Arguments] ${expected_entities_ids} ${response_body} Lists Should Be Equal ${expected_entities_ids} ${response_body} ignore_order=True +Check Response Body Containing Entities URIS set to + [Arguments] ${expected_entities_ids} ${response_body} + @{response_entities_ids}= Create List + FOR ${entity} IN @{response_body} + Append To List ${response_entities_ids} ${entity['id']} + END + + Lists Should Be Equal ${expected_entities_ids} ${response_entities_ids} + Check Response Body Content [Arguments] ${expectation_filename} ${response_body} ${additional_ignored_path}=${EMPTY} ${entity_payload}= Load JSON From File ${EXECDIR}/data/entities/expectations/${expectation_filename}