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 0000000000000000000000000000000000000000..a7aa85cdcdc910b737ca604b578b1a6f9585bc71 --- /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 0000000000000000000000000000000000000000..265f1d82ef2f2dd9ccd7856300ad42c45807ff73 --- /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 0000000000000000000000000000000000000000..9ba06b7bd24334dd4adc287e25df308c3f4a16fe --- /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 0000000000000000000000000000000000000000..952d8c5a74c7115111780a6af18817c552b0cd98 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/006.robot @@ -0,0 +1,22 @@ +*** 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 + +*** 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 0000000000000000000000000000000000000000..80945e1f7ab256cbdbff766a85ec958d1b890698 --- /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 0c4ec21f750aaf49ac1a3bae5e9829ae158ab81d..4e4ccb2db2ae44fe8556981d613a5ea2cf627ab0 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}