测试方法 text_update
ABAP RESTful 应用程序编程模型 › 测试 › 单元测试 › 为行为实施开发单元测试 › 为补充参考场景开发测试类 › 补充场景:实施测试方法 › 测试方法 text_update
此方法涵盖与测试测试方法 supplement_update_text_update 类似的大小写。但是,在此测试方法中,投影层的更新仅参考补充描述字段。
METHOD 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 = 'Test'
).
MODIFY ENTITIES OF /dmo/c_supplement
ENTITY supplement
UPDATE
FIELDS ( supplementdescription )
WITH VALUE #( ( c_update ) )
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_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 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_update-supplementdescription
act = act_i_cba-description ).
ENDMETHOD.
来源:SAP Help Portal · 2025 FPS02 (Oct 2026) · 中文为 SAP 官方机器翻译