测试方法 update_invalid_keys_descr

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

此方法涵盖与测试方法 update_with_invalid_keys 类似的案例。

但是,在此测试方法中,为两个实例提供了无效的键值。此外,提供补充描述的值,并为一个实例激活 %control 标志,而针对其他实例取消激活 标志。这应导致两个失败条目,失败原因为 NOT_FOUND。

METHOD update_invalid_keys_descr.
    TYPES:
      t_c_failed_supplement     LIKE LINE OF failed-supplement,
      t_c_failed_supplement_tky TYPE t_c_failed_supplement-%tky.

    DATA:
      c_update_no_flag     TYPE STRUCTURE FOR UPDATE /dmo/c_supplement\\supplement,
      c_update_invalid_key TYPE STRUCTURE FOR UPDATE /dmo/c_supplement\\supplement,
      i_update             TYPE STRUCTURE FOR UPDATE /dmo/i_supplement\\supplement.

    c_update_no_flag     = VALUE #( %is_draft = if_abap_behv=>mk-on  supplementid = 'TEST1'  supplementdescription = 'Test'  %control-supplementdescription = if_abap_behv=>mk-off ).
    c_update_invalid_key = VALUE #( %is_draft = if_abap_behv=>mk-on  supplementid = 'TEST2'  supplementdescription = 'Test'  %control-supplementdescription = if_abap_behv=>mk-on  ).

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

    cl_abap_unit_assert=>assert_not_initial( failed ).
    cl_abap_unit_assert=>assert_equals(
        exp = 2
        act = lines( failed-supplement )
      ).

    cl_abap_unit_assert=>assert_not_initial( VALUE #( failed-supplement[ KEY draft  %tky = CORRESPONDING #( c_update_no_flag-%tky    ) ] OPTIONAL ) ).
    cl_abap_unit_assert=>assert_equals(
        exp = if_abap_behv=>cause-not_found
        act = failed-supplement[ KEY draft  %tky = c_update_no_flag-%tky     ]-%fail-cause
      ).

    cl_abap_unit_assert=>assert_not_initial( VALUE #( failed-supplement[ KEY draft  %tky = CORRESPONDING #( c_update_invalid_key-%tky ) ] OPTIONAL ) ).
    cl_abap_unit_assert=>assert_equals(
        exp = if_abap_behv=>cause-not_found
        act = failed-supplement[ KEY draft  %tky = c_update_invalid_key-%tky ]-%fail-cause
      ).
  ENDMETHOD.

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

← 测试方法 update_with_invalid_keys · 为代理参考场景开发测试类 →