Commit 94612f5e authored by Arnaud Van der Poorten's avatar Arnaud Van der Poorten
Browse files

fix 046_01

parent 7a7da649
Loading
Loading
Loading
Loading
+28 −15
Original line number Diff line number Diff line
@@ -4,38 +4,51 @@ Resource ${EXECDIR}/resources/ApiUtils.resource
Resource          ${EXECDIR}/resources/AssertionUtils.resource
Resource          ${EXECDIR}/resources/JsonUtils.resource
Resource          ${EXECDIR}/resources/NotificationUtils.resource
Suite Setup       Setup Initial Subscriptions
Suite Teardown    Delete Initial Subscriptions
# Suite Setup       Setup Initial Subscriptions
# Suite Teardown    Delete Initial Subscriptions
Suite Setup    Before Test
Suite Teardown    After Test

*** Variable ***
${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-active.jsonld
#subscriptions/testsubscription.jsonld 
${building_id_prefix}=    urn:ngsi-ld:Building:
${entity_building_filepath}=    building-simple-attributes-sample.jsonld
#testentity.jsonld
${fragment_filename}=    airQualityLevel-fragment.jsonld
#testfragment.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}
    Create Subscription    ${subscription_id}    ${subscription_payload_file_path}    ${CONTENT_TYPE_LD_JSON}
    ${subscription_payload}=    Load Subscription Sample With Reachable Endpoint    ${subscription_payload_file_path}    ${subscription_id}    ${notification_server_send_url}
    # http://ptsv2.com/t/9jkg1-1625063286/post
    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
    Setup Initial Subscriptions
    NotificationUtils.Start Local Server    ${notification_server_host}    ${notification_server_port}

After Test
    Delete Initial Subscriptions
    Stop Local Server

    
*** Test Cases ***
Check that a notification is only sent if status is active
    [Arguments]      ${fragment_filename}    
    [Documentation]     Check that a notification is only sent if and only if the status is active
    [Tags]    sub-notification    5_11_7
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${subscription_payload}=    Load Subscription Sample With Reachable Endpoint    ${subscription_payload_file_path}    ${subscription_id}
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix} 
    Create Entity    ${entity_building_filepath}    ${entity_id}
    
    @{expected_notification_data_entities}=    Create List    Building
    
    Set Suite Variable    ${subscription_id}
    Update Entity Attributes    ${entity_id}    ${fragment_filename}    ${CONTENT_TYPE_LD_JSON}
    Wait for subscription notification and validate it  ${subscription_id}  ${expected_notification_data_entities}  timeout=${5}





    Wait for subscription notification and validate it  ${subscription_id}  ${expected_notification_data_entities}  timeout=${10}    expected_notification_type=Notification
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
{
    "airQualityLevel": {
        "type": "Property",
        "value": 5,
        "unitCode": "C62",
        "observedAt": "2020-10-10T16:40:00.000Z"
    },
    "@context": [
        "https://raw.githubusercontent.com/easy-global-market/ngsild-api-data-models/feature/add-json-ld-context-for-ngsi-ld-test-suite/ngsi-ld-test-suite/ngsi-ld-test-suite-context.jsonld"
    ]
}
 No newline at end of file
+20 −0
Original line number Diff line number Diff line
{
   "id":"urn:ngsi-ld:Subscription:randomUUID",
   "type":"Subscription",
   "isActive": true,
   "expiresAt": null,
   "entities":[
      {
         "type":"Building"
      }
   ],
   "notification":{
      "endpoint":{
         "uri":"http://my.endpoint.org/notify",
         "accept":"*/*"
      }
   },
   "@context":[
      "https://raw.githubusercontent.com/easy-global-market/ngsild-api-data-models/feature/add-json-ld-context-for-ngsi-ld-test-suite/ngsi-ld-test-suite/ngsi-ld-test-suite-context.jsonld"
   ]
}
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
@@ -691,6 +691,16 @@ Create Subscription
    Output  response
    [return]   ${response}

Create Subscription From Subscription Payload
    [Arguments]  ${subscription_payload}    ${content_type}=${CONTENT_TYPE_LD_JSON}    ${accept}=${EMPTY}    ${context}=${EMPTY}
    &{headers}=  Create Dictionary  Content-Type=${content_type}
    Run Keyword If     '${accept}'!=''       Set To Dictionary   ${headers}   Accept    ${accept}
    Run Keyword If     '${context}'!=''       Set To Dictionary   ${headers}    Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json"
    ${response}=  POST  ${SUBSCRIPTION_ENDPOINT_PATH}  body=${subscription_payload}  headers=${headers}
    Output  request
    Output  response


Create Subscription From File
    [Arguments]  ${filename}
    ${file_content}=    Get File    ${EXECDIR}/data/subscriptions/${filename}
+10 −8
Original line number Diff line number Diff line
@@ -9,11 +9,14 @@ Library ${EXECDIR}/libraries/dateTimeUtils.py
*** Variable ***
${notification_type}=  ContextSource Notfication
${date_format}=  %Y-%m-%dT%H:%M:%SZ
${date_format_with_millis}=  %Y-%m-%dT%H:%M:%S.%fZ


*** Keywords ***
Start Local Server    
    [Arguments]  ${host}=${notification_server_host}    ${port}=${notification_server_port}
    #Initialize HTTP Client And Server
    Start Server        0.0.0.0   8085
    Start Server        ${host}   ${port}

Wait for notification
    [Arguments]  ${timeout}=${5}
@@ -56,7 +59,7 @@ Wait for notification and validate it
    Run Keyword If     ${expected_notification_data_entities_length}>0       Check Notification Data Entities  ${notification}[data][0][information]    ${expected_notification_data_entities}

Wait for subscription notification and validate it
    [Arguments]  ${expected_subscription_id}  ${expected_notification_data_entities}=${EMPTY}  ${timeout}=${5}
    [Arguments]  ${expected_subscription_id}  ${expected_notification_data_entities}=${EMPTY}  ${timeout}=${5}    ${expected_notification_type}=${notification_type}
    #HTTP server receives it and checks incoming request for correctness
    #.. "Wait For Request"
    #.... This call is blocked until HTTP request arrives or timeout.
@@ -71,16 +74,15 @@ Wait for subscription notification and validate it
   

    log     ${notification}
    Should Be Equal     ${notification}[type]   ${notification_type}
    Should Be Equal     ${notification}[type]   ${expected_notification_type}
    Should Be Equal     ${notification}[subscriptionId]   ${expected_subscription_id}
    ${is_date}=    Is Date    ${notification}[notifiedAt]    ${date_format}
    Should Be True      ${is_date}
    ${is_date_with_millis}=    Is Date    ${notification}[notifiedAt]    ${date_format_with_millis}
    Should Be True    ${is_date} or ${is_date_with_millis}
    ${index}=    Set Variable    0
    
    Should Be Equal     '${notification_data_length}'     '${expected_notification_data_length}'
    
    # TODO Currently we check entities information of the first CSR returned in the notification, find a way to check them all
    Run Keyword If     ${expected_notification_data_entities_length}>0       Check Notification Data Entities  ${notification}[data][0][information]    ${expected_notification_data_entities}
    # Run Keyword If     ${expected_notification_data_entities_length}>0       Check Notification Data Entities  ${notification}[data][0][information]    ${expected_notification_data_entities}



Loading