Commit 95138a6f authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

Merge branch 'feature/jsonld-context-resolution' into 'develop'

feat: add JSON-LD @context resolution tests for batch entity creation endpoint

See merge request !5
parents 7b7759d9 dd072be9
Loading
Loading
Loading
Loading
+32 −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:

*** Test Case ***
Create a batch of 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}
    ${entity}=    Load Entity    building-simple-attributes-sample.json      ${entity_id}
    @{entities_to_be_created}=  Create List   ${entity}

    Batch Create Entities   @{entities_to_be_created}       content_type=${CONTENT_TYPE_JSON}       context=${ngsild_test_suite_context}

    Check Response Status Code Set To  201

    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 attribute
    Check Response Body Containing an Attribute set to   https://ngsi-ld-test-suite/context#almostFull

    @{entities_ids_to_be_deleted}=  Create List   ${entity_id}
    Batch Delete Entities       @{entities_ids_to_be_deleted}
+32 −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:

*** Test Case ***
Create a batch of 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}
    ${entity}=    Load Entity    building-simple-attributes-sample.json      ${entity_id}
    @{entities_to_be_created}=  Create List   ${entity}

    Batch Create Entities   @{entities_to_be_created}       content_type=${CONTENT_TYPE_JSON}

    Check Response Status Code Set To  201

    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}     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   https://uri.etsi.org/ngsi-ld/default-context/almostFull

    @{entities_ids_to_be_deleted}=  Create List   ${entity_id}
    Batch Delete Entities       @{entities_ids_to_be_deleted}
+23 −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:

*** Test Case ***
Create a batch of 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}
    ${entity}=    Load Entity    building-simple-attributes-sample.jsonld      ${entity_id}
    @{entities_to_be_created}=  Create List   ${entity}

    Batch Create Entities   @{entities_to_be_created}       content_type=${CONTENT_TYPE_JSON}

    Check Response Status Code Set To  400
    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}
+32 −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:

*** Test Case ***
Create a batch of 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}
    ${entity}=    Load Entity    building-simple-attributes-sample.jsonld      ${entity_id}
    @{entities_to_be_created}=  Create List   ${entity}

    Batch Create Entities   @{entities_to_be_created}       content_type=${CONTENT_TYPE_LD_JSON}

    Check Response Status Code Set To  201

    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

    @{entities_ids_to_be_deleted}=  Create List   ${entity_id}
    Batch Delete Entities       @{entities_ids_to_be_deleted}
+23 −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/ld+json" and the request payload body does not contain 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:

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

    ${entity_id}=     Generate Random Entity Id    ${building_id_prefix}
    ${entity}=    Load Entity    building-simple-attributes-sample.json      ${entity_id}
    @{entities_to_be_created}=  Create List   ${entity}

    Batch Create Entities   @{entities_to_be_created}       content_type=${CONTENT_TYPE_LD_JSON}

    Check Response Status Code Set To  400
    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}
Loading