CLCERT_CHKEXIT_TEST_UTIL - Utility Class for Unit Tests of Exits
BAL Application Log Documentation General Material DataThis documentation is copyright by SAP AG.
Functionality
This class supports unit tests of implementations of the check exit (method IFCERT_AE_CHECK~CHECK) inthe BC Deployment Framework. Check exit methods can only be tested within the framework , because they get data and message handler instances, which cannot be created independently, via its interface.
The exits are therefore tested by calling the Check for Deployment or Check for Synchronize method whichwas originally developed for the BC Design Time. The two methods only check configuration data beforedeployment; they do not deploy, and no data in IMG tables is changed. Check for Deployment and Check for Synchronize are encapsulated in the methods CALL_CHECK_FOR_DEPLOY and CALL_CHECK_FOR_SYNCHRONIZE.
The test data must be passed as XML strings in a special structure. The conversion methods TR ANSL_ITAB_TO_SCHEMA_BF_UPD and TRANSL_ITAB_TO_SCHEMA_BF_SYNC format the test data.
To be able to use the class, you must derive the local unit test class from it (see example).
Relationships
Example
Unit test class to test the check exit. See also the global class CLCERT_EXITS_COUNTRY.
CLASS lcl_exit_test DEFINITION FOR TESTING DURATION MEDIUM
RISK LEVEL HARMLESS
INHERITING FROM clcert_chkexit_test_util.
PUBLIC SECTION.
PRIVATE SECTION.
CLASS-METHODS: class_setup.
* class_teardown.
METHODS: setup FOR TESTING,
test_check_for_deploy FOR TESTING.
* Data declaration using the types CLCERT_CHKEXIT_TEST_UTIL provides:
CLASS-DATA: gt_xml_test_data TYPE lt_xml_upd_data_type.
DATA: gt_msg_expected TYPE lt_msg_type,
gs_msg_expected TYPE ls_msg_type.
ENDCLASS. "lcl_exit_test FOR TESTING DU
CLASS lcl_exit_test IMPLEMENTATION.
METHOD class_setup.
* Create test data in internal tables. As we want to call the Check-for-Update
* service, we need to separate the content in different tables depending on the
* change status (insertion, update or deletion).
DATA: lt_country_u TYPE STANDARD TABLE OF scert_country INITIAL SIZE 5,
lt_country_d TYPE STANDARD TABLE OF scert_country INITIAL SIZE 5,
ls_country TYPE scert_country.
DATA: lt_countryt_u TYPE STANDARD TABLE OF scert_countryt INITIAL SIZE 5,
lt_countryt_d TYPE STANDARD TABLE OF scert_countryt INITIAL SIZE 5,
ls_countryt TYPE scert_countryt.
ls_countryt = ls_country-country = 'DEU'. "#EC NOTEXT
ls_country-intca = 'DE'. "#EC NOTEXT
ls_country-history = 'Long long time ago'. "#EC NOTEXT
ls_countryt-langu = 'DE'. "#EC NOTEXT
ls_countryt-country = 'Deutschland'. "#EC NOTEXT
APPEND ls_countryt TO lt_countryt_u. APPEND ls_country TO lt_country_u.
CLEAR: ls_country, ls_countryt.
ls_countryt = ls_country-country = 'GBR'. "#EC NOTEXT
ls_country-intca = 'GB'. "#EC NOTEXT
ls_country-history = 'Very long time ago'. "#EC NOTEXT
ls_countryt-langu = 'DE'. "#EC NOTEXT
ls_countryt-country = 'Grossbritannien'. "#EC NOTEXT
APPEND ls_countryt TO lt_countryt_u. APPEND ls_country TO lt_country_u.
CLEAR: ls_country, ls_countryt.
* Trying to deletd the following entry shall cause a veto
ls_countryt = ls_country-country = 'XXX'. "#EC NOTEXT
ls_country-intca = 'XX'. "#EC NOTEXT
ls_country-history = 'Not long ago' . "#EC NOTEXT
ls_countryt-langu = 'DE'. "#EC NOTEXT
ls_countryt-country = 'Lummerland'. "#EC NOTEXT
APPEND ls_countryt TO lt_countryt_d. APPEND ls_country TO lt_country_d.
CLEAR: ls_country, ls_countryt.
* Translate and summarize test data for all tables. A check exit can be
* assigned to more than one IMG table. In this case, the internal table
* GT_XML_TEST_DATA will contain one entry for each IMG table.
CALL METHOD transl_itab_to_schema_bf_depl
EXPORTING
iv_tabname = 'SCERT_COUNTRY'
* IT_SOURCE_TAB_INS =
it_source_tab_upd = lt_country_u
it_source_tab_del = lt_country_d
CHANGING
ct_xml_content = gt_xml_test_data.
CALL METHOD transl_itab_to_schema_bf_depl
EXPORTING
iv_tabname = 'SCERT_COUNTRYT'
* IT_SOURCE_TAB_INS =
it_source_tab_upd = lt_countryt_u
it_source_tab_del = lt_countryt_d
CHANGING
ct_xml_content = gt_xml_test_data.
ENDMETHOD. "class_setup
METHOD setup.
* Set expected messages
gs_msg_expected-msgty = 'E'. "#EC NOTEXT
gs_msg_expected-msgid = 'SCERT_TEST'. "#EC NOTEXT
gs_msg_expected-msgno = '004'. "#EC NOTEXT
*MSGV1
*MSGV2
*MSGV3
*MSGV4
gs_msg_expected-language = sy-langu.
*SCHEMA_NODE
*ENTRY
*FIELDNAME
MESSAGE e004(scert_test) INTO gs_msg_expected-text.
* Veto ausgelöst
APPEND gs_msg_expected TO gt_msg_expected.
ENDMETHOD. "setup
METHOD test_check_for_deploy.
DATA: lt_msg TYPE lt_msg_type,
lv_rc TYPE sy-subrc.
* Start deployment simulation
CALL METHOD me->call_check_for_deploy
EXPORTING
it_content_to_check = gt_xml_test_data
IMPORTING
et_messages = lt_msg
ev_returncode = lv_rc.
* Check result
DATA: lv_asrt_fail TYPE abap_bool.
FIELD-SYMBOLS:
* Check return code, shall be equal to '4' when a veto has
* occurred.
CALL METHOD cl_aunit_assert=>assert_equals
EXPORTING
EXP = '4' "#EC NOTEXT
act = lv_rc
level = cl_aunit_assert=>fatal
quit = cl_aunit_assert=>no
* IGNORE_HASH_SEQUENCE = ABAP_FALSE
RECEIVING
assertion_failed = lv_asrt_fail.
* check message table for expected entry
lv_asrt_fail = 'X'. "#EC NOTEXT
LOOP AT lt_msg ASSIGNING
CHECK
AND
CLEAR lv_asrt_fail.
EXIT.
ENDLOOP.
IF lv_asrt_fail IS NOT INITIAL.
CALL METHOD cl_aunit_assert=>assert_equals
EXPORTING
EXP = gt_msg_expected "#EC NOTEXT
act = lt_msg
msg = 'Message table does not contain expected messages'"#EC NOTEXT
level = cl_aunit_assert=>fatal
quit = cl_aunit_assert=>method
RECEIVING
assertion_failed = lv_asrt_fail.
ENDIF.
ENDMETHOD. "test_check_for_deployment
ENDCLASS. "lcl_exit_test IMPLEMENTATION
Notes
What is the difference between the services 'Check for Deployment' and 'Check for Update'?
'Check for Update' expects the change status ("Insert", "To Be Changed" or "To Be Deleted") for eachtable row delivered, from the caller (usually BC Design Time). The change status is passed on to the check exit routine by the data handler.
'Check for Synchronize' gets no change status from the caller. The deployment framework determines whichIMG table contents are to be inserted, changed or deleted, to adjust the data received to the existingdata. The check exit is given the locally determined change status, so it sees no difference between the two services.
Use the 'Check for Update' service for unit tests, or else the test result will depend on the persistent IMG table contents, if you do not change data in the set-up method.
Further information
TXBHW - Original Tax Base Amount in Local Currency Addresses (Business Address Services)
This documentation is copyright by SAP AG.
Length: 17051 Date: 20120526 Time: 075333 triton ( 294 ms )






