Commit 9a3587b4 authored by Ranim Naimi's avatar Ranim Naimi Committed by Benoit Orihuela
Browse files

feat: add test cases for replace entity endpoint

parent 1c15d550
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can replace an existing entity and that its createdAt Temporal Property remains unchanged

Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Test Setup          Setup Initial Entity
Test Teardown       Delete Initial Entity


*** Variables ***
${building_id_prefix}               urn:ngsi-ld:Building:
${entity_filename}                  building-simple-attributes.json
${entity_replacement_filename}      building-locatedAt-and-name.json
${expectation_filename}             building-locatedAt-and-name-normalized.jsonld


*** Test Cases ***
054_01_01 Replace an existing entity
    [Documentation]    Check that one can replace an existing entity and that its createdAt Temporal Property remains unchanged
    [Tags]    e-replace    5_6_18    6_5_3_3    since_v1.6.1
    ${entity}=    Load Entity
    ...    entity_file_name=${entity_replacement_filename}
    ...    entity_id=${entity_id}
    ${response}=    Replace Entity Selecting Content Type
    ...    entity_id=${entity_id}
    ...    entity_fragment=${entity}
    ...    content_type=${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    204    ${response.status_code}
    ${response1}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    options=sysAttrs
    ${ignored_attributes}=    Create List    @context    createdAt    modifiedAt
    ${entity_expectation_payload}=    Load Test Sample    entities/expectations/${expectation_filename}    ${entity_id}
    Check Updated Resource Set To
    ...    updated_resource=${entity_expectation_payload}
    ...    response_body=${response1.json()}
    ...    ignored_keys=${ignored_attributes}
    Check Response Body Containing an Attribute set to
    ...    expected_attribute_name=createdAt
    ...    response_body=${response1.json()}
    ...    expected_attribute_value=${createdAt}


*** Keywords ***
Setup Initial Entity
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Test Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type
    ...    ${entity_filename}
    ...    ${entity_id}
    ...    ${CONTENT_TYPE_JSON}
    ...    ${ngsild_test_suite_context}
    Check Response Status Code    201    ${response.status_code}
    ${response}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    options=sysAttrs
    ${createdAt}=    Set Variable    ${response.json()['createdAt']}
    Set Test Variable    ${createdAt}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}
+56 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that if the target entity ID is faulty an error is raised

Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Test Setup          Setup Initial Entity
Test Teardown       Delete Initial Entity
Test Template       Replace an existing entity with a faulty ID


*** Variables ***
${building_id_prefix}               urn:ngsi-ld:Building:
${entity_filename}                  building-simple-attributes.json
${entity_replacement_filename}      building-locatedAt-and-name.json


*** Test Cases ***    FAULTY_ENTITY_ID    EXPECTED_STATUS_CODE
054_02_01 Replace an existing entity giving an invalid Id
    [Tags]    e-replace    5_6_18    6_5_3_3    since_v1.6.1
    invalidUri    400
054_02_02 Replace an existing entity without giving an Id
    [Tags]    e-replace    5_6_18    6_5_3_3    since_v1.6.1
    ${EMPTY}    400
054_02_03 Replace an existing entity giving a nonexsitent Id
    [Tags]    e-replace    5_6_18    6_5_3_3    since_v1.6.1
    urn:ngsi-ld:Building:Nonexistent    404


*** Keywords ***
Replace an existing entity with a faulty ID
    [Documentation]    Check that if the target entity ID is faulty an error is raised
    [Arguments]    ${faulty_entity_id}    ${expected_status_code}
    ${entity}=    Load Entity
    ...    entity_file_name=${entity_replacement_filename}
    ...    entity_id=${faulty_entity_id}
    ${response}=    Replace Entity Selecting Content Type
    ...    entity_id=${faulty_entity_id}
    ...    entity_fragment=${entity}
    ...    content_type=${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    ${expected_status_code}    ${response.status_code}

Setup Initial Entity
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Test Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type
    ...    ${entity_filename}
    ...    ${entity_id}
    ...    ${CONTENT_TYPE_JSON}
    ...    ${ngsild_test_suite_context}
    Check Response Status Code    201    ${response.status_code}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}
+15 −0
Original line number Diff line number Diff line
{
	"id": "urn:ngsi-ld:Building:randomUUID",
	"type": "Building",
	"name": {
		"type": "Property",
		"value": "Pisa Tower"
	},
	"locatedAt": {
		"type": "Relationship",
		"object": "urn:ngsi-ld:City:Pisa"
	},
	"@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
+15 −0
Original line number Diff line number Diff line
{
	"id": "urn:ngsi-ld:Building:randomUUID",
	"type": "Building",
	"name": {
		"type": "Property",
		"value": "Pisa Tower"
	},
	"locatedAt": {
		"type": "Relationship",
		"object": "urn:ngsi-ld:City:Pisa"
	},
	"@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
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ class GenerateRobotData:
            'Discovery/RetrieveDetailsOfAvailableAttributes': 'DISC',
            'Entity/RetrieveEntity': 'E',
            'Entities/CreateEntity': 'E',
            'Entities/ReplaceEntity': 'E',
            'Entity/QueryEntities': 'E',
            'Entities/DeleteEntity': 'E',
            'EntityAttributes/AppendEntityAttributes': 'EA',
Loading