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

test: create entity tests with redirect registration mode

parent 38857502
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation        Verify that, when one has a redirect registration on a Context Broker, one is not able to create entities on the Context Broker

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

Test Setup         Setup Entity Id And Registration
Test Teardown      Delete Created Entities 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-redirect.jsonld

*** Test Cases ***
D001_01_red Create Entity On The Context Source
    [Tags]    since_v1.6.1    dist-ops    4_3_3    cf_06    proxied-redirect    4_3_6_3    5_6_1
    [Documentation]    Check that if one requests the Context Broker to create an entity that matches a redirect registration, this is created only the Context Source 
    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}
    Check Response Status Code    207    ${response.status_code}

    Check JSON Value In Response Body    ['status']    409    ${response.json()['errors'][0]['error']}

    @{entities_id}=    Create List    ${entity_id}
    ${response_query_remote}=    Query Entities    entity_types=Vehicle    base_url=${remote_url}
    Check Response Body Containing Entities URIS set to    ${entities_id}    ${response_query_remote.json()}


*** Keywords ***
Setup Entity Id 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 Entities 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
+51 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation        Verify that, when one has an entity on a Context Source and a redirect registration on a Context Broker, one is not able to create that entity on the Context Source

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

Test Setup         Setup Entity On Remote And Registration
Test Teardown      Delete Created Entities 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-redirect.jsonld

*** Test Cases ***
D001_03_03_red Create an entity already existing remotely
    [Tags]    since_v1.6.1    dist-ops    4_3_3    cf_06    proxied-redirect    4_3_6_3    5_6_1    6_3_3
    [Documentation]    Check that if one requests the Context Broker to create an entity that matches a redirect registration and already exists remotely, this raises an error on both the Context Broker and Context Source
    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}
    Check Response Status Code    207    ${response.status_code}
    
    Check JSON Value In Response Body    ['status']    409    ${response.json()['errors'][0]['error']}
    Check JSON Value In Response Body    ['status']    409    ${response.json()['errors'][1]['error']}

*** 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}
    ...    entity_id=${entity_id}
    ${response1}=    Create Context Source Registration With Return    ${registration_payload}
    Check Response Status Code    201    ${response1.status_code}

Delete Created Entities 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