Commit 3f924c1d authored by Ken Zangelin's avatar Ken Zangelin
Browse files

feat(snapshots): Create Snapshot and Retrieve Snapshot status (069, 070)

parent c2e50af1
Loading
Loading
Loading
Loading
+48 −0
Changes for TP/NGSI-LD/Snapshots/CreateSnapshot/069_01.robot: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can create a Snapshot: 202 and the Location of the Snapshot

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

Suite Setup         Setup Initial Entity
Suite Teardown      Delete Entity    ${entity_id}
Test Teardown       Delete Created Snapshot


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


*** Test Cases ***
069_01_01 Create A Snapshot Without An Id
    [Documentation]    Check that the Snapshot is accepted (202) and that the Location header gives the relative path of the Snapshot, with an id generated by the broker
    [Tags]    since_v1.9.1    snap-create    core_16_2    http_13_2_3_1
    ${body}=    Snapshot Of The Entity    ${entity_id}    Building
    ${response}=    Create Snapshot    ${body}    context=${ngsild_test_suite_context}
    Check Response Status Code    202    ${response.status_code}
    Should Contain    ${response.headers['Location']}    ${SNAPSHOTS_ENDPOINT_PATH}/
    ${snapshot_id}=    Fetch From Right    ${response.headers['Location']}    /
    Set Test Variable    ${snapshot_id}

069_01_02 Create A Snapshot With An Id
    [Documentation]    Check that the Snapshot is accepted (202) and that the Location header gives the relative path of the Snapshot, with the id given in the request
    [Tags]    since_v1.9.1    snap-create    core_16_2    http_13_2_3_1
    ${snapshot_id}=    Generate Random Id    urn:ngsi-ld:Snapshot:
    ${body}=    Snapshot Of The Entity    ${entity_id}    Building    ${snapshot_id}
    ${response}=    Create Snapshot    ${body}    context=${ngsild_test_suite_context}
    Check Response Status Code    202    ${response.status_code}
    Set Test Variable    ${snapshot_id}
    Should End With    ${response.headers['Location']}    ${SNAPSHOTS_ENDPOINT_PATH}/${snapshot_id}


*** Keywords ***
Setup Initial Entity
    ${entity_id}=    Generate Random Building Entity Id
    Set Suite Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response.status_code}

Delete Created Snapshot
    ${snapshot_id}=    Get Variable Value    ${snapshot_id}    ${EMPTY}
    IF    '${snapshot_id}'!=''    Delete Snapshot    ${snapshot_id}
+60 −0
Changes for TP/NGSI-LD/Snapshots/CreateSnapshot/069_02.robot: 60 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one cannot create a Snapshot that does not meet the Snapshot data type (400), or whose id is that of an existing Snapshot (409)

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

Suite Setup         Setup Initial Snapshot
Suite Teardown      Delete Initial Snapshot
Test Template       Create A Snapshot With An Error


*** Variables ***
${filename}=            building-simple-attributes.jsonld
${building_query}=      {"type": "Query", "entities": [{"type": "Building"}]}


*** Test Cases ***    BODY    EXPECTED_STATUS_CODE    PROBLEM_TYPE
069_02_01 Create A Snapshot Without Queries
    [Tags]    since_v1.9.1    snap-create    core_16_2    core_5_2_6_5_4    http_13_2_3_1
    {"type": "Snapshot"}    400    ${ERROR_TYPE_BAD_REQUEST_DATA}
069_02_02 Create A Snapshot With An Id That Is Not A Valid URI
    [Tags]    since_v1.9.1    snap-create    core_16_2    core_5_2_6_5_4    http_13_2_3_1
    {"id": "thisisaninvaliduri", "type": "Snapshot", "snapshotQueries": [${building_query}]}    400    ${ERROR_TYPE_BAD_REQUEST_DATA}
069_02_03 Create A Snapshot With A Priority Out Of Range
    [Tags]    since_v1.9.1    snap-create    core_16_2    core_5_2_6_5_4    http_13_2_3_1
    {"type": "Snapshot", "snapshotQueries": [${building_query}], "snapshotPriority": 11}    400    ${ERROR_TYPE_BAD_REQUEST_DATA}
069_02_04 Create A Snapshot With A Temporal Query Among Its Queries
    [Tags]    since_v1.9.1    snap-create    core_16_2    core_5_2_6_5_4    http_13_2_3_1
    {"type": "Snapshot", "snapshotQueries": [{"type": "Query", "entities": [{"type": "Building"}], "temporalQ": {"timerel": "after", "timeAt": "2020-01-01T00:00:00Z"}}]}    400    ${ERROR_TYPE_BAD_REQUEST_DATA}
069_02_05 Create A Snapshot With The Id Of An Existing Snapshot
    [Tags]    since_v1.9.1    snap-create    core_16_2    http_13_2_3_1
    {"id": "${existing_snapshot_id}", "type": "Snapshot", "snapshotQueries": [${building_query}]}    409    ${ERROR_TYPE_ALREADY_EXISTS}


*** Keywords ***
Setup Initial Snapshot
    ${entity_id}=    Generate Random Building Entity Id
    Set Suite Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response.status_code}
    ${existing_snapshot_id}=    Generate Random Id    urn:ngsi-ld:Snapshot:
    Set Suite Variable    ${existing_snapshot_id}
    ${body}=    Snapshot Of The Entity    ${entity_id}    Building    ${existing_snapshot_id}
    ${response}=    Create Snapshot    ${body}    context=${ngsild_test_suite_context}
    Check Response Status Code    202    ${response.status_code}

Delete Initial Snapshot
    Delete Snapshot    ${existing_snapshot_id}
    Delete Entity    ${entity_id}

Create A Snapshot With An Error
    [Documentation]    Check that one cannot create a Snapshot that is not valid or that already exists
    [Arguments]    ${body}    ${expected_status_code}    ${problem_type}
    ${response}=    Create Snapshot    ${body}    context=${ngsild_test_suite_context}
    Check Response Status Code    ${expected_status_code}    ${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()}
+44 −0
Changes for TP/NGSI-LD/Snapshots/RetrieveSnapshotStatus/070_01.robot: 44 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can retrieve the status of a Snapshot: the Snapshot, the default priority, and the status "success" once its query has given a result

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

Suite Setup         Setup Initial Snapshot
Suite Teardown      Delete Initial Snapshot


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


*** Test Cases ***
070_01_01 Retrieve The Status Of A Snapshot
    [Documentation]    Check that the Snapshot has the id it was created with, the priority 5 (the default, TS 104 175 clause 16.2.4), an expiration date, and the status "success": its only query selects an existing Entity
    [Tags]    since_v1.9.1    snap-retrieve    core_16_4    core_16_2    core_5_2_6_5_4    http_13_3_3_1
    ${response}=    Retrieve Snapshot Status    ${snapshot_id}
    Check Response Status Code    200    ${response.status_code}
    Should Be Equal    ${response.json()['id']}    ${snapshot_id}
    Should Be Equal    ${response.json()['type']}    Snapshot
    Should Be Equal As Integers    ${response.json()['snapshotPriority']}    5
    Should Not Be Empty    ${response.json()['expiresAt']}
    Should Be Equal    ${response.json()['snapshotStatus']}    success


*** Keywords ***
Setup Initial Snapshot
    ${entity_id}=    Generate Random Building Entity Id
    Set Suite Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response.status_code}
    ${snapshot_id}=    Generate Random Id    urn:ngsi-ld:Snapshot:
    Set Suite Variable    ${snapshot_id}
    ${body}=    Snapshot Of The Entity    ${entity_id}    Building    ${snapshot_id}
    ${response}=    Create Snapshot    ${body}    context=${ngsild_test_suite_context}
    Check Response Status Code    202    ${response.status_code}
    Wait Until The Snapshot Is Prepared    ${snapshot_id}

Delete Initial Snapshot
    Delete Snapshot    ${snapshot_id}
    Delete Entity    ${entity_id}
+28 −0
Changes for TP/NGSI-LD/Snapshots/RetrieveSnapshotStatus/070_02.robot: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one cannot retrieve the status of a Snapshot if its id is not a valid URI (400) or if it is not known (404)

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

Test Template       Retrieve The Status Of A Snapshot With An Error


*** Test Cases ***    SNAPSHOT_ID    EXPECTED_STATUS_CODE    PROBLEM_TYPE
070_02_01 Retrieve The Status Of A Snapshot If The Snapshot Id Is Not A Valid URI
    [Tags]    since_v1.9.1    snap-retrieve    core_16_4    http_13_3_3_1
    thisisaninvaliduri    400    ${ERROR_TYPE_BAD_REQUEST_DATA}
070_02_02 Retrieve The Status Of A Snapshot If The Snapshot Is Not Known
    [Tags]    since_v1.9.1    snap-retrieve    core_16_4    http_13_3_3_1
    urn:ngsi-ld:Snapshot:unknown070    404    ${ERROR_TYPE_RESOURCE_NOT_FOUND}


*** Keywords ***
Retrieve The Status Of A Snapshot With An Error
    [Documentation]    Check that one cannot retrieve the status of a Snapshot that is not valid or not known
    [Arguments]    ${snapshot_id}    ${expected_status_code}    ${problem_type}
    ${response}=    Retrieve Snapshot Status    ${snapshot_id}
    Check Response Status Code    ${expected_status_code}    ${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()}
+2 −0
Changes for doc/analysis/generaterobotdata.py: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ class GenerateRobotData:
            'EntityMaps/RetrieveEntityMap': 'EM',
            'EntityMaps/UpdateEntityMap': 'EM',
            'EntityMaps/DeleteEntityMap': 'EM',
            'Snapshots/CreateSnapshot': 'SNAP',
            'Snapshots/RetrieveSnapshotStatus': 'SNAP',
            'Discovery/QueryCSRegistrations': 'DISC',
            'CommonResponses/VerifyLdContextNotAvailable': 'HTTP',
            'CommonResponses/VerifyMergePatchJson': 'HTTP',
Loading