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 0000000000000000000000000000000000000000..48e921f249fe8f2ed983454a6c1dacbaf6e169d3 --- /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/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 0000000000000000000000000000000000000000..1491771a2836078e4cfe567a34b4683796f67110 --- /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 0000000000000000000000000000000000000000..610604562980611c44b7ef7f0ab3ade030c96f0e --- /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 0000000000000000000000000000000000000000..1cbed680fdac4ec03dc1f29a14462d6df00aee57 --- /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 0000000000000000000000000000000000000000..4126526c0eb64fa90e0deaf80012e8f32869c442 --- /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 0000000000000000000000000000000000000000..e0e609f4390dd9b3298bbdce80bce0e0c5d3190d --- /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 0000000000000000000000000000000000000000..aa738d4c8ad042c1d38739b0c35bb068e7246ebf --- /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/data/entities/building-simple-attributes.jsonld b/data/entities/expectations/building-simple-attributes-sample-compacted-expectation.json similarity index 59% rename from data/entities/building-simple-attributes.jsonld rename to data/entities/expectations/building-simple-attributes-sample-compacted-expectation.json index bc3dd7959a5683a2a1a0ec04ab8eaf24ba29b93e..7b86aadd7f4f55f4990d69aed8c5732572a7f42e 100644 --- a/data/entities/building-simple-attributes.jsonld +++ b/data/entities/expectations/building-simple-attributes-sample-compacted-expectation.json @@ -1,5 +1,5 @@ { - "id": "urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9", + "id": "RandomUuidToBeReplaced", "type": "Building", "name": { "type": "Property", @@ -7,7 +7,7 @@ }, "subCategory": { "type": "Property", - "value": ["tourism"] + "value": "tourism" }, "airQualityLevel": { "type": "Property", @@ -18,9 +18,5 @@ "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 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 0000000000000000000000000000000000000000..134f722118d532c6024762c5c5d668bbbf48bc0b --- /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 diff --git a/resources/ApiUtils.resource b/resources/ApiUtils.resource index 66c2f9580d6c3f698f24ad1cd3009845789ec6a3..6246a66629811d9a92a1c7a0b173c0104c9282d0 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