Commit 01839849 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

Merge branch 'feature/add-tcs-datasetid-filter' into 'develop'

feat: add TCs for filtering of attributes instances based on datasetId

See merge request !210
parents d31b39d8 72a7a7dd
Loading
Loading
Loading
Loading
+74 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can filter attribute instances based on datasetId.

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 Entity
Suite Teardown      Delete Entity
Test Template       Filter attribute instances based on datasetId


*** Variables ***
${filename}     building-multi-instances-attributes.jsonld


*** Test Cases ***    ATTRS    DATASET_ID    EXPECTATION_FILENAME
019_12_01 filter based on attrs only
    [Tags]    e-query    4_5_5    5_7_2    since_v1.8.1
    name    ${EMPTY}    building-name-attribute.jsonld
019_12_02 filter based on datasetId only
    [Tags]    e-query    4_5_5    5_7_2    since_v1.8.1
    ${EMPTY}    urn:ngsi-ld:Dataset:french-name    building-french-datasetid-only.jsonld
019_12_03 filter based on two datasetIds
    [Tags]    e-query    4_5_5    5_7_2    since_v1.8.1
    ${EMPTY}    urn:ngsi-ld:Dataset:french-name,urn:ngsi-ld:Dataset:spanish-name    building-two-datasetids.jsonld
019_12_04 filter based on default instance
    [Tags]    e-query    4_5_5    5_7_2    since_v1.8.1
    ${EMPTY}    @none    building-default-instances.jsonld
019_12_05 filter based on attrs and default instance
    [Tags]    e-query    4_5_5    5_7_2    since_v1.8.1
    name    @none    building-name-attribute-default-instance.jsonld
019_12_06 filter based on attrs and datasetId
    [Tags]    e-query    4_5_5    5_7_2    since_v1.8.1
    name    urn:ngsi-ld:Dataset:german-name    building-name-attribute-german-instance.jsonld
019_12_07 filter based on attrs and datasetId with no match
    [Tags]    e-query    4_5_5    5_7_2    since_v1.8.1
    name    urn:ngsi-ld:Dataset:spanish-name    building-no-attributes.jsonld


*** Keywords ***
Filter attribute instances based on datasetId
    [Documentation]    Check that one can filter attribute instances based on datasetId.
    [Arguments]    ${attrs}    ${datasetId}    ${expectation_filename}

    ${attrsToMatch}=    Catenate
    ...    SEPARATOR=,
    ...    ${attrs}

    ${response}=    Query Entities
    ...    attrs=${attrsToMatch}
    ...    datasetId=${datasetId}
    ...    entity_types=Building
    ...    context=${ngsild_test_suite_context}
    ...    accept=${CONTENT_TYPE_LD_JSON}

    Check Response Status Code    200    ${response.status_code}
    Check Response Body Containing Entity element
    ...    expectation_filename=${expectation_filename}
    ...    entity_id=${entity_id}
    ...    response_body=${response.json()[0]}

Setup Initial Entity
    ${entity_id}=    Generate Random Building Entity Id
    Set Suite Variable    ${entity_id}
    ${create_response}=    Create Entity Selecting Content Type
    ...    ${filename}
    ...    ${entity_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${create_response.status_code}

Delete Entity
    Delete Entity by Id    ${entity_id}
+78 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can filter attribute instances of a temporal entity based on datasetId.

Resource            ${EXECDIR}/resources/ApiUtils/Common.resource
Resource            ${EXECDIR}/resources/ApiUtils/TemporalContextInformationConsumption.resource
Resource            ${EXECDIR}/resources/ApiUtils/TemporalContextInformationProvision.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Suite Setup         Setup Initial Temporal Entity
Suite Teardown      Delete Temporal Entity
Test Template       Filter attribute instances of a temporal entity based on datasetId


*** Variables ***
${filename}     vehicle-temporal-representation-with-multi-attributes-instances.jsonld
${timerel}      after
${timeat}       2020-08-01T12:04:00Z


*** Test Cases ***    ATTRS    DATASET_ID    EXPECTATION_FILENAME
021_18_01 filter based on attrs only
    [Tags]    te-query    4_5_5    5_7_4    since_v1.8.1
    speed    ${EMPTY}    vehicle-temporal-representation-speed-attribute.json
021_18_02 filter based on datasetId only
    [Tags]    te-query    4_5_5    5_7_4    since_v1.8.1
    ${EMPTY}    urn:ngsi-ld:Dataset:Common    vehicle-temporal-representation-common-datasetid.json
021_18_03 filter based on two datasetIds
    [Tags]    te-query    4_5_5    5_7_4    since_v1.8.1
    ${EMPTY}    urn:ngsi-ld:Dataset:Common,urn:ngsi-ld:Dataset:Speed    vehicle-temporal-representation-two-datasetids.json
021_18_04 filter based on default instance
    [Tags]    te-query    4_5_5    5_7_4    since_v1.8.1
    ${EMPTY}    @none    vehicle-temporal-representation-default-instances.json
021_18_05 filter based on attrs and default instance
    [Tags]    te-query    4_5_5    5_7_4    since_v1.8.1
    speed    @none    vehicle-temporal-representation-speed-default-instance.json
021_18_06 filter based on attrs and datasetId
    [Tags]    te-query    4_5_5    5_7_4    since_v1.8.1
    fuelLevel    urn:ngsi-ld:Dataset:fuel    vehicle-temporal-representation-fuellevel-attribute-fuel-datasetid.json
021_18_07 filter based on attrs and datasetId with no match
    [Tags]    te-query    4_5_5    5_7_4    since_v1.8.1
    speed    urn:ngsi-ld:Dataset:fuel    empty.json


*** Keywords ***
Filter attribute instances of a temporal entity based on datasetId
    [Documentation]    Check that one can filter attribute instances of a temporal entity based on datasetId.
    [Arguments]    ${attrs}    ${datasetId}    ${expectation_filename}

    ${attrsToMatch}=    Catenate
    ...    SEPARATOR=,
    ...    ${attrs}

    ${response}=    Query Temporal Representation Of Entities
    ...    attrs=${attrsToMatch}
    ...    datasetId=${datasetId}
    ...    entity_types=Vehicle
    ...    timerel=${timerel}
    ...    timeAt=${timeat}
    ...    context=${ngsild_test_suite_context}
    ...    options=temporalValues

    Check Response Status Code    200    ${response.status_code}
    Check Response Body Containing EntityTemporal element
    ...    filename=${expectation_filename}
    ...    temporal_entity_representation_id=${temporal_entity_id}
    ...    response_body=${response.json()}

Setup Initial Temporal Entity
    ${temporal_entity_id}=    Catenate    ${VEHICLE_ID_PREFIX}021-18-A
    Set Suite Variable    ${temporal_entity_id}
    ${create_response}=    Create Temporal Representation Of Entity
    ...    ${filename}
    ...    ${temporal_entity_id}
    Check Response Status Code    201    ${create_response.status_code}

Delete Temporal Entity
    Delete Temporal Representation Of Entity    ${temporal_entity_id}
+37 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can create a subscription with a datasetId

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

Suite Teardown      Delete Initial Subscription


*** Variables ***
${subscription_payload_file_path}           subscriptions/subscription-building-with-datasetId.jsonld
${subscription_expectation_file_path}       subscriptions/expectations/subscription-with-datasetId.jsonld


*** Test Cases ***
028_06 Create a subscription with a datasetId
    [Documentation]    Check that one can create a subscription with a datasetId
    [Tags]    sub-create    5_8_1    4_5_5    since_v1.8.1
    ${subscription_id}=    Generate Random Subscription Id
    Set Suite Variable    ${subscription_id}
    ${response}=    Create Subscription
    ...    ${subscription_id}
    ...    ${subscription_payload_file_path}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response.status_code}
    ${expected_subscription}=    Load Test Sample    ${subscription_expectation_file_path}    ${subscription_id}
    ${response1}=    Retrieve Subscription
    ...    id=${subscription_id}
    ...    accept=${CONTENT_TYPE_LD_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Created Resource Set To    ${expected_subscription}    ${response1.json()}


*** Keywords ***
Delete Initial Subscription
    Delete Subscription    ${subscription_id}
+74 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       If a subscription has a datasetId member instances should be filtered based on that datasetId.

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

Suite Setup         Before Test
Suite Teardown      After Test


*** Variables ***
${subscription_payload_file_path}       subscriptions/subscription-building-with-datasetId.jsonld
${entity_building_filepath}             building-multi-instances-attributes.jsonld
${fragment_filename}                    building-name-fragment.jsonld
${notification_server_send_url}         http://${notification_server_host}:${notification_server_port}/notify
${entity_expectation_file_path}         entity-with-datasetid-046-19.jsonld


*** Test Cases ***
046_19 Check that only the attribute instances that match the datasetId member are included in the entity in the notification
    [Documentation]    If a subscription has a datasetId member instances should be filtered based on that datasetId.
    [Tags]    sub-notification    4_5_5    5_8_6    since_v1.8.1

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

    ${notification}    ${headers}=    Wait for notification    timeout=${10}

    Should be Equal    ${subscription_id}    ${notification}[subscriptionId]
    Should be Equal    ${entity_id}    ${notification}[data][0][id]

    Check Notification Containing Entity Element
    ...    ${entity_expectation_file_path}
    ...    ${notification}


*** Keywords ***
Before Test
    Start Local Server    ${notification_server_host}    ${notification_server_port}
    Add Initial Entity
    Sleep    1s
    Setup Initial Subscription

Add Initial Entity
    ${entity_id}=    Generate Random Building Entity Id
    ${create_response}=    Create Entity    ${entity_building_filepath}    ${entity_id}
    Check Response Status Code    201    ${create_response.status_code}
    Set Suite Variable    ${entity_id}

Setup Initial Subscription
    ${subscription_id}=    Generate Random Subscription Id
    ${subscription_payload}=    Load Subscription Sample With Reachable Endpoint
    ...    ${subscription_payload_file_path}
    ...    ${subscription_id}
    ...    ${notification_server_send_url}
    ${subscription_payload}=    Set Entity Id In Subscription    ${subscription_payload}    ${entity_id}
    ${create_response}=    Create Subscription From Subscription Payload
    ...    ${subscription_payload}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${create_response.status_code}
    Set Suite Variable    ${subscription_id}

After Test
    Delete Initial Subscription
    Delete Initial Entity
    Stop Local Server

Delete Initial Subscription
    Delete Subscription    ${subscription_id}

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": "Eiffel Tower"
  },
  "locatedAt": {
    "type": "Relationship",
    "object": "urn:ngsi-ld:City:Paris"
  },
  "@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
Loading