Commit 4fa42769 authored by kzangeli's avatar kzangeli
Browse files

fix(local): D003_01_exc / D003_02_exc append must carry the @context to match the exclusive reg

Both tests appended attributes as application/json with NO Link header, so the
attribute names (e.g. speed) never expanded to the IRIs the exclusive
registration used. The exclusive match found nothing to forward, so the broker
made zero forwards where the tests expect one — D003_01_exc failed at the stub
count (0 != 1) and D003_02_exc timed out in Wait For Request. The broker is
correct: short names without a context cannot match the registration's
expanded IRIs.

Add an optional ${context} argument to the shared Append Entity Attributes and
Append Entity Attributes With Parameters keywords (emit the @context as a Link
header via Build Context Link; defaults to empty so the 17 existing callers are
unchanged), and pass context=${ngsild_test_suite_context} in both tests.

D003_01_exc also needed two latent fixes that only surfaced once the forward
worked: (a) the final check did Get From Dictionary ... speed on the local
view, which per § 4.3.6.3 correctly LACKS the exclusively-registered attribute
and raised before asserting — replaced with Should Not Contain on the entity
(as already done for D007_01_exc); (b) it used Retrieve Entity without
importing ContextInformationConsumption.resource where that keyword is defined.
parent c4cdb0cf
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
Documentation       Check that when appending entity attributes to an entity with an exclusive registration, the attributes managed locally are updated on the Context Broker, while attributes managed with the exclusive registration are updated in the Context Source.

Resource            ${EXECDIR}/resources/ApiUtils/Common.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextSourceRegistration.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
@@ -27,14 +28,15 @@ D003_01_exc Append Entity Attribute
    ...    ${entity_id}
    ...    ${fragment_filename}
    ...    ${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response.status_code}

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

    # speed is exclusively registered, so the local view must LACK it (§ 4.3.6.3).
    ${response}=    Retrieve Entity    ${entity_id}    context=${ngsild_test_suite_context}    local=true
    ${body}=    Get From Dictionary    ${response.json()}    speed
    Should Not Contain    ${body}    speed
    Should Not Contain    ${response.json()}    speed

*** Keywords ***
Create Entity And Registration On The Context Broker And Start Context Source Mock Server
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ D003_02_exc Append Entity Attribute
    ...    ${fragment_filename}
    ...    ${CONTENT_TYPE_JSON}
    ...    noOverwrite
    ...    context=${ngsild_test_suite_context}
    Wait for redirected request
    Check Response Status Code    207   ${response.status_code}

+14 −2
Original line number Diff line number Diff line
@@ -42,8 +42,14 @@ ${response} ${EMPTY}
*** Keywords ***
Append Entity Attributes
    [Tags]    actor_context-producer
    [Arguments]    ${id}    ${fragment_filename}    ${content_type}
    [Arguments]    ${id}    ${fragment_filename}    ${content_type}    ${context}=${EMPTY}
    &{headers}=    Create Dictionary    Content-Type=${content_type}
    # application/json fragment carries its @context via a Link header, so the
    # attribute names expand to the same IRIs a matching registration used.
    IF    '${context}'!=''
        ${context_link}=    Build Context Link    ${context}
        Set To Dictionary    ${headers}    Link    ${context_link}
    END
    ${file_content}=    Get File    ${EXECDIR}/data/entities/fragmentEntities/${fragment_filename}
    ${response}=    POST
    ...    url=${url}/${ENTITIES_ENDPOINT_PATH}${id}/attrs/
@@ -55,8 +61,14 @@ Append Entity Attributes

Append Entity Attributes With Parameters
    [Tags]    actor_context-producer
    [Arguments]    ${id}    ${fragment_filename}    ${content_type}    ${options}
    [Arguments]    ${id}    ${fragment_filename}    ${content_type}    ${options}    ${context}=${EMPTY}
    &{headers}=    Create Dictionary    Content-Type=${content_type}
    # application/json fragment carries its @context via a Link header, so the
    # attribute names expand to the same IRIs a matching registration used.
    IF    '${context}'!=''
        ${context_link}=    Build Context Link    ${context}
        Set To Dictionary    ${headers}    Link    ${context_link}
    END
    ${fragment_payload}=    Load JSON From File    ${EXECDIR}/data/entities/fragmentEntities/${fragment_filename}
    ${response}=    POST
    ...    url=${url}/${ENTITIES_ENDPOINT_PATH}${id}/attrs/?options=${options}