Commit 9de3ca3f authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

Merge branch 'feature/add-entity-type-selection-tests' into 'develop'

feat(subscription): add simple test for entity type selection

See merge request !124
parents 3e62fd28 e254f325
Loading
Loading
Loading
Loading
+61 −0
Original line number Original line Diff line number Diff line
*** Settings ***
Documentation       If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.

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_id_prefix}=              urn:ngsi-ld:Subscription:
${subscription_payload_file_path}=      subscriptions/subscription-building-entities-type-selection.jsonld
${building_id_prefix}=                  urn:ngsi-ld:Building:
${notification_server_send_url}=        http://${notification_server_host}:${notification_server_port}/notify
${entity_building_filepath}=            building-simple-attributes-sample.jsonld
${content_type}=                        application/ld+json


*** Test Cases ***
046_16_01 Check that a notification is sent with entity matching the entity type selection
    [Documentation]    If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.
    [Tags]    sub-notification    5_8_6    since_v1.5.1

    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${response}=    Create Entity Selecting Content Type
    ...    ${entity_building_filepath}
    ...    ${entity_id}
    ...    ${content_type}
    Set Suite Variable    ${entity_id}

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

    Should be Equal    ${subscription_id}    ${notification}[subscriptionId]
    Dictionary Should Contain Key    ${notification}    data
    Should Not Be Empty    ${notification}[data]    Notification data should not be empty
    Should be Equal    ${entity_id}    ${notification}[data][0][id]


*** Keywords ***
Setup Initial Subscription
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${subscription_payload}=    Load Subscription Sample With Reachable Endpoint
    ...    ${subscription_payload_file_path}
    ...    ${subscription_id}
    ...    ${notification_server_send_url}
    Create Subscription From Subscription Payload    ${subscription_payload}    ${CONTENT_TYPE_LD_JSON}
    Set Suite Variable    ${subscription_id}

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

After Test
    Delete Subscription    ${subscription_id}
    Delete Entity by Id    ${entity_id}
    Stop Local Server
+56 −0
Original line number Original line Diff line number Diff line
*** Settings ***
Documentation       If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.

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_id_prefix}=              urn:ngsi-ld:Subscription:
${subscription_payload_file_path}=      subscriptions/subscription-building-entities-type-selection.jsonld
${vehicle_id_prefix}=                   urn:ngsi-ld:Vehicle:
${notification_server_send_url}=        http://${notification_server_host}:${notification_server_port}/notify
${entity_vehicle_filepath}=             vehicle-simple-attributes-sample.jsonld
${content_type}=                        application/ld+json


*** Test Cases ***
046_16_02 Check that a notification is not sent if the entity type does not match the entity type selection
    [Documentation]    If a subscription defines an entity type selection query, a notification shall not be sent if the entity type does not match the query
    [Tags]    sub-notification    5_8_6    since_v1.5.1

    ${vehicle_id}=    Generate Random Entity Id    ${vehicle_id_prefix}
    ${response}=    Create Entity Selecting Content Type
    ...    ${entity_vehicle_filepath}
    ...    ${vehicle_id}
    ...    ${content_type}
    Set Suite Variable    ${vehicle_id}

    Wait for no notification


*** Keywords ***
Setup Initial Subscription
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${subscription_payload}=    Load Subscription Sample With Reachable Endpoint
    ...    ${subscription_payload_file_path}
    ...    ${subscription_id}
    ...    ${notification_server_send_url}
    Create Subscription From Subscription Payload    ${subscription_payload}    ${CONTENT_TYPE_LD_JSON}
    Set Suite Variable    ${subscription_id}

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

After Test
    Delete Subscription    ${subscription_id}
    Delete Entity by Id    ${vehicle_id}
    Stop Local Server
+18 −0
Original line number Original line Diff line number Diff line
{
    "id":"urn:ngsi-ld:Subscription:randomUUID",
    "type":"Subscription",
    "entities":[
       {
          "type":"(Building|Tower)"
       }
    ],
    "notificationTrigger": ["entityCreated"],
    "notification":{
       "endpoint":{
          "uri":"http://my.endpoint.org/notify"
       }
    },
    "@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
+40 −0
Original line number Original line Diff line number Diff line
{
  "tp_id": "TP/NGSI-LD/CI/SUB/046_16_01",
  "test_objective": "If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.",
  "reference": "ETSI GS CIM 009 V1.5.1 [], clause 5.8.6",
  "config_id": "",
  "parent_release": "v1.5.1",
  "clauses": [
    "5.8.6"
  ],
  "pics_selection": "",
  "keywords": [
    "Setup Initial Subscription",
    "Before Test",
    "After Test"
  ],
  "teardown": "After Test",
  "initial_condition": "with {\n   the SUT containing an initial state\n}",
  "test_cases": [
    {
      "name": "046_16_01 Check that a notification is sent with entity matching the entity type selection",
      "permutation_tp_id": "TP/NGSI-LD/CI/SUB/046_16_01",
      "doc": "If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.",
      "tags": [
        "5_8_6",
        "since_v1.5.1",
        "sub-notification"
      ],
      "setup": null,
      "teardown": null,
      "template": null,
      "then": "then {\n    the client at '${endpoint}' receives a valid Notification containing:\n        Notification received After waiting '5' seconds     and\n        Notification received Notification data: '${notification}[subscriptionId]' equal to '${subscription_id}'     and\n        Notification received Notification data: '${notification}[data][0][id]' equal to '${entity_id}'     and\n        Notification received The dictionary `${notification}' should contain the key 'data'     and\n        Notification received The variable `${notification}[data]' should not be '${EMPTY}'\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/entities/'\n        method set to 'POST'\n        Request Header['Content-Type'] set to 'application/ld+json' and\n payload defined in file: 'building-simple-attributes-sample.jsonld'\n}",
      "http_verb": "POST",
      "endpoint": "entities/"
    }
  ],
  "permutations": [],
  "robotpath": "ContextInformation/Subscription/SubscriptionNotificationBehaviour",
  "robotfile": "046_16_01"
}
 No newline at end of file
+40 −0
Original line number Original line Diff line number Diff line
{
  "tp_id": "TP/NGSI-LD/CI/SUB/046_16_02",
  "test_objective": "If a subscription defines an entity type selection query, a notification shall be sent whenever an entity matches the query.",
  "reference": "ETSI GS CIM 009 V1.5.1 [], clause 5.8.6",
  "config_id": "",
  "parent_release": "v1.5.1",
  "clauses": [
    "5.8.6"
  ],
  "pics_selection": "",
  "keywords": [
    "Setup Initial Subscription",
    "Before Test",
    "After Test"
  ],
  "teardown": "After Test",
  "initial_condition": "with {\n   the SUT containing an initial state\n}",
  "test_cases": [
    {
      "name": "046_16_02 Check that a notification is not sent if the entity type does not match the entity type selection",
      "permutation_tp_id": "TP/NGSI-LD/CI/SUB/046_16_02",
      "doc": "If a subscription defines an entity type selection query, a notification shall not be sent if the entity type does not match the query",
      "tags": [
        "5_8_6",
        "since_v1.5.1",
        "sub-notification"
      ],
      "setup": null,
      "teardown": null,
      "template": null,
      "then": "then {\n    the client at '${endpoint}' receives a valid Notification containing:\n        Notification received Waiting for no Notification data and\n    Query Parameter: timeout set to '5'\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/entities/'\n        method set to 'POST'\n        Request Header['Content-Type'] set to 'application/ld+json' and\n payload defined in file: 'vehicle-simple-attributes-sample.jsonld'\n}",
      "http_verb": "POST",
      "endpoint": "entities/"
    }
  ],
  "permutations": [],
  "robotpath": "ContextInformation/Subscription/SubscriptionNotificationBehaviour",
  "robotfile": "046_16_02"
}
 No newline at end of file
Loading