Commit 9c5e459a authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

Merge branch 'feature/add-tps-for-jsonld-context-resolution' into 'develop'

feat: add TCs for JSON-LD context resolution in create and retrieve entity endpoints

See merge request !31
parents c0ca2470 2ef8f217
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that the JSON-LD @context is obtained from a Link header if present and that the default JSON-LD @context is used if not present
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

Suite Setup         Setup Initial Entity
Suite Teardown      Delete Created Entity

Test Template       Check Json-LD Resolution When retrieving an entity

*** Variable ***
${building_id_prefix}=  urn:ngsi-ld:Building:
${filename}=  building-simple-attributes-sample.json
${empty_jsonld_expectation_filename}=  building-simple-attributes-sample-expanded-expectation.json
${creation_jsonld_expectation_filename}=  building-simple-attributes-sample-compacted-expectation.json

*** Test Cases ***                        CONTEXT                           EXPECTED_PAYLOAD
EmptyJsonLdContext                        ${EMPTY}                          ${empty_jsonld_expectation_filename}
CreationTimeJsonLdContext                 ${ngsild_test_suite_context}      ${creation_jsonld_expectation_filename}

*** Keywords ***
Check Json-LD Resolution When retrieving an entity
    [Arguments]  ${context}     ${expected_payload}
    [Documentation]  Check that the JSON-LD @context is obtained from a Link header if present and that the default JSON-LD @context is used if not present
    [Tags]  mandatory

    ${response}=    Query Entity    ${entity_id}    ${CONTENT_TYPE_JSON}     context=${context}
    Check Response Status Code  200    ${response['status']}
    Check Response Body Containing Entity element    ${expected_payload}    ${entity_id}    ${response['body']}

Setup Initial Entity
    ${entity_id}=     Generate Random Entity Id    ${building_id_prefix}
    Create Entity Selecting Content Type  ${filename}     ${entity_id}    ${CONTENT_TYPE_JSON}   context=${ngsild_test_suite_context}

    Set Suite Variable  ${entity_id}

Delete Created Entity
    Delete Entity by Id Returning Response   ${entity_id}
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that the @context is obtained from a Link Header if the Content-Type header is "application/json"
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${building_id_prefix}=  urn:ngsi-ld:Building:
${filename}=    building-simple-attributes-sample.json

*** Test Case ***
Create one entity using a provided Link header with JSON content type
    [Documentation]  Check that the @context is obtained from a Link Header if the Content-Type header is "application/json"
    [Tags]  mandatory

    ${entity_id}=     Generate Random Entity Id    ${building_id_prefix}

    Create Entity Selecting Content Type  ${filename}     ${entity_id}    ${CONTENT_TYPE_JSON}   context=${ngsild_test_suite_context}

    Retrieve Entity by Id  ${entity_id}       context=${ngsild_test_suite_context}
    # Attribute should be compacted as we used the same context as provided when creating the entity
    Check Response Body Containing an Attribute set to   almostFull

    Retrieve Entity by Id  ${entity_id}
    # Attribute should not be compacted as we did not provide a context containing this term
    Check Response Body Containing an Attribute set to   https://ngsi-ld-test-suite/context#almostFull

    Delete Entity by Id     ${entity_id}
+28 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that the default @context is used if the Content-Type header is "application/json" and the Link header does not contain a JSON-LD @context
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${building_id_prefix}=  urn:ngsi-ld:Building:
${filename}=    building-simple-attributes-sample.json

*** Test Case ***
Create one entity using the default context with JSON content type
    [Documentation]  Check that the default @context is used if the Content-Type header is "application/json" and the Link header does not contain a JSON-LD @context
    [Tags]  mandatory

    ${entity_id}=     Generate Random Entity Id    ${building_id_prefix}

    Create Entity Selecting Content Type  ${filename}     ${entity_id}    ${CONTENT_TYPE_JSON}

    Retrieve Entity by Id  ${entity_id}
    # Attribute should be compacted as we used the same default context as provided when creating the entity
    Check Response Body Containing an Attribute set to   almostFull

    Retrieve Entity by Id  ${entity_id}         ${CONTENT_TYPE_JSON}    context=${ngsild_test_suite_context}
    # Attribute should not be compacted as we did not provide a context containing this term
    Check Response Body Containing an Attribute set to   ngsi-ld:default-context/almostFull

    Delete Entity by Id     ${entity_id}
+22 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that an HTTP error response of type BadRequestData is raised if the Content-Type header is "application/json" and the request payload body (as JSON) contains a "@context" term
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${building_id_prefix}=  urn:ngsi-ld:Building:
${filename}=    building-simple-attributes-sample.jsonld

*** Test Case ***
Create one entity containing a JSON-LD @context with a JSON content type
    [Documentation]  Check that an HTTP error response of type BadRequestData is raised if the Content-Type header is "application/json" and the request payload body (as JSON) contains a "@context" term
    [Tags]  mandatory

    ${entity_id}=     Generate Random Entity Id    ${building_id_prefix}

    ${request}    ${response}=    Create Entity Selecting Content Type  ${filename}     ${entity_id}    ${CONTENT_TYPE_JSON}

    Check Response Status Code  400     ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to      ${response}     ${ERROR_TYPE_BAD_REQUEST_DATA}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response}
+28 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that the @context is obtained from the request payload body itself if the Content-Type header is "application/ld+json" 
Resource    ${EXECDIR}/resources/ApiUtils.resource
Resource    ${EXECDIR}/resources/AssertionUtils.resource
Resource    ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${building_id_prefix}=  urn:ngsi-ld:Building:
${filename}=    building-simple-attributes-sample.jsonld

*** Test Case ***
Create one entity using a JSON-LD @context obtained from the request payload
    [Documentation]  Check that the @context is obtained from the request payload body itself if the Content-Type header is "application/ld+json" 
    [Tags]  mandatory

    ${entity_id}=     Generate Random Entity Id    ${building_id_prefix}

    Create Entity Selecting Content Type  ${filename}     ${entity_id}    ${CONTENT_TYPE_LD_JSON}

    Retrieve Entity by Id  ${entity_id}       context=${ngsild_test_suite_context}
    # Attribute should be compacted as we used the same context as provided when creating the entity
    Check Response Body Containing an Attribute set to   almostFull

    Retrieve Entity by Id  ${entity_id}
    # Attribute should not be compacted as we did not provide a context containing this term
    Check Response Body Containing an Attribute set to   https://ngsi-ld-test-suite/context#almostFull

    Delete Entity by Id     ${entity_id}
Loading