diff --git a/.gitignore b/.gitignore index 3e9e56a4f1159b2ac98cad93024fd178f9e3b606..438bfca99fa85337a380cc00f64aa30d78785490 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ resources/__pycache__ results *.pyc +*.http \ No newline at end of file diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001.robot new file mode 100644 index 0000000000000000000000000000000000000000..9ce9d5cf3ec1545b85b8f71ec270e2e04326e67c --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001.robot @@ -0,0 +1,33 @@ +*** Settings *** +Documentation Check that you can create an entity +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Test Template Create Entity Scenarios + +*** Variable *** +${building_id_prefix}= urn:ngsi-ld:Building: + +*** Test Cases *** FILENAME CONTENT_TYPE +001_01_MinimalEntity building-minimal-without-context-sample.jsonld application/json +001_02_EntityWithSimpleProperties building-simple-attributes-sample.jsonld application/ld+json +001_03_EntityWithRelationshipsProperties building-relationship-of-property-sample.jsonld application/ld+json +#001_04_EntityWithNoContext building-minimal-without-context-sample.jsonld application/ld+json +001_05_EntityWithLocationAttribute building-location-attribute.jsonld application/ld+json + + + +*** Keywords *** +Create Entity Scenarios + [Arguments] ${filename} ${content_type} + [Documentation] Check that you can create an entity + [Tags] mandatory entityOperations + + ${entity_id}= Generate Random Entity Id ${building_id_prefix} + + Create Entity Selecting Content Type ${filename} ${entity_id} ${content_type} + Check Response Status Code Set To 201 + Check Response Headers Containing URI set to ${request['path']} ${entity_id} + + [Teardown] Delete Entity by Id ${entity_id} \ No newline at end of file diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/002.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/002.robot new file mode 100644 index 0000000000000000000000000000000000000000..8885ef5df505fb9024d196dc844be8e70585720f --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/002.robot @@ -0,0 +1,22 @@ +*** Settings *** +Documentation Check that you cannot create an entity with an invalid request +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource + +Test Template Create Entity With Invalid Request Scenarios + +*** Test Cases *** FILENAME PROBLEM_TYPE EXPECTED_CODE +002_01_InvalidJson invalid-json-sample.jsonld ${ERROR_TYPE_INVALID_REQUEST} 406 +002_02_EmptyJson empty-sample.jsonld ${ERROR_TYPE_BAD_REQUEST_DATA} 400 + +*** Keywords *** +Create Entity With Invalid Request Scenarios + [Arguments] ${filename} ${problem_type} ${expected_code} + [Documentation] Check that you cannot create an entity with an invalid request + [Tags] mandatory + + Request Entity From File ${filename} + + Check RL Response Status Code Set To Expected Code ${expected_code} + Check RL Response Body Containing ProblemDetails Element Containing Type Element set to ${response} ${problem_type} + Check RL Response Body Containing ProblemDetails Element Containing Title Element ${response} \ No newline at end of file diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/003.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/003.robot new file mode 100644 index 0000000000000000000000000000000000000000..973171d83cf38459cea74ea3f4de4cb0b8a92ddc --- /dev/null +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/003.robot @@ -0,0 +1,28 @@ +*** Settings *** +Documentation Check that you cannot create an entity with and existing id +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Variable *** +${building_id_prefix}= urn:ngsi-ld:Building: +${expected_error_message}= Already exists. +${filename}= building-minimal-sample.jsonld +${content_type}= application/ld+json + +*** Test Case *** +Create one valid entity and one invalid entity + [Documentation] Check that you cannot create an entity with and existing id + [Tags] mandatory + + ${entity_id}= Generate Random Entity Id ${building_id_prefix} + Create Entity Selecting Content Type ${filename} ${entity_id} ${content_type} + Check Response Status Code Set To 201 + + #creating entity with the same id + Create Entity Selecting Content Type ${filename} ${entity_id} ${content_type} + Check Response Status Code Set To 409 + Check Response Body Details Containing Information Error ${expected_error_message} + + [Teardown] Delete Entity by Id ${entity_id} + diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/AlreadyExists.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/AlreadyExists.robot deleted file mode 100644 index ef8a80505ae638dabafec371aad4c6156b5840a1..0000000000000000000000000000000000000000 --- a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/AlreadyExists.robot +++ /dev/null @@ -1,50 +0,0 @@ -*** Settings *** -Documentation Check that the IUT refuses to create an entity if one exists with the same identifier -Variables ../../../../../../resources/variables.py -#Resource ../../../../../../resources/ApiUtils.resource -Library REST ${url} -Library JSONSchemaLibrary ${EXECDIR}/schemas -Library BuiltIn - -#Suite Setup Create Entity building-minimal.jsonld -#Suite Teardown Delete Entity by Id urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9 - -*** Variable *** -${endpoint}= entities - -*** Test Case *** -AlreadyExists - [Documentation] Check that the IUT refuses to create an entity if one exists with the same identifier - [Tags] mandatory - Create Entity building-minimal.jsonld - Create Entity building-minimal.jsonld - Check HTTP Status Code Is 409 - Check HTTP Response Body Json Schema Is error_response - Delete Entity by Id urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9 - -*** Keywords *** -Create Entity - [Arguments] ${filename} - &{headers}= Create Dictionary Content-Type=application/ld+json - ${response}= POST ${endpoint} body=${EXECDIR}/data/entities/${filename} headers=${headers} - Output request - Output response - Set Test Variable ${response} - -Check HTTP Status Code Is - [Arguments] ${status} - ${response_status}= convert to string ${response['status']} - Should Be Equal ${response_status} ${status} - -Check HTTP Response Body Json Schema Is - [Arguments] ${input} - Should Contain ${response['headers']['Content-Type']} application/json - ${schema}= Catenate SEPARATOR= ${input} .schema.json - Validate Json ${schema} ${response['body']} - Log Json Schema Validation OK - -Delete Entity by Id - [Arguments] ${id} - ${response}= DELETE ${endpoint}/${id} - Output request - Output response \ No newline at end of file diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/SuccessCases-datadriven.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/SuccessCases-datadriven.robot deleted file mode 100644 index d4a31dd4fd3ea9b2174240ccb0b1662ca7d13be5..0000000000000000000000000000000000000000 --- a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/SuccessCases-datadriven.robot +++ /dev/null @@ -1,41 +0,0 @@ -*** Settings *** -Documentation Check that the IUT accepts the creation of an entity -Variables ../../../../../../resources/variables.py -Library REST ${url} -Library JSONSchemaLibrary ${EXECDIR}/schemas - -Test Template Create Entity Scenarios - -*** Variable *** -${endpoint}= entities -${id}= urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9 - -*** Test Cases *** FILENAME -SuccessCases_MinimalEntity building-minimal.jsonld -SuccessCases_EntityWithSimpleProperties building-simple-attributes.jsonld - -*** Keywords *** -Create Entity Scenarios - [Arguments] ${filename} - Create Entity ${filename} - Check HTTP Status Code Is 201 - Delete Entity by Id ${id} - -Create Entity - [Arguments] ${filename} - &{headers}= Create Dictionary Content-Type=application/ld+json - ${response}= POST ${endpoint} body=${EXECDIR}/data/entities/${filename} headers=${headers} - Output request - Output response - Set Test Variable ${response} - -Check HTTP Status Code Is - [Arguments] ${status} - ${response_status}= convert to string ${response['status']} - Should Be Equal ${response_status} ${status} - -Delete Entity by Id - [Arguments] ${id} - ${response}= DELETE ${endpoint}/${id} - Output request - Output response \ No newline at end of file diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/SuccessCases.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/SuccessCases.robot deleted file mode 100644 index 47474e20b49f83a646af5aa9835e6fe5495aaa30..0000000000000000000000000000000000000000 --- a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/SuccessCases.robot +++ /dev/null @@ -1,44 +0,0 @@ -*** Settings *** -Documentation Check that the IUT accepts the creation of an entity -Variables ../../../../../../resources/variables.py -#Resource ../../../../../../resources/ApiUtils.resource -Library REST ${url} - -*** Variable *** -${endpoint}= entities -${id}= urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9 - -*** Test Case *** -SuccessCases_MinimalEntity - [Documentation] Create an entity with a JSON-LD payload containing the minimal information - [Tags] mandatory - Create Entity building-minimal.jsonld - Check HTTP Status Code Is 201 - Delete Entity by Id ${id} - -SuccessCases_EntityWithSimpleProperties - [Documentation] Create an entity with a JSON-LD payload containing only simple properties - Create Entity building-simple-attributes.jsonld - Check HTTP Status Code Is 201 - Delete Entity by Id ${id} - - -*** Keywords *** -Create Entity - [Arguments] ${filename} - &{headers}= Create Dictionary Content-Type=application/ld+json - ${response}= POST ${endpoint} body=${EXECDIR}/data/entities/${filename} headers=${headers} - Output request - Output response - Set Test Variable ${response} - -Check HTTP Status Code Is - [Arguments] ${status} - ${response_status}= convert to string ${response['status']} - Should Be Equal ${response_status} ${status} - -Delete Entity by Id - [Arguments] ${id} - ${response}= DELETE ${endpoint}/${id} - Output request - Output response diff --git a/data/entities/building-minimal-without-context-sample.jsonld b/data/entities/building-minimal-without-context-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..78ff356510e1e04eaebead06bdd868d98d53a0b7 --- /dev/null +++ b/data/entities/building-minimal-without-context-sample.jsonld @@ -0,0 +1,4 @@ +{ + "id": "urn:ngsi-ld:Building:randomUUID", + "type": "Building" +} \ No newline at end of file diff --git a/data/entities/empty-sample.jsonld b/data/entities/empty-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..0637a088a01e8ddab3bf3fa98dbe804cbde1a0dc --- /dev/null +++ b/data/entities/empty-sample.jsonld @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/data/entities/invalid-json-sample.jsonld b/data/entities/invalid-json-sample.jsonld new file mode 100644 index 0000000000000000000000000000000000000000..dcbdb010b6149a81bca30da6d7af54953560ba81 --- /dev/null +++ b/data/entities/invalid-json-sample.jsonld @@ -0,0 +1,10 @@ +[ + { + "id":"urn:ngsi-ld:Building:randomUUID",, + "type":"Building", + "@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 50407fe7ff822f4865c9eb058b08265b8feee8f6..9bd4b663ce3e19d72e33dbb27575ffb4b2d28357 100644 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -12,15 +12,15 @@ ${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 +${ENTITIES_ENDPOINT_PATH} entities/ ${TEMPORAL_ENTITIES_ENDPOINT_PATH} temporal/entities ${TEMPORAL_ENTITY_OPERATIONS_ENDPOINT_PATH} temporal/entityOperations ${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 -${ERROR_TYPE_INVALID_REQUEST} https://uri.etsi.org/ngsi-ld/errors/InvalidRequest +${ERROR_TYPE_BAD_REQUEST_DATA} http://uri.etsi.org/ngsi-ld/errors/BadRequestData +${ERROR_TYPE_INVALID_REQUEST} http://uri.etsi.org/ngsi-ld/errors/InvalidRequest ${ERROR_TYPE_RESOURCE_NOT_FOUND} https://uri.etsi.org/ngsi-ld/errors/ResourceNotFound ${response} @@ -52,7 +52,7 @@ Api DEL request Delete Entity by Id [Arguments] ${id} - ${response}= DELETE ${ENTITIES_ENDPOINT_PATH}/${id} + ${response}= DELETE ${ENTITIES_ENDPOINT_PATH}${id} Output request Output response @@ -64,7 +64,20 @@ Retrieve Entity by Id ${response}= GET ${ENTITIES_ENDPOINT_PATH}/${id} headers=${headers} Output request Output response - Set Test Variable ${response} + Set Test Variable ${response} + +Create Entity Selecting Content Type + [Arguments] ${filename} ${entity_id} ${content_type} + ${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=${content_type} + ${response}= POST ${ENTITIES_ENDPOINT_PATH} body=${entity} headers=${headers} + Output request + Output response + Set Test Variable ${response} + ${request}= Output request + Set Test Variable ${request} Create Entity [Arguments] ${filename} ${entity_id} @@ -110,6 +123,14 @@ Batch Delete Entities Output response Run Keyword If not ${teardown} Set Test Variable ${response} +Request Entity From File + [Arguments] ${filename} + ${file_content}= Get File ${EXECDIR}/data/entities/${filename} + Create Session OneRequest ${url} + &{headers}= Create Dictionary Content-Type=application/ld+json + ${response}= POST Request OneRequest ${ENTITIES_ENDPOINT_PATH} data=${file_content} headers=${headers} + Set Test Variable ${response} + Batch Request Entities From File [Arguments] ${batchOperation} ${filename} ${file_content}= Get File ${EXECDIR}/data/entities/${filename} diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index ef5d6446c20dffbeb3b9d78f68891b2239dbd3ae..52d195074def0d40f8f5719caf91a37783cbdd03 100644 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -10,6 +10,10 @@ Check Response Status Code Set To ${response_status}= convert to string ${response['status']} Should Be Equal ${response_status} ${expected_status} +Check RL Response Status Code Set To Expected Code + [Arguments] ${expected_status} + Status Should Be ${expected_status} ${response} + Check RL Response Status Code Set To [Arguments] ${expected_status} Status Should Be ${expected_status} ${response} @@ -18,10 +22,19 @@ 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 Headers Containing URI set to +# upon success, the http response shall include a loication http header that countains the uri of the created entity resource + [Arguments] ${expected_path} ${expected_entity_id} + Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['location']} 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 Details Containing Information Error + [Arguments] ${expected_error_message} + Should be Equal ${expected_error_message} ${response['body']['details']} + Check Response Body Containing Batch Operation Result [Arguments] ${expected_batch_operation_result} @{expected_successful_entities_ids}= Get From Dictionary ${expected_batch_operation_result} success diff --git a/resources/variables.py b/resources/variables.py index 1917f8e89d7fb7d86468fe19bd7a0e674cab5fad..88e1f536955c150a7437b12fde7f9f48819e492a 100644 --- a/resources/variables.py +++ b/resources/variables.py @@ -1,6 +1,7 @@ def get_variables(arg=None): variables = { - 'url': 'http://10.5.1.214:9090/ngsi-ld/v1', + 'url': 'http://localhost:9090/ngsi-ld/v1', 'ngsild_test_suite_context': 'https://raw.githubusercontent.com/easy-global-market/ngsild-api-data-models/feature/add-json-ld-context-for-ngsi-ld-test-suite/ngsi-ld-test-suite/ngsi-ld-test-suite-context.jsonld' } return variables + \ No newline at end of file