Commit 4ddc0b82 authored by Ken Zangelin's avatar Ken Zangelin
Browse files

feat(entitymaps): Create EntityMap via POST and Retrieve EntityMap (065, 066)

parent be575c14
Loading
Loading
Loading
Loading
+67 −0
Changes for TP/NGSI-LD/ContextSource/EntityMaps/CreateEntityMap/065_01.robot: 67 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can create an EntityMap with POST /entityMaps/: the EntityMap lists the matching Entities and its resource URI is in the NGSILD-EntityMap header

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

Suite Setup         Setup Initial Entities
Suite Teardown      Delete Initial Entities
Test Teardown       Delete Created EntityMap


*** Variables ***
${filename}=    building-simple-attributes.jsonld


*** Test Cases ***
065_01_01 Create An EntityMap For An Entity Type And A List Of Entity Ids
    [Documentation]    Check that the EntityMap lists the two Entities whose ids are given, and not the third one
    [Tags]    since_v1.8.1    em-create    core_14_5    core_5_2_6_5_5    http_11_2_3_2
    ${first_entity}=    Create Dictionary    type=Building    id=${first_id}
    ${second_entity}=    Create Dictionary    type=Building    id=${second_id}
    @{entities}=    Create List    ${first_entity}    ${second_entity}
    ${response}=    Create EntityMap Via POST
    ...    entities=${entities}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    201    ${response.status_code}
    Set Test Variable    ${entity_map_id}    ${response.json()['id']}
    @{expected_entity_ids}=    Create List    ${first_id}    ${second_id}
    Check Response Body Containing EntityMap element    ${expected_entity_ids}    ${response.json()}
    Check Response Headers Containing NGSILD-EntityMap set to    ${entity_map_id}    ${response.headers}

065_01_02 Create An EntityMap For An Entity Type And An Id Pattern
    [Documentation]    Check that the EntityMap lists the three Entities whose ids match the pattern
    [Tags]    since_v1.8.1    em-create    core_14_5    core_5_2_6_5_5    http_11_2_3_2
    ${entity}=    Create Dictionary    type=Building    idPattern=^${id_prefix}-.*
    @{entities}=    Create List    ${entity}
    ${response}=    Create EntityMap Via POST
    ...    entities=${entities}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    201    ${response.status_code}
    Set Test Variable    ${entity_map_id}    ${response.json()['id']}
    @{expected_entity_ids}=    Create List    ${first_id}    ${second_id}    ${third_id}
    Check Response Body Containing EntityMap element    ${expected_entity_ids}    ${response.json()}
    Check Response Headers Containing NGSILD-EntityMap set to    ${entity_map_id}    ${response.headers}


*** Keywords ***
Setup Initial Entities
    ${id_prefix}=    Generate Random Building Entity Id
    Set Suite Variable    ${id_prefix}
    Set Suite Variable    ${first_id}    ${id_prefix}-a
    Set Suite Variable    ${second_id}    ${id_prefix}-b
    Set Suite Variable    ${third_id}    ${id_prefix}-c
    FOR    ${entity_id}    IN    ${first_id}    ${second_id}    ${third_id}
        ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
        Check Response Status Code    201    ${response.status_code}
    END

Delete Initial Entities
    FOR    ${entity_id}    IN    ${first_id}    ${second_id}    ${third_id}
        Delete Entity    ${entity_id}
    END

Delete Created EntityMap
    ${entity_map_id}=    Get Variable Value    ${entity_map_id}    ${EMPTY}
    IF    '${entity_map_id}'!=''    Delete EntityMap    ${entity_map_id}
+76 −0
Changes for TP/NGSI-LD/ContextSource/EntityMaps/CreateEntityMap/065_02.robot: 76 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can create an EntityMap with GET /entityMaps/: the EntityMap lists the matching Entities and its resource URI is in the NGSILD-EntityMap header

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

Suite Setup         Setup Initial Entities
Suite Teardown      Delete Initial Entities
Test Teardown       Delete Created EntityMap


*** Variables ***
${filename}=    building-simple-attributes.jsonld


*** Test Cases ***
065_02_01 Create An EntityMap For An Entity Type And A List Of Entity Ids
    [Documentation]    Check that the EntityMap lists the two Entities whose ids are given, and not the third one
    [Tags]    since_v1.8.1    em-create    core_14_5    core_5_2_6_5_5    http_11_2_3_1
    ${response}=    Create EntityMap Via GET
    ...    type=Building
    ...    id=${first_id},${second_id}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    201    ${response.status_code}
    Set Test Variable    ${entity_map_id}    ${response.json()['id']}
    @{expected_entity_ids}=    Create List    ${first_id}    ${second_id}
    Check Response Body Containing EntityMap element    ${expected_entity_ids}    ${response.json()}
    Check Response Headers Containing NGSILD-EntityMap set to    ${entity_map_id}    ${response.headers}

065_02_02 Create An EntityMap For An Entity Type And An Id Pattern
    [Documentation]    Check that the EntityMap lists the three Entities whose ids match the pattern
    [Tags]    since_v1.8.1    em-create    core_14_5    core_5_2_6_5_5    http_11_2_3_1
    ${response}=    Create EntityMap Via GET
    ...    type=Building
    ...    idPattern=^${id_prefix}-.*
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    201    ${response.status_code}
    Set Test Variable    ${entity_map_id}    ${response.json()['id']}
    @{expected_entity_ids}=    Create List    ${first_id}    ${second_id}    ${third_id}
    Check Response Body Containing EntityMap element    ${expected_entity_ids}    ${response.json()}
    Check Response Headers Containing NGSILD-EntityMap set to    ${entity_map_id}    ${response.headers}

065_02_03 Create An EntityMap With Local Scope And An Id Pattern
    [Documentation]    Check that local scope is enough of a restriction without an Entity type (TS 104 175 clause 14.5.4 e), and that the EntityMap lists the three Entities whose ids match the pattern
    [Tags]    since_v1.8.1    em-create    core_14_5    core_5_2_6_5_5    http_11_2_3_1
    ${response}=    Create EntityMap Via GET
    ...    idPattern=^${id_prefix}-.*
    ...    local=true
    Check Response Status Code    201    ${response.status_code}
    Set Test Variable    ${entity_map_id}    ${response.json()['id']}
    @{expected_entity_ids}=    Create List    ${first_id}    ${second_id}    ${third_id}
    Check Response Body Containing EntityMap element    ${expected_entity_ids}    ${response.json()}
    Check Response Headers Containing NGSILD-EntityMap set to    ${entity_map_id}    ${response.headers}


*** Keywords ***
Setup Initial Entities
    ${id_prefix}=    Generate Random Building Entity Id
    Set Suite Variable    ${id_prefix}
    Set Suite Variable    ${first_id}    ${id_prefix}-a
    Set Suite Variable    ${second_id}    ${id_prefix}-b
    Set Suite Variable    ${third_id}    ${id_prefix}-c
    FOR    ${entity_id}    IN    ${first_id}    ${second_id}    ${third_id}
        ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
        Check Response Status Code    201    ${response.status_code}
    END

Delete Initial Entities
    FOR    ${entity_id}    IN    ${first_id}    ${second_id}    ${third_id}
        Delete Entity    ${entity_id}
    END

Delete Created EntityMap
    ${entity_map_id}=    Get Variable Value    ${entity_map_id}    ${EMPTY}
    IF    '${entity_map_id}'!=''    Delete EntityMap    ${entity_map_id}
+42 −0
Changes for TP/NGSI-LD/ContextSource/EntityMaps/CreateEntityMap/065_03.robot: 42 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one cannot create an EntityMap with POST /entityMaps/ when the query is too wide, an Entity id is not a valid URI or the NGSI-LD Query is not valid (400)

Resource            ${EXECDIR}/resources/ApiUtils/EntityMaps.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource

Test Template       Create An EntityMap Via POST With An Error


*** Test Cases ***    ENTITY_TYPE    ENTITY_ID    Q    PROBLEM_TYPE
065_03_01 Create An EntityMap Without Entity Type, Attributes, Query Or GeoQuery
    [Tags]    since_v1.8.1    em-create    core_14_5    http_11_2_3_2
    ${EMPTY}    ${EMPTY}    ${EMPTY}    ${ERROR_TYPE_BAD_REQUEST_DATA}
065_03_02 Create An EntityMap With An Entity Id That Is Not A Valid URI
    [Tags]    since_v1.8.1    em-create    core_14_5    http_11_2_3_2
    Building    thisisaninvaliduri    ${EMPTY}    ${ERROR_TYPE_BAD_REQUEST_DATA}
065_03_03 Create An EntityMap With An NGSI-LD Query That Is Not Valid
    [Tags]    since_v1.8.1    em-create    core_14_5    http_11_2_3_2
    Building    ${EMPTY}    name==    ${ERROR_TYPE_BAD_REQUEST_DATA}


*** Keywords ***
Create An EntityMap Via POST With An Error
    [Documentation]    Check that one cannot create an EntityMap from a query that is too wide or not valid
    [Arguments]    ${entity_type}    ${entity_id}    ${q}    ${problem_type}
    @{entities}=    Create List
    IF    '${entity_type}'!=''
        ${entity}=    Create Dictionary    type=${entity_type}
        IF    '${entity_id}'!=''
            Set To Dictionary    ${entity}    id=${entity_id}
        END
        Append To List    ${entities}    ${entity}
    END
    ${response}=    Create EntityMap Via POST
    ...    entities=${entities}
    ...    q=${q}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    400    ${response.status_code}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to
    ...    ${response.json()}
    ...    ${problem_type}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response.json()}
+35 −0
Changes for TP/NGSI-LD/ContextSource/EntityMaps/CreateEntityMap/065_04.robot: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one cannot create an EntityMap with GET /entityMaps/ when the query is too wide, an Entity id is not a valid URI or the NGSI-LD Query is not valid (400)

Resource            ${EXECDIR}/resources/ApiUtils/EntityMaps.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource

Test Template       Create An EntityMap Via GET With An Error


*** Test Cases ***    ENTITY_TYPE    ENTITY_ID    Q    PROBLEM_TYPE
065_04_01 Create An EntityMap Without Entity Type, Attributes, Query, GeoQuery Or Local Scope
    [Tags]    since_v1.8.1    em-create    core_14_5    http_11_2_3_1
    ${EMPTY}    ${EMPTY}    ${EMPTY}    ${ERROR_TYPE_BAD_REQUEST_DATA}
065_04_02 Create An EntityMap With An Entity Id That Is Not A Valid URI
    [Tags]    since_v1.8.1    em-create    core_14_5    http_11_2_3_1
    Building    thisisaninvaliduri    ${EMPTY}    ${ERROR_TYPE_BAD_REQUEST_DATA}
065_04_03 Create An EntityMap With An NGSI-LD Query That Is Not Valid
    [Tags]    since_v1.8.1    em-create    core_14_5    http_11_2_3_1
    Building    ${EMPTY}    name==    ${ERROR_TYPE_BAD_REQUEST_DATA}


*** Keywords ***
Create An EntityMap Via GET With An Error
    [Documentation]    Check that one cannot create an EntityMap from a query that is too wide or not valid
    [Arguments]    ${entity_type}    ${entity_id}    ${q}    ${problem_type}
    ${response}=    Create EntityMap Via GET
    ...    type=${entity_type}
    ...    id=${entity_id}
    ...    q=${q}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    400    ${response.status_code}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to
    ...    ${response.json()}
    ...    ${problem_type}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response.json()}
+50 −0
Changes for TP/NGSI-LD/ContextSource/EntityMaps/RetrieveEntityMap/066_01.robot: 50 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can retrieve an EntityMap: the same id, the same Entities and an expiration date

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

Suite Setup         Setup Initial Entities
Suite Teardown      Delete Initial Entities


*** Variables ***
${filename}=    building-simple-attributes.jsonld


*** Test Cases ***
066_01_01 Retrieve An EntityMap
    [Documentation]    Check that the retrieved EntityMap is the one that was created
    [Tags]    since_v1.8.1    em-retrieve    core_14_2    core_5_2_6_5_5    http_11_4_3_1
    ${response}=    Retrieve EntityMap    ${entity_map_id}
    Check Response Status Code    200    ${response.status_code}
    Should Be Equal    ${response.json()['id']}    ${entity_map_id}
    @{expected_entity_ids}=    Create List    ${first_id}    ${second_id}
    Check Response Body Containing EntityMap element    ${expected_entity_ids}    ${response.json()}


*** Keywords ***
Setup Initial Entities
    ${first_id}=    Generate Random Building Entity Id
    ${second_id}=    Generate Random Building Entity Id
    Set Suite Variable    ${first_id}
    Set Suite Variable    ${second_id}
    FOR    ${entity_id}    IN    ${first_id}    ${second_id}
        ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
        Check Response Status Code    201    ${response.status_code}
    END
    ${first_entity}=    Create Dictionary    type=Building    id=${first_id}
    ${second_entity}=    Create Dictionary    type=Building    id=${second_id}
    @{entities}=    Create List    ${first_entity}    ${second_entity}
    ${response}=    Create EntityMap Via POST
    ...    entities=${entities}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    201    ${response.status_code}
    Set Suite Variable    ${entity_map_id}    ${response.json()['id']}

Delete Initial Entities
    Delete EntityMap    ${entity_map_id}
    FOR    ${entity_id}    IN    ${first_id}    ${second_id}
        Delete Entity    ${entity_id}
    END
Loading