Commit 396f9d39 authored by Ranim Naimi's avatar Ranim Naimi
Browse files

test case : return the total number of matching results if count is set to true

parent 0134d819
Loading
Loading
Loading
Loading
+58 −0
Original line number Original line 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 Teardown      Delete Entities


*** 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}=                 https://ngsi-ld-test-suite/context#Building
${airQualityLevel}=             https://ngsi-ld-test-suite/context#airQualityLevel==6


*** Test Cases ***
019_07_01 Check that the total number of matching results is returned if the count parameter is set to true.
    [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    6_3_13
    ${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}

    ${response}=    Query Entities
    ...    entity_types=${entity_type}
    ...    count=${True}

    Check Response Status Code    200    ${response.status_code}

    Check Response Headers Containing NGSILD-Results-Count    2    ${response.headers}
    ${response}=    Query Entities
    ...    entity_types=${entity_type}
    ...    q=${airQualityLevel}
    ...    count=${True}

    Check Response Status Code    200    ${response.status_code}
    Check Response Headers Containing NGSILD-Results-Count    1    ${response.headers}


*** Keywords ***
Delete Entities
    Delete Entity by Id    ${first_entity_id}
    Delete Entity by Id    ${second_entity_id}
+25 −0
Original line number Original line 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"
    ]
}
+4 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,8 @@ Query Entities
    ...    ${georel}=${EMPTY}
    ...    ${georel}=${EMPTY}
    ...    ${coordinates}=${EMPTY}
    ...    ${coordinates}=${EMPTY}
    ...    ${geometry}=${EMPTY}
    ...    ${geometry}=${EMPTY}
    ...    ${count}=${EMPTY}
    ...    ${q}=${EMPTY}
    ${attrs_length}=    Get Length    ${attrs}
    ${attrs_length}=    Get Length    ${attrs}
    ${accept_length}=    Get Length    ${accept}
    ${accept_length}=    Get Length    ${accept}
    ${options_length}=    Get Length    ${options}
    ${options_length}=    Get Length    ${options}
@@ -77,6 +79,8 @@ Query Entities
    IF    '${geometry}'!=''
    IF    '${geometry}'!=''
        Set To Dictionary    ${params}    geometry=${geometry}
        Set To Dictionary    ${params}    geometry=${geometry}
    END
    END
    IF    '${count}'!=''    Set To Dictionary    ${params}    count=${count}
    IF    '${q}'!=''    Set To Dictionary    ${params}    q=${q}


    ${response}=    GET
    ${response}=    GET
    ...    url=${url}/${ENTITIES_ENDPOINT_PATH}
    ...    url=${url}/${ENTITIES_ENDPOINT_PATH}
+4 −0
Original line number Original line Diff line number Diff line
@@ -60,6 +60,10 @@ Check Response Headers Containing URI set to
        ...    ignore_order=True
        ...    ignore_order=True
    END
    END


Check Response Headers Containing NGSILD-Results-Count
    [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)
# Since Http headers names are case-insensitive (from Http specification)
# We check both Location and location headers
# We check both Location and location headers