Commit bbbbac07 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

Merge remote-tracking branch...

Merge remote-tracking branch 'origin/feature/add-entity-type-selection-language-tests' into parsespec

# Conflicts:
#	doc/tests/test_ContextInformation_Consumption.py
#	resources/AssertionUtils.resource
parents 534f055e 9fd9d65a
Loading
Loading
Loading
Loading
+82 −0
Original line number Diff line number Diff line
*** 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    EXPECTED_LENGTH
019_08_01 query with one type    ${building_entity_type}    ${first_expected_entities_ids}    2
019_08_02 query with the AND operator    (${building_entity_type};${tourist_destination_entity_type})    ${third_entity_id_as_a_list}    1
019_08_03 query with the OR operator    ${building_entity_type},${parking_entity_type}    ${second_expected_entities_ids}    3
019_08_04 different query with the OR operator    ${parking_entity_type},${tourist_destination_entity_type}    ${third_expected_entities_ids}    2
019_08_05 query with two operators    (${building_entity_type};${parking_entity_type}),${tourist_destination_entity_type}    ${third_entity_id_as_a_list}    1


*** Keywords ***
Query entities using Entity Type Selection Language
    [Documentation]    Query entities with Entity Type Selection Language.
    [Tags]    e-query    4_17    5_7_2
    [Arguments]    ${entity_types_selection}    ${expected_entities_ids}    ${expected_length}

    ${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
    ...    ${expected_entities_ids}
    ...    ${response.json()}
    ...    ${expected_length}

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}
    @{first_expected_entities_ids}=    Create List    ${first_entity_id}    ${third_entity_id}
    Set Suite Variable    ${first_expected_entities_ids}
    @{second_expected_entities_ids}=    Create List    ${first_entity_id}    ${second_entity_id}    ${third_entity_id}
    Set Suite Variable    @{second_expected_entities_ids}
    @{third_expected_entities_ids}=    Create List    ${second_entity_id}    ${third_entity_id}
    Set Suite Variable    @{third_expected_entities_ids}
    @{third_entity_id_as_a_list}=    Create List    ${third_entity_id}
    Set Suite Variable    @{third_entity_id_as_a_list}

Delete Initial Entities
    Delete Entity by Id    ${first_entity_id}
    Delete Entity by Id    ${second_entity_id}
    Delete Entity by Id    ${third_entity_id}
+12 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:MultiTypes:randomUUID",
    "type": ["Parking" ],
    "name": {
        "type": "Property",
        "value": "Eiffel Tower"
    },

    "@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
+11 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:MultiTypes:randomUUID",
    "type": ["Building", "TouristDestination" ],
    "name": {
        "type": "Property",
        "value": "Eiffel Tower"
    },
    "@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
+11 −0
Original line number Diff line number Diff line
@@ -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':
@@ -141,6 +143,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', 'expected_length'],
                'position': [0, 1, 2]
            },
            'Check Response Body Containing ProblemDetails Element Containing Type Element set to': {
                'params': ['type'],
                'position': [1]
@@ -466,6 +472,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}'
@@ -1102,6 +1112,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'))
+7 −0
Original line number Diff line number Diff line
@@ -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'
Loading