Commit 6034ced5 authored by Houcem Kacem's avatar Houcem Kacem
Browse files

feat: add tests for batch entity update

parent 20f84d79
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you cannot update a batch of entities with an invalid request
Variables   ../../../../../../resources/variables.py
Resource    ../../../../../../resources/ApiUtils.resource
Resource    ../../../../../../resources/AssertionUtils.resource
Resource    ../../../../../../resources/JsonUtils.resource
Library     RequestsLibrary
Library     JSONLibrary
Library     OperatingSystem

*** Variable ***
${batch_endpoint}=    entityOperations/update
${endpoint}=    entities

*** Test Case ***
With invalid json document
    [Documentation]  Check that you cannot update a batch of entities with an invalid json document
    [Tags]  critical

    Batch Request Entities From File   batch/invalid-json-sample.jsonld

    Check Response Status Code Set To  400
    Check Response Body Containing Problem Details Element Containing Detail Element    ${response}

With json-ld document not syntactically correct according to the @context
    [Documentation]  Check that you cannot update a batch of entities with a json-ld document not syntactically correct according to the @context
    [Tags]  critical

    #TODO: Use a json-ld document not syntactically correct according to the @context
    Batch Request Entities From File   batch/invalid-json-ld-sample.jsonld

    Check Response Status Code Set To  400
    Check Response Body Containing Problem Details Element Containing Detail Element    ${response}
+9 −12
Original line number Diff line number Diff line
@@ -21,27 +21,24 @@ Update a batch of entities
    [Documentation]  Check that you can update a batch of entities
    [Tags]  critical

    ${first_entity}=    Load Entity    building-minimal-sample.jsonld      ${first_entity_id}
    ${second_entity}=    Load Entity    building-minimal-sample.jsonld      ${second_entity_id}
    @{entities_to_be_upserted}=  Create List   ${first_entity}     ${second_entity}
    ${first_entity}=    Load Entity    building-relationship-of-property-sample.jsonld      ${first_entity_id}
    ${second_entity}=    Load Entity    building-relationship-of-property-sample.jsonld      ${second_entity_id}
    @{entities_to_be_updated}=  Create List   ${first_entity}     ${second_entity}

    Batch Upsert Entities   @{entities_to_be_upserted}
    Batch Update Entities   @{entities_to_be_updated}

    @{expected_entities_ids}=  Create List   ${new_entity_id}
    Check Response Status Code Set To  201
    Check Response Body Containing Array Of URIs set to   @{expected_entities_ids}
    Check Response Status Code Set To  204

    #TODO call Batch Delete Entities
    Delete Entity by Id  ${new_entity_id}
    Delete Entity by Id  ${first_existing_entity_id}
    Delete Entity by Id  ${second_existing_entity_id}
    Delete Entity by Id  ${first_entity_id}
    Delete Entity by Id  ${second_entity_id}

*** Keywords ***
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  building-minimal-sample.jsonld     ${first_entity_id}
    Create Entity  building-minimal-sample.jsonld     ${second_entity_id}
    Create Entity  building-simple-attributes-sample.jsonld     ${first_entity_id}
    Create Entity  building-simple-attributes-sample.jsonld     ${second_entity_id}

    Set Suite Variable  ${first_entity_id}
    Set Suite Variable  ${second_entity_id}
+44 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you can update a batch of entities with noOverwrite option
Variables   ../../../../../../resources/variables.py
Resource    ../../../../../../resources/ApiUtils.resource
Resource    ../../../../../../resources/AssertionUtils.resource
Resource    ../../../../../../resources/JsonUtils.resource
Library     REST    ${url}
Library     JSONLibrary
Library     String
Library     Collections

Suite Setup      Setup Initial Entities

*** Variable ***
${batch_endpoint}=    entityOperations/update
${endpoint}=    entities
${building_id_prefix}=  urn:ngsi-ld:Building:

*** Test Case ***
Update a batch of entities with noOverwrite option
    [Documentation]  Check that you can update a batch of entities with noOverwrite option
    [Tags]  critical

    ${first_entity}=    Load Entity    building-relationship-of-property-sample.jsonld      ${first_entity_id}
    ${second_entity}=    Load Entity    building-relationship-of-property-sample.jsonld      ${second_entity_id}
    @{entities_to_be_updated}=  Create List   ${first_entity}     ${second_entity}

    Batch Update Entities   @{entities_to_be_updated}       overwrite_option=noOverwrite

    Check Response Status Code Set To  204

    #TODO call Batch Delete Entities
    Delete Entity by Id  ${first_entity_id}
    Delete Entity by Id  ${second_entity_id}

*** Keywords ***
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  building-simple-attributes-sample.jsonld     ${first_entity_id}
    Create Entity  building-simple-attributes-sample.jsonld     ${second_entity_id}

    Set Suite Variable  ${first_entity_id}
    Set Suite Variable  ${second_entity_id}
+52 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you can update a batch of entities where some will succeed and others will fail
Variables   ../../../../../../resources/variables.py
Resource    ../../../../../../resources/ApiUtils.resource
Resource    ../../../../../../resources/AssertionUtils.resource
Resource    ../../../../../../resources/JsonUtils.resource
Library     REST    ${url}
Library     JSONLibrary
Library     String
Library     Collections

Suite Setup      Setup Initial Entities

*** Variable ***
${batch_endpoint}=    entityOperations/update
${endpoint}=    entities
${building_id_prefix}=  urn:ngsi-ld:Building:

*** Test Case ***
Update a batch of non existing and existing entities
    [Documentation]  Check that you can update a batch of non existing and existing entities
    [Tags]  critical

    ${first_existing_entity}=    Load Entity    building-relationship-of-property-sample.jsonld      ${first_existing_entity_id}
    ${second_existing_entity}=    Load Entity    building-relationship-of-property-sample.jsonld      ${second_existing_entity_id}
    ${new_entity_id}=     Generate Random Entity Id    ${building_id_prefix}
    ${new_entity}=    Load Entity    building-relationship-of-property-sample.jsonld      ${new_entity_id}

    @{entities_to_be_updated}=  Create List   ${first_existing_entity}     ${second_existing_entity}    ${new_entity}

    Batch Update Entities   @{entities_to_be_updated}


    @{expected_successful_entities_ids}=  Create List   ${first_existing_entity_id}     ${second_existing_entity_id}
    @{expected_failed_entities_ids}=  Create List   ${new_entity_id}
    &{expected_batch_operation_result}=  Create Batch Operation Result   ${expected_successful_entities_ids}     ${expected_failed_entities_ids}
    Check Response Status Code Set To  207
    Check Response Body Containing Batch Operation Result   ${expected_batch_operation_result}

    #TODO call Batch Delete Entities
    Delete Entity by Id  ${first_existing_entity_id}
    Delete Entity by Id  ${second_existing_entity_id}

*** Keywords ***
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-simple-attributes-sample.jsonld     ${first_existing_entity_id}
    Create Entity  building-simple-attributes-sample.jsonld     ${second_existing_entity_id}

    Set Suite Variable  ${first_existing_entity_id}
    Set Suite Variable  ${second_existing_entity_id}
+12 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:randomUUID",
    "type": "Building",
    "locatedAt": {
        "type": "Relationship",
        "object": "urn:ngsi-ld:City:Paris"
    },
    "@context": [
        "https://fiware.github.io/data-models/context.jsonld",
        "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
    ]
}
 No newline at end of file
Loading