Commit 032b8be7 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

Merge branch 'feature/batch-entity-operations-tests' into 'develop'

feature: add tests for batch entity create

See merge request !1
parents b2c2c313 3a5e8747
Loading
Loading
Loading
Loading
+62 −1
Original line number Diff line number Diff line
# NGSI-LD Test Suite
# Quick start guide

## Install Python & PIP   

* Install Python3 by running the following command:

```$ sudo dnf install python3``` (Ubuntu)

```$ brew install python3``` (MacOS)

* Confirm its installation with:   

```$ python --version``` (Ubuntu)

```$ python3 --version``` (MacOS)

* At this point, you can launch Python3 interpreter:    

```$ python``` (Ubuntu)

```$ python3``` (MacOS)

* Pip should be included by default. To confirm, run:   

```$ command -v pip``` (Ubuntu)

```$ pip3 --version``` (MacOS)

* In case pip is not installed, [follow the official pip installation guide](https://pip.pypa.io/en/latest/installing/).

## Install IDE (VSCode)

* Install [Visual Studio Code](https://code.visualstudio.com/docs/setup/linux)

* Install [Robot Framework Intellisense](https://marketplace.visualstudio.com/items?itemName=TomiTurtiainen.rf-intellisense)

## Checkout the base project   

```$ git clone git@forge.etsi.org:cim/ngsi-ld-test-suite.git```

## Install the project requirements

Browse the base project root folder and execute the following command:   

```$ python -m pip install -r requirements.txt``` (Ubuntu)

```$ python3 -m pip install -r requirements.txt``` (MacOS)

Further details on each library can be found in [PyPi](https://pypi.org/) and [Robot Framework Standard Libraries](http://robotframework.org/robotframework/#standard-libraries)

## Execute the tests

Configure the context broker URL in the resources/variables.py file

Launch the tests with the following command:

```$ robot --outputdir ./results .```   

For more running instructions please consult [scripts/run_tests.sh](https://github.com/easy-global-market/isg-cim-tpdl-demo/blob/rf-demo/scripts/run_tests.sh).

# Useful links   

* [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#output-file)   
+32 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you cannot create a batch of entities with an invalid request
Variables   ../../../../../../resources/variables.py
Resource    ../../../../../../resources/ApiUtils.resource
Resource    ../../../../../../resources/AssertionUtils.resource
Library     RequestsLibrary
Library     JSONLibrary
Library     OperatingSystem


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

*** Test Case ***
With invalid json document
    [Documentation]  Check that you cannot create 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 empty json document
    [Documentation]  Check that you cannot create a batch of entities with an empty json document
    [Tags]  critical

    Batch Request Entities From File   batch/empty-sample.jsonld

    Check Response Status Code Set To  400
    Check Response Body Containing Problem Details Element Containing Detail Element    ${response}
+76 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you can create a batch of entities
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

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

*** Test Case ***
Create a batch of minimal entities
    [Documentation]  Check that you can create a batch of minimal entities
    [Tags]  critical

    ${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_created}=  Create List   ${first_entity}     ${second_entity}

    Batch Create Entities   @{entities_to_be_created}

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

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

Create a batch of entities having only simple properties
    [Documentation]  Check that you can create a batch of entities having only simple properties
    [Tags]  critical

    ${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-simple-attributes-sample.jsonld      ${first_entity_id}
    ${second_entity}=    Load Entity    building-simple-attributes-sample.jsonld      ${second_entity_id}
    @{entities_to_be_created}=  Create List   ${first_entity}     ${second_entity}

    Batch Create Entities   @{entities_to_be_created}

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

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

Create a batch of entities having multiple attributes
    [Documentation]  Check that you can create a batch of entities having multiple attributes
    [Tags]  critical

    ${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-relationship-of-property-sample.jsonld      ${first_entity_id}
    ${second_entity}=    Load Entity    building-relationship-of-property-sample.jsonld      ${second_entity_id}
    @{entities_to_be_created}=  Create List   ${first_entity}     ${second_entity}

    Batch Create Entities   @{entities_to_be_created}

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

    #TODO call Batch Delete Entities
    Delete Entity by Id  ${first_entity_id}
    Delete Entity by Id  ${second_entity_id}
+49 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you can create 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/create
${endpoint}=    entities
${building_id_prefix}=  urn:ngsi-ld:Building:

*** Test Case ***
Create a batch of two valid entities and one invalid entity
    [Documentation]  Check that you can create a batch of two valid entities and one invalid entity
    [Tags]  critical

    ${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}
    ${already_existing_entity}=    Load Entity    building-minimal-sample.jsonld      ${existing_entity_id}
    @{entities_to_be_created}=  Create List   ${first_entity}     ${second_entity}     ${already_existing_entity}

    Batch Create Entities   @{entities_to_be_created}

    @{expected_successful_entities_ids}=  Create List   ${first_entity_id}     ${second_entity_id}
    @{expected_failed_entities_ids}=  Create List   ${existing_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_entity_id}
    Delete Entity by Id  ${second_entity_id}
    Delete Entity by Id  ${existing_entity_id}
    
*** Keywords ***
Setup Initial Entities
    ${existing_entity_id}=     Generate Random Entity Id    ${building_id_prefix}
    Create Entity  building-minimal-sample.jsonld     ${existing_entity_id}
    Set Suite Variable  ${existing_entity_id}
+32 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that you cannot delete a batch of entities with an invalid request
Variables   ../../../../../../resources/variables.py
Resource    ../../../../../../resources/ApiUtils.resource
Resource    ../../../../../../resources/AssertionUtils.resource
Library     RequestsLibrary
Library     JSONLibrary
Library     OperatingSystem


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

*** Test Case ***
With invalid json document
    [Documentation]  Check that you cannot delete 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 empty json document
    [Documentation]  Check that you cannot delete a batch of entities with an empty json document
    [Tags]  critical

    Batch Request Entities From File   batch/empty-sample.jsonld

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