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

Merge remote-tracking branch 'origin/feature/add-entity-type-selection-tests' into parsespec

# Conflicts:
#	TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_15.robot
parents 4fc421a5 e4ba64b9
Loading
Loading
Loading
Loading
+61 −0
Original line number 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

    ${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 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

    ${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 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
+14 −0
Original line number Diff line number Diff line
@@ -203,6 +203,20 @@ class TestCISubscription(TestCase):

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_046_16_01(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_01.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_16_01.json'
        difference_file = f'{self.folder_test_suites}/doc/results/out_046_16_01.json'

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_046_16_02(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/SubscriptionNotificationBehaviour/046_16_02.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/046_16_02.json'
        difference_file = f'{self.folder_test_suites}/doc/results/out_046_16_02.json'

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_031_01(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Subscription/QuerySubscriptions/031_01.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Subscription/031_01.json'