LocationAPI_Functions.ttcn 27.2 KB
Newer Older
/**
 *    @author   ETSI / TTF T012
 *    @version  $URL$
 *              $ID:$
 *    @desc     This module provides the custom templates for ITS HTTP based protocols.
 *    @copyright   ETSI Copyright Notification
 *                 No part may be reproduced except as authorized by written permission.
 *                 The copyright and the foregoing restriction extend to reproduction in all media.
 *                 All rights reserved.
 */
module LocationAPI_Functions {

  // JSON
  import from JSON all;

  // LibCommon
  import from LibCommon_BasicTypesAndValues all;
  import from LibCommon_Time all;
  import from LibCommon_VerdictControl all;
  import from LibCommon_Sync all;

  // LibHttp
  import from LibItsHttp_TypesAndValues all;
  import from LibItsHttp_Functions all;
  import from LibItsHttp_Templates all;
  import from LibItsHttp_JsonTemplates all;
  import from LibItsHttp_TestSystem all;

  // LibMec/LocationAPI
  import from LocationAPI_TypesAndValues all;
  import from LocationAPI_Templates all;
  import from LocationAPI_Pixits all;

  // LibMec
  import from LibMec_Templates all;
  import from LibMec_Functions all;
  import from LibMec_Pics all;
  import from LibMec_Pixits all;

  function f_create_user_tracking_subscription(
                                               out UserTrackingSubscription p_user_tracking_subscription
                                               ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;

    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_post(
                                                     PICS_ROOT_API & PX_ME_APP_Q_USERS_LOC_SUB_URI,
                                                     v_headers,
                                                     m_http_message_body_json(
                                                                              m_body_json_user_tracking_subscription(
                                                                                                                     m_user_tracking_subscription(
                                                                                                                                                  PX_CLIENT_ID,
                                                                                                                                                  PX_CALLBACK_REF_URL,
                                                                                                                                                  PX_USER
                                                                                                                                                  ))))));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_201_created(
                                                                        mw_http_message_body_json(
                                                                                                  mw_body_json_user_tracking_subscription(
                                                                                                                                          mw_user_tracking_subscription(
                                                                                                                                                                        PX_CLIENT_ID,
                                                                                                                                                                        PX_CALLBACK_REF_URL,
                                                                                                                                                                        PX_USER
                                                                                                                                                                        )))))) -> value v_response {
        tc_ac.stop;

        p_user_tracking_subscription := v_response.response.body.json_body.userTrackingSubscription;
        log("f_create_user_tracking_subscription: INFO: IUT successfully responds to the subscription: ", p_user_tracking_subscription);
      }
      [] tc_ac.timeout {
        log("f_create_user_tracking_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
    
  } // End of function f_create_user_tracking_subscription

  function f_delete_user_tracking_subscription(
                                               in UserTrackingSubscription p_user_tracking_subscription
                                               ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    var charstring v_uri :=regexp(
                                  oct2char(unichar2oct(p_user_tracking_subscription.resourceURL)),
                                  "?+" & PX_ME_APP_Q_USERS_LOC_SUB_URI & "/(?*)",
                                  0
                                  );
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_delete(
                                                       PICS_ROOT_API & PX_ME_APP_Q_USERS_LOC_SUB_URI & "/" & v_uri,
                                                       v_headers
                                                       )));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_204_no_content
                                           )) {
        tc_ac.stop;
      }
      [] tc_ac.timeout {
        log("f_delete_user_tracking_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
    
  } // End of function f_delete_user_tracking_subscription

  function f_create_periodic_notification_subscription(
                                                       out PeriodicNotificationSubscription p_periodic_notification_subscription
                                                       ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_post(
                                                     PICS_ROOT_API & PX_ME_APP_Q_USERS_TRACK_SUB_URI,
                                                     v_headers,
                                                     m_http_message_body_json(
                                                                              m_body_json_periodic_notification_subscription(
                                                                                                                             m_periodic_notification_subscription(
                                                                                                                                                                  { PX_IP_ADDRESS },
                                                                                                                                                                  PX_CALLBACK_REF_URL,
                                                                                                                                                                  -, -,
                                                                                                                                                                  PX_USER
                                                                                                                                                                  ))))));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_201_created(
                                                                        mw_http_message_body_json(
                                                                                                  mw_body_json_periodic_notification_subscription(
                                                                                                                                                  mw_periodic_notification_subscription(
                                                                                                                                                                                        { PX_IP_ADDRESS },
                                                                                                                                                                                        PX_CALLBACK_REF_URL,
                                                                                                                                                                                        -, -,
                                                                                                                                                                                        PX_USER,
                                                                                                                                                                                        ?
                                                                                                                                                                                        )))))) -> value v_response {
        tc_ac.stop;

        p_periodic_notification_subscription := v_response.response.body.json_body.periodicNotificationSubscription;
        log("f_create_periodic_notification_subscription: INFO: IUT successfully responds to the subscription: ", p_periodic_notification_subscription);
      }
      [] tc_ac.timeout {
        log("f_create_periodic_notification_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
    
  } // End of function f_create_periodic_notification_subscription

  function f_delete_periodic_notification_subscription(
                                                       in PeriodicNotificationSubscription p_position_notification_subscription
                                                       ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    var charstring v_uri := regexp(
                                   oct2char(unichar2oct(p_position_notification_subscription.resourceURL)),
                                   "?+" & PX_ME_APP_Q_USERS_TRACK_SUB_URI & "/(?*)",
                                   0
                                   );
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_delete(
                                                       PICS_ROOT_API & PX_ME_APP_Q_USERS_TRACK_SUB_URI & "/" & v_uri,
                                                       v_headers
                                                       )));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_204_no_content
                                           )) {
        tc_ac.stop;
      }
      [] tc_ac.timeout {
        log("f_delete_periodic_notification_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
  } // End of function f_delete_periodic_notification_subscription

  function f_create_zonal_traffic_subscription(
                                               out ZonalTrafficSubscription p_zonal_traffic_subscription
                                               ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_post(
                                                     PICS_ROOT_API & PX_ME_APP_Q_USERS_INF_SUB_URI,
                                                     v_headers,
                                                     m_http_message_body_json(
                                                                              m_body_json_zonal_traffic_subscription(
                                                                                                                     m_zonal_traffic_subscription(
                                                                                                                                                  PX_CLIENT_ID,
                                                                                                                                                  PX_CALLBACK_REF_URL,
                                                                                                                                                  PX_ZONE_ID
                                                                                                                                                  ))))));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_201_created(
                                                                        mw_http_message_body_json(
                                                                                                  mw_body_json_zonal_traffic_subscription(
                                                                                                                                          mw_zonal_traffic_subscription(
                                                                                                                                                                        PX_CLIENT_ID,
                                                                                                                                                                        PX_CALLBACK_REF_URL,
                                                                                                                                                                        PX_ZONE_ID
                                                                                                                                                                        )))))) -> value v_response {
      tc_ac.stop;

        p_zonal_traffic_subscription := v_response.response.body.json_body.zonalTrafficSubscription;
        log("f_create_zonal_traffic_subscription: INFO: IUT successfully responds to the subscription: ", p_zonal_traffic_subscription);
      }
      [] tc_ac.timeout {
        log("f_create_zonal_traffic_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
    
  } // End of function f_create_zonal_traffic_subscription

  function f_delete_zonal_traffic_subscription(
                                               in ZonalTrafficSubscription p_zonal_traffic_subscription
                                               ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    var charstring v_uri := regexp(
                                   oct2char(unichar2oct(p_zonal_traffic_subscription.resourceURL)),
                                   "?+" & PX_ME_APP_Q_USERS_INF_SUB_URI & "/(?*)",
                                   0
                                   );
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_delete(
                                                       PICS_ROOT_API & PX_ME_APP_Q_USERS_INF_SUB_URI & "/" & v_uri,
                                                       v_headers
                                                       )));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_204_no_content
                                           )) {
        tc_ac.stop;
      }
      [] tc_ac.timeout {
        log("f_delete_zonal_traffic_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
  } // End of function f_delete_zonal_traffic_subscription

  function f_create_circle_notification_subscription(
                                                     out CircleNotificationSubscription p_circle_notification_subscription
                                                     ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_post(
                                                     PICS_ROOT_API & PX_ME_APP_Q_AREA_SUB_URI,
                                                     v_headers,
                                                     m_http_message_body_json(
                                                                              m_body_json_circle_notification_subscription(
                                                                                                                           m_circle_notification_subscription(
                                                                                                                                                              PX_CLIENT_ID, //clientCorrelator
                                                                                                                                                              PX_AREA_SUB_CALLBACK_URI, // callbackReference
                                                                                                                                                              { PX_IP_ADDRESS } // address
                                                                                                                                                              ))))));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_201_created(
                                                                        mw_http_message_body_json(
                                                                                                  mw_body_json_circle_notification_subscription(
                                                                                                                                          mw_circle_notification_subscription(
                                                                                                                                                                              PX_CLIENT_ID
                                                                                                                                                                              )))))) -> value v_response {
        tc_ac.stop;
        
        p_circle_notification_subscription := v_response.response.body.json_body.circleNotificationSubscription;
        log("f_create_circle_notification_subscription: INFO: IUT successfully responds to the subscription: ", p_circle_notification_subscription);
      }
      [] tc_ac.timeout {
        log("f_create_circle_notification_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
    
  } // End of function f_create_circle_notification_subscription

  function f_delete_circle_notification_subscription(
                                                     in CircleNotificationSubscription p_circle_notification_subscription
                                                     ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    var charstring v_uri := regexp(
                                   oct2char(unichar2oct(p_circle_notification_subscription.resourceURL)),
                                   "?+" & PX_ME_APP_Q_AREA_SUB_URI & "/(?*)",
                                   0
                                   );
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_delete(
                                                       PICS_ROOT_API & PX_ME_APP_Q_AREA_SUB_URI & "/" & v_uri,
                                                       v_headers
                                                       )));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_204_no_content
                                           )) {
        tc_ac.stop;
      }
      [] tc_ac.timeout {
        log("f_delete_circle_notification_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
  } // End of function f_delete_circle_notification_subscription











  function f_create_distance_notification_subscription(
                                                       out DistanceNotificationSubscription p_distance_notification_subscription
                                                       ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_post(
                                                     PICS_ROOT_API & PX_ME_APP_Q_DIST_URI,
                                                     v_headers,
                                                     m_http_message_body_json(
                                                                              m_body_json_distance_notification_subscription(
                                                                                                                             m_distance_notification_subscription(
                                                                                                                                                                  PX_UE_DIST_SUB_CALLBACK_URI, // callbackReference
                                                                                                                                                                  -, // checkImmediate
                                                                                                                                                                  PX_CLIENT_ID, //clientCorrelator
                                                                                                                                                                  -, // criteria
                                                                                                                                                                  10.0, // distance
                                                                                                                                                                  -,
                                                                                                                                                                  { PX_UE_MONITORED_IP_ADDRESS } // monitoredAddress
                                                                                                                                                                  ))))));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_201_created(
                                                                        mw_http_message_body_json(
                                                                                                  mw_body_json_distance_notification_subscription(
                                                                                                                                          mw_distance_notification_subscription(
                                                                                                                                                                                PX_UE_DIST_SUB_CALLBACK_URI, // callbackReference
                                                                                                                                                                                -,
                                                                                                                                                                                PX_CLIENT_ID, //clientCorrelator
                                                                                                                                                                                -, -, -,
                                                                                                                                                                                { PX_UE_MONITORED_IP_ADDRESS } // monitoredAddress
                                                                                                                                                                                )))))) -> value v_response {
        tc_ac.stop;
        
        p_distance_notification_subscription := v_response.response.body.json_body.distanceNotificationSubscription;
        log("f_create_distance_notification_subscription: INFO: IUT successfully responds to the subscription: ", p_distance_notification_subscription);
      }
      [] tc_ac.timeout {
        log("f_create_distance_notification_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
    
  } // End of function f_create_distance_notification_subscription

  function f_delete_distance_notification_subscription(
                                                     in DistanceNotificationSubscription p_distance_notification_subscription
                                                     ) runs on HttpComponent {
    var Headers v_headers;
    var HttpMessage v_response;
    var charstring v_uri := regexp(
                                   oct2char(unichar2oct(p_distance_notification_subscription.resourceURL)),
                                   "?+" & PX_ME_APP_Q_DIST_URI & "/(?*)",
                                   0
                                   );
    
    f_init_default_headers_list(-, -, v_headers);
    httpPort.send(
                  m_http_request(
                                 m_http_request_delete(
                                                       PICS_ROOT_API & PX_ME_APP_Q_DIST_URI & "/" & v_uri,
                                                       v_headers
                                                       )));
    tc_ac.start;
    alt {
      [] httpPort.receive(
                          mw_http_response(
                                           mw_http_response_204_no_content
                                           )) {
        tc_ac.stop;
      }
      [] tc_ac.timeout {
        log("f_delete_distance_notification_subscription: INCONC: Expected message not received");
      }
    } // End of 'alt' statement
  } // End of function f_delete_distance_notification_subscription

} // End of module LocationAPI_Functions