Commit 7c6afdac authored by kzangeli's avatar kzangeli
Browse files

fix: mock CP responses must carry their own @context (D009/D016 retrieve-back)

A forwarded read response is interpreted with the context that travels WITH it
(its Link header / embedded @context), per § 6.3.5 — the consumer cannot expand
the Context Source's short names with the request's context. The mock CP GET
stubs returned a bare entity document with NO @context, so a spec-correct
consumer expands 'speed' with core only → the default-context IRI, not the test
suite's https://ngsi-ld-test-suite/context#speed → the attribute mis-keys and is
dropped on merge ("Dictionary does not contain key 'speed'").

Embed @context=${ngsild_test_suite_context} in the stub entity documents so the
mock is a conformant Context Source. Fixes D009_01_exc, D009_01_red and
D016_01_red (single-object and array/query forms both verified). The remaining
D010_01_exc + D011_* query-back tests have the same defect (separate commit).
parent 7ba59095
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ D016_01_red Merge Batch Entities On The Context Source
    # query is forwarded there, so the mocks must serve them. The old form
    # left the query-back unstubbed (the broker received nothing and
    # correctly returned []) and then asserted 'speed' as a list ELEMENT.
    ${merged_first}=    Create Dictionary    id=${first_entity_id}    type=Vehicle    speed=${new_first_entity}[speed]
    ${merged_second}=    Create Dictionary    id=${second_entity_id}    type=Vehicle    speed=${new_second_entity}[speed]
    ${merged_first}=    Create Dictionary    @context=${ngsild_test_suite_context}    id=${first_entity_id}    type=Vehicle    speed=${new_first_entity}[speed]
    ${merged_second}=    Create Dictionary    @context=${ngsild_test_suite_context}    id=${second_entity_id}    type=Vehicle    speed=${new_second_entity}[speed]
    @{cs_entities}=    Create List    ${merged_first}    ${merged_second}
    Set Stub Reply    GET    /broker1/ngsi-ld/v1/entities    200    ${cs_entities}
    Set Stub Reply    GET    /broker2/ngsi-ld/v1/entities    200    ${cs_entities}
+5 −2
Original line number Diff line number Diff line
@@ -42,8 +42,11 @@ D009_01_exc Replace Entity Attribute
    Should Be Equal As Integers    ${stub_count}    1

    # The Context Source serves the entity carrying the replaced attribute —
    # the stub reply must be an entity document, not the bare entity id.
    ${entity_reply}=    Create Dictionary    id=${entity_id}    type=Vehicle    speed=${attribute_payload}[speed]
    # a conformant NGSI-LD response, so it MUST carry its own @context (§ 6.3.5):
    # the consumer interprets the CP's short names with the context that travels
    # with the response, not the request's. Without it the broker correctly
    # expands 'speed' with core only → wrong IRI → dropped on merge.
    ${entity_reply}=    Create Dictionary    @context=${ngsild_test_suite_context}    id=${entity_id}    type=Vehicle    speed=${attribute_payload}[speed]
    Set Stub Reply    GET    /broker1/ngsi-ld/v1/entities/${entity_id}    200    ${entity_reply}
    ${response}=    Retrieve Entity    ${entity_id}    context=${ngsild_test_suite_context}
    ${new_attribute}=    Get From Dictionary    ${response.json()}    speed
+4 −2
Original line number Diff line number Diff line
@@ -48,8 +48,10 @@ D009_01_red Replace Entity Attribute
    Should Be Equal As Integers    ${stub_count}    1

    # The Context Sources serve the entity carrying the replaced attribute —
    # the stub replies must be entity documents, not the bare entity id.
    ${entity_reply}=    Create Dictionary    id=${entity_id}    type=Vehicle    speed=${attribute_payload}[speed]
    # a conformant NGSI-LD response, so it MUST carry its own @context (§ 6.3.5):
    # the consumer interprets the CP's short names with the context that travels
    # with the response, not the request's.
    ${entity_reply}=    Create Dictionary    @context=${ngsild_test_suite_context}    id=${entity_id}    type=Vehicle    speed=${attribute_payload}[speed]
    Set Stub Reply    GET    /broker1/ngsi-ld/v1/entities/${entity_id}    200    ${entity_reply}
    ${response}=    Retrieve Entity    ${entity_id}    context=${ngsild_test_suite_context}
    ${new_attribute}=    Get From Dictionary    ${response.json()}    speed