diff --git a/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_07.robot b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_07.robot new file mode 100644 index 0000000000000000000000000000000000000000..73484e24301bec660e34cb129e241048c3d8838c --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_07.robot @@ -0,0 +1,61 @@ +*** Settings *** +Documentation If the count parameter is set to true the special HTTP header NGSILD-Results-Count is set in the response and it must contain the total number of matching results. + +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 With Count + + +*** Variables *** +${building_id_prefix}= urn:ngsi-ld:Building: +${first_entity_filename}= building-simple-attributes-sample.jsonld +${second_entity_filename}= building-simple-attributes-second-sample.jsonld +${entity_type}= Building +${airQualityLevel}= airQualityLevel==6 + + +*** Test Cases *** Q_PARAMETER EXPECTED_STATUS EXPECTED_COUNT +019_07_01 Check that the total number of matching results is returned if the count parameter is set to true and only the entity type is provided + ${EMPTY} 200 2 +019_07_02 Check that the total number of matching results is returned if the count parameter is set to true and a q parameter is provided + ${airQualityLevel} 200 1 + + +*** Keywords *** +Query Entities With Count + [Documentation] If the count parameter is set to true the special HTTP header NGSILD-Results-Count is set in the response and it must contain the total number of matching results. + [Tags] e-query 5_7_2 6_3_13 + [Arguments] ${q} ${expected_status_code} ${expected_count} + ${response}= Query Entities + ... entity_types=${entity_type} + ... q=${q} + ... count=${True} + ... context=${ngsild_test_suite_context} + + Check Response Status Code ${expected_status_code} ${response.status_code} + Check Response Headers Containing NGSILD-Results-Count Equals To ${expected_count} ${response.headers} + +Setup Initial Entities + ${first_entity_id}= Generate Random Entity Id ${building_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 ${building_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} + +Delete Initial Entities + Delete Entity by Id ${first_entity_id} + Delete Entity by Id ${second_entity_id} diff --git a/data/entities/building-simple-attributes-second-sample.jsonld b/data/entities/building-simple-attributes-second-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..a79af10ebaaebb4a46e91aec914ac85f6b6e901f --- /dev/null +++ b/data/entities/building-simple-attributes-second-sample.jsonld @@ -0,0 +1,25 @@ +{ + "id": "urn:ngsi-ld:Building:randomUUID", + "type": "Building", + "name": { + "type": "Property", + "value": "Pisa Tower" + }, + "subCategory": { + "type": "Property", + "value": "tourism" + }, + "airQualityLevel": { + "type": "Property", + "value": 6, + "unitCode": "C62", + "observedAt": "2020-10-10T16:40:00.000Z" + }, + "almostFull": { + "type": "Property", + "value": true + }, + "@context": [ + "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld" + ] +} diff --git a/doc/analysis/checks.py b/doc/analysis/checks.py index f65242bf89b33ae0b2fba538772f01407a01deb4..70b7a570479e1b2fffe178139546ae208582081e 100644 --- a/doc/analysis/checks.py +++ b/doc/analysis/checks.py @@ -105,7 +105,9 @@ class Checks: 'Check Response Reason set to': Checks.check_response_reason_set_to, 'Check Response Does Not Contain Body': - Checks.check_response_does_not_contain_body + Checks.check_response_does_not_contain_body, + 'Check Response Headers Containing NGSILD-Results-Count Equals To' : + Checks.check_response_header_contains_ngsild_results_count_equals_to, } self.args = { @@ -303,6 +305,11 @@ class Checks: 'params': ['response'], 'position': [0] } + , + 'Check Response Headers Containing NGSILD-Results-Count Equals To': { + 'params': ['expected_result_count' , 'response_headers'], + 'position': [0, 1] + } } @staticmethod @@ -871,6 +878,14 @@ class Checks: else: raise Exception(f"ERROR, Expected 'expected_value' and 'obtained_value' parameters but received: '{kwargs}'") + @staticmethod + def check_response_header_contains_ngsild_results_count_equals_to(kwargs: list) -> str: + if 'expected_result_count' in kwargs: + expected_result_count = kwargs['expected_result_count'] + return f'Response Header: NGSILD-Results-Count equals to {expected_result_count}' + else: + raise Exception(f"ERROR, Expected 'expected_result_count' but received: '{kwargs}'") + def get_checks(self, **kwargs) -> str: checking = None @@ -977,6 +992,7 @@ if __name__ == "__main__": 'Check Created Resources Set To'] , status_code=201)) print() + print(data.get_checks(checks='Check Response Headers Containing NGSILD-Results-Count Equals To')) # Check exceptions try: diff --git a/doc/analysis/requests.py b/doc/analysis/requests.py index 96f2933c08f3fd4334a2c40bdc9c53975b52ae50..66bc76bfc7827db62b4dbfb7e6a6037f1350a4e0 100644 --- a/doc/analysis/requests.py +++ b/doc/analysis/requests.py @@ -85,7 +85,7 @@ class Requests: 'params': ['entity_ids', 'entity_types', 'accept', 'attrs', 'context', 'geoproperty', 'options', 'limit', 'entity_id_pattern', - 'georel', 'coordinates', 'geometry'] + 'georel', 'coordinates', 'geometry', 'count', 'q'] }, 'Query Entities Via POST': { 'positions': [], @@ -1131,7 +1131,7 @@ class Requests: expected_parameters = ['entity_ids', 'entity_types', 'accept', 'attrs', 'context', 'geoproperty', 'options', 'limit', 'entity_id_pattern', - 'georel', 'coordinates', 'geometry'] + 'georel', 'coordinates', 'geometry', 'count' , 'q'] result = [x for x in kwargs if x not in expected_parameters] response = "Get Entities Request:" @@ -1162,6 +1162,10 @@ class Requests: response = f"{response} and\n Query Parameter: coordinates set to '{value}'" case 'geometry': response = f"{response} and\n Query Parameter: geometry set to '{value}'" + case 'count': + response = f"{response} and\n Query Parameter: count set to '{value}'" + case 'q': + response = f"{response} and\n Query Parameter: q set to '{value}'" case _: raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are " f"'{expected_parameters}', but received: {kwargs}") diff --git a/doc/files/ContextInformation/Consumption/019_07.json b/doc/files/ContextInformation/Consumption/019_07.json new file mode 100644 index 0000000000000000000000000000000000000000..72bc4f6a9cd27605cdf4e35b199379635ee5217f --- /dev/null +++ b/doc/files/ContextInformation/Consumption/019_07.json @@ -0,0 +1,55 @@ +{ + "tp_id": "TP/NGSI-LD/CI/Cons/E/019_07", + "test_objective": "If the count parameter is set to true the special HTTP header NGSILD-Results-Count is set in the response and it must contain the total number of matching results.", + "reference": "ETSI GS CIM 009 V1.3.1 [], clause 6.3.13", + "config_id": "", + "parent_release": "v1.3.1", + "pics_selection": "PICS_6_3_13", + "keywords": [ + "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_07_01 Check that the total number of matching results is returned if the count parameter is set to true and only the entity type is provided", + "permutation_tp_id": "TP/NGSI-LD/CI/Cons/E/019_07_01", + "doc": "If the count parameter is set to true the special HTTP header NGSILD-Results-Count is set in the response and it must contain the total number of matching results.", + "tags": [ + "e-query", + "5_7_2", + "6_3_13" + ], + "setup": null, + "teardown": null, + "template": "Query Entities With Count", + "then": "then {\n the SUT sends a valid Response for the operations:\n Query Entities with Response Status Code set to ${expected_status_code} and\n Query Entities with Response Header: NGSILD-Results-Count equals to 2\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 'Building' and\n Query Parameter: q set to '${q}' and\n Query Parameter: count set to '${True}' 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_07_02 Check that the total number of matching results is returned if the count parameter is set to true and a q parameter is provided", + "permutation_tp_id": "TP/NGSI-LD/CI/Cons/E/019_07_02", + "doc": "If the count parameter is set to true the special HTTP header NGSILD-Results-Count is set in the response and it must contain the total number of matching results.", + "tags": [ + "e-query", + "5_7_2", + "6_3_13" + ], + "setup": null, + "teardown": null, + "template": "Query Entities With Count", + "then": "then {\n the SUT sends a valid Response for the operations:\n Query Entities with Response Status Code set to ${expected_status_code} and\n Query Entities with Response Header: NGSILD-Results-Count equals to 1\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 'Building' and\n Query Parameter: q set to '${q}' and\n Query Parameter: count set to '${True}' 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": [ + "then" + ], + "robotpath": "ContextInformation/Consumption/Entity/QueryEntities", + "robotfile": "019_07" +} \ No newline at end of file diff --git a/doc/tests/test_ContextInformation_Consumption.py b/doc/tests/test_ContextInformation_Consumption.py index 8f059be8ed6757c0cbca3deec20ff8bb64e12867..1e9fddf9b284f5bae3b2c2ca95f8d3c4de49f632 100644 --- a/doc/tests/test_ContextInformation_Consumption.py +++ b/doc/tests/test_ContextInformation_Consumption.py @@ -224,6 +224,13 @@ class TestCIConsumptions(TestCase): self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) + def test_019_07(self): + robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_07.robot' + expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Consumption/019_07.json' + difference_file = f'{self.folder_test_suites}/doc/results/out_019_07.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/ApiUtils/ContextInformationConsumption.resource b/resources/ApiUtils/ContextInformationConsumption.resource index 0fbad1d81c11a658dfec8b3bb8b3e2258942c8fd..6f3d9d02437f1bba87c0efffc3107a4f0f453bd8 100755 --- a/resources/ApiUtils/ContextInformationConsumption.resource +++ b/resources/ApiUtils/ContextInformationConsumption.resource @@ -38,6 +38,8 @@ Query Entities ... ${georel}=${EMPTY} ... ${coordinates}=${EMPTY} ... ${geometry}=${EMPTY} + ... ${count}=${EMPTY} + ... ${q}=${EMPTY} ${attrs_length}= Get Length ${attrs} ${accept_length}= Get Length ${accept} ${options_length}= Get Length ${options} @@ -77,6 +79,8 @@ Query Entities IF '${geometry}'!='' Set To Dictionary ${params} geometry=${geometry} END + IF '${count}'!='' Set To Dictionary ${params} count=${count} + IF '${q}'!='' Set To Dictionary ${params} q=${q} ${response}= GET ... url=${url}/${ENTITIES_ENDPOINT_PATH} diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index f288c8a8603ef0d321c0d6bcf636cb568d013bd0..91ef5da9587d992a177477948434538d89b793fc 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -60,6 +60,10 @@ Check Response Headers Containing URI set to ... ignore_order=True END +Check Response Headers Containing NGSILD-Results-Count Equals To + [Arguments] ${expected_result_count} ${response_headers} + Should Be Equal ${response_headers['NGSILD-Results-Count']} ${expected_result_count} + # Since Http headers names are case-insensitive (from Http specification) # We check both Location and location headers