Skip to content
046_14.robot 3.14 KiB
Newer Older
Gert De Tant @ Sirus's avatar
Gert De Tant @ Sirus committed
*** Settings ***
Documentation       The Notification content shall be JSON-LD when endpoint.accept is set to JSON-LD
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
Gert De Tant @ Sirus's avatar
Gert De Tant @ Sirus committed

*** Variables ***
${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://${notification_server_host}:${notification_server_port}/notify
lopezaguilar's avatar
lopezaguilar committed
046_14_01 Check that a notification is sent as JSON-LD
lopezaguilar's avatar
lopezaguilar committed
    [Documentation]    The Notification content shall be JSON-LD when endpoint.accept is set to 'application/ld+json'
    [Tags]    sub-notification    5_8_6

    Add Initial Entity
    Sleep    1s
    Setup Initial Subscriptions
lopezaguilar's avatar
lopezaguilar committed
    Sleep    1s
lopezaguilar's avatar
lopezaguilar committed
    ${response}=    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}
lopezaguilar's avatar
lopezaguilar committed
    ${notification}    ${headers}=    Wait For Notification    timeout=${10}
    Reply By    200

    ${notification_headers}=    Get Request Headers
    ${notification_headers_dict}=    Convert To Dictionary    ${notification_headers}
    Dictionary Should Not Contain Key    ${notification_headers_dict}    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


*** 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}
Gert De Tant @ Sirus's avatar
Gert De Tant @ Sirus committed

poujol's avatar
poujol committed
    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}