Commit 3f4951e3 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

fix: ensure test data is always cleaned up after a test

- calling Suite Teardown only cleans up data from last TC in the suite
- clearly identify setups steps in TCs
- prefer Set Test Variable when variable is set in a TC
parent 36c4793b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Suite Teardown      Delete Initial Entities
Test Teardown       Delete Initial Entities


*** Variables ***
@@ -18,7 +18,7 @@ ${building_id_prefix}= urn:ngsi-ld:Building:
    [Documentation]    Check that the @context is obtained from the request payload body itself if the Content-Type header is "application/ld+json" and the response attribute should be compacted as we used the same context as provided when creating the entity
    [Tags]    be-create    6_3_5
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Suite Variable    ${entity_id}
    Set Test Variable    ${entity_id}
    ${entity}=    Load Entity    building-simple-attributes-sample.jsonld    ${entity_id}
    @{entities_to_be_created}=    Create List    ${entity}
    ${response}=    Batch Create Entities    @{entities_to_be_created}    content_type=${CONTENT_TYPE_LD_JSON}
@@ -35,7 +35,7 @@ ${building_id_prefix}= urn:ngsi-ld:Building:
    [Documentation]    Check that the @context is obtained from the request payload body itself if the Content-Type header is "application/ld+json" and response attribute should not be compacted as we did not provide a context containing this term
    [Tags]    be-create    6_3_5
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Suite Variable    ${entity_id}
    Set Test Variable    ${entity_id}
    ${entity}=    Load Entity    building-simple-attributes-sample.jsonld    ${entity_id}
    @{entities_to_be_created}=    Create List    ${entity}
    ${response}=    Batch Create Entities    @{entities_to_be_created}    content_type=${CONTENT_TYPE_LD_JSON}
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Suite Teardown      Delete Initial Entity
Test Teardown       Delete Initial Entity


*** Variables ***
+8 −1
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@ Resource ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Test Teardown       Delete Initial Entity


*** Variables ***
${building_id_prefix}=      urn:ngsi-ld:Building:
@@ -17,22 +19,27 @@ ${filename}= building-simple-attributes-sample.jsonld
    [Documentation]    Check that the @context is obtained from the request payload body itself if the Content-Type header is "application/ld+json" and retrieve with ld context
    [Tags]    e-create    6_3_5
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Suite Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    ${response}=    Retrieve Entity by Id    id=${entity_id}    context=${ngsild_test_suite_context}
    # Attribute should be compacted as we used the same context as provided when creating the entity
    Check Response Body Containing an Attribute set to
    ...    expected_attribute_name=almostFull
    ...    response_body=${response.json()}
    Delete Entity by Id    ${entity_id}

001_07_02 Create one entity using a JSON-LD @context obtained from the request payload without context
    [Documentation]    Check that the @context is obtained from the request payload body itself if the Content-Type header is "application/ld+json" and retrieve without context
    [Tags]    e-create    6_3_5
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Suite Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type    ${filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    ${response}=    Retrieve Entity by Id    id=${entity_id}
    # Attribute should not be compacted as we did not provide a context containing this term
    Check Response Body Containing an Attribute set to
    ...    expected_attribute_name=https://ngsi-ld-test-suite/context#almostFull
    ...    response_body=${response.json()}


*** Keywords ***
Delete Initial Entity
    Delete Entity by Id    ${entity_id}
+8 −7
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ Resource ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.re
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Suite Teardown      Delete Entity
Test Teardown       Delete Entity
Test Template       Update Attributes


@@ -13,19 +13,20 @@ Test Template Update Attributes
${vehicle_id_prefix}=       urn:ngsi-ld:Vehicle:


*** Test Cases ***    ENTITY_INVALID_ID    FILENAME    FRAGMENT_FILENAME
*** Test Cases ***    ENTITY_INVALID_ID    FRAGMENT_FILENAME
011_02_01 Update an attribute if the Entity Id is not present
    ${EMPTY}    vehicle-two-datasetid-attributes-sample.jsonld    vehicle-speed-two-datasetid-01-fragment.jsonld
    [Setup]    Initialize Environment    vehicle-two-datasetid-attributes-sample.jsonld
    ${EMPTY}    vehicle-speed-two-datasetid-01-fragment.jsonld
011_02_02 Update an attribute if the Entity Id is not a valid URI
    thisisaninvaliduri    vehicle-two-datasetid-attributes-sample.jsonld    vehicle-speed-two-datasetid-01-fragment.jsonld
    [Setup]    Initialize Environment    vehicle-two-datasetid-attributes-sample.jsonld
    thisisaninvaliduri    vehicle-speed-two-datasetid-01-fragment.jsonld


*** Keywords ***
Update Attributes
    [Documentation]    Check that you cannot update entity attributes with invalid/missing id or invalid request body
    [Tags]    ea-update    5_6_2
    [Arguments]    ${entity_invalid_id}    ${filename}    ${fragment_filename}
    Initialize Environment    ${filename}
    [Arguments]    ${entity_invalid_id}    ${fragment_filename}
    ${response}=    Update Entity Attributes    ${entity_invalid_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    400    ${response.status_code}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to
@@ -36,7 +37,7 @@ Update Attributes
Initialize Environment
    [Arguments]    ${filename}
    ${entity_id}=    Generate Random Entity Id    ${vehicle_id_prefix}
    Set Global Variable    ${entity_id}
    Set Test Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type
    ...    ${filename}
    ...    ${entity_id}
+13 −16
Original line number Diff line number Diff line
@@ -7,8 +7,9 @@ Resource ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource
Resource            ${EXECDIR}/resources/NotificationUtils.resource

Suite Setup         Before Test
Suite Teardown      After Test
Suite Setup         Before Suite
Suite Teardown      After Suite
Test Teardown       After Test


*** Variables ***
@@ -28,7 +29,7 @@ ${date_format_with_millis} %Y-%m-%dT%H:%M:%S.%fZ
046_07_01 Check notification structure
    [Documentation]    The structure of the notification message shall be as mandated by clause 5.3. Valid notification with attributes as stated above
    [Tags]    sub-notification    5_8_6    046_07_01
    Setup Initial Subscriptions
    [Setup]    Setup Initial Subscriptions    ${subscription_payload_file_path}

    ${response}=    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}

@@ -41,7 +42,7 @@ ${date_format_with_millis} %Y-%m-%dT%H:%M:%S.%fZ
046_07_02 Check correct attributes are included
    [Documentation]    The structure of the notification message shall be as mandated by clause 5.3.    The Entity Attributes included (Properties or Relationships) shall be those specified by the notification.attributes member in the Subscription data type (clause 5.2.12).
    [Tags]    sub-notification    5_8_6    046_07_02
    Setup Initial Subscriptions    ${subscription_payload_file_path_watchedAttributes}
    [Setup]    Setup Initial Subscriptions    ${subscription_payload_file_path_watchedAttributes}

    ${response}=    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}

@@ -55,7 +56,7 @@ ${date_format_with_millis} %Y-%m-%dT%H:%M:%S.%fZ
046_07_03 Check URI expansion is observed
    [Documentation]    The structure of the notification message shall be as mandated by clause 5.3.    URI expansion shall be observed (clause 5.5.7).
    [Tags]    sub-notification    5_8_6    046_07_03
    Setup Initial Subscriptions    ${subscription_payload_file_path_default_context}
    [Setup]    Setup Initial Subscriptions    ${subscription_payload_file_path_default_context}

    ${response}=    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}

@@ -68,11 +69,11 @@ ${date_format_with_millis} %Y-%m-%dT%H:%M:%S.%fZ


*** Keywords ***
Before Test
Before Suite
    Start Local Server    ${notification_server_host}    ${notification_server_port}

Setup Initial Subscriptions
    [Arguments]    ${subscription_payload_path}=${subscription_payload_file_path}
    [Arguments]    ${subscription_payload_path}
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${subscription_payload}=    Load Subscription Sample With Reachable Endpoint
@@ -80,8 +81,8 @@ Setup Initial Subscriptions
    ...    ${subscription_id}
    ...    ${notification_server_send_url}
    ${subscription_payload}=    Set Entity Id In Subscription    ${subscription_payload}    ${entity_id}
    Set Suite Variable    ${entity_id}
    Set Suite Variable    ${subscription_id}
    Set Test Variable    ${entity_id}
    Set Test Variable    ${subscription_id}

    Create Entity    ${entity_building_filepath}    ${entity_id}
    Sleep    1s
@@ -89,12 +90,8 @@ Setup Initial Subscriptions
    Sleep    1s

After Test
    Delete Initial Subscriptions
    Delete Initial Entity
    Stop Local Server

Delete Initial Subscriptions
    Delete Subscription    ${subscription_id}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}

After Suite
    Stop Local Server
Loading