Commit 1f5777a9 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

feat: add tests for multi-typing in batch operations

parent 20744098
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can update types of entities in a batch update operation

Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Test Setup          Setup Initial Entities
Test Teardown       Delete Initial Entities
Test Template       Batch Update Entity Scenarios


*** Variables ***
${building_id_prefix}=          urn:ngsi-ld:Building:
${entity_payload_filename}=     building-minimal-sample.jsonld


*** Test Cases ***    FILENAME    UPDATE_FRAGMENT_FILENAME
005_05_01 EntityWithNewType
    [Tags]    be-update    5_6_9    4_16
    building-minimal-with-new-type.jsonld    fragmentEntities/building-two-types-fragment.jsonld


*** Keywords ***
Batch Update Entity Scenarios
    [Documentation]    Check that you can update types of entities in a batch update operation
    [Arguments]    ${filename}    ${update_fragment_filename}
    ${first_entity}=    Load Entity    ${filename}    ${first_entity_id}
    ${second_entity}=    Load Entity    ${filename}    ${second_entity_id}
    @{entities_ids_to_be_updated}=    Create List    ${first_entity_id}    ${second_entity_id}
    @{entities_to_be_updated}=    Create List    ${first_entity}    ${second_entity}
    ${response}=    Batch Update Entities    @{entities_to_be_updated}
    Check Response Status Code    204    ${response.status_code}
    ${first_created_entity}=    Load Test Sample    entities/${entity_payload_filename}    ${first_entity_id}
    ${second_created_entity}=    Load Test Sample    entities/${entity_payload_filename}    ${second_entity_id}
    ${update_fragment}=    Load Test Sample    entities/${update_fragment_filename}
    ${first_updated_entity}=    Upsert Element In Entity    ${first_created_entity}    ${update_fragment}
    ${second_updated_entity}=    Upsert Element In Entity    ${second_created_entity}    ${update_fragment}
    @{updated_entities}=    Create List    ${first_updated_entity}    ${second_updated_entity}
    ${expected_entities_ids}=    Catenate    SEPARATOR=,    @{entities_ids_to_be_updated}
    ${response1}=    Query Entities
    ...    entity_ids=${expected_entities_ids}
    ...    entity_types=Building
    ...    context=${ngsild_test_suite_context}
    ...    accept=${CONTENT_TYPE_LD_JSON}
    Check Updated Resources Set To    ${updated_entities}    ${response1.json()}

Setup Initial Entities
    ${first_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${second_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Create Entity    ${entity_payload_filename}    ${first_entity_id}
    Create Entity    ${entity_payload_filename}    ${second_entity_id}
    Set Test Variable    ${first_entity_id}
    Set Test Variable    ${second_entity_id}

Delete Initial Entities
    @{entities_ids_to_be_deleted}=    Create List    ${first_entity_id}    ${second_entity_id}
    Batch Delete Entities    entities_ids_to_be_deleted=@{entities_ids_to_be_deleted}
+52 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can upsert a batch of existing entities with new types and they will be replaced

Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Test Setup          Setup Initial Entities
Test Teardown       Delete Initial Entities
Test Template       Batch Upsert Existing Entities Scenarios


*** Variables ***
${building_id_prefix}=      urn:ngsi-ld:Building:


*** Test Cases ***    FILENAME
004_08_01 EntityWithNewTypes
    [Tags]    be-upsert    5_6_8    4_16
    building-minimal-with-new-types.jsonld


*** Keywords ***
Batch Upsert Existing Entities Scenarios
    [Documentation]    Check that you can upsert a batch of existing entities with new types
    [Arguments]    ${filename}
    ${first_existing_entity}=    Load Entity    ${filename}    ${first_existing_entity_id}
    ${second_existing_entity}=    Load Entity    ${filename}    ${second_existing_entity_id}
    @{entities_to_be_upserted}=    Create List    ${first_existing_entity}    ${second_existing_entity}
    ${response}=    Batch Upsert Entities    @{entities_to_be_upserted}
    Check Response Status Code    204    ${response.status_code}
    @{upserted_entities_ids}=    Create List    ${first_existing_entity_id}    ${second_existing_entity_id}
    ${expected_updated_entities_ids}=    Catenate    SEPARATOR=,    @{upserted_entities_ids}
    ${response1}=    Query Entities
    ...    entity_ids=${expected_updated_entities_ids}
    ...    entity_types=Building
    ...    context=${ngsild_test_suite_context}
    ...    accept=${CONTENT_TYPE_LD_JSON}
    Check Updated Resources Set To    ${entities_to_be_upserted}    ${response1.json()}

Setup Initial Entities
    ${first_existing_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${second_existing_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Create Entity    building-minimal-sample.jsonld    ${first_existing_entity_id}
    Create Entity    building-minimal-sample.jsonld    ${second_existing_entity_id}
    Set Test Variable    ${first_existing_entity_id}
    Set Test Variable    ${second_existing_entity_id}

Delete Initial Entities
    @{entities_ids_to_be_deleted}=    Create List    ${first_existing_entity_id}    ${second_existing_entity_id}
    Batch Delete Entities    entities_ids_to_be_deleted=@{entities_ids_to_be_deleted}
+7 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:randomUUID",
    "type": "Vehicle",
    "@context": [
        "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld"
    ]
}
+7 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:randomUUID",
    "type": ["Building" ,"Vehicle"],
    "@context": [
        "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld"
    ]
}
+3 −0
Original line number Diff line number Diff line
{
  "type": ["Building", "Vehicle"]
}
 No newline at end of file
Loading