diff --git a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/001.robot b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/001.robot new file mode 100644 index 0000000000000000000000000000000000000000..8a2543723265c8b9101bf28f14799a4fecd0f2ff --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/001.robot @@ -0,0 +1,32 @@ +*** Settings *** +Documentation Check that you can append entity attributes +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Template Append Attributes + +*** Variable *** +${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: + +*** Test Cases *** STATUS_CODE OVERWRITE FILENAME FRAGMENT_FILENAME EXPECTATION_FILENAME +001_01_Append entity attributes 204 ${EMPTY} vehicle-datasetid-attributes-sample.jsonld vehicle-fragment-datasetid-sample-01-02.jsonld vehicle-attributes-sample-append-expectation-01.jsonld +001_02_Append entity attributes 207 noOverwrite vehicle-datasetid-attributes-sample.jsonld vehicle-fragment-datasetid-sample-01-02.jsonld vehicle-attributes-sample-append-expectation-02.jsonld +001_03_Append entity attributes 204 ${EMPTY} vehicle-datasetid-attributes-sample.jsonld vehicle-fragment-datasetid-sample-03-04.jsonld vehicle-attributes-sample-append-expectation-03-04.jsonld +001_04_Append entity attributes 204 noOverwrite vehicle-datasetid-attributes-sample.jsonld vehicle-fragment-datasetid-sample-03-04.jsonld vehicle-attributes-sample-append-expectation-03-04.jsonld + +*** Keywords *** +Append Attributes + [Arguments] ${status_code} ${overwrite} ${filename} ${fragment_filename} ${expectation_filename} + [Documentation] Check that you can append entity attributes + [Tags] mandatory failing + + ${entity_id}= Generate Random Entity Id ${vehicle_id_prefix} + ${request} ${response}= Create Entity Selecting Content Type ${filename} ${entity_id} ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${response['status']} + + ${response}= Append Entity Attributes ${entity_id} ${fragment_filename} ${CONTENT_TYPE_LD_JSON} ${overwrite} + Check Response Status Code ${status_code} ${response['status']} + Check Response Body Containing Entity element ${expectation_filename} ${entity_id} ${response['body']} + + [Teardown] Delete Entity by Id Returning Response ${entity_id} \ No newline at end of file diff --git a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/002.robot b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/002.robot new file mode 100644 index 0000000000000000000000000000000000000000..017334121a55b93491f8ad6d273e4d42a952e83c --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/002.robot @@ -0,0 +1,33 @@ +*** Settings *** +Documentation Check that you cannot append entity attributes with invalid/missing id or invalid request body +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Template Append Attributes + +*** Variable *** +${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: +${filename}= vehicle-datasetid-attributes-sample.jsonld +${fragment_filename}= vehicle-fragment-datasetid-sample-01-02.jsonld + +*** Test Cases *** STATUS_CODE ENTITY_INVALID_ID +002_01_Append entity attributes if the entity Id is not present 400 ${EMPTY} +002_02_Append entity attributes if the Entity Id is not a valid URI 400 thisisaninvaliduri + +*** Keywords *** +Append Attributes + [Arguments] ${status_code} ${entity_invalid_id} + [Documentation] Check that you cannot append entity attributes with invalid/missing id or invalid request body + [Tags] mandatory failing + + ${entity_id}= Generate Random Entity Id ${vehicle_id_prefix} + ${request} ${response}= Create Entity Selecting Content Type ${filename} ${entity_id} ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${response['status']} + + ${response}= Append Entity Attributes ${entity_invalid_id} ${fragment_filename} ${CONTENT_TYPE_LD_JSON} ${EMPTY} + Check Response Status Code ${status_code} ${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} + + [Teardown] Delete Entity by Id Returning Response ${entity_id} \ No newline at end of file diff --git a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/002_03.robot b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/002_03.robot new file mode 100644 index 0000000000000000000000000000000000000000..3124540f26cc93ece2fbb78852535a306ba153cd --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/002_03.robot @@ -0,0 +1,26 @@ +*** Settings *** +Documentation Check that you cannot append entity attributes with invalid entity fragments +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Variable *** +${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: +${filename}= vehicle-datasetid-attributes-sample.jsonld +${fragment_filename}= invalid-vehicle-fragment-datasetid-sample.jsonld + +*** Test Cases *** +Append entity attributes with invalid entity fragments + [Documentation] Check that you cannot append entity attributes with invalid entity fragments + [Tags] mandatory failing + + ${entity_id}= Generate Random Entity Id ${vehicle_id_prefix} + ${request} ${response}= Create Entity Selecting Content Type ${filename} ${entity_id} ${CONTENT_TYPE_LD_JSON} + Check Response Status Code 201 ${response['status']} + + ${response}= Append Entity Attributes Using Session ${entity_id} ${fragment_filename} ${CONTENT_TYPE_LD_JSON} ${EMPTY} + Check Response Status Code 400 ${response} + 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} + + [Teardown] Delete Entity by Id Returning Response ${entity_id} \ No newline at end of file diff --git a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/003.robot b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/003.robot new file mode 100644 index 0000000000000000000000000000000000000000..49e3a993b7b28fdb3bfacda50999c92b62aaba6d --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/003.robot @@ -0,0 +1,23 @@ +*** Settings *** +Documentation Check that you cannot append entity attributes if the entity id or attributes are not known to the system +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Variable *** +${vehicle_id_prefix}= urn:ngsi-ld:Vehicle: +${fragment_filename}= vehicle-fragment-datasetid-sample-01-02.jsonld + +*** Test Cases *** +003_Append entity attributes when the entity id is not known to the system + [Documentation] Check that you cannot append entity attributes if the entity id or attributes are not known to the system + [Tags] mandatory failing + + ${entity_id}= Generate Random Entity Id ${vehicle_id_prefix} + ${response}= Append Entity Attributes ${entity_id} ${fragment_filename} ${CONTENT_TYPE_LD_JSON} ${EMPTY} + Check Response Status Code 404 ${response['status']} + Check Response Body Containing ProblemDetails Element Containing Type Element set to ${response} ${ERROR_TYPE_RESOURCE_NOT_FOUND} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response} + +*** Keywords *** + [Teardown] Delete Entity by Id Returning Response ${entity_id} \ No newline at end of file diff --git a/data/entities/expectations/vehicle-attributes-sample-append-expectation-01.jsonld b/data/entities/expectations/vehicle-attributes-sample-append-expectation-01.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..60bd3de9c0c0bdbb7953cc4986276696128109cc --- /dev/null +++ b/data/entities/expectations/vehicle-attributes-sample-append-expectation-01.jsonld @@ -0,0 +1,39 @@ +{ + "id": "urn:ngsi-ld:Vehicle:randomUUID", + "type": "Vehicle", + "brandName": { + "type": "Property", + "value": "BMW" + }, + "isParked": { + "type": "Relationship", + "object": "urn:ngsi-ld:OffStreetParking:Downtown1", + "observedAt": "2017-07-29T12:00:04Z", + "providedBy": { + "type": "Relationship", + "object": "urn:ngsi-ld:Person:Bob" + } + }, + "speed": [{ + "type": "Property", + "value": 56, + "source": { + "type": "Property", + "value": "Speedometer" + }, + "datasetId": "urn:ngsi-ld:Property:speedometerA4567-speed" + }, + { + "type": "Property", + "value": 54.5, + "source": { + "type": "Property", + "value": "GPS" + }, + "datasetId": "urn:ngsi-ld:Property:gpsBxyz123-speed" + }], + "@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/vehicle-attributes-sample-append-expectation-02.jsonld b/data/entities/expectations/vehicle-attributes-sample-append-expectation-02.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..e29f48752c622b56deda792ae02af3a616d636bc --- /dev/null +++ b/data/entities/expectations/vehicle-attributes-sample-append-expectation-02.jsonld @@ -0,0 +1,30 @@ +{ + "id": "urn:ngsi-ld:Vehicle:randomUUID", + "type": "Vehicle", + "brandName": { + "type": "Property", + "value": "Mercedes" + }, + "isParked": { + "type": "Relationship", + "object": "urn:ngsi-ld:OffStreetParking:Downtown1", + "observedAt": "2017-07-29T12:00:04Z", + "providedBy": { + "type": "Relationship", + "object": "urn:ngsi-ld:Person:Bob" + } + }, + "speed": { + "type": "Property", + "value": 56, + "source": { + "type": "Property", + "value": "Speedometer" + }, + "datasetId": "urn:ngsi-ld:Property:speedometerA4567-speed" + }, + "@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/vehicle-attributes-sample-append-expectation-03-04.jsonld b/data/entities/expectations/vehicle-attributes-sample-append-expectation-03-04.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..e29f48752c622b56deda792ae02af3a616d636bc --- /dev/null +++ b/data/entities/expectations/vehicle-attributes-sample-append-expectation-03-04.jsonld @@ -0,0 +1,30 @@ +{ + "id": "urn:ngsi-ld:Vehicle:randomUUID", + "type": "Vehicle", + "brandName": { + "type": "Property", + "value": "Mercedes" + }, + "isParked": { + "type": "Relationship", + "object": "urn:ngsi-ld:OffStreetParking:Downtown1", + "observedAt": "2017-07-29T12:00:04Z", + "providedBy": { + "type": "Relationship", + "object": "urn:ngsi-ld:Person:Bob" + } + }, + "speed": { + "type": "Property", + "value": 56, + "source": { + "type": "Property", + "value": "Speedometer" + }, + "datasetId": "urn:ngsi-ld:Property:speedometerA4567-speed" + }, + "@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/fragmentEntities/invalid-vehicle-fragment-datasetid-sample.jsonld b/data/entities/fragmentEntities/invalid-vehicle-fragment-datasetid-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..c4a970b30ad4d1042f4e92992899d6ebe91cbf7f --- /dev/null +++ b/data/entities/fragmentEntities/invalid-vehicle-fragment-datasetid-sample.jsonld @@ -0,0 +1,19 @@ +{ + "speed": { + "type": "Property",, + "value": 56, + "source": { + "type": "Property", + "value": "Speedometer" + }, + "datasetId": "urn:ngsi-ld:Property:speedometerA4567-speed2" + }, + "brandName": { + "type": "Property", + "value": "BMW" + }, + "@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/fragmentEntities/vehicle-fragment-datasetid-sample-01-02.jsonld b/data/entities/fragmentEntities/vehicle-fragment-datasetid-sample-01-02.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..3bc230138b9ead06acb15b92b8c55b2d629b5280 --- /dev/null +++ b/data/entities/fragmentEntities/vehicle-fragment-datasetid-sample-01-02.jsonld @@ -0,0 +1,19 @@ +{ + "speed": { + "type": "Property", + "value": 56, + "source": { + "type": "Property", + "value": "Speedometer" + }, + "datasetId": "urn:ngsi-ld:Property:speedometerA4567-speed2" + }, + "brandName": { + "type": "Property", + "value": "BMW" + }, + "@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/fragmentEntities/vehicle-fragment-datasetid-sample-03-04.jsonld b/data/entities/fragmentEntities/vehicle-fragment-datasetid-sample-03-04.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..4aa9726c8607bda9e9f91efc4a22a4597fc89b74 --- /dev/null +++ b/data/entities/fragmentEntities/vehicle-fragment-datasetid-sample-03-04.jsonld @@ -0,0 +1,19 @@ +{ + "speed": { + "type": "Property", + "value": 56, + "source": { + "type": "Property", + "value": "Speedometer" + }, + "datasetId": "urn:ngsi-ld:Property:speedometerA4567-speed" + }, + "brandName": { + "type": "Property", + "value": "BMW" + }, + "@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/vehicle-datasetid-attributes-sample.jsonld b/data/entities/vehicle-datasetid-attributes-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..1654928a99c4c150119165e2830417ce70ed52fa --- /dev/null +++ b/data/entities/vehicle-datasetid-attributes-sample.jsonld @@ -0,0 +1,39 @@ +{ + "id": "urn:ngsi-ld:Vehicle:randomUUID", + "type": "Vehicle", + "brandName": { + "type": "Property", + "value": "Mercedes" + }, + "isParked": { + "type": "Relationship", + "object": "urn:ngsi-ld:OffStreetParking:Downtown1", + "observedAt": "2017-07-29T12:00:04Z", + "providedBy": { + "type": "Relationship", + "object": "urn:ngsi-ld:Person:Bob" + } + }, + "speed": [{ + "type": "Property", + "value": 55, + "source": { + "type": "Property", + "value": "Speedometer" + }, + "datasetId": "urn:ngsi-ld:Property:speedometerA4567-speed" + }, + { + "type": "Property", + "value": 54.5, + "source": { + "type": "Property", + "value": "GPS" + }, + "datasetId": "urn:ngsi-ld:Property:gpsBxyz123-speed" + }], + "@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/resources/ApiUtils.resource b/resources/ApiUtils.resource index 4a2621c04bc93a8258503972f53094465c520ed1..6ead6b3672e7f797914a9feadb39d02908a89a95 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -118,7 +118,7 @@ Query Entities Via POST Run Keyword If ${attrs_length}>0 Set To Dictionary ${params} attrs=${attrs} Run Keyword If '${entity_id_pattern}'!='' Set To Dictionary ${params} idPattern=${entity_id_pattern} Run Keyword If '${geoproperty}'!='' Set To Dictionary ${params} geoproperty=${geoproperty} - ${response}= POST ${ENTITY_OPERATIONS_QUERY_ENDPOINT_PATH} query=${params} headers=${headers} + ${response}= POST ${ENTITY_OPERATIONS_QUERY_ENDPOINT_PATH} query=${params} headers=${headers} Output request Output response [return] ${response} @@ -143,11 +143,28 @@ Create Entity Selecting Content Type Output response [return] ${request} ${response} +Append Entity Attributes + [Arguments] ${id} ${fragment_filename} ${content_type} ${options} + &{headers}= Create Dictionary Content-Type=${content_type} + ${fragment_payload}= Load Json From File ${EXECDIR}/data/entities/fragmentEntities/${fragment_filename} + ${response}= POST ${ENTITIES_ENDPOINT_PATH}${id}/attrs/?options=${options} body=${fragment_payload} headers=${headers} + Output request + Output response + [return] ${response} + +Append Entity Attributes Using Session + [Arguments] ${id} ${filename} ${content_type} ${options} + ${file_content}= Get File ${EXECDIR}/data/entities/fragmentEntities/${fragment_filename} + Create Session OneRequest ${url} + &{headers}= Create Dictionary Content-Type=${content_type} + ${response}= POST On Session OneRequest ${ENTITIES_ENDPOINT_PATH}${id}/attrs params=options=${options} data=${file_content} headers=${headers} expected_status=any + Output ${response.json()} + [return] ${response} + Create Entity [Arguments] ${filename} ${entity_id} ${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=application/ld+json ${response}= POST ${ENTITIES_ENDPOINT_PATH} body=${entity} headers=${headers} Output request diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 1b7cf8acc8ff82653d923c5710bdd92d80f627cc..6db6f83a1e284db68ba7843a50d037e8ada12fdb 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -98,12 +98,13 @@ Check Response Body Containing ProblemDetails Element Containing Title Element Check RL Response Body Containing ProblemDetails Element Containing Type Element set to [Arguments] ${response} ${type} - ${json_response_body}= To Json ${response.content} + ${json_response_body}= Set Variable ${response.json()} + Should Be Equal ${json_response_body['type']} ${type} Check RL Response Body Containing ProblemDetails Element Containing Title Element [Arguments] ${response} - ${json_response_body}= To Json ${response.content} + ${json_response_body}= Set Variable ${response.json()} Should Not Be Empty ${json_response_body['title']} Assert response status code