Commit 036b5a3e authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

feat: add tests for replace entity wrt types and scopes

parent 90d84a4f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -25,6 +25,12 @@ ${building_id_prefix}= urn:ngsi-ld:Building:
004_03_03 EntityWithRelationshipsProperties
    [Tags]    be-upsert    5_6_8
    building-relationship-of-property.jsonld
004_03_04 EntityWithScope
    [Tags]    be-upsert    4_18    5_6_8
    building-with-one-scope.jsonld
004_03_05 EntityWithTypes
    [Tags]    be-upsert    4_16    5_6_8
    building-with-two-types.jsonld


*** Keywords ***
+52 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can replace an existing entity and that scopes are replaced

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

Test Setup          Setup Initial Entity
Test Teardown       Delete Initial Entity


*** Variables ***
${building_id_prefix}               urn:ngsi-ld:Building:
${entity_filename}                  building-minimal-with-one-scope.json
${entity_replacement_filename}      building-minimal-with-many-scopes.json
${expectation_filename}             building-minimal-with-two-scopes.json


*** Test Cases ***
054_03_01 Replace an existing entity having scopes
    [Documentation]    Check that one can replace an existing entity and that scopes are replaced
    [Tags]    e-replace    4_18    5_6_18    6_5_3_3    since_v1.6.1
    ${response}=    Replace Entity
    ...    entity_id=${entity_id}
    ...    filename=${entity_replacement_filename}
    ...    content_type=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response.status_code}

    ${response1}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    accept=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Body Containing Entity element
    ...    expectation_filename=${expectation_filename}
    ...    entity_id=${entity_id}
    ...    response_body=${response1.json()}


*** 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}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}
+8 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:randomUUID",
    "type": "Building",
    "scope": "/Madrid/Gardens/ParqueNorte",
    "@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
+31 −0
Original line number Diff line number Diff line
@@ -102,6 +102,10 @@ class Requests:
                'positions': [0],
                'params': ['id']
            },
            'Replace Entity': {
                'positions': [0, 1, 2, 3],
                'params': ['entity_id', 'filename', 'content_type', 'context']
            },
            'Replace Entity Selecting Content Type': {
                'positions': [0, 1, 2, 3],
                'params': ['entity_id', 'entity_fragment', 'content_type', 'context']
@@ -318,6 +322,8 @@ class Requests:
                Requests.query_entities,
            'Delete Entity by Id':
                Requests.delete_entity_by_id,
            'Replace Entity':
                Requests.replace_entity,
            'Replace Entity Selecting Content Type':
                Requests.replace_entity_selecting_content_type,
            'Replace Attribute Selecting Content Type':
@@ -1364,6 +1370,31 @@ class Requests:
        if 'id' in kwargs:
            return f"Delete Entity Request with id set to '{kwargs['id']}'"

    @staticmethod
    def replace_entity(kwargs) -> str:
        expected_parameters = ['entity_id', 'filename', 'content_type', 'context']

        if 'context' not in kwargs:
            kwargs['context'] = '${EMPTY}'

        result = [x for x in kwargs if x not in expected_parameters]
        response = "Replace Entity"
        for key, value in kwargs.items():
            match key:
                case 'entity_id':
                    response = f"{response} and\n    Query Parameter: entity_id set to '{value}'"
                case 'filename':
                    response = f"{response} and\n    Query Parameter: filename set to '{value}'"
                case 'content_type':
                    response = f"{response} and\n    Query Parameter: content_type set to '{value}'"
                case 'context':
                    response = f"{response} and\n    Query Parameter: context set to '{value}'"
                case _:
                    raise Exception(f"ERROR: unexpected attribute {result}, the attributes expected are "
                                    f"{expected_parameters}, but received: {kwargs}")

        return response

    @staticmethod
    def replace_entity_selecting_content_type(kwargs) -> str:
        expected_parameters = ['entity_id', 'entity_fragment', 'content_type', 'context']
+41 −5
Original line number Diff line number Diff line
{
  "tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03",
  "test_objective": "Check that you can upsert a batch of existing entities and they will be replaced",
  "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.6.8",
  "test_objective": "Check that one can upsert a batch of existing entities and they will be replaced",
  "reference": "ETSI GS CIM 009 V1.3.1 [], clauses 4.16, 4.18, 5.6.8",
  "config_id": "",
  "parent_release": "v1.3.1",
  "clauses": [
    "4.16",
    "4.18",
    "5.6.8"
  ],
  "pics_selection": "",
@@ -19,7 +21,7 @@
    {
      "name": "004_03_01 EntityWithSimpleProperties",
      "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_01",
      "doc": "Check that you can upsert a batch of existing entities",
      "doc": "Check that one can upsert a batch of existing entities",
      "tags": [
        "5_6_8",
        "be-upsert"
@@ -35,7 +37,7 @@
    {
      "name": "004_03_02 EntityWithSimpleRelationships",
      "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_02",
      "doc": "Check that you can upsert a batch of existing entities",
      "doc": "Check that one can upsert a batch of existing entities",
      "tags": [
        "5_6_8",
        "be-upsert"
@@ -51,7 +53,7 @@
    {
      "name": "004_03_03 EntityWithRelationshipsProperties",
      "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_03",
      "doc": "Check that you can upsert a batch of existing entities",
      "doc": "Check that one can upsert a batch of existing entities",
      "tags": [
        "5_6_8",
        "be-upsert"
@@ -63,6 +65,40 @@
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/entityOperations/upsert?options=${update_option}'\n        method set to 'POST'\n        Request batch upsert operation over entity from filename '@{entities_to_be_upserted}' with update_option set to 'replace' and Content-Type set to 'application/ld+json'\n}",
      "http_verb": "POST",
      "endpoint": "entityOperations/upsert?options=${update_option}"
    },
    {
      "name": "004_03_04 EntityWithScope",
      "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_04",
      "doc": "Check that one can upsert a batch of existing entities",
      "tags": [
        "4_18",
        "5_6_8",
        "be-upsert"
      ],
      "setup": "Setup Initial Entities",
      "teardown": "Delete Initial Entities",
      "template": "Batch Upsert Existing Entities Scenarios",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Batch Upsert Entities with Response Status Code set to 204     and\n        Query Entities with Updated Entities set to '${entities_to_be_upserted}' valid entities\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/entityOperations/upsert?options=${update_option}'\n        method set to 'POST'\n        Request batch upsert operation over entity from filename '@{entities_to_be_upserted}' with update_option set to 'replace' and Content-Type set to 'application/ld+json'\n}",
      "http_verb": "POST",
      "endpoint": "entityOperations/upsert?options=${update_option}"
    },
    {
      "name": "004_03_05 EntityWithTypes",
      "permutation_tp_id": "TP/NGSI-LD/CI/Prov/BE/004_03_05",
      "doc": "Check that one can upsert a batch of existing entities",
      "tags": [
        "4_16",
        "5_6_8",
        "be-upsert"
      ],
      "setup": "Setup Initial Entities",
      "teardown": "Delete Initial Entities",
      "template": "Batch Upsert Existing Entities Scenarios",
      "then": "then {\n    the SUT sends a valid Response for the operations:\n        Batch Upsert Entities with Response Status Code set to 204     and\n        Query Entities with Updated Entities set to '${entities_to_be_upserted}' valid entities\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/entityOperations/upsert?options=${update_option}'\n        method set to 'POST'\n        Request batch upsert operation over entity from filename '@{entities_to_be_upserted}' with update_option set to 'replace' and Content-Type set to 'application/ld+json'\n}",
      "http_verb": "POST",
      "endpoint": "entityOperations/upsert?options=${update_option}"
    }
  ],
  "permutations": [],
Loading