测试方法 text_create

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

此方法涵盖与测试测试方法 supplement_update_text_create 类似的大小写。但是,在此测试方法中,投影层的更新仅参考补充描述字段。

METHOD text_create.
    " Preparation
    DATA:
      i_supplement_create      TYPE STRUCTURE FOR CREATE /dmo/i_supplement\\supplement.

    i_supplement_create = VALUE #(
        %cid               = 'TEST_CID'
        %is_draft          = if_abap_behv=>mk-on
        supplementcategory = 'XX'
        price              = '10'
        currencycode       = 'USD'
      ).
    MODIFY ENTITIES OF /dmo/i_supplement
      ENTITY supplement
        CREATE
          FIELDS ( supplementcategory price currencycode )
          WITH VALUE #( ( i_supplement_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_initial( 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 = 'Test'
                 ).

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

    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 #( i_supplement_create EXCEPT supplementid ).
    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_update · 测试方法 text_update →