测试方法 supplement_update_text_update

ABAP RESTful 应用程序编程模型 › 测试 › 单元测试 › 为行为实施开发单元测试 › 为补充参考场景开发测试类 › 补充场景:实施测试方法 › 测试方法 supplement_update_text_update

此测试涵盖请求更新补充实例的情况。要更新的实例已包含字段补充描述的值。然后通过更新请求更新此值。

在第一步中,方法通过在基础层上执行“修改创建”和“按关联创建”请求来准备补充实例和补充文本实例。后一个实例包含描述字段的值。

实际测试由投影层上的 MODIFY 更新请求执行,该请求为补充描述字段设置值。然后分别读取和检查补充和补充文本实例的数据。

METHOD supplement_update_text_update.
    " Preparation
    DATA:
      i_supplement_create      TYPE STRUCTURE FOR CREATE /dmo/i_supplement\\supplement,
      i_supplement_text_create TYPE STRUCTURE FOR CREATE /dmo/i_supplement\\supplement\_supplementtext.

    i_supplement_create = VALUE #(
        %cid               = 'TEST_CID'
        %is_draft          = if_abap_behv=>mk-on
        supplementcategory = 'XX'
        price              = '10'
        currencycode       = 'USD'
      ).
    i_supplement_text_create = VALUE #(
        %cid_ref  = i_supplement_create-%cid
        %is_draft = if_abap_behv=>mk-on
        %target   = VALUE #(
            (
              %is_draft          = if_abap_behv=>mk-on
              languagecode = sy-langu
              description  = 'Before Description'
            )
          )
      ).
    MODIFY ENTITIES OF /dmo/i_supplement
      ENTITY supplement
        CREATE
          FIELDS ( supplementcategory price currencycode )
          WITH VALUE #( ( i_supplement_create ) )
        CREATE BY \_supplementtext
          AUTO FILL CID
          FIELDS ( description )
          WITH VALUE #( ( i_supplement_text_create ) )
      MAPPED    i_mapped
      FAILED    i_failed
      REPORTED  i_reported.

    cl_abap_unit_assert=>assert_initial( i_failed ).
    cl_abap_unit_assert=>assert_initial( i_reported ).

    cl_abap_unit_assert=>assert_not_initial( i_mapped-supplement ).
    cl_abap_unit_assert=>assert_equals( exp = 1
                                        act = lines( i_mapped-supplement ) ).
    cl_abap_unit_assert=>assert_not_initial( i_mapped-supplementtext ).
    cl_abap_unit_assert=>assert_equals( exp = 1
                                        act = lines( i_mapped-supplementtext ) ).

    DATA(supplementid_to_test) = VALUE #( i_mapped-supplement[ 1 ]-supplementid ).

    " Test
    DATA:
      c_update TYPE STRUCTURE FOR UPDATE /dmo/c_supplement\\supplement,
      i_update TYPE STRUCTURE FOR UPDATE /dmo/i_supplement\\supplement.

    c_update = VALUE #(
                   %is_draft             = if_abap_behv=>mk-on
                   supplementid          = supplementid_to_test
                   supplementdescription = 'Updated Description'
                   price                 = '42'
                   currencycode          = 'EUR'
                 ).

    MODIFY ENTITIES OF /dmo/c_supplement
      ENTITY supplement
        UPDATE
          FIELDS ( supplementdescription price currencycode )
          WITH VALUE #( ( c_update ) )
      MAPPED    mapped
      FAILED    failed
      REPORTED  reported.

    cl_abap_unit_assert=>assert_initial( failed ).
    cl_abap_unit_assert=>assert_initial( reported ).
    cl_abap_unit_assert=>assert_initial( mapped ).

    READ ENTITIES OF /dmo/i_supplement
      ENTITY supplement
        FIELDS ( supplementcategory price currencycode )
        WITH CORRESPONDING #( i_mapped-supplement )
        RESULT DATA(supplements)
      ENTITY supplement
        BY \_supplementtext
        FIELDS ( description )
        WITH CORRESPONDING #( i_mapped-supplement )
        RESULT DATA(supplement_texts)
      FAILED    i_failed
      REPORTED  i_reported.

    cl_abap_unit_assert=>assert_initial( i_failed ).
    cl_abap_unit_assert=>assert_initial( i_reported ).

    " Supplement
    cl_abap_unit_assert=>assert_not_initial( supplements ).
    cl_abap_unit_assert=>assert_equals( exp = 1
                                        act = lines( supplements ) ).

    DATA:
      i_supplement_exp TYPE STRUCTURE FOR UPDATE /dmo/i_supplement\\supplement,
      i_supplement_act TYPE STRUCTURE FOR UPDATE /dmo/i_supplement\\supplement.

    i_supplement_exp = CORRESPONDING #( c_update EXCEPT supplementid ).
    i_supplement_exp-supplementcategory = i_supplement_create-supplementcategory.
    i_supplement_act = CORRESPONDING #( supplements[ 1 ] EXCEPT supplementid ).
    cl_abap_unit_assert=>assert_equals( exp = i_supplement_exp
                                        act = i_supplement_act ).

    " Supplement Text
    cl_abap_unit_assert=>assert_not_initial( supplement_texts ).
    cl_abap_unit_assert=>assert_equals( exp = 1
                                        act = lines( supplement_texts ) ).
    cl_abap_unit_assert=>assert_not_initial( supplement_texts[ 1 ] ).
    DATA(act_i_update) = supplement_texts[ 1 ].
    cl_abap_unit_assert=>assert_equals( exp = sy-langu
                                        act = act_i_update-languagecode ).
    cl_abap_unit_assert=>assert_equals( exp = c_update-supplementdescription
                                        act = act_i_update-description ).
ENDMETHOD.

来源:SAP Help Portal · 2025 FPS02 (Oct 2026) · 中文为 SAP 官方机器翻译

← 测试方法 supplement_update_text_create · 测试方法 text_create →