Commit 593df5f9 authored by Ranim Naimi's avatar Ranim Naimi
Browse files

check notification's behaviour when a subscription defines a throttling member

parent 36952add
Loading
Loading
Loading
Loading
+5 −9
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that you cannot create a subscription with negative/in conjunction with timeInterval throttling
Documentation       Check that you cannot create a subscription with invalid throttling (a negative throttling or in conjunction with timeInterval throttling)

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

Test Template       Create Subscription With Different Requests
Test Template       Create Subscription With Invalid Throttling


*** Test Cases ***    FILENAME    EXPECTED_STATUS
028_05_01 ThrottlingAndTimeIntervalConjunction
    subscription-throttling-timeInterval-invalid-sample.jsonld    ${ERROR_TYPE_BAD_REQUEST_DATA}
028_05_02 NegativeThrottling
    subscription-negative-throttling-sample.jsonld    ${ERROR_TYPE_BAD_REQUEST_DATA}
    subscription-invalid-negative-throttling-sample.jsonld    ${ERROR_TYPE_BAD_REQUEST_DATA}


*** Keywords ***
Create Subscription With Different Requests
    [Documentation]    Check that you cannot create a subscription with negative/in conjunction with timeInterval throttling
Create Subscription With Invalid Throttling
    [Documentation]    Check that you cannot create a subscription with invalid throttling (a negative throttling or in conjunction with timeInterval throttling)
    [Tags]    sub-create    5_8_1
    [Arguments]    ${filename}    ${expected_status}
    ${response}=    Create Subscription From File    ${filename}
    Check Response Status Code    400    ${response.status_code}
    Check RL Response Body Containing ProblemDetails Element Containing Type Element set to
    ...    ${response.json()}
    ...    ${expected_status}
    Check RL Response Body Containing ProblemDetails Element Containing Title Element    ${response.json()}
+72 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       If a Subscription defines a throttling member, a Notification shall be sent after the throttling specified (in seconds) has elapsed.

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-with-valid-throttling-sample.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
${fragment_filename}=                   airQualityLevel-fragment.jsonld


*** Test Cases ***
046_15_01 Check that a notification is sent after the throttling has elapsed
    [Documentation]    If a Subscription defines a throttling member, a Notification shall be sent after the throttling specified (in seconds) has elapsed.
    [Tags]    sub-notification    5_8_6    046_15
    Setup Initial Subscriptions

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

    ${notification}    ${headers}=    Wait for notification    timeout=${15}
    Sleep    2
    ${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]
    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 ***
Before Test
    Start Local Server    ${notification_server_host}    ${notification_server_port}

Setup Initial Subscriptions
    ${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
    ...    ${subscription_payload_file_path}
    ...    ${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}

    Create Entity    ${entity_building_filepath}    ${entity_id}
    Sleep    1s
    Create Subscription From Subscription Payload    ${subscription_payload}    ${CONTENT_TYPE_LD_JSON}
    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}
+67 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       If a Subscription defines a throttling member, a Notification shall not be sent if the throttling specified (in seconds) has not elapsed yet.

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-with-valid-throttling-sample.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
${fragment_filename}=                   airQualityLevel-fragment.jsonld


*** Test Cases ***
046_16_01 Check that a notification is not sent if the throttling has not elapsed yet
    [Documentation]    If a Subscription defines a throttling member, a Notification shall not be sent if the throttling specified (in seconds) has not elapsed yet.
    [Tags]    sub-notification    5_8_6    046_16
    Setup Initial Subscriptions

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

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

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

    Wait for no notification


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

Setup Initial Subscriptions
    ${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
    ...    ${subscription_payload_file_path}
    ...    ${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}

    Create Entity    ${entity_building_filepath}    ${entity_id}
    Sleep    1s
    Create Subscription From Subscription Payload    ${subscription_payload}    ${CONTENT_TYPE_LD_JSON}
    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}
+17 −0
Original line number Diff line number Diff line
{
   "id":"urn:ngsi-ld:Subscription:randomUUID",
   "type":"Subscription",
   "entities":[
      {
         "type":"Building"
      }
   ],
   "notification":{
      "format":"keyValues",
      "endpoint":{
         "uri":"http://my.endpoint.org/notify",
         "accept":"application/json"
      }
   },
   "throttling" : -30
}
 No newline at end of file
+1 −4
Original line number Diff line number Diff line
@@ -14,8 +14,5 @@
         "accept":"application/json"
      }
   },
   "throttling" : 30,
   "@context":[
      "https://easy-global-market.github.io/ngsild-api-data-models/ngsi-ld-test-suite/ngsi-ld-test-suite-compound-v1.7.jsonld"
   ]
   "throttling" : 30
}
 No newline at end of file
Loading