From 9123c718d65d9d37cfbd5335dd9dd9920efe8a4d Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sun, 14 Feb 2021 09:16:16 +0100 Subject: [PATCH 1/2] feat: add TC for 036_05 --- .../036_05.robot | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 TP/NGSI-LD/ContextSource/Registration/RetrieveContextSourceRegistration/036_05.robot diff --git a/TP/NGSI-LD/ContextSource/Registration/RetrieveContextSourceRegistration/036_05.robot b/TP/NGSI-LD/ContextSource/Registration/RetrieveContextSourceRegistration/036_05.robot new file mode 100644 index 00000000..368f6259 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/RetrieveContextSourceRegistration/036_05.robot @@ -0,0 +1,42 @@ +*** 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 Context Source Registration +Suite Teardown Delete Created Context Source Registration + +Test Template Check JSON-LD resolution when retrieving a context source registration + +*** Variable *** +${context_source_registration_id_prefix}= urn:ngsi-ld:ContextSourceRegistration: +${context_source_registration_payload_file_path}= csourceRegistrations/context-source-registration-sample.jsonld +${expectation_file_path_compacted}= csourceRegistrations/expectations/context-source-registration.json +${expectation_file_path_expanded}= csourceRegistrations/expectations/context-source-registration-expanded-format.json + +*** Test Cases *** CONTEXT EXPECTED_PAYLOAD +EmptyJsonLdContext ${EMPTY} ${expectation_file_path_expanded} +CreationTimeJsonLdContext ${ngsild_test_suite_context} ${expectation_file_path_compacted} + +*** Keywords *** +Check JSON-LD resolution when retrieving a context source registration + [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 + + Retrieve Context Source Registration ${context_source_registration_id} context=${context} + + Check Response Status Code Set To 200 + Check Response Body Containing Context Source Registration element ${expected_payload} ${context_source_registration_id} + +Setup Initial Context Source Registration + ${context_source_registration_id}= Generate Random Entity Id ${context_source_registration_id_prefix} + ${context_source_registration_payload}= Load Test Sample ${context_source_registration_payload_file_path} ${context_source_registration_id} + + Create Context Source Registration ${context_source_registration_payload} + + Set Suite Variable ${context_source_registration_id} + +Delete Created Context Source Registration + Delete Context Source Registration ${context_source_registration_id} -- GitLab From 8bf1e4728fd83ef1c6be15d510f66827309a03c5 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sun, 14 Feb 2021 11:05:56 +0100 Subject: [PATCH 2/2] feat: add JSON-LD context resolution TCs for create context source registration endpoint --- .../033_04.robot | 29 +++++++++++++++++++ .../033_05.robot | 29 +++++++++++++++++++ .../033_06.robot | 24 +++++++++++++++ .../033_07.robot | 29 +++++++++++++++++++ .../033_08.robot | 24 +++++++++++++++ .../033_09.robot | 24 +++++++++++++++ .../context-source-registration-sample.json | 14 +++++++++ resources/ApiUtils.resource | 5 ++-- resources/AssertionUtils.resource | 14 ++------- 9 files changed, 179 insertions(+), 13 deletions(-) create mode 100644 TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_04.robot create mode 100644 TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_05.robot create mode 100644 TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_06.robot create mode 100644 TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_07.robot create mode 100644 TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_08.robot create mode 100644 TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_09.robot create mode 100644 data/csourceRegistrations/context-source-registration-sample.json diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_04.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_04.robot new file mode 100644 index 00000000..c03dae1e --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_04.robot @@ -0,0 +1,29 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_05.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_05.robot new file mode 100644 index 00000000..3d0410e9 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_05.robot @@ -0,0 +1,29 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_06.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_06.robot new file mode 100644 index 00000000..c79245ee --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_06.robot @@ -0,0 +1,24 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_07.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_07.robot new file mode 100644 index 00000000..17057c04 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_07.robot @@ -0,0 +1,29 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_08.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_08.robot new file mode 100644 index 00000000..f09aaf23 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_08.robot @@ -0,0 +1,24 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_09.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_09.robot new file mode 100644 index 00000000..1c6c0058 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/033_09.robot @@ -0,0 +1,24 @@ +*** Settings *** +Documentation Check that an HTTP error response of type BadRequestData is raised if the Content-Type header is "application/ld+json" and a JSON-LD Link header is present in the incoming HTTP request +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 with a Link header and 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 a JSON-LD Link header is present in the incoming HTTP request + [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} ${ngsild_test_suite_context} + + 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} diff --git a/data/csourceRegistrations/context-source-registration-sample.json b/data/csourceRegistrations/context-source-registration-sample.json new file mode 100644 index 00000000..b4a6b06e --- /dev/null +++ b/data/csourceRegistrations/context-source-registration-sample.json @@ -0,0 +1,14 @@ +{ + "id":"urn:ngsi-ld:ContextSourceRegistration:randomUUID", + "type":"ContextSourceRegistration", + "information":[ + { + "entities":[ + { + "type":"Building" + } + ] + } + ], + "endpoint":"http://my.csource.org:1026" +} \ No newline at end of file diff --git a/resources/ApiUtils.resource b/resources/ApiUtils.resource index 66c2f958..b6c58074 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -225,8 +225,9 @@ Retrieve Attribute Set Test Variable ${response} Create Context Source Registration With Return - [Arguments] ${payload} - &{headers}= Create Dictionary Content-Type=application/ld+json + [Arguments] ${payload} ${content_type}=${CONTENT_TYPE_LD_JSON} ${context}=${EMPTY} + &{headers}= Create Dictionary Content-Type=${content_type} + Run Keyword If '${context}'!='' Set To Dictionary ${headers} Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json" ${response}= POST ${CONTEXT_SOURCE_REGISTRATION_ENDPOINT_PATH} body=${payload} headers=${headers} ${request}= Output request Output response diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 2116fcfb..1055fbe9 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -239,17 +239,9 @@ Check HTTP Response Body Json Schema Is Validate Json ${schema} ${response['body']} Log Json Schema Validation OK -Should Be Present In Json List - [Arguments] ${expr} ${json_field} ${json_value} - Log Check if ${json_field} is present in ${expr} with the value ${jsonvalue} - :FOR ${item} IN @{expr} - \ Exit For Loop If "${item['${json_field}']}" == "${json_value}" - Log Item found ${item} - [return] ${item} - -Check Result Contains - [Arguments] ${source} ${parameter} ${value} - Should Be Present In Json List ${source} ${parameter} ${value} +Check JSON Value In Response Body + [Arguments] ${json_path_expr} ${value_to_check} + Should Be Equal As Strings ${response['body']${json_path_expr}} ${value_to_check} Check NotificationParams [Arguments] ${filename} ${expected_additional_members} -- GitLab