测试方法 supplement_create

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

此测试方法涵盖对补充实体的创建操作(含补充描述字段的字段设置)的请求情况。这将导致在基础层上创建补充和补充文本实例。

在第一步中,该方法使用测试数据在投影层触发 EML 创建请求,并通过断言其响应结构来检查是否执行了请求。

在第二步中,该方法读取并检查基础层上补充实例和补充文本实例的结果实例数据。由于增强方法需要使用通过关联创建操作添加补充文本实例,因此通过关联读取此实例的数据。

METHOD supplement_create.
    " Test
    DATA:
      c_create TYPE STRUCTURE FOR CREATE /dmo/c_supplement\\supplement,
      i_create TYPE STRUCTURE FOR CREATE /dmo/i_supplement\\supplement.

    c_create = VALUE #(
                   %cid                  = 'TEST_CID'
                   %is_draft             = if_abap_behv=>mk-on
                   supplementcategory    = 'XX'
                   supplementdescription = 'Test'
                   price                 = '42'
                   currencycode          = 'EUR'
                 ).

    MODIFY ENTITIES OF /dmo/c_supplement
      ENTITY supplement
        CREATE AUTO FILL CID
          FIELDS ( supplementcategory supplementdescription price currencycode )
          WITH VALUE #( ( c_create ) )
      MAPPED    mapped
      FAILED    failed
      REPORTED  reported.

    " Verification
    cl_abap_unit_assert=>assert_initial( failed ).
    cl_abap_unit_assert=>assert_initial( reported ).

    cl_abap_unit_assert=>assert_not_initial( mapped-supplement ).

    READ ENTITIES OF /dmo/i_supplement
      ENTITY supplement
        FIELDS ( supplementcategory price currencycode )
        WITH CORRESPONDING #( mapped-supplement )
        RESULT DATA(supplements)
      ENTITY supplement
        BY \_supplementtext
        FIELDS ( description )
        WITH CORRESPONDING #( 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 ) ).

    i_create = CORRESPONDING #( c_create ).
    DATA: created_supplement_without_id LIKE LINE OF supplements.
    created_supplement_without_id = CORRESPONDING #( supplements[ 1 ] EXCEPT supplementid ).
    cl_abap_unit_assert=>assert_equals( exp = i_create-%data
                                        act = created_supplement_without_id-%data ).
    cl_abap_unit_assert=>assert_equals( exp = i_create-%is_draft
                                        act = created_supplement_without_id-%is_draft ).

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

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

← 补充场景:实施测试方法 · 测试方法 supplement_create_text_update →