From 4cdf3d03efc0892b3c472c65473f30daac186478 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Fri, 12 Feb 2021 18:17:18 +0100 Subject: [PATCH 1/3] feat: add TC for 018_06 --- .../Consumption/Entity/018_06.robot | 39 +++++++++++++++++++ ...tributes-sample-compacted-expectation.json | 22 +++++++++++ ...ttributes-sample-expanded-expectation.json | 22 +++++++++++ 3 files changed, 83 insertions(+) create mode 100644 TP/NGSI-LD/ContextInformation/Consumption/Entity/018_06.robot create mode 100644 data/entities/expectations/building-simple-attributes-sample-compacted-expectation.json create mode 100644 data/entities/expectations/building-simple-attributes-sample-expanded-expectation.json diff --git a/TP/NGSI-LD/ContextInformation/Consumption/Entity/018_06.robot b/TP/NGSI-LD/ContextInformation/Consumption/Entity/018_06.robot new file mode 100644 index 00000000..48e921f2 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Consumption/Entity/018_06.robot @@ -0,0 +1,39 @@ +*** 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 diff --git a/data/entities/expectations/building-simple-attributes-sample-compacted-expectation.json b/data/entities/expectations/building-simple-attributes-sample-compacted-expectation.json new file mode 100644 index 00000000..7b86aadd --- /dev/null +++ b/data/entities/expectations/building-simple-attributes-sample-compacted-expectation.json @@ -0,0 +1,22 @@ +{ + "id": "RandomUuidToBeReplaced", + "type": "Building", + "name": { + "type": "Property", + "value": "Eiffel Tower" + }, + "subCategory": { + "type": "Property", + "value": "tourism" + }, + "airQualityLevel": { + "type": "Property", + "value": 4, + "unitCode": "C62", + "observedAt": "2020-09-09T16:40:00.000Z" + }, + "almostFull": { + "type": "Property", + "value": false + } +} \ No newline at end of file diff --git a/data/entities/expectations/building-simple-attributes-sample-expanded-expectation.json b/data/entities/expectations/building-simple-attributes-sample-expanded-expectation.json new file mode 100644 index 00000000..134f7221 --- /dev/null +++ b/data/entities/expectations/building-simple-attributes-sample-expanded-expectation.json @@ -0,0 +1,22 @@ +{ + "id": "urn:ngsi-ld:Building:randomUUID", + "type": "https://ngsi-ld-test-suite/context#Building", + "name": { + "type": "Property", + "value": "Eiffel Tower" + }, + "https://ngsi-ld-test-suite/context#airQualityLevel": { + "type": "Property", + "value": 4, + "observedAt": "2020-09-09T16:40:00.000Z", + "unitCode": "C62" + }, + "https://ngsi-ld-test-suite/context#almostFull": { + "type": "Property", + "value": false + }, + "https://ngsi-ld-test-suite/context#subCategory": { + "type": "Property", + "value": "tourism" + } +} \ No newline at end of file -- GitLab From d9b65f7cd3c85cc656cb013b1bebcdb0c6d4625d Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sat, 13 Feb 2021 08:21:41 +0100 Subject: [PATCH 2/3] feat: add JSON-LD context resolution TCs for create entity endpoint --- .../Entities/CreateEntity/001_04.robot | 28 +++++++++++++++++++ .../Entities/CreateEntity/001_05.robot | 28 +++++++++++++++++++ .../Entities/CreateEntity/001_06.robot | 22 +++++++++++++++ .../Entities/CreateEntity/001_07.robot | 28 +++++++++++++++++++ .../Entities/CreateEntity/001_08.robot | 22 +++++++++++++++ .../Entities/CreateEntity/001_09.robot | 22 +++++++++++++++ resources/ApiUtils.resource | 2 +- 7 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_04.robot create mode 100644 TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_05.robot create mode 100644 TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_06.robot create mode 100644 TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_07.robot create mode 100644 TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_08.robot create mode 100644 TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_09.robot diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_04.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_04.robot new file mode 100644 index 00000000..1491771a --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_04.robot @@ -0,0 +1,28 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_05.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_05.robot new file mode 100644 index 00000000..61060456 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_05.robot @@ -0,0 +1,28 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_06.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_06.robot new file mode 100644 index 00000000..1cbed680 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_06.robot @@ -0,0 +1,22 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_07.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_07.robot new file mode 100644 index 00000000..4126526c --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_07.robot @@ -0,0 +1,28 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_08.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_08.robot new file mode 100644 index 00000000..e0e609f4 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_08.robot @@ -0,0 +1,22 @@ +*** 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: +${filename}= building-simple-attributes-sample.json + +*** Test Case *** +Create 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} + + ${request} ${response}= Create Entity Selecting Content Type ${filename} ${entity_id} ${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/ContextInformation/Provision/Entities/CreateEntity/001_09.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_09.robot new file mode 100644 index 00000000..aa738d4c --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_09.robot @@ -0,0 +1,22 @@ +*** 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 *** +${building_id_prefix}= urn:ngsi-ld:Building: +${filename}= building-simple-attributes-sample.jsonld + +*** Test Case *** +Create one entity 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 + + ${entity_id}= Generate Random Entity Id ${building_id_prefix} + + ${request} ${response}= Create Entity Selecting Content Type ${filename} ${entity_id} ${CONTENT_TYPE_LD_JSON} context=${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/resources/ApiUtils.resource b/resources/ApiUtils.resource index 66c2f958..6246a666 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -118,7 +118,7 @@ Create Entity Selecting Content Type ${entity_payload}= Load Json From File ${EXECDIR}/data/entities/${filename} ${entity}= Update Value To Json ${entity_payload} $..id ${entity_id} &{headers}= Create Dictionary Content-Type=${content_type} - Run Keyword If '${content_type}'=='${CONTENT_TYPE_JSON}' and '${context}'!='${EMPTY}' Set To Dictionary ${headers} Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json" + Run Keyword If '${context}'!='${EMPTY}' Set To Dictionary ${headers} Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json" ${response}= POST ${ENTITIES_ENDPOINT_PATH} body=${entity} headers=${headers} ${request}= Output request Output response -- GitLab From 3196e86267d029a1a4c891941009412e97e74db3 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sat, 13 Feb 2021 08:22:00 +0100 Subject: [PATCH 3/3] chore: remove unused fixture file --- .../building-simple-attributes.jsonld | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 data/entities/building-simple-attributes.jsonld diff --git a/data/entities/building-simple-attributes.jsonld b/data/entities/building-simple-attributes.jsonld deleted file mode 100644 index bc3dd795..00000000 --- a/data/entities/building-simple-attributes.jsonld +++ /dev/null @@ -1,26 +0,0 @@ -{ - "id": "urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9", - "type": "Building", - "name": { - "type": "Property", - "value": "Eiffel Tower" - }, - "subCategory": { - "type": "Property", - "value": ["tourism"] - }, - "airQualityLevel": { - "type": "Property", - "value": 4, - "unitCode": "C62", - "observedAt": "2020-09-09T16:40:00.000Z" - }, - "almostFull": { - "type": "Property", - "value": false - }, - "@context": [ - "https://fiware.github.io/data-models/context.jsonld", - "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld" - ] -} \ No newline at end of file -- GitLab