Commit 36685b47 authored by Benedetta Arena's avatar Benedetta Arena
Browse files

fix: improve logic of replace entity attribute tests

parent 224bb14b
Loading
Loading
Loading
Loading
+12 −16
Original line number Diff line number Diff line
@@ -15,46 +15,42 @@ Test Teardown Delete Created Entity And Registration And Stop Context Sour


*** Variables ***
${entity_id_prefix}                     urn:ngsi-ld:Vehicle:
${entity_payload_filename}              vehicle-simple-different-attributes.jsonld
${entity_attribute_filename}            fragmentEntities/vehicle-speed-two-datasetid-01-fragment.json
${registration_id_prefix}               urn:ngsi-ld:Registration:
${entity_attribute_filename}            fragmentEntities/vehicle-speed-two-datasetid-05-fragment.json
${registration_payload_file_path}       csourceRegistrations/context-source-registration-vehicle-speed-with-redirection-ops.jsonld

${attribute_name}                       speed

*** Test Cases ***
D009_01_exc Replace Entity Attribute
    [Documentation]    Check that one can replace an existing entity attribute, the changes will be forwarded to the Context Source thanks to an exclusive registration
    [Tags]    since_v1.6.1    dist-ops    4_3_3    cf_04    proxy-exclusive    4_3_6_3    5_6_19    6_3_18

    Set Stub Reply    POST    /broker1/ngsi-ld/v1/entities   201
    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}
    Check Response Status Code    201    ${response.status_code}

    ${attribute_payload}=    Load Entity    ${entity_attribute_filename}    ${entity_id}
    Set Stub Reply    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}/attrs/speed    204
    Set Stub Reply    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}/attrs/${attribute_name}    204

    ${response}=    Replace Attribute Selecting Content Type
    ...    entity_id=${entity_id}
    ...    attr_id=speed
    ...    attr_id=${attribute_name}
    ...    attribute_fragment=${attribute_payload}
    ...    content_type=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response.status_code}

    ${stub_count}=    Get Stub Count    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}/attrs/speed
    ${stub_count}=    Get Stub Count    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}/attrs/${attribute_name}
    Should Be Equal As Integers    ${stub_count}    1

    Set Stub Reply    GET    /broker1/ngsi-ld/v1/entities/${entity_id}    200    ${entity_id}
    ${response}=    Retrieve Entity    ${entity_id}    context=${ngsild_test_suite_context}
    ${new_attribute}=    Get From Dictionary    ${response.json()}    speed
    Should Be Equal    ${attribute_payload}[speed][value]    ${new_attribute}[value]

    ${response}=    Retrieve Entity    ${entity_id}    context=${ngsild_test_suite_context}    local=true
    Should Not Contain    ${response.json()}    ${attribute_name}

*** Keywords ***
Create Entity And Registration On The Context Broker And Start Context Source Mock Server
    ${entity_id}=    Generate Random Vehicle Entity Id
    Set Suite Variable    ${entity_id}

    ${response}=    Create Entity    ${entity_payload_filename}    ${entity_id}    local=true
    Check Response Status Code    201    ${response.status_code}

    ${registration_id}=    Generate Random CSR Id
    Set Suite Variable    ${registration_id}
    ${registration_payload}=    Prepare Context Source Registration From File
@@ -62,7 +58,7 @@ Create Entity And Registration On The Context Broker And Start Context Source Mo
    ...    ${registration_payload_file_path}
    ...    entity_id=${entity_id}
    ...    mode=exclusive
    ...    endpoint=/broker1
    ...    endpoint=${context_source_url}/broker1
    ${response}=    Create Context Source Registration With Return    ${registration_payload}
    Check Response Status Code    201    ${response.status_code}

+6 −10
Original line number Diff line number Diff line
@@ -15,12 +15,10 @@ Test Teardown Delete Created Entity And Registration And Stop Context Sour


*** Variables ***
${entity_id_prefix}                     urn:ngsi-ld:Vehicle:
${entity_payload_filename}              vehicle-simple-different-attributes.jsonld
${entity_attribute_filename}            fragmentEntities/vehicle-speed-two-datasetid-01-fragment.json
${registration_id_prefix}               urn:ngsi-ld:Registration:
${entity_attribute_filename}            fragmentEntities/vehicle-speed-two-datasetid-05-fragment.json
${registration_payload_file_path}       csourceRegistrations/context-source-registration-vehicle-redirection-ops.jsonld

${attribute_name}                       speed

*** Test Cases ***
D009_01_inc Replace Entity Attribute
@@ -28,21 +26,19 @@ D009_01_inc Replace Entity Attribute
    [Tags]    since_v1.6.1    dist-ops    4_3_3    cf_04    additive-inclusive    4_3_6_2    5_6_19    6_3_18

    ${attribute_payload}=    Load Entity    ${entity_attribute_filename}    ${entity_id}
    Set Stub Reply    PUT    /ngsi-ld/v1/entities/${entity_id}/attrs/speed    204
    Set Stub Reply    PUT    /ngsi-ld/v1/entities/${entity_id}/attrs/${attribute_name}    204

    ${response}=    Replace Attribute Selecting Content Type
    ...    entity_id=${entity_id}
    ...    attr_id=speed
    ...    attr_id=${attribute_name}
    ...    attribute_fragment=${attribute_payload}
    ...    content_type=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response.status_code}

    Set Stub Reply    GET    /ngsi-ld/v1/entities/${entity_id}    200    ${entity_id}
    ${response}=    Retrieve Entity    ${entity_id}    context=${ngsild_test_suite_context}
    ${new_attribute}=    Get From Dictionary    ${response.json()}    speed
    Should Be Equal    ${attribute_payload}[speed][value]    ${new_attribute}[value]

    Check Response Status Code    200    ${response.status_code}
    Should Be Equal    ${attribute_payload}[value]    ${response.json()}[${attribute_name}][value]

*** Keywords ***
Create Entity And Registration On The Context Broker And Start Context Source Mock Server
+10 −23
Original line number Diff line number Diff line
@@ -15,12 +15,10 @@ Test Teardown Delete Created Entity And Registration And Stop Context Sour


*** Variables ***
${entity_id_prefix}                     urn:ngsi-ld:Vehicle:
${entity_payload_filename}              vehicle-simple-different-attributes.jsonld
${entity_attribute_filename}            fragmentEntities/vehicle-speed-two-datasetid-01-fragment.json
${registration_id_prefix}               urn:ngsi-ld:Registration:
${entity_attribute_filename}            fragmentEntities/vehicle-speed-two-datasetid-05-fragment.json
${registration_payload_file_path}       csourceRegistrations/context-source-registration-vehicle-redirection-ops.jsonld

${attribute_name}                       speed

*** Test Cases ***
D009_01_red Replace Entity Attribute
@@ -31,33 +29,22 @@ D009_01_red Replace Entity Attribute
    Set Stub Reply    POST    /broker2/ngsi-ld/v1/entities    201    ${entity_id}

    ${attribute_payload}=    Load Entity    ${entity_attribute_filename}    ${entity_id}
    Set Stub Reply    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}/attrs/speed    204
    Set Stub Reply    PUT    /broker2/ngsi-ld/v1/entities/${entity_id}/attrs/speed    204
    Set Stub Reply    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}/attrs/${attribute_name}    204
    Set Stub Reply    PUT    /broker2/ngsi-ld/v1/entities/${entity_id}/attrs/${attribute_name}    204

    ${response}=    Replace Attribute Selecting Content Type
    ...    entity_id=${entity_id}
    ...    attr_id=speed
    ...    attr_id=${attribute_name}
    ...    attribute_fragment=${attribute_payload}
    ...    content_type=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response.status_code}

    ${stub_count}=    Get Stub Count    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}/attrs/speed
    ${stub_count}=    Get Stub Count    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}/attrs/${attribute_name}
    Should Be Equal As Integers    ${stub_count}    1
    ${stub_count}=    Get Stub Count    PUT    /broker2/ngsi-ld/v1/entities/${entity_id}/attrs/speed
    ${stub_count}=    Get Stub Count    PUT    /broker2/ngsi-ld/v1/entities/${entity_id}/attrs/${attribute_name}
    Should Be Equal As Integers    ${stub_count}    1

    Set Stub Reply    GET    /broker1/ngsi-ld/v1/entities/${entity_id}    200    ${entity_id}
    ${response}=    Retrieve Entity    ${entity_id}    context=${ngsild_test_suite_context}
    ${new_attribute}=    Get From Dictionary    ${response.json()}    speed
    Should Be Equal    ${attribute_payload}[speed][value]    ${new_attribute}[value]

    Set Stub Reply    GET    /broker2/ngsi-ld/v1/entities/${entity_id}    200    ${entity_id}
    ${response}=    Retrieve Entity    ${entity_id}    context=${ngsild_test_suite_context}
    ${new_attribute}=    Get From Dictionary    ${response.json()}    speed
    Should Be Equal    ${attribute_payload}[speed][value]    ${new_attribute}[value]


*** Keywords ***
Setup Registration And Start Context Source Mock Server
    ${entity_id}=    Generate Random Vehicle Entity Id
@@ -70,18 +57,18 @@ Setup Registration And Start Context Source Mock Server
    ...    ${registration_payload_file_path}
    ...    entity_id=${entity_id}
    ...    mode=redirect
    ...    endpoint=/broker1
    ...    endpoint=${context_source_url}/broker1
    ${response}=    Create Context Source Registration With Return    ${registration_payload}
    Check Response Status Code    201    ${response.status_code}

    ${registration_id2}=    Generate Random CSR Id
    Set Suite Variable    ${registration_id2}
    ${registration_payload2}=    Prepare Context Source Registration From File
    ...    ${registration_id}
    ...    ${registration_id2}
    ...    ${registration_payload_file_path}
    ...    entity_id=${entity_id}
    ...    mode=redirect
    ...    endpoint=/broker2
    ...    endpoint=${context_source_url}/broker2
    ${response}=    Create Context Source Registration With Return    ${registration_payload2}
    Check Response Status Code    201    ${response.status_code}

+9 −0
Original line number Diff line number Diff line
{
    "type": "Property",
        "value": 99,
        "source": {
            "type": "Property",
            "value": "Speedometer"
        },
        "datasetId": "urn:ngsi-ld:Property:speedometerA4567-speed2"
}
 No newline at end of file