diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_01.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_01.robot new file mode 100644 index 0000000000000000000000000000000000000000..b416b584a5b989f7d81c9ba2ff82214689171214 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_01.robot @@ -0,0 +1,24 @@ +*** Settings *** +Documentation Check that you can create a context source registration with specific ID and expiration date +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: +${registration_payload_file_path}= csourceRegistrations/registration-with-expiration-sample.jsonld + +*** Test Case *** +Create Context Source Registration With Specific Date Expiration Date + [Documentation] Check that you can create a context source registration with specific ID and expiration date + [Tags] mandatory + ${registration_id}= Generate Random Entity Id ${registration_id_prefix} + + ${payload}= Load Json From File ${EXECDIR}/data/${registration_payload_file_path} + ${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']} + Check Response Headers Containing URI set to ${request['path']}/ ${registration_id} ${response} + + [Teardown] Delete Context Source Registration ${registration_id} diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_02.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_02.robot new file mode 100644 index 0000000000000000000000000000000000000000..61fed06c5a3ae9b82fc9a52dbb3abc8e7637dd2a --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_02.robot @@ -0,0 +1,24 @@ +*** Settings *** +Documentation Check that you can create a context source registration that never expires +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: +${registration_payload_file_path}= csourceRegistrations/registration-sample.jsonld + +*** Test Case *** +Create Context Source Registration That Never Expires + [Documentation] Check that you can create a context source registration that never expires + [Tags] mandatory + ${registration_id}= Generate Random Entity Id ${registration_id_prefix} + + ${payload}= Load Json From File ${EXECDIR}/data/${registration_payload_file_path} + ${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']} + Check Response Headers Containing URI set to ${request['path']}/ ${registration_id} ${response} + + [Teardown] Delete Context Source Registration ${registration_id} diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_03.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_03.robot new file mode 100644 index 0000000000000000000000000000000000000000..bafec59a22fee4dbb47f54053c76c6f629c5fc98 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/001_03.robot @@ -0,0 +1,22 @@ +*** Settings *** +Documentation Check that when creating a context source registration without specifying an ID +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: +${registration_payload_file_path}= csourceRegistrations/registration-no-id-sample.jsonld + +*** Test Case *** +Create Context Source Registration Without A Sprecified ID + [Documentation] Check that when creating a context source registration without specifying an ID + [Tags] mandatory + + ${payload}= Load Json From File ${EXECDIR}/data/${registration_payload_file_path} + ${request} ${response}= Create Context Source Registration ${payload} + Check Response Status Code 201 ${response['status']} + ${registration_id}= Check Response Headers ID Not Empty ${response} + + [Teardown] Delete Context Source Registration ${registration_id} \ No newline at end of file diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/002.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/002.robot new file mode 100644 index 0000000000000000000000000000000000000000..78b751ee05b8fead88d86121698ebdd30d376449 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/002.robot @@ -0,0 +1,30 @@ +*** Settings *** +Documentation Check that you cannot create a context source with invalid content +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Template Create Context Source With Invalid Content + + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: + +*** Test Cases *** FILENAME +002_02_Create a context source registration with a different data structure than CsourRegistration data type csourceRegistrations/registration-invalid-structure-sample.jsonld +002_03_Create a context source registration with a date in the past csourceRegistrations/registration-past-expiration-sample.jsonld + +*** Keywords *** +Create Context Source With Invalid Content + [Arguments] ${filename} + [Documentation] Check that you cannot create a context source with invalid content + [Tags] mandatory + ${registration_id}= Generate Random Entity Id ${registration_id_prefix} + + ${payload}= Load Json From File ${EXECDIR}/data/${filename} + ${updated_payload}= Update Value To Json ${payload} $..id ${registration_id} + ${request} ${response}= Create Context Source Registration ${updated_payload} + Check Response Status Code 400 ${response['status']} + Check Response Headers Containing URI set to ${request['path']}/ ${registration_id} ${response} + + [Teardown] Delete Context Source Registration ${registration_id} diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/002_01.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/002_01.robot new file mode 100644 index 0000000000000000000000000000000000000000..b89f36b0699b4e5260c817da8c27be80b903bb5b --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/002_01.robot @@ -0,0 +1,22 @@ +*** Settings *** +Documentation Create a context source registration with invalid JSON file +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: +${registration_payload_file_path}= registration-invalid-sample.jsonld + +*** Test Cases *** +Create a context source registration with invalid JSON file + [Documentation] Create a context source registration with invalid JSON file + [Tags] mandatory + ${registration_id}= Generate Random Entity Id ${registration_id_prefix} + + ${response}= Create Context Source Registration Using Session ${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 Entity by Id Returning Response ${registration_id} \ No newline at end of file diff --git a/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/003.robot b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/003.robot new file mode 100644 index 0000000000000000000000000000000000000000..8eabac9ed64d6c10e858edf8a830cd8d00cf4697 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/Registration/CreateContextSourceRegistration/003.robot @@ -0,0 +1,26 @@ +*** Settings *** +Documentation Check that you cannot create a context source registration that already exists +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + + +*** Variable *** +${registration_id_prefix}= urn:ngsi-ld:Registration: +${filename}= csourceRegistrations/registration-sample.jsonld + +*** Test Cases *** +Create a context source registration that already exists + [Documentation] Check that you cannot create a context source registration that already exists + [Tags] mandatory + ${registration_id}= Generate Random Entity Id ${registration_id_prefix} + ${payload}= Load Json From File ${EXECDIR}/data/${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']} + + ${request} ${response}= Create Context Source Registration ${updated_payload} + Check Response Status Code 409 ${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-invalid-sample.jsonld b/data/csourceRegistrations/registration-invalid-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..b0ffbb3e4fc11b8f1961f777e45a413555b89407 --- /dev/null +++ b/data/csourceRegistrations/registration-invalid-sample.jsonld @@ -0,0 +1,43 @@ +{ + "id": "urn:ngsi-ld:ContextSourceRegistration:randomUUID",, + "type": "ContextSourceRegistration", + "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/data/csourceRegistrations/registration-invalid-structure-sample.jsonld b/data/csourceRegistrations/registration-invalid-structure-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..cc6bf6c3f421229508708018cf29d8224ab0dd31 --- /dev/null +++ b/data/csourceRegistrations/registration-invalid-structure-sample.jsonld @@ -0,0 +1,7 @@ +{ + "id": "urn:ngsi-ld:ContextSourceRegistration:randomUUID", + "type": "ContextSourceRegistration", + "@context": [ + "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.3.jsonld" + ] +} \ No newline at end of file diff --git a/data/csourceRegistrations/registration-no-id-sample.jsonld b/data/csourceRegistrations/registration-no-id-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..f2abff253935a94c8d68942460c1a7b20570d331 --- /dev/null +++ b/data/csourceRegistrations/registration-no-id-sample.jsonld @@ -0,0 +1,42 @@ +{ + "type": "ContextSourceRegistration", + "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/data/csourceRegistrations/registration-past-expiration-sample.jsonld b/data/csourceRegistrations/registration-past-expiration-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..f9f762640537e2e05a7c36b74ea6cba27813693d --- /dev/null +++ b/data/csourceRegistrations/registration-past-expiration-sample.jsonld @@ -0,0 +1,44 @@ +{ + "id": "urn:ngsi-ld:ContextSourceRegistration:randomUUID", + "type": "ContextSourceRegistration", + "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" + }, + "expiresAt": " 2018-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/data/csourceRegistrations/registration-sample.jsonld b/data/csourceRegistrations/registration-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..956aeda47b248be59b00971bbcb9d060c775467f --- /dev/null +++ b/data/csourceRegistrations/registration-sample.jsonld @@ -0,0 +1,43 @@ +{ + "id": "urn:ngsi-ld:ContextSourceRegistration:randomUUID", + "type": "ContextSourceRegistration", + "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/data/csourceRegistrations/registration-with-expiration-sample.jsonld b/data/csourceRegistrations/registration-with-expiration-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..bb9ae21083d30ec6d8c45b136a855cb0ce3c53c4 --- /dev/null +++ b/data/csourceRegistrations/registration-with-expiration-sample.jsonld @@ -0,0 +1,44 @@ +{ + "id": "urn:ngsi-ld:ContextSourceRegistration:randomUUID", + "type": "ContextSourceRegistration", + "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" + }, + "expiresAt": " 2025-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 0d06d1e89591b36e532c8946edfb0cfd99d7e19c..240a23e304e13bbd856986ce82166e2ec1c4a314 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -16,6 +16,7 @@ ${ENTITIES_ENDPOINT_PATH} entities/ ${ENTITY_OPERATIONS_QUERY_ENDPOINT_PATH} entityOperations/query ${TEMPORAL_ENTITIES_ENDPOINT_PATH} temporal/entities ${TEMPORAL_ENTITY_OPERATIONS_ENDPOINT_PATH} temporal/entityOperations +${CONTEXT_SOURCE_REGISTRATION_ENDPOINT_PATH} csourceRegistrations ${CONTEXT_SOURCE_REGISTRATION_SUBSCRIPTION_ENDPOINT_PATH} csourceSubscriptions ${CONTENT_TYPE_JSON} application/json @@ -176,6 +177,31 @@ Partial Update Entity Attributes Output response [return] ${response} +Create Context Source Registration + [Arguments] ${payload} + &{headers}= Create Dictionary Content-Type=application/ld+json + ${response}= POST ${CONTEXT_SOURCE_REGISTRATION_ENDPOINT_PATH} body=${payload} headers=${headers} + ${request}= Output request + Output response + [return] ${request} ${response} + +Create Context Source Registration Using Session + [Arguments] ${filename} ${content_type} + ${file_content}= Get File ${EXECDIR}/data/csourceRegistrations/${filename} + Create Session OneRequest ${url} + &{headers}= Create Dictionary Content-Type=${content_type} + ${response}= POST On Session OneRequest ${CONTEXT_SOURCE_REGISTRATION_ENDPOINT_PATH} data=${file_content} headers=${headers} expected_status=any + Output ${response.json()} + [return] ${response} + + +Delete Context Source Registration + [Arguments] ${registration_id} + ${response}= DELETE ${CONTEXT_SOURCE_REGISTRATION_ENDPOINT_PATH}/${registration_id} + Output request + Output response + [return] ${response} + Create Entity [Arguments] ${filename} ${entity_id} ${entity_payload}= Load Json From File ${EXECDIR}/data/entities/${filename} diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index b368ff369185fab7296850aa01c2cc0f063e6c37..6849b177fe9a03c2cd42ab03c28da00c25664eed 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -37,6 +37,12 @@ Check Response Headers Containing URI set to [Arguments] ${expected_path} ${expected_entity_id} ${response} Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['location']} ignore_order=True +Check Response Headers ID Not Empty + [Arguments] ${response} + ${id}= Fetch From Right ${response['headers']['location']} / + Should Not Be Empty ${id} + [return] ${id} + Check Response Body Containing an Attribute set to [Arguments] ${expected_attribute_name} Should Not Be Empty ${response['body']['${expected_attribute_name}']}