*** Settings ***
Documentation Query entities with Entity Type Selection Language.
Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
Resource ${EXECDIR}/resources/AssertionUtils.resource
Resource ${EXECDIR}/resources/JsonUtils.resource
Suite Setup Setup Initial Entities
Suite Teardown Delete Initial Entities
Test Template Query entities with multiple types using Entity Type Selection Language
*** Variables ***
${entity_id_prefix} urn:ngsi-ld:MultiTypes:
${first_entity_filename} building-simple-attributes-sample.jsonld
${second_entity_filename} building-with-different-type-sample.jsonld
${third_entity_filename} building-with-two-types-sample.jsonld
${first_entity_type} Building
${second_entity_type} Parking
${third_entity_type} TouristDestination
${options_parameter} keyValues
*** Test Cases *** ENTITY_TYPES_SELECTION EXPECTED_ENTITIES_IDS EXPECTED_LENGTH
019_08_01 entities first query ${first_entity_type} ${first_expected_entities_ids} 2
019_08_02 entities second query (${first_entity_type};${third_entity_type}) ${third_entity_id_as_a_list} 1
019_08_03 entities third query ${first_entity_type},${second_entity_type} ${second_expected_entities_ids} 3
019_08_04 entities fourth query ${second_entity_type},${third_entity_type} ${third_expected_entities_ids} 2
019_08_05 entities fifth query (${first_entity_type};${second_entity_type}),${third_entity_type} ${third_entity_id_as_a_list} 1
*** Keywords ***
Query entities with multiple types using Entity Type Selection Language
[Documentation] Query entities with Entity Type Selection Language.
[Tags] e-query 4_17
[Arguments] ${entity_types_selection} ${expected_entities_ids} ${expected_length}
${response}= Query Entities
... entity_types=${entity_types_selection}
... context=${ngsild_test_suite_context}
... options=${options_parameter}
Check Response Status Code 200 ${response.status_code}
Check Response Body Containing Entities URIS set to
... ${expected_entities_ids}
... ${response.json()}
... ${expected_length}
Setup Initial Entities
${first_entity_id}= Generate Random Entity Id ${entity_id_prefix}
Set Suite Variable ${first_entity_id}
${create_response1}= Create Entity Selecting Content Type
... ${first_entity_filename}
... ${first_entity_id}
... ${CONTENT_TYPE_LD_JSON}
Check Response Status Code 201 ${create_response1.status_code}
${second_entity_id}= Generate Random Entity Id ${entity_id_prefix}
Set Suite Variable ${second_entity_id}
${create_response2}= Create Entity Selecting Content Type
... ${second_entity_filename}
... ${second_entity_id}
... ${CONTENT_TYPE_LD_JSON}
Check Response Status Code 201 ${create_response2.status_code}
${third_entity_id}= Generate Random Entity Id ${entity_id_prefix}
Set Suite Variable ${third_entity_id}
${create_response3}= Create Entity Selecting Content Type
... ${third_entity_filename}
... ${third_entity_id}
... ${CONTENT_TYPE_LD_JSON}
Check Response Status Code 201 ${create_response3.status_code}
@{first_expected_entities_ids}= Create List ${first_entity_id} ${third_entity_id}
Set Suite Variable ${first_expected_entities_ids}
@{second_expected_entities_ids}= Create List ${first_entity_id} ${second_entity_id} ${third_entity_id}
Set Suite Variable @{second_expected_entities_ids}
@{third_expected_entities_ids}= Create List ${second_entity_id} ${third_entity_id}
Set Suite Variable @{third_expected_entities_ids}
@{third_entity_id_as_a_list}= Create List ${third_entity_id}
Set Suite Variable @{third_entity_id_as_a_list}
Delete Initial Entities
Delete Entity by Id ${first_entity_id}
Delete Entity by Id ${second_entity_id}
Delete Entity by Id ${third_entity_id}
{
"id": "urn:ngsi-ld:MultiTypes:randomUUID",
"type": ["Parking" ],
"name": {
"type": "Property",
"value": "Eiffel Tower"
},
"subCategory": {
"type": "Property",
"value": "tourism"
},
"airQualityLevel": {
"type": "Property",
"value": 4,
"unitCode": "C62",
"observedAt": "2020-09-09T16:40:00.000Z"
},
"almostFull": {
"type": "Property",
"value": false
},
"@context": [
"https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld"
]
}
\ No newline at end of file
{
"id": "urn:ngsi-ld:MultiTypes:randomUUID",
"type": ["Building", "TouristDestination" ],
"name": {
"type": "Property",
"value": "Eiffel Tower"
},
"subCategory": {
"type": "Property",
"value": "tourism"
},
"airQualityLevel": {
"type": "Property",
"value": 4,
"unitCode": "C62",
"observedAt": "2020-09-09T16:40:00.000Z"
},
"almostFull": {
"type": "Property",
"value": false
},
"@context": [
"https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld"
]
}
\ No newline at end of file
...@@ -8,6 +8,8 @@ class Checks: ...@@ -8,6 +8,8 @@ class Checks:
Checks.check_response_status_code, Checks.check_response_status_code,
'Check Response Body Containing Array Of URIs set to': 'Check Response Body Containing Array Of URIs set to':
Checks.check_response_body_containing_array_of_uris_set_to, Checks.check_response_body_containing_array_of_uris_set_to,
'Check Response Body Containing Entities URIS set to' :
Checks.check_response_body_containing_entities_uris_set_to,
'Check Created Resources Set To': 'Check Created Resources Set To':
Checks.check_created_resources_set_to, Checks.check_created_resources_set_to,
'Check Response Headers Containing Content-Type set to': 'Check Response Headers Containing Content-Type set to':
...@@ -117,6 +119,10 @@ class Checks: ...@@ -117,6 +119,10 @@ class Checks:
'params': ['expected_entities_ids', 'response_body'], 'params': ['expected_entities_ids', 'response_body'],
'position': [0, 1] 'position': [0, 1]
}, },
'Check Response Body Containing Entities URIS set to': {
'params': ['expected_entities_ids', 'response_body', 'expected_length'],
'position': [0, 1, 2]
},
'Check Response Body Containing ProblemDetails Element Containing Type Element set to': { 'Check Response Body Containing ProblemDetails Element Containing Type Element set to': {
'params': ['type'], 'params': ['type'],
'position': [1] 'position': [1]
...@@ -394,6 +400,10 @@ class Checks: ...@@ -394,6 +400,10 @@ class Checks:
def check_response_body_containing_array_of_uris_set_to(kwargs: list) -> str: def check_response_body_containing_array_of_uris_set_to(kwargs: list) -> str:
return 'Response Body set to an array of created entities ids' return 'Response Body set to an array of created entities ids'
@staticmethod
def check_response_body_containing_entities_uris_set_to(kwargs: list) -> str:
return 'Response Body contains entities ids'
@staticmethod @staticmethod
def check_created_resources_set_to(kwargs: list) -> str: def check_created_resources_set_to(kwargs: list) -> str:
return 'Created resources set to ${entities}' return 'Created resources set to ${entities}'
...@@ -896,6 +906,7 @@ if __name__ == "__main__": ...@@ -896,6 +906,7 @@ if __name__ == "__main__":
print(data.get_checks(checks='Check Response Status Code', print(data.get_checks(checks='Check Response Status Code',
status_code=201)) status_code=201))
print(data.get_checks(checks='Check Response Body Containing Array Of URIs set to')) print(data.get_checks(checks='Check Response Body Containing Array Of URIs set to'))
print(data.get_checks(checks='Check Response Body Containing Entities URIS set to'))
print(data.get_checks(checks='Check Created Resources Set To')) print(data.get_checks(checks='Check Created Resources Set To'))
print(data.get_checks(checks='Check Response Headers Containing Content-Type set to', print(data.get_checks(checks='Check Response Headers Containing Content-Type set to',
content_type='application/json')) content_type='application/json'))
......
...@@ -224,6 +224,13 @@ class TestCIConsumptions(TestCase): ...@@ -224,6 +224,13 @@ class TestCIConsumptions(TestCase):
self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file) self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)
def test_019_08(self):
robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_08.robot'
expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Consumption/019_08.json'
difference_file = f'{self.folder_test_suites}/doc/results/out_019_08.json'
self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)
def test_018_01_01(self): def test_018_01_01(self):
robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Consumption/Entity/RetrieveEntity/018_01_01.robot' robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Consumption/Entity/RetrieveEntity/018_01_01.robot'
expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Consumption/018_01_01.json' expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Consumption/018_01_01.json'
......
...@@ -8,12 +8,12 @@ Resource ${EXECDIR}/resources/ApiUtils/ContextSourceDiscovery.resource ...@@ -8,12 +8,12 @@ Resource ${EXECDIR}/resources/ApiUtils/ContextSourceDiscovery.resource
*** Variables *** *** Variables ***
${id_regex_expr}= root\\['id'\\] ${id_regex_expr} root\\['id'\\]
${instance_id_regex_expr}= root\\[.*\\]\\['instanceId'\\] ${instance_id_regex_expr} root\\[.*\\]\\['instanceId'\\]
${notification_timestamps_regex_expr}= root\\['last.*'\\] ${notification_timestamps_regex_expr} root\\['last.*'\\]
${notification_endpoint_uri_regex_expr}= root\\['endpoint'\\]\\['uri'\\] ${notification_endpoint_uri_regex_expr} root\\['endpoint'\\]\\['uri'\\]
${context_regex_expr}= root\\['@context'\\] ${context_regex_expr} root\\['@context'\\]
${status_regex_expr}= root\\['status'\\] ${status_regex_expr} root\\['status'\\]
*** Keywords *** *** Keywords ***
...@@ -29,6 +29,17 @@ Check Response Body Containing Array Of URIs set to ...@@ -29,6 +29,17 @@ Check Response Body Containing Array Of URIs set to
[Arguments] ${expected_entities_ids} ${response_body} [Arguments] ${expected_entities_ids} ${response_body}
Lists Should Be Equal ${expected_entities_ids} ${response_body} ignore_order=True Lists Should Be Equal ${expected_entities_ids} ${response_body} ignore_order=True
Check Response Body Containing Entities URIS set to
[Arguments] ${expected_entities_ids} ${response_body} ${expected_length}
@{response_entities_ids}= Create List
FOR ${item} IN ${response_body}
FOR ${index} IN RANGE ${expected_length}
Append To List ${response_entities_ids} ${item[${index}]['id']}
END
END
Lists Should Be Equal ${expected_entities_ids} ${response_entities_ids}
Check Response Body Content Check Response Body Content
[Arguments] ${expectation_filename} ${response_body} ${additional_ignored_path}=${EMPTY} [Arguments] ${expectation_filename} ${response_body} ${additional_ignored_path}=${EMPTY}
${entity_payload}= Load JSON From File ${EXECDIR}/data/entities/expectations/${expectation_filename} ${entity_payload}= Load JSON From File ${EXECDIR}/data/entities/expectations/${expectation_filename}
......