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

integration: D007/D013/D016 assertion + stub fixes (doubt #101)

parent 979c66ce
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -44,6 +44,16 @@ D016_01_red Merge Batch Entities On The Context Source
    ${stub_count}=    Get Stub Count    POST    /broker2/ngsi-ld/v1/entityOperations/merge
    Should Be Equal As Integers    ${stub_count}    1

    # The merged entities live on the Context Sources (redirect) — the final
    # 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]
    @{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}

    ${expected_entities_ids}=    Catenate    SEPARATOR=,    @{entities_ids_to_be_merged}
    ${response}=    Query Entities
    ...    entity_ids=${expected_entities_ids}
@@ -51,7 +61,10 @@ D016_01_red Merge Batch Entities On The Context Source
    ...    context=${ngsild_test_suite_context}
    ...    accept=${CONTENT_TYPE_LD_JSON}

    Should Contain    ${response.json()}    speed
    Should Not Be Empty    ${response.json()}
    FOR    ${entity}    IN    @{response.json()}
        Dictionary Should Contain Key    ${entity}    speed
    END

*** Keywords ***
Create Entity And Registration On The Context Broker And Start Context Source Mock Server
+4 −0
Original line number Diff line number Diff line
@@ -38,6 +38,10 @@ D013_01_red Batch Upsert Entities With Redirect Registration Without Update Flag
    Wait for redirected request
    ${request_payload}=    Get Request Body
    ${payload}=    Evaluate    json.loads('''${request_payload}''')    json
    # An application/json + Link forward carries the @context in the Link
    # header, not in each entity — compare without the fixture's @context.
    Remove From Dictionary    ${new_first_entity}    @context
    Remove From Dictionary    ${new_second_entity}    @context
    Should Contain    ${payload}    ${new_first_entity}
    Should Contain    ${payload}    ${new_second_entity}
    
+4 −0
Original line number Diff line number Diff line
@@ -41,6 +41,10 @@ D013_02_red Batch Upsert Entities With Redirect Registration With Update Flag

    ${request_payload}=    Get Request Body
    ${payload}=    Evaluate    json.loads('''${request_payload}''')    json
    # An application/json + Link forward carries the @context in the Link
    # header, not in each entity — compare without the fixture's @context.
    Remove From Dictionary    ${new_first_entity}    @context
    Remove From Dictionary    ${new_second_entity}    @context
    Should Contain    ${payload}    ${new_first_entity}
    Should Contain    ${payload}    ${new_second_entity}
    
+5 −2
Original line number Diff line number Diff line
@@ -36,9 +36,12 @@ D007_01_exc Replace Entity
    ${stub_count}=    Get Stub Count    PUT    /broker1/ngsi-ld/v1/entities/${entity_id}
    Should Be Equal As Integers    ${stub_count}    1

    # § 4.3.6.3 — the exclusively-registered attribute lives on the Context
    # Source, so the LOCAL part of the replaced entity must not carry it.
    # (The old form fetched 'speed' from a view that correctly lacks it,
    # dying in Get From Dictionary before asserting anything.)
    ${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 ***
+29 −28
Original line number Diff line number Diff line
@@ -2669,31 +2669,32 @@ doesn't match the URL id.



## 100. D009 Replace Attribute family — entity-id string as GET stub body, list-blind assertion

Two test-side defects shared by `D009_01_exc` / `D009_01_inc` /
`D009_01_red`:

**a) GET stub body:** every retrieve-back stub was registered as
`Set Stub Reply GET .../entities/${entity_id} 200 ${entity_id}` — the
REPLY BODY is the bare entity-id string, not an entity document. No
broker can produce the asserted `speed` attribute from that. The stubs
now reply with an entity built from the test's own fragment
(`{id, type, speed=${attribute_payload}[speed]}`), mirroring what
`D010_01_exc` does with its payload file.

**b) `D009_01_inc` multi-instance:** the local entity keeps its
datasetId'd `speed` instance (inclusive — nothing is detached), so after
the replace the retrieve legitimately carries `speed` as a two-instance
array and `${new_attribute}[value]` died with "List used with invalid
index 'value'". The assertion now selects the default (datasetId-less)
instance before comparing.

**(Broker side, recorded for context: the D005/D009 captures exposed
write-forward bodies leaving the broker with fully-expanded IRIs when
the registration declares no contextSourceInfo.jsonldContext — forward
bodies are now compacted with the effective forward context (csi >
incoming request context > core) and the Link header follows suit; and
the name-keyed "wrapped" Attribute-Fragment form the suite PATCHes/PUTs
was stored verbatim as an attribute instance — it is now unwrapped for
local processing while forwards keep the incoming shape.)**
## 101. D007/D013/D016 distop assertions — @context-rigid dict compare, self-defeating fetch, unstubbed query-back

Four test-side defects across three DistOps Provision families:

**a) `D013_01_red` / `D013_02_red`:** the captured forward payload is
dict-compared against the fixture INCLUDING its `"@context"` member —
but an `application/json` + Link forward legitimately carries the
@context in the Link header, not in each entity. The comparison now
strips `@context` from the expected entities first.

**b) `D007_01_exc`:** the final check fetched the `speed` attribute from
the `local=true` view — which per § 4.3.6.3 correctly LACKS the
exclusively-registered attribute — and died inside Get From Dictionary
before asserting anything. It now asserts the absence directly
(`Should Not Contain` on the entity).

**c) `D016_01_red`:** the merged entities live on the Context Sources
(redirect), so the final query is forwarded there — but the query-back
was never stubbed: the broker received nothing and correctly returned
`[]`. The mocks now serve the merged entities. The assertion also
checked `'speed'` as a list ELEMENT of the response array; it now checks
each returned entity for the key.

**(Broker side, recorded for context: D013_01/02_red also exposed the
batch upsert/update redirect chop running with detach=true — the first
redirect CSR stripped the fragment and the second-and-onwards got NO
forward (D008_01_red-class); and batch update 404-gated on local
existence BEFORE dispatch, where § 9.4 reserves ResourceNotFound for
"unknown locally AND no matching registrations". Both fixed broker-side.)**