Commit 0065ff51 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

fix(046_XX): tests checking status of notifications

parent fcd90775
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -57,9 +57,7 @@ Check that timesSent is increased by one


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


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


    Retrieve Subscription    ${subscription_id}    accept=${CONTENT_TYPE_LD_JSON}   context=${ngsild_test_suite_context}
    Retrieve Subscription    ${subscription_id}    accept=${CONTENT_TYPE_LD_JSON}   context=${ngsild_test_suite_context}


+17 −6
Original line number Original line Diff line number Diff line
@@ -14,7 +14,7 @@ Suite Teardown After Test
${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-active.jsonld
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-active.jsonld
${building_id_prefix}=    urn:ngsi-ld:Building:
${building_id_prefix}=    urn:ngsi-ld:Building:
${entity_building_filepath}=    building-no-attributes.jsonld
${entity_building_filepath}=    building-simple-attributes-sample.jsonld
${fragment_filename}=    airQualityLevel-fragment.jsonld
${fragment_filename}=    airQualityLevel-fragment.jsonld
${notification_server_send_url}=     http://${send_notification_server_host}:${send_notification_server_port}/notify
${notification_server_send_url}=     http://${send_notification_server_host}:${send_notification_server_port}/notify


@@ -47,7 +47,7 @@ Delete Initial Entity


*** Test Cases ***
*** Test Cases ***
Check that lastNotification is updated
Check that lastNotification is updated
    [Documentation]     The notification.lastNotification member shall be updated with a timestamp representing the current date and time. This test will check the format. 
    [Documentation]     The status, lastNotification and lastSuccess members shall be updated with expected value and dates. This test will check these formats. 
    [Tags]    sub-notification    5_11_7    046_12
    [Tags]    sub-notification    5_11_7    046_12


    Add Initial Entity
    Add Initial Entity
@@ -55,12 +55,23 @@ Check that lastNotification is updated


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


    ${notification}=    Wait for notification    timeout=${10}
    Wait for notification    timeout=${10}
    
    
    Dictionary Should Contain Key    ${notification}    lastNotification
    Retrieve Subscription    ${subscription_id}    accept=${CONTENT_TYPE_LD_JSON}   context=${ngsild_test_suite_context}


    ${is_date}=    Is Date    ${notification}[lastNotification]    ${date_format}
    ${notification_info}=   Get Value From Json     ${response}     $.body.notification
    ${is_date_with_millis}=    Is Date    ${notification}[lastNotification]    ${date_format_with_millis}
    Output  ${notification_info}

    Dictionary Should Contain Key    ${notification_info}[0]    status
    Should Be Equal    ok     ${notification_info}[0][status]

    Dictionary Should Contain Key    ${notification_info}[0]    lastNotification
    ${is_date}=    Is Date    ${notification_info}[0][lastNotification]    ${date_format}
    ${is_date_with_millis}=    Is Date    ${notification_info}[0][lastNotification]    ${date_format_with_millis}
    Should Be True    ${is_date} or ${is_date_with_millis}
    Should Be True    ${is_date} or ${is_date_with_millis}


    Dictionary Should Contain Key    ${notification_info}[0]    lastSuccess
    ${is_date}=    Is Date    ${notification_info}[0][lastSuccess]    ${date_format}
    ${is_date_with_millis}=    Is Date    ${notification_info}[0][lastSuccess]    ${date_format_with_millis}
    Should Be True    ${is_date} or ${is_date_with_millis}
+33 −14
Original line number Original line Diff line number Diff line
*** Settings ***
*** Settings ***
Documentation     The notification.lastNotification member shall be updated with a timestamp representing the current date and time. This test will check the format.
Documentation     If the response to the notification request is different than 200 OK then implementations shall: Update notification.lastFailure with a timestamp representing the current date and time, update notification.status to "failed

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

Suite Setup       Before Test
Suite Setup       Setup Initial Subscription
Suite Teardown    After Test
Suite Teardown    Delete Initial Subscription


*** Variable ***
*** Variable ***
${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-active.jsonld
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-active.jsonld
${building_id_prefix}=    urn:ngsi-ld:Building:
${building_id_prefix}=    urn:ngsi-ld:Building:
${entity_building_filepath}=    building-simple-attributes-sample.jsonld
${fragment_filename}=    airQualityLevel-fragment.jsonld
${fragment_filename}=    airQualityLevel-fragment.jsonld


*** Test Case ***
*** Test Case ***
Check that a notification is only sent if statis is active
Check that lastFailure and status are updated if a notification could not be sent
    [Documentation]     The notification.lastNotification member shall be updated with a timestamp representing the current date and time. This test will check the format.
    [Documentation]     If the response to the notification request is different than 200 OK then implementations shall: Update notification.lastFailure with a timestamp representing the current date and time, update notification.status to "failed
    [Tags]    sub-notification    5_11_7    046_13
    [Tags]    sub-notification    5_11_7    046_13
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}


    @{expected_notification_data_entities}=    Create List    Building
    @{expected_notification_data_entities}=    Create List    Building
    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}
    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}


    Wait for redirected request
    Sleep   10s 

    Retrieve Subscription    ${subscription_id}    accept=${CONTENT_TYPE_LD_JSON}   context=${ngsild_test_suite_context}

    ${notification_info}=   Get Value From Json     ${response}     $.body.notification
    Output  ${notification_info}


    @{expected_notification_additional_members}=    Create List    lastNotification    lastSuccess
    Dictionary Should Contain Key    ${notification_info}[0]    status
    Check NotificationParams    ${notification_expectation_file_path}    ${expected_notification_additional_members}
    Should Be Equal    failed     ${notification_info}[0][status]


    Dictionary Should Contain Key    ${notification_info}[0]    lastFailure
    ${is_date}=    Is Date    ${notification_info}[0][lastFailure]    ${date_format}
    ${is_date_with_millis}=    Is Date    ${notification_info}[0][lastFailure]    ${date_format_with_millis}
    Should Be True    ${is_date} or ${is_date_with_millis}


*** Keywords ***
*** Keywords ***
Setup Initial Subscription
Setup Initial Subscription
    Start Local Server
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    Create Subscription     ${subscription_id}     ${subscription_payload_file_path}    ${CONTENT_TYPE_LD_JSON} 
    Create Subscription     ${subscription_id}     ${subscription_payload_file_path}    ${CONTENT_TYPE_LD_JSON} 
    Set Suite Variable    ${subscription_id}
    Set Suite Variable    ${subscription_id}


Delete Initial Subscription
Delete Initial Subscription
    Stop Local Server
    Delete Subscription      ${subscription_id}
    Delete Subscription      ${subscription_id}


Add Initial Entity
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix} 
    Create Entity    ${entity_building_filepath}    ${entity_id}
    Set Suite Variable    ${entity_id}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}


Before Test
    Setup Initial Subscription
    Add Initial Entity

After Test
    Delete Initial Subscription
    Delete Initial Entity
+50 −23
Original line number Original line Diff line number Diff line
*** Settings ***
*** Settings ***
Documentation     If the response to the notification request is different than 200 OK then implementations shall: Update notification.lastFailure with a timestamp representing the current date and time., Update notification.status to "failed
Documentation     A Notification shall be sent (as mandated by each concrete binding and including any optional endpoint.info defined by clause 5.2.22) to the endpoint specified by the endpoint.uri member of the notification structure defined by clause 5.2.14


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

Suite Setup       Setup Initial Subscription
Suite Setup    Before Test
Suite Teardown    Delete Initial Subscription
Suite Teardown    After Test


*** Variable ***
*** Variable ***
${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-active.jsonld
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-accept-jsonld.jsonld
${building_id_prefix}=    urn:ngsi-ld:Building:
${building_id_prefix}=    urn:ngsi-ld:Building:
${entity_building_filepath}=    building-simple-attributes-sample.jsonld
${fragment_filename}=    airQualityLevel-fragment.jsonld
${fragment_filename}=    airQualityLevel-fragment.jsonld
${notification_server_send_url}=     http://${send_notification_server_host}:${send_notification_server_port}/notify


*** Test Case ***
*** Keywords ***
Check that a notification is only sent if statis is active
Setup Initial Subscriptions
    [Documentation]     If the response to the notification request is different than 200 OK then implementations shall: Update notification.lastFailure with a timestamp representing the current date and time., Update notification.status to "failed
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    [Tags]    sub-notification    5_11_7    046_14
    ${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 Subscription From Subscription Payload    ${subscription_payload}    ${CONTENT_TYPE_LD_JSON}
    Set Suite Variable    ${subscription_id}

Delete Initial Subscriptions
    Delete Subscription    ${subscription_id}

Before Test
    NotificationUtils.Start Local Server    ${notification_server_host}    ${notification_server_port}

After Test
    Delete Initial Subscriptions
    Delete Initial Entity
    Stop Local Server

Add Initial Entity
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix} 
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix} 
    Create Entity    ${entity_building_filepath}    ${entity_id}
    Set Suite Variable    ${entity_id}


    @{expected_notification_data_entities}=    Create List    Building
Delete Initial Entity
    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}
    Delete Entity by Id    ${entity_id}


    Wait for redirected failed request
*** Test Cases ***
Check that a notification is sent as JSON-LD
    [Documentation]     The Notification content shall be JSON-LD when we set endpoint.accept to 'application/ld+json'
    [Tags]    sub-notification    5_11_7    046_14


    @{expected_notification_additional_members}=    Create List    lastNotification    lastFailure
    Add Initial Entity
    Check NotificationParams    ${notification_expectation_file_path}    ${expected_notification_additional_members}
    Setup Initial Subscriptions


*** Keywords ***
    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}
Setup Initial Subscription
    Start Local Server
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    Create Subscription     ${subscription_id}     ${subscription_payload_file_path}    ${CONTENT_TYPE_LD_JSON} 
    Set Suite Variable    ${subscription_id}


Delete Initial Subscription
    Wait For Request    timeout=${10}
    Stop Local Server
    Reply By   200
    Delete Subscription      ${subscription_id}

    ${notification_headers} =    Get Request Headers
    Dictionary Should Not Contain Key    ${notification_headers}    Link

    ${notification_payload}=     Get Request Body
    # json.loads parses the payload as json. It fails if the payload is malformed
    ${notification}    Evaluate    json.loads('''${notification_payload}''')    json
    Dictionary Should Contain Key    ${notification}[data][0]    @context


+0 −69
Original line number Original line Diff line number Diff line
*** Settings ***
Documentation     A Notification shall be sent (as mandated by each concrete binding and including any optional endpoint.info defined by clause 5.2.22) to the endpoint specified by the endpoint.uri member of the notification structure defined by clause 5.2.14


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

Suite Setup    Before Test
Suite Teardown    After Test

*** Variable ***
${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-accept-jsonld.jsonld
${building_id_prefix}=    urn:ngsi-ld:Building:
${entity_building_filepath}=    building-simple-attributes-sample.jsonld
${fragment_filename}=    airQualityLevel-fragment.jsonld
${notification_server_send_url}=     http://${send_notification_server_host}:${send_notification_server_port}/notify

*** Keywords ***
Setup Initial Subscriptions
    ${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}
    ${subscription_payload}=    Set Entity Id In Subscription    ${subscription_payload}    ${entity_id}
    Create Subscription From Subscription Payload    ${subscription_payload}    ${CONTENT_TYPE_LD_JSON}
    Set Suite Variable    ${subscription_id}

Delete Initial Subscriptions
    Delete Subscription    ${subscription_id}

Before Test
    NotificationUtils.Start Local Server    ${notification_server_host}    ${notification_server_port}

After Test
    Delete Initial Subscriptions
    Delete Initial Entity
    Stop Local Server

Add Initial Entity
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix} 
    Create Entity    ${entity_building_filepath}    ${entity_id}
    Set Suite Variable    ${entity_id}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}

*** Test Cases ***
Check that a notification is sent as JSON-LD
    [Documentation]     The Notification content shall be JSON-LD when we set endpoint.accept to 'application/ld+json'
    [Tags]    sub-notification    5_11_7    046_10

    Add Initial Entity
    Setup Initial Subscriptions

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

    Wait For Request    timeout=${10}
    Reply By   200

    ${notification_headers} =    Get Request Headers
    Dictionary Should Not Contain Key    ${notification_headers}    Link

    ${notification_payload}=     Get Request Body
    # json.loads parses the payload as json. It fails if the payload is malformed
    ${notification}    Evaluate    json.loads('''${notification_payload}''')    json
    Dictionary Should Contain Key    ${notification}[data][0]    @context