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

feat: add tests for batch operations with more than one instance of the same entity

parent 0134d819
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can create a batch of entities where two have the same id

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

Test Teardown       Delete Entities


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


*** Test Cases ***
003_10_01 Create a batch of three valid entities where two have the same id
    [Documentation]    Check that you can create a batch of entities where two have the same id
    [Tags]    be-create    5_6_7
    ${first_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Suite Variable    ${first_entity_id}
    ${second_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Suite Variable    ${second_entity_id}
    ${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_created}=    Create List    ${first_entity}    ${second_entity}    ${first_entity}

    ${response}=    Batch Create Entities    @{entities_to_be_created}

    @{expected_successful_entities_ids}=    Create List    ${first_entity_id}    ${second_entity_id}
    Set Test Variable    @{expected_successful_entities_ids}
    @{expected_failed_entities_ids}=    Create List    ${first_entity_id}
    &{expected_batch_operation_result}=    Create Batch Operation Result
    ...    ${expected_successful_entities_ids}
    ...    ${expected_failed_entities_ids}
    Check Response Status Code    207    ${response.status_code}
    Check Response Body Containing Batch Operation Result    ${expected_batch_operation_result}    ${response.json()}


*** Keywords ***
Delete Entities
    ${response}=    Batch Delete Entities
    ...    entities_ids_to_be_deleted=@{expected_successful_entities_ids}
+38 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can delete a batch of entities with the same id

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 Entity


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


*** Test Cases ***
006_04_01 Delete a batch of existing entities with the same id
    [Documentation]    Check that you can delete a batch entities with the same id
    [Tags]    be-delete    5_6_10
    ${new_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    @{entities_ids_to_be_deleted}=    Create List    ${entity_id}    ${entity_id}

    ${response}=    Batch Delete Entities    entities_ids_to_be_deleted=@{entities_ids_to_be_deleted}

    @{expected_successful_entities_ids}=    Create List    ${entity_id}
    @{expected_failed_entities_ids}=    Create List    ${entity_id}
    &{response1}=    Create Batch Operation Result
    ...    ${expected_successful_entities_ids}
    ...    ${expected_failed_entities_ids}
    Check Response Status Code    207    ${response.status_code}
    Check Response Body Containing Batch Operation Result    ${response1}    ${response.json()}


*** Keywords ***
Setup Initial Entity
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Create Entity    building-simple-attributes-sample.jsonld    ${entity_id}
    Set Test Variable    ${entity_id}
+37 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you can upsert a batch of entities where two have the same id

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

Test Teardown       Delete Entities


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


*** Test Cases ***
004_07_01 Upsert a batch of three valid entities where two have the same id
    [Documentation]    Check that you can upsert a batch of where two have the same id
    [Tags]    be-upsert    5_6_8
    ${first_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${second_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${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}

    ${response}=    Batch Upsert Entities    @{entities_to_be_upserted}

    @{expected_successful_entities_ids}=    Create List    ${first_entity_id}    ${second_entity_id}
    Set Test Variable    @{expected_successful_entities_ids}
    Check Response Status Code    201    ${response.status_code}
    Check Response Body Containing Array Of URIs set to    ${expected_successful_entities_ids}    ${response.json()}


*** Keywords ***
Delete Entities
    ${response}=    Batch Delete Entities
    ...    entities_ids_to_be_deleted=@{expected_successful_entities_ids}
+21 −0
Original line number Diff line number Diff line
@@ -105,6 +105,13 @@ class TestCIProvision(TestCase):

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_003_10(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_10.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/003_10.json'
        difference_file = f'{self.folder_test_suites}/doc/results/out_003_10.json'

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_006_01(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_01.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/006_01.json'
@@ -126,6 +133,13 @@ class TestCIProvision(TestCase):

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_006_04(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_04.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/006_04.json'
        difference_file = f'{self.folder_test_suites}/doc/results/out_006_04.json'

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_005_01(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_01.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/005_01.json'
@@ -196,6 +210,13 @@ class TestCIProvision(TestCase):

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_004_07(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_07.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/004_07.json'
        difference_file = f'{self.folder_test_suites}/doc/results/out_004_07.json'

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_001_01(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_01.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Provision/001_01.json'