Commit 81fb776d authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

feat: add TCs JSON-LD @context resolution on context source registrations

parent 11da221b
Loading
Loading
Loading
Loading
+29 −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 ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${registration_payload_file_path}=   csourceRegistrations/context-source-registration-sample.json

*** Test Case ***
Create one context source registration 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
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}

    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_payload_file_path}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return  ${updated_payload}    ${CONTENT_TYPE_JSON}    ${ngsild_test_suite_context}
    Check Response Status Code  201    ${response['status']}

    Retrieve Context Source Registration  ${registration_id}   context=${ngsild_test_suite_context}
    Check JSON Value In Response Body   ['information']['entities'][0]['type']      Building

    Retrieve Context Source Registration  ${registration_id}
    Check JSON Value In Response Body   ['information']['entities'][0]['type']      https://ngsi-ld-test-suite/context#Building

    [Teardown]  Delete Context Source Registration    ${registration_id}
+29 −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 ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${registration_payload_file_path}=   csourceRegistrations/context-source-registration-sample.json

*** Test Case ***
Create one context source registration 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
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}

    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_payload_file_path}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return  ${updated_payload}    ${CONTENT_TYPE_JSON}
    Check Response Status Code  201    ${response['status']}

    Retrieve Context Source Registration  ${registration_id}   context=${ngsild_test_suite_context}
    Check JSON Value In Response Body   ['information']['entities'][0]['type']      ngsi-ld:default-context/Building

    Retrieve Context Source Registration  ${registration_id}
    Check JSON Value In Response Body   ['information']['entities'][0]['type']      Building

    [Teardown]  Delete Context Source Registration    ${registration_id}
+24 −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 ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${registration_payload_file_path}=   csourceRegistrations/context-source-registration-sample.jsonld

*** Test Case ***
Create one context source registration 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
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}

    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_payload_file_path}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return  ${updated_payload}    ${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}
+29 −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 ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${registration_payload_file_path}=   csourceRegistrations/context-source-registration-sample.jsonld

*** Test Case ***
Create one context source registration 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
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}

    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_payload_file_path}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return  ${updated_payload}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code  201    ${response['status']}

    Retrieve Context Source Registration  ${registration_id}   context=${ngsild_test_suite_context}
    Check JSON Value In Response Body   ['information']['entities'][0]['type']      Building

    Retrieve Context Source Registration  ${registration_id}
    Check JSON Value In Response Body   ['information']['entities'][0]['type']      https://ngsi-ld-test-suite/context#Building

    [Teardown]  Delete Context Source Registration    ${registration_id}
+24 −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 ***
${registration_id_prefix}=  urn:ngsi-ld:Registration:
${registration_payload_file_path}=   csourceRegistrations/context-source-registration-sample.json

*** Test Case ***
Create one context source registration 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
    ${registration_id}=     Generate Random Entity Id    ${registration_id_prefix}

    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_payload_file_path}
    ${updated_payload}=    Update Value To Json    ${payload}     $..id   ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return  ${updated_payload}    ${CONTENT_TYPE_LD_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}
Loading