Commit 408472e9 authored by Mubeena Ishaq's avatar Mubeena Ishaq
Browse files

Validation and fixes for MEC048 using mock server

parent c2c85f85
Loading
Loading
Loading
Loading
+57 −26
Original line number Original line Diff line number Diff line
@@ -18,15 +18,19 @@ int json_codec_mec048::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& ms
  if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_tenantInfo)) {
  if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_tenantInfo)) {
    const SelfServiceEnablementAPI__TypesAndValues::TenantInfo& tenant_info = msg.tenantInfo();
    const SelfServiceEnablementAPI__TypesAndValues::TenantInfo& tenant_info = msg.tenantInfo();
    tenant_info.encode(SelfServiceEnablementAPI__TypesAndValues::TenantInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    tenant_info.encode(SelfServiceEnablementAPI__TypesAndValues::TenantInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = /*char2oct(CHARSTRING("{\"TenantInfo\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
    data = char2oct(CHARSTRING("{\"tenantInfo\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_resourceUsageSubscription)) {
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_resourceUsageSubscription)) {
    const SelfServiceEnablementAPI__TypesAndValues::ResourceUsageSubscription& resource_usage_subscription = msg.resourceUsageSubscription();
    const SelfServiceEnablementAPI__TypesAndValues::ResourceUsageSubscription& resource_usage_subscription = msg.resourceUsageSubscription();
    resource_usage_subscription.encode(SelfServiceEnablementAPI__TypesAndValues::ResourceUsageSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    resource_usage_subscription.encode(SelfServiceEnablementAPI__TypesAndValues::ResourceUsageSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = /*char2oct(CHARSTRING("{\"ResourceUsageSubscription\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
    data = char2oct(CHARSTRING("{\"resourceUsageSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_siteResourceUsageSubscription)) {
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_siteResourceUsageSubscription)) {
    const SelfServiceEnablementAPI__TypesAndValues::SiteResourceUsageSubscription& site_resource_usage_subscription = msg.siteResourceUsageSubscription();
    const SelfServiceEnablementAPI__TypesAndValues::SiteResourceUsageSubscription& site_resource_usage_subscription = msg.siteResourceUsageSubscription();
    site_resource_usage_subscription.encode(SelfServiceEnablementAPI__TypesAndValues::SiteResourceUsageSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    site_resource_usage_subscription.encode(SelfServiceEnablementAPI__TypesAndValues::SiteResourceUsageSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = /*char2oct(CHARSTRING("{\"SiteResourceUsageSubscription\": ")) + */OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
    data = char2oct(CHARSTRING("{\"siteResourceUsageSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_resourceQuotaInfo)) {
    const SelfServiceEnablementAPI__TypesAndValues::ResourceQuotaInfo& resource_quota_info = msg.resourceQuotaInfo();
    resource_quota_info.encode(SelfServiceEnablementAPI__TypesAndValues::ResourceQuotaInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"resourceQuotaInfo\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else {
  } else {
    return json_codec::encode(msg, data);
    return json_codec::encode(msg, data);
  }
  }
@@ -62,30 +66,37 @@ int json_codec_mec048::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBo
  } else {
  } else {
    str = it->second;
    str = it->second;
  }
  }
  // ..and create the decoding buffer
  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
  TTCN_EncDec::clear_error();
  loggers::get_instance().log("json_codec_mec048::decode: decoding_buffer='%c' / '%s'", str[0], str.c_str());
  TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));


  if (it->second.find("\"tenantId\"") != std::string::npos) { // Be careful to the order
  // Handle tenantInfo wrapper
    if (it->second[0] == '[') {
  std::string decoded_str;
      SelfServiceEnablementAPI__TypesAndValues::TenantInfoList tenant_info_list;
  if (str.find("\"tenantInfo\"") != std::string::npos) {
      tenant_info_list.decode(SelfServiceEnablementAPI__TypesAndValues::TenantInfoList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    // Extract the inner JSON object
      msg.tenantInfoList() = tenant_info_list;
    size_t start = str.find_first_of('{', str.find("\"tenantInfo\"") + 11); // Skip past "tenantInfo":
    size_t end = str.rfind('}'); // Find the last closing brace
    if (start != std::string::npos && end != std::string::npos && end > start) {
      decoded_str = str.substr(start, end - start + 1);
    } else {
    } else {
      SelfServiceEnablementAPI__TypesAndValues::TenantInfo tenant_info;
      loggers::get_instance().warning("json_codec_mec048::decode: Invalid tenantInfo JSON structure: %s", str.c_str());
      tenant_info.decode(SelfServiceEnablementAPI__TypesAndValues::TenantInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
      return -1;
      msg.tenantInfo() = tenant_info;
    }
    }
  } else if (
  } else if (str.find("\"resourceUsageSubscription\"") != std::string::npos) {
              (it->second.find("\"_links\"") != std::string::npos) && 
    // Extract the inner JSON object for resourceUsageSubscription
              ((it->second.find("\"subscriptions\"") != std::string::npos) || (it->second.find("\"subscriptionType\"") == std::string::npos))
    size_t start = str.find_first_of('{', str.find("\"resourceUsageSubscription\"") + 25); // Skip past "resourceUsageSubscription":
            ) {
    size_t end = str.rfind('}'); // Find the last closing brace
    SelfServiceEnablementAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
    if (start != std::string::npos && end != std::string::npos && end > start) {
    subscription_link_list.decode(SelfServiceEnablementAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
        decoded_str = str.substr(start, end - start + 1);
    msg.subscriptionLinkList__cse() = subscription_link_list;
    } else {
  } else if ((it->second.find("\"subscriptionType\"") != std::string::npos) && (it->second.find("\"ResourceUsageSubscription\"") != std::string::npos)) {
        loggers::get_instance().warning("json_codec_mec048::decode: Invalid resourceUsageSubscription JSON structure: %s", str.c_str());
        return -1;
    }
  } else {
    decoded_str = str; // Use original string if no tenantInfo wrapper
  }

  // Create decoding buffer with the adjusted JSON
  TTCN_Buffer decoding_buffer(OCTETSTRING(decoded_str.length(), (const unsigned char*)decoded_str.c_str()));

  if ((it->second.find("\"subscriptionType\"") != std::string::npos) && (it->second.find("\"ResourceUsageSubscription\"") != std::string::npos)) {
    SelfServiceEnablementAPI__TypesAndValues::ResourceUsageSubscription resource_usage_subscription;
    SelfServiceEnablementAPI__TypesAndValues::ResourceUsageSubscription resource_usage_subscription;
    resource_usage_subscription.decode(SelfServiceEnablementAPI__TypesAndValues::ResourceUsageSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    resource_usage_subscription.decode(SelfServiceEnablementAPI__TypesAndValues::ResourceUsageSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.resourceUsageSubscription() = resource_usage_subscription;
    msg.resourceUsageSubscription() = resource_usage_subscription;
@@ -93,8 +104,28 @@ int json_codec_mec048::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBo
    SelfServiceEnablementAPI__TypesAndValues::SiteResourceUsageSubscription site_resource_usage_subscription;
    SelfServiceEnablementAPI__TypesAndValues::SiteResourceUsageSubscription site_resource_usage_subscription;
    site_resource_usage_subscription.decode(SelfServiceEnablementAPI__TypesAndValues::SiteResourceUsageSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    site_resource_usage_subscription.decode(SelfServiceEnablementAPI__TypesAndValues::SiteResourceUsageSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.siteResourceUsageSubscription() = site_resource_usage_subscription;
    msg.siteResourceUsageSubscription() = site_resource_usage_subscription;
  } else if (
              (it->second.find("\"_links\"") != std::string::npos) && 
              ((it->second.find("\"subscriptions\"") != std::string::npos) || (it->second.find("\"subscriptionType\"") == std::string::npos))
            ) {
    SelfServiceEnablementAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
    subscription_link_list.decode(SelfServiceEnablementAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.subscriptionLinkList__cse() = subscription_link_list;
  } else if (it->second.find("\"tenantId\"") != std::string::npos) { // Be careful to the order
    if (it->second[0] == '[') {
      SelfServiceEnablementAPI__TypesAndValues::TenantInfoList tenant_info_list;
      tenant_info_list.decode(SelfServiceEnablementAPI__TypesAndValues::TenantInfoList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
      msg.tenantInfoList() = tenant_info_list;
    } else{
      SelfServiceEnablementAPI__TypesAndValues::TenantInfo tenant_info;
      tenant_info.decode(SelfServiceEnablementAPI__TypesAndValues::TenantInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
      msg.tenantInfo() = tenant_info;
    }
  } else {
  } else {
    return json_codec::decode(p_data, msg, p_params);
      loggers::get_instance().warning("json_codec_mec048::decode: No matching structure found, assigning raw");
      // Assign raw alternative of union with full original string
      msg.raw() = CHARSTRING(str.c_str());
      loggers::get_instance().log("json_codec_mec048::decode: Assigned raw='%s'", str.c_str());
  }
  }


  loggers::get_instance().log_msg("<<< json_codec_mec048::decode: ", (const Base_Type&)msg);
  loggers::get_instance().log_msg("<<< json_codec_mec048::decode: ", (const Base_Type&)msg);
+242 −207

File changed.

Preview size limit exceeded, changes collapsed.

+151 −131

File changed.

Preview size limit exceeded, changes collapsed.

+33 −29
Original line number Original line Diff line number Diff line
@@ -9,7 +9,7 @@ module SelfServiceEnablementAPI_Pixits {
  // LibMec/SelfServiceEnablementAPI
  // LibMec/SelfServiceEnablementAPI
  import from SelfServiceEnablementAPI_TypesAndValues all;
  import from SelfServiceEnablementAPI_TypesAndValues all;


  modulepar Json.String PX_CSE_CUSTOMER_ID_1           := ""
  modulepar Json.String PX_CSE_CUSTOMER_ID_1            := "customer01"


  modulepar Json.String PX_CSE_CUSTOMER_NAME_1          := "customerName";
  modulepar Json.String PX_CSE_CUSTOMER_NAME_1          := "customerName";


@@ -17,18 +17,22 @@ module SelfServiceEnablementAPI_Pixits {


  modulepar Json.String PX_CSE_TENANT_NAME_1            := "tenantX";
  modulepar Json.String PX_CSE_TENANT_NAME_1            := "tenantX";


  modulepar Json.String PX_CSE_CUSTOMER_ID_2           := ""
  modulepar Json.String PX_CSE_CUSTOMER_ID_2            := "customer02"


  modulepar Json.String PX_CSE_CUSTOMER_NAME_2          := "customerName02";
  modulepar Json.String PX_CSE_CUSTOMER_NAME_2          := "customerName02";


  modulepar Json.String PX_CSE_TENANT_NAME_2            := "tenantY";
  modulepar Json.String PX_CSE_TENANT_NAME_2            := "tenantY";


  modulepar Json.String PX_CSE_CUSTOMER_ID_3          := ""
  modulepar Json.String PX_CSE_CUSTOMER_ID_3            := "customer03"


  modulepar Json.String PX_CSE_CUSTOMER_NAME_3          := "customerName03";
  modulepar Json.String PX_CSE_CUSTOMER_NAME_3          := "customerName03";


  modulepar Json.String PX_CSE_TENANT_NAME_3            := "tenantName03";
  modulepar Json.String PX_CSE_TENANT_NAME_3            := "tenantName03";


  modulepar Json.String PX_CSE_SITE_ID_1                := "site-001";

  modulepar Json.String PX_CSE_SITE_ID_2                := "site-002";

  modulepar Json.String PX_NON_EXISTENT_TENANT_ID       := "9344";
  modulepar Json.String PX_NON_EXISTENT_TENANT_ID       := "9344";


  modulepar Json.String PX_NEW_CUSTOMER_ID              := "";
  modulepar Json.String PX_NEW_CUSTOMER_ID              := "";
+6 −6
Original line number Original line Diff line number Diff line
@@ -19,7 +19,7 @@ module SelfServiceEnablementAPI_Templates {
                                            in template (omit) Json.String p_tenantId,
                                            in template (omit) Json.String p_tenantId,
                                            in Json.String p_tenantName,
                                            in Json.String p_tenantName,
                                            in template (omit) ResourceInfo p_resourceUseInfo := omit,
                                            in template (omit) ResourceInfo p_resourceUseInfo := omit,
                                            in template (omit) SiteInfo p_siteList := omit
                                            in template (omit) SiteInfoList p_siteList := omit
                                            ) := {
                                            ) := {
    customerId              := p_customerId,
    customerId              := p_customerId,
    customerName            := p_customerName,
    customerName            := p_customerName,
@@ -37,7 +37,7 @@ module SelfServiceEnablementAPI_Templates {
                                               template Json.String p_tenantId := *,
                                               template Json.String p_tenantId := *,
                                               template (present) Json.String p_tenantName := ?,
                                               template (present) Json.String p_tenantName := ?,
                                               template ResourceInfo p_resourceUseInfo := *,
                                               template ResourceInfo p_resourceUseInfo := *,
                                               template SiteInfo p_siteList := *
                                               template SiteInfoList p_siteList := *
                                              ) := {
                                              ) := {
    customerId              := p_customerId,
    customerId              := p_customerId,
    customerName            := p_customerName,
    customerName            := p_customerName,
@@ -333,7 +333,7 @@ module SelfServiceEnablementAPI_Templates {
  } // End of template mw_site_resource_use_info
  } // End of template mw_site_resource_use_info


  template (value) ExpiryNotification m_cse_expiry_notification(
  template (value) ExpiryNotification m_cse_expiry_notification(
                                                                in template (value) LinkExpiry p_links,
                                                                in template (value) LinksExpiry p_links,
                                                                in template (value) TimeStamp p_expiryDeadline
                                                                in template (value) TimeStamp p_expiryDeadline
                                                                ) := {
                                                                ) := {
    notificationType      := "ExpiryNotification",
    notificationType      := "ExpiryNotification",
@@ -342,7 +342,7 @@ module SelfServiceEnablementAPI_Templates {
  } // End of template m_expiry_notification
  } // End of template m_expiry_notification


  template (present) ExpiryNotification mw_cse_expiry_notification(
  template (present) ExpiryNotification mw_cse_expiry_notification(
                                                                    template (present) LinkExpiry p_links := ?,
                                                                    template (present) LinksExpiry p_links := ?,
                                                                    template (present) TimeStamp p_expiryDeadline := ?
                                                                    template (present) TimeStamp p_expiryDeadline := ?
                                                                    ) := {
                                                                    ) := {
    notificationType := "ExpiryNotification",
    notificationType := "ExpiryNotification",
@@ -467,13 +467,13 @@ module SelfServiceEnablementAPI_Templates {
    diskRemain   := p_diskRemain
    diskRemain   := p_diskRemain
 } // End of template mw_resource_info
 } // End of template mw_resource_info


  template (value) LinkExpiry m_link_expiry(
  template (value) LinksExpiry m_link_expiry(
                                            in template (value) LinkType p_subscription
                                            in template (value) LinkType p_subscription
                                            ) := {
                                            ) := {
    subscription    := p_subscription
    subscription    := p_subscription
  } //End of temaplate m_link_expiry
  } //End of temaplate m_link_expiry


  template (present) LinkExpiry mw_link_expiry(
  template (present) LinksExpiry mw_link_expiry(
                                                template (present) LinkType p_subscription := ?
                                                template (present) LinkType p_subscription := ?
                                                ) := {
                                                ) := {
    subscription    := p_subscription
    subscription    := p_subscription
Loading