Commit de3866b0 authored by Andrea Il Grande's avatar Andrea Il Grande
Browse files

test: create entity and delete entity with local flag and query entities via POST

parent 38857502
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation        Verify that, when one has an inclusive registration on a Context Broker and an entity only on a Context Source, if one queries the Context Broker via POST the query gets forwarded to the Context Source correctly

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

Suite Setup         Setup Entity On Remote And Registration
Suite Teardown      Delete Created Entity And Registration


*** Variables ***
${entity_id_prefix}                     urn:ngsi-ld:Vehicle:
${entity_payload_filename}              vehicle-simple-attributes.jsonld
${registration_id_prefix}               urn:ngsi-ld:Registration:
${registration_payload_file_path}       csourceRegistrations/context-source-registration-vehicle-complete.jsonld

*** Test Cases ***
D011_03_inc Query The Context Broker With Type Via POST
    [Tags]    since_v1.6.1    dist-ops    4_3_3    cf_06    additive-inclusive    4_3_6_2    5_7_2    6_23_3_1
    [Documentation]    Check that if one queries the Context Broker for type via POST, entity with matching type on a Context Source gets returned
    @{entities_id}=    Create List    ${entity_id}
    ${response}=    Query Entities Via POST    entity_types=Vehicle    context=${ngsild_test_suite_context}
    Check Response Status Code    200    ${response.status_code}
    Check Response Body Containing Entities URIS set to    ${entities_id}    ${response.json()}


*** Keywords ***
Setup Entity On Remote And Registration
    ${entity_id}=    Generate Random Entity Id    ${entity_id_prefix}
    Set Suite Variable    ${entity_id}
    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}    base_url=${remote_url}
    Check Response Status Code    201    ${response.status_code}

    ${registration_id}=    Generate Random Entity Id    ${registration_id_prefix}
    Set Suite Variable    ${registration_id}
    ${registration_payload}=    Prepare Context Source Registration From File   
    ...    ${registration_id}
    ...    ${registration_payload_file_path}
    ${response1}=    Create Context Source Registration With Return    ${registration_payload}
    Check Response Status Code    201    ${response1.status_code}
    


Delete Created Entity And Registration
    Delete Context Source Registration    ${registration_id}
    Delete Entity By Id    ${entity_id}    base_url=${remote_url}
 No newline at end of file
+48 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation        Verify that, when one has an inclusive registration on a Context Broker, one is able to create an entity only on the Context Broker with local flag

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

Suite Setup         Setup Entity On Remote And Registration
Suite Teardown      Delete Created Entity And Registration


*** Variables ***
${entity_id_prefix}                     urn:ngsi-ld:Vehicle:
${entity_payload_filename}              vehicle-simple-attributes.jsonld
${registration_id_prefix}               urn:ngsi-ld:Registration:
${registration_payload_file_path}       csourceRegistrations/context-source-registration-vehicle-redirection-ops.jsonld

*** Test Cases ***
D001_04_inc Create Entity With Local Flag
    [Tags]    since v1.6.1    dist-ops    4_3_3    cf_06    additive-inclusive    4_3_6_2    5_6_1    6_3_18
    [Documentation]    Verify that, when one has an inclusive registration on a Context Broker, one is able to create an entity with local flag and the operation should not be forwarded to the Context Source
    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}    local=true
    Check Response Status Code    201    ${response.status_code}

    ${response}=    Query Entities    entity_types=Vehicle    context=${ngsild_test_suite_context}    base_url=${remote_url}
    Check Response Status Code    200    ${response.status_code}
    Should Be Empty    ${response.json()}

*** Keywords ***
Setup Entity On Remote And Registration
    ${entity_id}=    Generate Random Entity Id    ${entity_id_prefix}
    Set Suite Variable    ${entity_id}

    ${registration_id}=    Generate Random Entity Id    ${registration_id_prefix}
    Set Suite Variable    ${registration_id}
    ${registration_payload}=    Prepare Context Source Registration From File
    ...    ${registration_id}
    ...    ${registration_payload_file_path}
    ...    entity_id=${entity_id}
    ${response1}=    Create Context Source Registration With Return    ${registration_payload}
    Check Response Status Code    201    ${response1.status_code}

Delete Created Entity And Registration
    Delete Context Source Registration    ${registration_id}
    Delete Entity By Id    ${entity_id}
    Delete Entity By Id    ${entity_id}    base_url=${remote_url}
 No newline at end of file
+54 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation        Verify that, when one has an inclusive registration on a Context Broker, one is able to delete an entity only on the Context Broker with local flag

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

Suite Setup         Setup Entity On Remote And Registration
Suite Teardown      Delete Created Entity And Registration


*** Variables ***
${entity_id_prefix}                     urn:ngsi-ld:Vehicle:
${entity_payload_filename}              vehicle-simple-attributes.jsonld
${registration_id_prefix}               urn:ngsi-ld:Registration:
${registration_payload_file_path}       csourceRegistrations/context-source-registration-vehicle-redirection-ops.jsonld

*** Test Cases ***
D002_03_inc Delete Entity With Local Flag
    [Tags]    since_v1.6.1    dist-ops    4_3_3    cf_06    additive-inclusive    4_3_6_2    5_6_6    6_3_18
    [Documentation]    Verify that, when one has an inclusive registration on a Context Broker, one is able to delete an entity with local flag and the operation should not be forwarded to the Context Source
    ${response}=    Delete Entity by Id    ${entity_id}    local=true
    Check Response Status Code    204    ${response.status_code}

    @{entities_id}=    Create List    ${entity_id}
    ${response}=    Query Entities    entity_types=Vehicle    context=${ngsild_test_suite_context}    base_url=${remote_url}
    Check Response Status Code    200    ${response.status_code}
    Check Response Body Containing Entities URIS set to    ${entities_id}    ${response.json()}


*** Keywords ***
Setup Entity On Remote And Registration
    ${entity_id}=    Generate Random Entity Id    ${entity_id_prefix}
    Set Suite Variable    ${entity_id}
    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}
    Check Response Status Code    201    ${response.status_code}
    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}    base_url=${remote_url}
    Check Response Status Code    201    ${response.status_code}

    ${registration_id}=    Generate Random Entity Id    ${registration_id_prefix}
    Set Suite Variable    ${registration_id}
    ${registration_payload}=    Prepare Context Source Registration From File
    ...    ${registration_id}
    ...    ${registration_payload_file_path}
    ...    entity_id=${entity_id}
    ${response1}=    Create Context Source Registration With Return    ${registration_payload}
    Check Response Status Code    201    ${response1.status_code}

Delete Created Entity And Registration
    Delete Context Source Registration    ${registration_id}
    Delete Entity By Id    ${entity_id}
    Delete Entity By Id    ${entity_id}    base_url=${remote_url}
 No newline at end of file
+15 −1
Original line number Diff line number Diff line
@@ -97,11 +97,15 @@ Query Entities
Query Entities Via POST
    [Arguments]
    ...    ${entities}=${EMPTY}
    ...    ${entity_id}=${EMPTY}
    ...    ${entity_types}=${EMPTY}
    ...    ${entity_id_pattern}=${EMPTY}
    ...    ${content_type}=${CONTENT_TYPE_JSON}
    ...    ${accept}=${CONTENT_TYPE_JSON}
    ...    ${context}=${EMPTY}
    ...    ${attrs}=${EMPTY}
    ...    ${geometry_property}=${EMPTY}
    ...    ${base_url}=${url}
    &{headers}=    Create Dictionary
    Set To Dictionary    ${headers}    Content-Type    ${content_type}
    Set To Dictionary    ${headers}    Accept    ${accept}
@@ -112,6 +116,16 @@ Query Entities Via POST
    END
    &{body}=    Create Dictionary
    Set To Dictionary    ${body}    type=Query
    &{entities}=    Create Dictionary
    IF    '${entity_id}'!=''
        Set To Dictionary    ${entities}    id=${entity_id}
    END
    IF    '${entity_types}'!=''
        Set To Dictionary    ${entities}    type=${entity_types}
    END
    IF    '${entity_id_pattern}'!=''
        Set To Dictionary    ${entities}    idPattern=${entity_id_pattern}
    END
    ${entities_length}=    Get Length    ${entities}
    IF    ${entities_length}>0
        Set To Dictionary    ${body}    entities=${entities}
@@ -122,7 +136,7 @@ Query Entities Via POST
        Set To Dictionary    ${body}    geometryProperty=${geometry_property}
    END
    ${response}=    POST
    ...    url=${url}/${ENTITY_OPERATIONS_QUERY_ENDPOINT_PATH}
    ...    url=${base_url}/${ENTITY_OPERATIONS_QUERY_ENDPOINT_PATH}
    ...    json=${body}
    ...    headers=${headers}
    ...    expected_status=any
+8 −2
Original line number Diff line number Diff line
@@ -148,13 +148,16 @@ Batch Upsert Entities
    RETURN    ${response}

Create Entity
    [Arguments]    ${filename}    ${entity_id}    ${base_url}=${url}
    [Arguments]    ${filename}    ${entity_id}    ${base_url}=${url}    ${local}=${EMPTY}
    &{params}=    Create Dictionary
    IF    '${local}'!=''    Set To Dictionary    ${params}    local=${local}
    ${entity_payload}=    Load JSON From File    ${EXECDIR}/data/entities/${filename}
    ${entity}=    Update Value To JSON    ${entity_payload}    $..id    ${entity_id}
    &{headers}=    Create Dictionary    Content-Type=application/ld+json
    ${response}=    POST
    ...    url=${base_url}/${ENTITIES_ENDPOINT_PATH}
    ...    json=${entity}
    ...    params=${params}
    ...    headers=${headers}
    ...    expected_status=any
    Output    ${response}    Create Entity
@@ -235,9 +238,12 @@ Delete Entity Attributes
    RETURN    ${response}

Delete Entity by Id
    [Arguments]    ${id}    ${base_url}=${url}
    [Arguments]    ${id}    ${base_url}=${url}    ${local}=${EMPTY}
    &{params}=    Create Dictionary
    IF    '${local}'!=''    Set To Dictionary    ${params}    local=${local}
    ${response}=    DELETE
    ...    url=${base_url}/${ENTITIES_ENDPOINT_PATH}${id}
    ...    params=${params}
    ...    expected_status=any
    Output    ${response}    Delete Entity by Id
    RETURN    ${response}