From 2f231fdf6dec4e3cb1a1f79252567e0b4881358c Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Mon, 16 Oct 2023 15:56:26 +0200 Subject: [PATCH 1/2] fix(019_02): query entities via POST not using the correct syntax --- .../Entity/QueryEntities/019_02_01.robot | 33 +++++------ .../Entity/QueryEntities/019_02_02.robot | 52 ++++++++--------- .../Entity/QueryEntities/019_02_03.robot | 26 +++++---- .../Entity/QueryEntities/019_02_04.robot | 56 ++++++++++--------- .../two-vehicles-expectation.jsonld | 42 ++++++++++++++ ...e-attributes-core-context-expectation.json | 17 ++++++ .../ContextInformationConsumption.resource | 43 ++++++++------ 7 files changed, 172 insertions(+), 97 deletions(-) create mode 100644 data/entities/expectations/two-vehicles-expectation.jsonld create mode 100644 data/entities/expectations/vehicle-simple-attributes-core-context-expectation.json diff --git a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_01.robot b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_01.robot index 3d0d9fa0..8c8d9120 100644 --- a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_01.robot +++ b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_01.robot @@ -1,11 +1,12 @@ *** Settings *** -Documentation Check that you can query several entities via POST Interaction based on ids +Documentation Check that you can query one entity via POST Interaction based on id Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource Resource ${EXECDIR}/resources/AssertionUtils.resource Resource ${EXECDIR}/resources/JsonUtils.resource +Suite Setup Create Entities Suite Teardown Delete Entities @@ -17,9 +18,22 @@ ${entity_type}= https://ngsi-ld-test-suite/context#Building *** Test Cases *** -019_02_01 Query several entities via POST Interaction based on ids - [Documentation] Check that you can query several entities via POST Interaction based on ids +019_02_01 Query one entity via POST Interaction based on id + [Documentation] Check that you can query one entity via POST Interaction based on id [Tags] e-query 5_7_2 + @{entities_ids_to_be_compared}= Create List ${first_entity_id} + ${response}= Query Entities Via POST + ... entity_id=${first_entity_id} + ... entity_type=${entity_type} + Check Response Status Code 200 ${response.status_code} + Check Response Body Containing List Containing Entity elements + ... ${expectation_filename} + ... ${entities_ids_to_be_compared} + ... ${response.json()} + + +*** Keywords *** +Create Entities ${first_entity_id}= Generate Random Entity Id ${building_id_prefix} Set Suite Variable ${first_entity_id} ${response}= Create Entity Selecting Content Type @@ -41,20 +55,7 @@ ${entity_type}= https://ngsi-ld-test-suite/context#Building ... ${third_entity_id} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code 201 ${response.status_code} - @{entities_ids_to_be_compared}= Create List ${first_entity_id} ${second_entity_id} - ${entities_ids_to_be_retrieved}= Catenate SEPARATOR=, ${first_entity_id} ${second_entity_id} - ${entity_types_to_be_retrieved}= Catenate SEPARATOR=, ${entity_type} - ${response}= Query Entities Via POST - ... entity_ids=${entities_ids_to_be_retrieved} - ... entity_types=${entity_types_to_be_retrieved} - Check Response Status Code 200 ${response.status_code} - Check Response Body Containing List Containing Entity elements - ... ${expectation_filename} - ... ${entities_ids_to_be_compared} - ... ${response.json()} - -*** Keywords *** Delete Entities Delete Entity by Id Returning Response ${first_entity_id} Delete Entity by Id Returning Response ${second_entity_id} diff --git a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_02.robot b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_02.robot index 168f397c..a55452e7 100644 --- a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_02.robot +++ b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_02.robot @@ -1,31 +1,43 @@ *** Settings *** -Documentation Check that you can query several entities via POST Interaction based on the entities types +Documentation Check that you can query several entities via POST Interaction based on the entity type Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource Resource ${EXECDIR}/resources/AssertionUtils.resource Resource ${EXECDIR}/resources/JsonUtils.resource +Suite Setup Create Entities Suite Teardown Delete Entities *** Variables *** ${building_id_prefix}= urn:ngsi-ld:Building: ${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: -${parking_id_prefix}= urn:ngsi-ld:OffStreetParking: ${building_filename}= building-minimal-sample.jsonld ${vehicle_filename}= vehicle-simple-attributes-sample.jsonld -${parking_filename}= parking-simple-attributes-sample.jsonld -${expectation_filename}= two-types-vehicle-offstreetparking-expectation.jsonld +${expectation_filename}= two-vehicles-expectation.jsonld ${building_entity_type}= https://ngsi-ld-test-suite/context#Building ${vehicle_entity_type}= https://ngsi-ld-test-suite/context#Vehicle -${parking_entity_type}= https://ngsi-ld-test-suite/context#OffStreetParking *** Test Cases *** 019_02_02 Query several entities via POST Interaction based on the entities types - [Documentation] Check that you can query several entities via POST Interaction based on the entities types + [Documentation] Check that you can query several entities via POST Interaction based on the entity type [Tags] e-query 5_7_2 + ${entities_ids_to_be_compared}= Create List ${first_vehicle_entity_id} ${second_vehicle_entity_id} + ${response}= Query Entities Via POST + ... entity_type=${vehicle_entity_type} + ... accept=${CONTENT_TYPE_LD_JSON} + Check Response Status Code 200 ${response.status_code} + Check Response Body Containing List Containing Entity Elements With Different Types + ... ${expectation_filename} + ... ${entities_ids_to_be_compared} + ... ${response.json()} + ... ignore_core_context_version=True + + +*** Keywords *** +Create Entities ${building_entity_id}= Generate Random Entity Id ${building_id_prefix} Set Suite Variable ${building_entity_id} ${response}= Create Entity Selecting Content Type @@ -33,32 +45,22 @@ ${parking_entity_type}= https://ngsi-ld-test-suite/context#OffStreetParking ... ${building_entity_id} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code 201 ${response.status_code} - ${vehicle_entity_id}= Generate Random Entity Id ${vehicle_id_prefix} - Set Suite Variable ${vehicle_entity_id} + ${first_vehicle_entity_id}= Generate Random Entity Id ${vehicle_id_prefix} + Set Suite Variable ${first_vehicle_entity_id} ${response}= Create Entity Selecting Content Type ... ${vehicle_filename} - ... ${vehicle_entity_id} + ... ${first_vehicle_entity_id} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code 201 ${response.status_code} - ${parking_entity_id}= Generate Random Entity Id ${parking_id_prefix} - Set Suite Variable ${parking_entity_id} + ${second_vehicle_entity_id}= Generate Random Entity Id ${vehicle_id_prefix} + Set Suite Variable ${second_vehicle_entity_id} ${response}= Create Entity Selecting Content Type - ... ${parking_filename} - ... ${parking_entity_id} + ... ${vehicle_filename} + ... ${second_vehicle_entity_id} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code 201 ${response.status_code} - @{entity_types_to_be_compared}= Create List ${vehicle_entity_type} ${parking_entity_type} - ${entity_types_to_be_retrieved}= Catenate SEPARATOR=, ${vehicle_entity_type} ${parking_entity_type} - ${response}= Query Entities Via POST entity_types=${entity_types_to_be_retrieved} - Check Response Status Code 200 ${response.status_code} - Check Response Body Containing List Containing Entity elements - ... ${expectation_filename} - ... ${entity_types_to_be_compared} - ... ${response.json()} - -*** Keywords *** Delete Entities Delete Entity by Id Returning Response ${building_entity_id} - Delete Entity by Id Returning Response ${vehicle_entity_id} - Delete Entity by Id Returning Response ${parking_entity_id} + Delete Entity by Id Returning Response ${first_vehicle_entity_id} + Delete Entity by Id Returning Response ${second_vehicle_entity_id} diff --git a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_03.robot b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_03.robot index 3ac26510..514238f2 100644 --- a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_03.robot +++ b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_03.robot @@ -6,6 +6,7 @@ Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption. Resource ${EXECDIR}/resources/AssertionUtils.resource Resource ${EXECDIR}/resources/JsonUtils.resource +Suite Setup Create Entities Suite Teardown Delete Entities @@ -21,6 +22,19 @@ ${entity_id_pattern}= urn:ngsi-ld:Building:.* 019_02_03 Query several entities via POST Interaction based on the given id pattern [Documentation] Check that you can query several entities via POST Interaction based on the given id pattern [Tags] e-query 5_7_2 + @{entities_ids_to_be_compared}= Create List ${first_entity_id} ${second_entity_id} + ${response}= Query Entities Via POST + ... entity_id_pattern=${entity_id_pattern} + ... entity_type=${entity_type} + Check Response Status Code 200 ${response.status_code} + Check Response Body Containing List Containing Entity elements + ... ${expectation_filename} + ... ${entities_ids_to_be_compared} + ... ${response.json()} + + +*** Keywords *** +Create Entities ${first_entity_id}= Generate Random Entity Id ${building_id_prefix} Set Suite Variable ${first_entity_id} ${response}= Create Entity Selecting Content Type @@ -35,19 +49,7 @@ ${entity_id_pattern}= urn:ngsi-ld:Building:.* ... ${second_entity_id} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code 201 ${response.status_code} - @{entities_ids_to_be_compared}= Create List ${first_entity_id} ${second_entity_id} - ${entity_types_to_be_retrieved}= Catenate SEPARATOR=, ${entity_type} - ${response}= Query Entities Via POST - ... entity_id_pattern=${entity_id_pattern} - ... entity_types=${entity_types_to_be_retrieved} - Check Response Status Code 200 ${response.status_code} - Check Response Body Containing List Containing Entity elements - ... ${expectation_filename} - ... ${entities_ids_to_be_compared} - ... ${response.json()} - -*** Keywords *** Delete Entities Delete Entity by Id Returning Response ${first_entity_id} Delete Entity by Id Returning Response ${second_entity_id} diff --git a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_04.robot b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_04.robot index 58a65d1e..71e3d751 100644 --- a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_04.robot +++ b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_02_04.robot @@ -6,49 +6,51 @@ Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption. Resource ${EXECDIR}/resources/AssertionUtils.resource Resource ${EXECDIR}/resources/JsonUtils.resource +Suite Setup Create Entities Suite Teardown Delete Entities *** Variables *** -${building_id_prefix}= urn:ngsi-ld:Building: -${filename}= building-minimal-sample.jsonld -${expectation_filename}= building-minimal-expectation.json -${attribute_airqualitylevel}= https://ngsi-ld-test-suite/context#airQualityLevel -${attribute_subcategory}= https://ngsi-ld-test-suite/context#subCategory +${building_id_prefix}= urn:ngsi-ld:Building: +${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: +${building_filename}= building-minimal-sample.jsonld +${vehicle_filename}= vehicle-simple-attributes-sample.jsonld +${expectation_filename}= vehicle-simple-attributes-core-context-expectation.json +${attribute_brandname}= https://ngsi-ld-test-suite/context#brandName +${attribute_isparked}= https://uri.etsi.org/ngsi-ld/default-context/isParked *** Test Cases *** 019_02_04 Query several entities via POST Interaction based on attribute names [Documentation] Check that you can query several entities via POST Interaction based on attribute names [Tags] e-query 5_7_2 - ${first_entity_id}= Generate Random Entity Id ${building_id_prefix} - Set Suite Variable ${first_entity_id} - ${response}= Create Entity Selecting Content Type - ... ${filename} - ... ${first_entity_id} - ... ${CONTENT_TYPE_LD_JSON} - Check Response Status Code 201 ${response.status_code} - ${second_entity_id}= Generate Random Entity Id ${building_id_prefix} - Set Suite Variable ${second_entity_id} - ${response}= Create Entity Selecting Content Type - ... ${filename} - ... ${second_entity_id} - ... ${CONTENT_TYPE_LD_JSON} - Check Response Status Code 201 ${response.status_code} - ${attributes_to_be_retrieved}= Catenate - ... SEPARATOR=, - ... ${attribute_airqualitylevel} - ... ${attribute_subcategory} - @{entities_ids_to_be_retrieved}= Create List ${first_entity_id} ${second_entity_id} + @{attributes_to_be_retrieved}= Create List ${attribute_brandname} ${attribute_isparked} + @{entities_ids_to_be_retrieved}= Create List ${vehicle_entity_id} ${response}= Query Entities Via POST attrs=${attributes_to_be_retrieved} Check Response Status Code 200 ${response.status_code} - Check Response Body Containing List Containing Entity elements + Check Response Body Containing List Containing Entity Elements ... ${expectation_filename} ... ${entities_ids_to_be_retrieved} ... ${response.json()} *** Keywords *** +Create Entities + ${building_entity_id}= Generate Random Entity Id ${building_id_prefix} + Set Suite Variable ${building_entity_id} + ${response}= Create Entity Selecting Content Type + ... ${building_filename} + ... ${building_entity_id} + ... ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${response.status_code} + ${vehicle_entity_id}= Generate Random Entity Id ${vehicle_id_prefix} + Set Suite Variable ${vehicle_entity_id} + ${response}= Create Entity Selecting Content Type + ... ${vehicle_filename} + ... ${vehicle_entity_id} + ... ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${response.status_code} + Delete Entities - Delete Entity by Id Returning Response ${first_entity_id} - Delete Entity by Id Returning Response ${second_entity_id} + Delete Entity by Id Returning Response ${building_entity_id} + Delete Entity by Id Returning Response ${vehicle_entity_id} diff --git a/data/entities/expectations/two-vehicles-expectation.jsonld b/data/entities/expectations/two-vehicles-expectation.jsonld new file mode 100644 index 00000000..66aa4628 --- /dev/null +++ b/data/entities/expectations/two-vehicles-expectation.jsonld @@ -0,0 +1,42 @@ +[ + { + "id": "urn:ngsi-ld:Vehicle:8012188779712372", + "type": "https://ngsi-ld-test-suite/context#Vehicle", + "https://ngsi-ld-test-suite/context#brandName": { + "type": "Property", + "value": "Mercedes" + }, + "isParked": { + "type": "Relationship", + "providedBy": { + "type": "Relationship", + "object": "urn:ngsi-ld:Person:Bob" + }, + "object": "urn:ngsi-ld:OffStreetParking:Downtown1", + "observedAt": "2017-07-29T12:00:04Z" + }, + "@context": [ + "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld" + ] + }, + { + "id": "urn:ngsi-ld:Vehicle:8012188779712372", + "type": "https://ngsi-ld-test-suite/context#Vehicle", + "https://ngsi-ld-test-suite/context#brandName": { + "type": "Property", + "value": "Mercedes" + }, + "isParked": { + "type": "Relationship", + "providedBy": { + "type": "Relationship", + "object": "urn:ngsi-ld:Person:Bob" + }, + "object": "urn:ngsi-ld:OffStreetParking:Downtown1", + "observedAt": "2017-07-29T12:00:04Z" + }, + "@context": [ + "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld" + ] + } +] \ No newline at end of file diff --git a/data/entities/expectations/vehicle-simple-attributes-core-context-expectation.json b/data/entities/expectations/vehicle-simple-attributes-core-context-expectation.json new file mode 100644 index 00000000..54eca925 --- /dev/null +++ b/data/entities/expectations/vehicle-simple-attributes-core-context-expectation.json @@ -0,0 +1,17 @@ +{ + "id": "urn:ngsi-ld:Vehicle:3542857210001312", + "type": "https://ngsi-ld-test-suite/context#Vehicle", + "https://ngsi-ld-test-suite/context#brandName": { + "type": "Property", + "value": "Mercedes" + }, + "isParked": { + "type": "Relationship", + "providedBy": { + "type": "Relationship", + "object": "urn:ngsi-ld:Person:Bob" + }, + "object": "urn:ngsi-ld:OffStreetParking:Downtown1", + "observedAt": "2017-07-29T12:00:04Z" + } +} \ No newline at end of file diff --git a/resources/ApiUtils/ContextInformationConsumption.resource b/resources/ApiUtils/ContextInformationConsumption.resource index 7782d2f0..17e702e3 100755 --- a/resources/ApiUtils/ContextInformationConsumption.resource +++ b/resources/ApiUtils/ContextInformationConsumption.resource @@ -12,7 +12,9 @@ ${ENTITIES_ENDPOINT_PATH} entities/ ${ENTITY_OPERATIONS_QUERY_ENDPOINT_PATH} entityOperations/query ${ENTITIES_TYPES_ENDPOINT_PATH} types +${CONTENT_TYPE_JSON} application/json ${CONTENT_TYPE_LD_JSON} application/ld+json +${CONTENT_TYPE_GEOJSON} application/geo+json ${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 @@ -86,34 +88,41 @@ Query Entities Query Entities Via POST [Arguments] - ... ${entity_ids}=${EMPTY} - ... ${entity_types}=${EMPTY} - ... ${content_type}=${CONTENT_TYPE_LD_JSON} + ... ${entity_id}=${EMPTY} + ... ${entity_type}=${EMPTY} + ... ${content_type}=${CONTENT_TYPE_JSON} + ... ${accept}=${CONTENT_TYPE_JSON} ... ${attrs}=${EMPTY} ... ${entity_id_pattern}=${EMPTY} - ... ${geoproperty}=${EMPTY} + ... ${geometry_property}=${EMPTY} &{headers}= Create Dictionary - &{params}= Create Dictionary - ${entity_ids_length}= Get Length ${entity_ids} - ${entity_types_length}= Get Length ${entity_types} - ${attrs_length}= Get Length ${attrs} Set To Dictionary ${headers} Content-Type ${content_type} - IF ${entity_ids_length}>0 - Set To Dictionary ${params} id=${entity_ids} + Set To Dictionary ${headers} Accept ${accept} + &{body}= Create Dictionary + Set To Dictionary ${body} type=Query + &{entities}= Create Dictionary + IF '${entity_id}'!='' + Set To Dictionary ${entities} id=${entity_id} END - IF ${entity_types_length}>0 - Set To Dictionary ${params} type=${entity_types} + IF '${entity_type}'!='' + Set To Dictionary ${entities} type=${entity_type} END - IF ${attrs_length}>0 Set To Dictionary ${params} attrs=${attrs} IF '${entity_id_pattern}'!='' - Set To Dictionary ${params} idPattern=${entity_id_pattern} + Set To Dictionary ${entities} idPattern=${entity_id_pattern} END - IF '${geoproperty}'!='' - Set To Dictionary ${params} geoproperty=${geoproperty} + ${entities_length}= Get Length ${entities} + IF ${entities_length}>0 + ${entities_list}= Create List ${entities} + Set To Dictionary ${body} entities=${entities_list} + END + ${attrs_length}= Get Length ${attrs} + IF ${attrs_length}>0 Set To Dictionary ${body} attrs=${attrs} + IF '${geometry_property}'!='' + Set To Dictionary ${body} geometryProperty=${geometry_property} END ${response}= POST ... url=${url}/${ENTITY_OPERATIONS_QUERY_ENDPOINT_PATH} - ... json=${params} + ... json=${body} ... headers=${headers} ... expected_status=any Output ${response} Query Entities Via POST -- GitLab From bbc8de41ed81eb55891581cfb094ff6b45c84dfe Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Mon, 16 Oct 2023 18:12:46 +0200 Subject: [PATCH 2/2] fix(021_03): invalid query for query temporal entities via POST test case --- .../entity-operations-after-query.jsonld | 11 ++++++++--- .../entity-operations-before-query.jsonld | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/data/temporalEntities/entity-operations-after-query.jsonld b/data/temporalEntities/entity-operations-after-query.jsonld index 4eeabb72..22271295 100644 --- a/data/temporalEntities/entity-operations-after-query.jsonld +++ b/data/temporalEntities/entity-operations-after-query.jsonld @@ -1,5 +1,10 @@ { - "type":"Vehicle", - "timerel":"after", - "timeAt":"2020-08-02T12:05:00Z" + "type": "Query", + "entities": [{ + "type": "Vehicle" + }], + "temporalQ": { + "timerel":"after", + "timeAt":"2020-08-02T12:05:00Z" + } } \ No newline at end of file diff --git a/data/temporalEntities/entity-operations-before-query.jsonld b/data/temporalEntities/entity-operations-before-query.jsonld index 03791c34..41e11c34 100644 --- a/data/temporalEntities/entity-operations-before-query.jsonld +++ b/data/temporalEntities/entity-operations-before-query.jsonld @@ -1,5 +1,10 @@ { - "type":"Vehicle", - "timerel":"before", - "timeAt":"2020-08-02T12:05:00Z" + "type": "Query", + "entities": [{ + "type": "Vehicle" + }], + "temporalQ": { + "timerel":"before", + "timeAt":"2020-08-02T12:05:00Z" + } } \ No newline at end of file -- GitLab