From 28c7f2998d84b7fbc719f6e4263f55c5b333e5f5 Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Mon, 25 Jan 2021 17:25:24 +0000 Subject: [PATCH 1/2] Added update context source registration suite --- .../UpdateContextSourceRegistration/004.robot | 32 ++++++++++++++ .../UpdateContextSourceRegistration/005.robot | 40 +++++++++++++++++ .../005_05.robot | 27 ++++++++++++ .../UpdateContextSourceRegistration/006.robot | 23 ++++++++++ .../registration-different-type-sample.jsonld | 43 +++++++++++++++++++ resources/ApiUtils.resource | 17 ++++++++ 6 files changed, 182 insertions(+) create mode 100644 TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/004.robot create mode 100644 TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/005.robot create mode 100644 TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/005_05.robot create mode 100644 TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot create mode 100644 data/csourceRegistrations/registration-different-type-sample.jsonld diff --git a/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/004.robot b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/004.robot new file mode 100644 index 00000000..a7aa85cd --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/004.robot @@ -0,0 +1,32 @@ +*** Settings *** +Documentation Check that you can update a context source registration by id +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Template Update Context Source + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: + +*** Test Case *** FILENAME UPDATE_FILENAME +004_01_Update a context source registration by id registration-sample.jsonld registration-with-expiration-sample.jsonld +004_02_Update a context source registration to never expire registration-with-expiration-sample.jsonld registration-sample.jsonld + +*** Keywords *** +Update Context Source + [Arguments] ${filename} ${update_filename} + [Documentation] Check that you can update a context source registration by id + [Tags] mandatory + ${registration_id}= Generate Random Entity Id ${registration_id_prefix} + ${payload}= Load Json From File ${EXECDIR}/data/csourceRegistrations/${filename} + ${updated_payload}= Update Value To Json ${payload} $..id ${registration_id} + ${request} ${response}= Create Context Source Registration ${updated_payload} + Check Response Status Code 201 ${response['status']} + + ${fragment}= Load Json From File ${EXECDIR}/data/csourceRegistrations/${update_filename} + ${fragment_with_id}= Update Value To Json ${fragment} $..id ${registration_id} + ${response}= Update Context Source Registration ${registration_id} ${fragment_with_id} + Check Response Status Code 204 ${response['status']} + + [Teardown] Delete Context Source Registration ${registration_id} diff --git a/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/005.robot b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/005.robot new file mode 100644 index 00000000..265f1d82 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/005.robot @@ -0,0 +1,40 @@ +*** Settings *** +Documentation Check that you cannot update a context source registration under some conditions +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Suite Setup Setup Initial Entities +Test Template Update Context Source + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: +${filename}= registration-sample.jsonld + +*** Test Case *** REGISTRATION_ID FRAGMENT_FILENAME +005_01_Update a context source registration by id if the Id is not present ${EMPTY} registration-with-expiration-sample.jsonld +005_02_Update a context source registration by id if the Id is not a valid URI invalidURI registration-with-expiration-sample.jsonld +005_03_Update a context source registration if the request body is not of the same data type ${valid_registration_id} registration-different-type-sample.jsonld +005_04_Update a context source registration if you attempt to remove a mandatory property ${valid_registration_id} registration-invalid-structure-sample.jsonld + +*** Keywords *** +Update Context Source + [Arguments] ${registration_id} ${fragment_filename} + [Documentation] Check that you cannot update a context source registration under some conditions + [Tags] mandatory + ${payload}= Load Json From File ${EXECDIR}/data/csourceRegistrations/${filename} + ${updated_payload}= Update Value To Json ${payload} $..id ${valid_registration_id} + ${request} ${response}= Create Context Source Registration ${updated_payload} + Check Response Status Code 201 ${response['status']} + + ${fragment}= Load Json From File ${EXECDIR}/data/csourceRegistrations/${fragment_filename} + ${fragment_with_id}= Update Value To Json ${fragment} $..id ${registration_id} + ${response}= Update Context Source Registration ${registration_id} ${fragment_with_id} + Check Response Status Code 400 ${response['status']} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response} + + [Teardown] Delete Context Source Registration ${valid_registration_id} + +Setup Initial Entities + ${valid_registration_id}= Generate Random Entity Id ${registration_id_prefix} + Set Suite Variable ${valid_registration_id} \ No newline at end of file diff --git a/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/005_05.robot b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/005_05.robot new file mode 100644 index 00000000..9ba06b7b --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/005_05.robot @@ -0,0 +1,27 @@ +*** Settings *** +Documentation Check that you cannot update a context source registration if the request body is invalid +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: +${filename}= registration-sample.jsonld +${registration_payload_file_path}= registration-invalid-sample.jsonld + +*** Test Case *** +005_04_Update a context source registration if the request body is invalid + [Documentation] Check that you cannot update a context source registration if the request body is invalid + [Tags] mandatory + ${registration_id}= Generate Random Entity Id ${registration_id_prefix} + ${payload}= Load Json From File ${EXECDIR}/data/csourceRegistrations/${filename} + ${updated_payload}= Update Value To Json ${payload} $..id ${registration_id} + ${request} ${response}= Create Context Source Registration ${updated_payload} + Check Response Status Code 201 ${response['status']} + + ${response}= Update Context Source Registration Using Session ${registration_id} ${registration_payload_file_path} ${CONTENT_TYPE_LD_JSON} + Check Response Status Code ${response} + Check Response Body Type When Using Session Request ${response.json()} ${ERROR_TYPE_BAD_REQUEST_DATA} + Check Response Body Title When Using Session Request ${response.json()} + + [Teardown] Delete Context Source Registration ${registration_id} diff --git a/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot new file mode 100644 index 00000000..2b64dbc4 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot @@ -0,0 +1,23 @@ +*** Settings *** +Documentation Check that you cannot update a context source registration by id if the id is not known to the system +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: +${filename}= registration-sample.jsonld +${registration_payload_file_path}= registration-invalid-sample.jsonld + +*** Test Case *** +006_Update a context source registration by id if the id is not known to the system + [Documentation] Check that you cannot update a context source registration by id if the id is not known to the system + [Tags] mandatory + ${registration_id}= Generate Random Entity Id ${registration_id_prefix} + ${fragment}= Load Json From File ${EXECDIR}/data/csourceRegistrations/${filename} + ${fragment_with_id}= Update Value To Json ${fragment} $..id ${registration_id} + ${response}= Update Context Source Registration ${registration_id} ${fragment_with_id} + Check Response Status Code 400 ${response['status']} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response} + + [Teardown] Delete Context Source Registration ${registration_id} diff --git a/data/csourceRegistrations/registration-different-type-sample.jsonld b/data/csourceRegistrations/registration-different-type-sample.jsonld new file mode 100644 index 00000000..80945e1f --- /dev/null +++ b/data/csourceRegistrations/registration-different-type-sample.jsonld @@ -0,0 +1,43 @@ +{ + "id": "urn:ngsi-ld:ContextSourceRegistration:randomUUID", + "type": "building", + "information": [ + { + "entities": [ + { + "id": "urn:ngsi-ld:Vehicle:A456", + "type": "Vehicle" + } + ], + "propertyNames": ["brandName","speed"], + "relationshipNames": ["isParked"] + }, + { + "entities": [ + { + "idPattern": ".*downtown$", + "type": "OffStreetParking" + }, + { + "idPattern": ".*47$", + "type": "OffStreetParking" + } + ], + "propertyNames": ["availableSpotNumber","totalSpotNumber"], + "relationshipNames": ["isNextToBuilding"] + } + ], + "endpoint": "http://my.csource.org:1026", + "location": { + "type": "Polygon", + "coordinates": [ + [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], + [100.0, 1.0], [100.0, 0.0]] ] + }, + "timestamp": { + "startAt": " 2017-11-29T14:53:15Z" + }, + "@context": [ + "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld" + ] +} \ No newline at end of file diff --git a/resources/ApiUtils.resource b/resources/ApiUtils.resource index 0c4ec21f..4e4ccb2d 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -194,6 +194,23 @@ Create Context Source Registration Using Session Output ${response.json()} [return] ${response} +Update Context Source Registration + [Arguments] ${registration_id} ${fragment} + &{headers}= Create Dictionary Content-Type=application/ld+json + ${response}= PATCH ${CONTEXT_SOURCE_REGISTRATION_ENDPOINT_PATH}/${registration_id} body=${fragment} headers=${headers} + ${request}= Output request + Output response + [return] ${response} + +Update Context Source Registration Using Session + [Arguments] ${registration_id} ${filename} ${content_type} + ${file_content}= Get File ${EXECDIR}/data/csourceRegistrations/${filename} + Create Session OneRequest ${url} + &{headers}= Create Dictionary Content-Type=${content_type} + ${response}= PATCH On Session OneRequest ${CONTEXT_SOURCE_REGISTRATION_ENDPOINT_PATH}/${registration_id} data=${file_content} headers=${headers} expected_status=any + ${request}= Output request + Output response + [return] ${response} Delete Context Source Registration [Arguments] ${registration_id} -- GitLab From f96f99e94766c1f60d57d1bc131462eff68b25ee Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Mon, 25 Jan 2021 17:49:29 +0000 Subject: [PATCH 2/2] fixed minor bug --- .../Registration/UpdateContextSourceRegistration/006.robot | 1 - 1 file changed, 1 deletion(-) diff --git a/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot index 2b64dbc4..952d8c5a 100644 --- a/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot +++ b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot @@ -7,7 +7,6 @@ Resource ${EXECDIR}/resources/JsonUtils.resource *** Variable *** ${registration_id_prefix}= urn:ngsi-ld:Registration: ${filename}= registration-sample.jsonld -${registration_payload_file_path}= registration-invalid-sample.jsonld *** Test Case *** 006_Update a context source registration by id if the id is not known to the system -- GitLab