feat: add Test cases for querying entities with count parameter set to true

check the result returned after querying entities when the count parameter is set to true.

Merge request reports

Loading
+61 −0
Changes for TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_07.robot: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** 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}
+25 −0
Changes for data/entities/building-simple-attributes-second-sample.jsonld: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
{
    "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"
    ]
}
+17 −1
Changes for doc/analysis/checks.py: 17 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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:
+6 −2
Changes for doc/analysis/requests.py: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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}")
+55 −0
Changes for doc/files/ContextInformation/Consumption/019_07.json: 55 added lines, 0 removed lines.
Original line number Diff line number Diff line
{
  "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
Loading
Loading