diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_03.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_03.robot index 916fcd5c4185040797726190adf685de35691bca..81a0f4ada2cb150f8db0645142a78ca840f12f72 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_03.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_03.robot @@ -18,4 +18,4 @@ Create Batch Entity With Invalid Request Scenarios Batch Request Entities From File create filename=${filename} Check RL Response Status Code Set To 400 - Check RL Response Body Containing Problem Details Element Containing Detail Element ${response} + Check RL Response Body Containing ProblemDetails Element Containing Detail Element ${response} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_04.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_04.robot new file mode 100644 index 0000000000000000000000000000000000000000..484baea7b676703a81f090780597e65a93422a15 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_04.robot @@ -0,0 +1,32 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_05.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_05.robot new file mode 100644 index 0000000000000000000000000000000000000000..9a489158d738bd38e734c60575b7c2877a21b065 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_05.robot @@ -0,0 +1,32 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_06.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_06.robot new file mode 100644 index 0000000000000000000000000000000000000000..b67ba32eb98afbc7a473ef26b25fdb8a0b13bca0 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_06.robot @@ -0,0 +1,23 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_07.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_07.robot new file mode 100644 index 0000000000000000000000000000000000000000..89d4cfde84e282be9abccbdd92ab225ba562f9fd --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_07.robot @@ -0,0 +1,32 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_08.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_08.robot new file mode 100644 index 0000000000000000000000000000000000000000..7646496a468748e93c2e8647d27bb7c985218e78 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_08.robot @@ -0,0 +1,23 @@ +*** 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_09.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_09.robot new file mode 100644 index 0000000000000000000000000000000000000000..88ebf3aca8ce741d355223044907452bf81902c9 --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_09.robot @@ -0,0 +1,23 @@ +*** 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: + +*** Test Case *** +Create a batch of 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} + ${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} context=${ngsild_test_suite_context} + + 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} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_03.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_03.robot index ae664944563a48f7e979ec546c62c5be9adcc284..d3a32f42161bc0fe36c8123cd1e43ab8708c2bad 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_03.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_03.robot @@ -18,4 +18,4 @@ Batch Delete Entity With Invalid Request Scenarios Batch Request Entities From File delete filename=${filename} Check RL Response Status Code Set To 400 - Check RL Response Body Containing Problem Details Element Containing Detail Element ${response} + Check RL Response Body Containing ProblemDetails Element Containing Detail Element ${response} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_04.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_04.robot index 2c7b8fd195b212de568f8603212d1da53b64761a..f9a32ae5f4bb8554efc597462c881177682df2b6 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_04.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_04.robot @@ -18,4 +18,4 @@ Batch Update Entity With Invalid Request Scenarios Batch Request Entities From File update filename=${filename} Check RL Response Status Code Set To 400 - Check RL Response Body Containing Problem Details Element Containing Detail Element ${response} + Check RL Response Body Containing ProblemDetails Element Containing Detail Element ${response} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_06.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_06.robot index aae23c2888906b1401c2f69eb739419160355890..d3a02b9c227d826bccc424ffca504739e6f77cbe 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_06.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_06.robot @@ -18,4 +18,4 @@ Batch Upsert Entity With Invalid Request Scenarios Batch Request Entities From File upsert filename=${filename} Check RL Response Status Code Set To 400 - Check RL Response Body Containing Problem Details Element Containing Detail Element ${response} + Check RL Response Body Containing ProblemDetails Element Containing Detail Element ${response} diff --git a/data/entities/building-simple-attributes-sample.json b/data/entities/building-simple-attributes-sample.json new file mode 100644 index 0000000000000000000000000000000000000000..c0beff52e7ef76265db017a5a9451b68f210e7c7 --- /dev/null +++ b/data/entities/building-simple-attributes-sample.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/resources/ApiUtils.resource b/resources/ApiUtils.resource index 547834a9f07ccbb2adcdcfb7b8b7850be96a85d3..946c63e44f27dd7d73531cf3f932f06acf86558d 100644 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -11,10 +11,16 @@ ${BATCH_CREATE_ENDPOINT_PATH} entityOperations/create ${BATCH_UPSERT_ENDPOINT_PATH} entityOperations/upsert ${BATCH_UPDATE_ENDPOINT_PATH} entityOperations/update ${BATCH_DELETE_ENDPOINT_PATH} entityOperations/delete +&{BATCH_OPERATION_ENDPOINT_MAPPING} create=${BATCH_CREATE_ENDPOINT_PATH} upsert=${BATCH_UPSERT_ENDPOINT_PATH} update=${BATCH_UPDATE_ENDPOINT_PATH} delete=${BATCH_DELETE_ENDPOINT_PATH} ${ENTITIES_ENDPOINT_PATH} entities ${TEMPORAL_ENTITIES_ENDPOINT_PATH} temporal/entities + +${CONTENT_TYPE_JSON} application/json +${CONTENT_TYPE_LD_JSON} application/ld+json + +${ERROR_TYPE_BAD_REQUEST_DATA} https://uri.etsi.org/ngsi-ld/errors/BadRequestData + ${response} -&{BATCH_OPERATION_ENDPOINT_MAPPING} create=${BATCH_CREATE_ENDPOINT_PATH} upsert=${BATCH_UPSERT_ENDPOINT_PATH} update=${BATCH_UPDATE_ENDPOINT_PATH} delete=${BATCH_DELETE_ENDPOINT_PATH} *** Keywords *** Api POST request @@ -47,6 +53,16 @@ Delete Entity by Id Output request Output response +Retrieve Entity by Id + [Arguments] ${id} ${accept}=${CONTENT_TYPE_LD_JSON} ${context}=${EMPTY} + ${headers}= Create Dictionary + Set To Dictionary ${headers} Accept ${accept} + Run Keyword If '${context}'!='' Set To Dictionary ${headers} Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json" + ${response}= GET ${ENTITIES_ENDPOINT_PATH}/${id} headers=${headers} + Output request + Output response + Set Test Variable ${response} + Create Entity [Arguments] ${filename} ${entity_id} ${entity_payload}= Load Json From File ${EXECDIR}/data/entities/${filename} @@ -58,8 +74,10 @@ Create Entity Output response Batch Create Entities - [Arguments] @{entities_to_be_created} - &{headers}= Create Dictionary Content-Type=application/ld+json + [Arguments] @{entities_to_be_created} ${content_type}=${CONTENT_TYPE_LD_JSON} ${context}=${EMPTY} + ${headers}= Create Dictionary + Set To Dictionary ${headers} 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 ${BATCH_CREATE_ENDPOINT_PATH} body=@{entities_to_be_created} headers=${headers} Output request Output response diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index c27409d5a59d978a9b3b3fc6c9ee299643ad137c..6ed5b6776d0d2f018e65be81a3219f10b0273fbc 100644 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -18,6 +18,10 @@ Check Response Body Containing Array Of URIs set to [Arguments] @{expected_entities_ids} Lists Should Be Equal ${expected_entities_ids} ${response['body']} ignore_order=True +Check Response Body Containing an Attribute set to + [Arguments] ${expected_attribute_name} + Should Not Be Empty ${response['body']['${expected_attribute_name}']} + Check Response Body Containing Batch Operation Result [Arguments] ${expected_batch_operation_result} @{expected_successful_entities_ids}= Get From Dictionary ${expected_batch_operation_result} success @@ -41,11 +45,15 @@ Check Response Body Containing EntityTemporal element ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response['body']} ${temporal_entity_representation} ${instance_id_regex_expr} Should Be True ${comparaison_result} msg=EntityTemporal Comparaison Failed -Check Response Body Containing Problem Details Element Containing Detail Element +Check Response Body Containing ProblemDetails Element Containing Type Element set to + [Arguments] ${response_body} ${type} + Should Be Equal ${response['body']['type']} ${type} + +Check Response Body Containing ProblemDetails Element Containing Title Element [Arguments] ${response_body} - Should Not Be Empty ${response_body['detail']} + Should Not Be Empty ${response['body']['title']} -Check RL Response Body Containing Problem Details Element Containing Detail Element +Check RL Response Body Containing ProblemDetails Element Containing Detail Element [Arguments] ${response_body} ${json_response_body}= To Json ${response_body.content} Should Not Be Empty ${json_response_body['detail']}