Commit 5da88413 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

fix(046_06): mismatch between subscription and CSR subscription

parent 7d47d698
Loading
Loading
Loading
Loading
+18 −11
Original line number Original line Diff line number Diff line
@@ -5,33 +5,40 @@ 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
Suite Setup       Setup Initial Subscriptions
Suite Setup       Setup Server And Subscriptions
Suite Teardown    Delete Initial Subscriptions
Suite Teardown    Delete Server And Subscriptions


*** 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-query.json
${subscription_payload_file_path}=    subscriptions/subscription-building-entities-active-query.jsonld
${building_id_prefix}=    urn:ngsi-ld:Building:
${building_id_prefix}=    urn:ngsi-ld:Building:
${building_filename}=    building-location-attribute.jsonld
${building_filename}=    building-location-attribute.jsonld
${notification_server_send_url}=     http://${send_notification_server_host}:${send_notification_server_port}/notify


*** Keywords ***
*** Keywords ***
Setup Initial Subscriptions
Setup Server And Subscriptions
    ${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}
    ${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}
    Set Suite Variable    ${subscription_id}
    NotificationUtils.Start Local Server    ${notification_server_host}    ${notification_server_port}


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


*** Test Case ***
*** Test Case ***
Check that a notification is sent with all entities with matching context source
Check that a notification is sent with all matching entities
    [Documentation]     only the subscribed Entities whose origin Context Source matches the referred filter shall be included.
    [Documentation]     only the subscribed Entities matching the query and watched attributes shall be included.
    [Tags]    sub-notification    5_11_7    046_06
    [Tags]    sub-notification    5_11_7    046_06
    ${subscription_payload}=    Load Subscription Sample With Reachable Endpoint    ${subscription_payload_file_path}    ${subscription_id}
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${entity_building}=    Create Entity Selecting Content Type    ${building_filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    ${entity_building}=    Create Entity Selecting Content Type    ${building_filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}


    Wait for subscription notification and validate it  ${subscription_id}  ${entity_building}  timeout=${5}
    ${notification}=    Wait for notification    timeout=${10}

    Output  ${notification}
    Should be Equal    ${subscription_id}    ${notification}[subscriptionId]
    Should be Equal    ${entity_id}    ${notification}[data][0][id]






+22 −0
Original line number Original line Diff line number Diff line
{
{
   "id":"urn:ngsi-ld:Subscription:randomUUID",
   "type":"Subscription",
   "type":"Subscription",
   "isActive": true,
   "isActive": true,
   "expiresAt": null,
   "entities":[
   "entities":[
      {
      {
         "type":"Building"
         "type":"Building"
      }
      }
   ],
   ],
   "q":"name=\"Eifel Tower\"",
   "watchedAttributes": ["name"],
   "q":"name==\"Eiffel Tower\"",
   "notification":{
   "notification":{
      "format":"keyValues",
      "format":"keyValues",
      "endpoint":{
      "endpoint":{
         "uri":"http://my.endpoint.org/notify",
         "uri":"http://my.endpoint.org/notify",
         "accept":"application/json"
         "accept":"application/json"
      }
      }
   }
   },
   "@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
+0 −26
Original line number Original line Diff line number Diff line
@@ -62,32 +62,6 @@ Wait for notification and validate it
    # TODO Currently we check entities information of the first CSR returned in the notification, find a way to check them all
    # 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}


Wait for subscription notification and validate it
    [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.
    #.... Further detaills: https://annoviko.github.io/robotframework-httpctrl/server.html#Wait%20For%20Request
    Wait For Request    ${timeout}
    Reply By   200

    ${notification_payload}=     Get Request Body
    ${notification}    Evaluate    json.loads('''${notification_payload}''')    json
    ${notification_data_length}=    Get length    ${notification}[data]
    ${expected_notification_data_entities_length}=    Get length    ${expected_notification_data_entities}

    log     ${notification}
    Should Be Equal     ${notification}[type]   ${expected_notification_type}
    Should Be Equal     ${notification}[subscriptionId]   ${expected_subscription_id}
    ${is_date}=    Is Date    ${notification}[notifiedAt]    ${date_format}
    ${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
    
    # 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}
    [return] ${notification}

Wait for no notification
Wait for no notification
    [Arguments]  ${timeout}=${5}
    [Arguments]  ${timeout}=${5}
    #HTTP server receives it and checks incoming request for correctness
    #HTTP server receives it and checks incoming request for correctness