From 65ff5e1ca202839bc798f6ec923e54a53f602c74 Mon Sep 17 00:00:00 2001 From: oblomov <102328295+oblomov-dev@users.noreply.github.com> Date: Wed, 3 May 2023 20:58:03 +0200 Subject: [PATCH] unit test (#211) * fixes * examples * unit test * unit tests * abaplint fix * unit test * fix downport * abaplint fix --- src/00/z2ui5_cl_app_demo_03.clas.abap | 2 +- src/00/z2ui5_cl_app_demo_47.clas.abap | 38 ------- src/00/z2ui5_cl_app_demo_48.clas.abap | 102 +++++++++++++++++ src/00/z2ui5_cl_app_demo_48.clas.xml | 16 +++ ...z2ui5_cl_http_handler.clas.locals_imp.abap | 107 ++++++++++-------- ...2ui5_cl_http_handler.clas.testclasses.abap | 88 ++++++++------ 6 files changed, 234 insertions(+), 119 deletions(-) create mode 100644 src/00/z2ui5_cl_app_demo_48.clas.abap create mode 100644 src/00/z2ui5_cl_app_demo_48.clas.xml diff --git a/src/00/z2ui5_cl_app_demo_03.clas.abap b/src/00/z2ui5_cl_app_demo_03.clas.abap index df0a9c32..d7f5eec4 100644 --- a/src/00/z2ui5_cl_app_demo_03.clas.abap +++ b/src/00/z2ui5_cl_app_demo_03.clas.abap @@ -76,7 +76,7 @@ CLASS z2ui5_cl_app_demo_03 IMPLEMENTATION. icon = '{ICON}' info = '{INFO}' press = client->_event( 'TEST' ) - type = `Navigation` + " type = `Navigation` selected = `{SELECTED}` ). diff --git a/src/00/z2ui5_cl_app_demo_47.clas.abap b/src/00/z2ui5_cl_app_demo_47.clas.abap index f9be453f..0962d2b8 100644 --- a/src/00/z2ui5_cl_app_demo_47.clas.abap +++ b/src/00/z2ui5_cl_app_demo_47.clas.abap @@ -35,44 +35,6 @@ CLASS z2ui5_cl_app_demo_47 IMPLEMENTATION. time = sy-uzeit. dec1 = -1 / 3. -* /ui2/cl_json=>serialize( -* EXPORTING -* data = time -** compress = -** name = -** pretty_name = -** type_descr = -** assoc_arrays = -** ts_as_iso8601 = -** expand_includes = -** assoc_arrays_opt = -** numc_as_string = -** name_mappings = -** conversion_exits = -** format_output = -** hex_as_base64 = -* RECEIVING -* r_json = data(lv_json) -* ). -* -* data(lv_test) = conv string( lv_json ). -* lv_test = lv_test+1. -* lv_test = shift_right( val = lv_test sub = `"` ). -* -* /ui2/cl_json=>deserialize( -* EXPORTING -* json = lv_test -** jsonx = -** pretty_name = -** assoc_arrays = -** assoc_arrays_opt = -** name_mappings = -* conversion_exits = abap_true -** hex_as_base64 = -* CHANGING -* data = time2 -* ). - ENDIF. CASE client->get( )-event. diff --git a/src/00/z2ui5_cl_app_demo_48.clas.abap b/src/00/z2ui5_cl_app_demo_48.clas.abap new file mode 100644 index 00000000..e32882ec --- /dev/null +++ b/src/00/z2ui5_cl_app_demo_48.clas.abap @@ -0,0 +1,102 @@ +CLASS z2ui5_cl_app_demo_48 DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + INTERFACES z2ui5_if_app. + + TYPES: + BEGIN OF ty_row, + title TYPE string, + value TYPE string, + descr TYPE string, + icon TYPE string, + info TYPE string, + highlight type string, + wrapCharLimit type i, + selected TYPE abap_bool, + checkbox TYPE abap_bool, + END OF ty_row. + + DATA t_tab TYPE STANDARD TABLE OF ty_row WITH EMPTY KEY. + DATA check_initialized TYPE abap_bool. + + PROTECTED SECTION. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS z2ui5_cl_app_demo_48 IMPLEMENTATION. + + METHOD z2ui5_if_app~main. + + IF check_initialized = abap_false. + check_initialized = abap_true. + + t_tab = VALUE #( + ( title = 'Peter' info = 'Information' descr = 'this is a description1 1234567890 1234567890' icon = 'sap-icon://badge' highlight = 'Information' wrapCharLimit = '100' ) + ( title = 'Peter1' info = 'Success' descr = 'this is a description2 1234567890 1234567890' icon = 'sap-icon://favorite' highlight = 'Success' wrapCharLimit = '10') + ( title = 'Peter2' info = 'Warning' descr = 'this is a description3 1234567890 1234567890' icon = 'sap-icon://employee' highlight = 'Warning' wrapCharLimit = '100') + ( title = 'Peter3' info = 'Error' descr = 'this is a description4 1234567890 1234567890' icon = 'sap-icon://accept' highlight = 'Error' wrapCharLimit = '10' ) + ( title = 'Peter4' info = 'None' descr = 'this is a description5 1234567890 1234567890' icon = 'sap-icon://activities' highlight = 'None' wrapCharLimit = '10') + ( title = 'Peter5' info = 'Information' descr = 'this is a description6 1234567890 1234567890' icon = 'sap-icon://account' highlight = 'Information' wrapCharLimit = '100' ) + ). + + ENDIF. + + CASE client->get( )-event. + WHEN 'TEST'. + " DATA(lt_sel1) = t_tab. + client->popup_message_box( `Test` ). + + WHEN 'SELCHANGE'. + DATA(lt_sel) = t_tab. + DELETE lt_sel WHERE selected = abap_false. + client->popup_message_box( `go to details for item ` && lt_sel[ 1 ]-title ). + + + WHEN 'BACK'. + client->nav_app_leave( client->get_app( client->get( )-id_prev_app_stack ) ). + ENDCASE. + + DATA(page) = z2ui5_cl_xml_view=>factory( )->shell( + )->page( + title = 'abap2UI5 - List' + navbuttonpress = client->_event( 'BACK' ) + shownavbutton = abap_true + )->header_content( + )->link( + text = 'Source_Code' target = '_blank' + href = z2ui5_cl_xml_view=>hlp_get_source_code_url( app = me get = client->get( ) ) + )->get_parent( ). + + page->list( + headertext = 'List Ouput' + items = client->_bind( t_tab ) + mode = `SingleSelectMaster` + selectionchange = client->_event( 'SELCHANGE' ) + )->_generic( + name = `StandardListItem` + t_prop = VALUE #( + ( n = `title` v = '{TITLE}' ) + ( n = `description` v = '{DESCR}' ) + ( n = `icon` v = '{ICON}' ) + ( n = `iconInset` v = 'false' ) + ( n = `highlight` v = '{HIGHLIGHT}' ) + ( n = `info` v = '{INFO}' ) + ( n = `infoState` v = '{HIGHLIGHT}' ) + ( n = `infoStateInverted` v = 'true' ) + ( n = 'type' v = `Detail` ) + ( n = 'wrapping' v = `true` ) + ( n = 'wrapCharLimit' v = `{WRAPCHARLIMIT}` ) + ( n = 'selected' v = `{SELECTED}` ) + ( n = 'detailPress' v = client->_event( 'TEST' ) ) + + ) ). + client->set_next( VALUE #( xml_main = page->get_root( )->xml_get( ) ) ). + + ENDMETHOD. + +ENDCLASS. diff --git a/src/00/z2ui5_cl_app_demo_48.clas.xml b/src/00/z2ui5_cl_app_demo_48.clas.xml new file mode 100644 index 00000000..4e0a8842 --- /dev/null +++ b/src/00/z2ui5_cl_app_demo_48.clas.xml @@ -0,0 +1,16 @@ + + + + + + Z2UI5_CL_APP_DEMO_48 + E + tab - list test + 1 + X + X + X + + + + diff --git a/src/z2ui5_cl_http_handler.clas.locals_imp.abap b/src/z2ui5_cl_http_handler.clas.locals_imp.abap index 32b15f80..4851ec6d 100644 --- a/src/z2ui5_cl_http_handler.clas.locals_imp.abap +++ b/src/z2ui5_cl_http_handler.clas.locals_imp.abap @@ -6,6 +6,7 @@ CLASS z2ui5_lcl_utility DEFINITION INHERITING FROM cx_no_check. BEGIN OF ty_attri, name TYPE string, type_kind TYPE string, + type TYPE string, bind_type TYPE string, data_stringify TYPE string, gen_type_kind TYPE string, @@ -282,7 +283,21 @@ CLASS z2ui5_lcl_utility IMPLEMENTATION. ENDLOOP. LOOP AT lt_attri INTO ls_attri. - APPEND CORRESPONDING #( ls_attri ) TO result. + + DATA(ls_attri2) = VALUE ty_attri( ). + ls_attri2 = CORRESPONDING #( ls_attri ). + + FIELD-SYMBOLS TYPE any. + UNASSIGN . + DATA(lv_assign) = `IO_APP->` && ls_attri-name. + ASSIGN (lv_assign) TO . + DATA(lo_descr) = cl_abap_datadescr=>describe_by_data( ). + CASE lo_descr->kind. + WHEN lo_descr->kind_elem. + ls_attri2-type = CAST cl_abap_elemdescr( lo_descr )->get_relative_name( ). + ENDCASE. + + APPEND ls_attri2 TO result. ENDLOOP. ENDMETHOD. @@ -346,17 +361,15 @@ CLASS z2ui5_lcl_utility IMPLEMENTATION. CLEAR t_result. - DATA lr_row TYPE REF TO data. - CREATE DATA lr_row LIKE LINE OF t_result. - ASSIGN lr_row->* TO FIELD-SYMBOL(). - - DATA(lo_descr) = cl_abap_datadescr=>describe_by_data( ). - DATA(lo_struc) = CAST cl_abap_structdescr( lo_descr ). + DATA(lo_tab) = CAST cl_abap_tabledescr( cl_abap_datadescr=>describe_by_data( t_result ) ). + DATA(lo_struc) = CAST cl_abap_structdescr( lo_tab->get_table_line_type( ) ). DATA(lt_components) = lo_struc->get_components( ). LOOP AT INTO DATA(lr_from). - CLEAR . + DATA lr_row TYPE REF TO data. + CREATE DATA lr_row LIKE LINE OF t_result. + ASSIGN lr_row->* TO FIELD-SYMBOL(). ASSIGN lr_from->* TO FIELD-SYMBOL(). raise( when = xsdbool( sy-subrc <> 0 ) ). @@ -1337,22 +1350,29 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. EXPORTING ir_tab_from = lo_model->get_attribute( lr_attri->name )->mr_actual IMPORTING t_result = ). - WHEN 'D' OR 'T' OR 'C'. + WHEN OTHERS. + DATA(lo_attri) = lo_model->get_attribute( lr_attri->name ). FIELD-SYMBOLS TYPE any. ASSIGN lo_attri->mr_actual->* TO . - /ui2/cl_json=>deserialize( - EXPORTING - json = `"` && && `"` - CHANGING - data = - ). - - WHEN OTHERS. - lo_attri = lo_model->get_attribute( lr_attri->name ). - ASSIGN lo_attri->mr_actual->* TO . - = . + CASE lr_attri->type_kind. + WHEN 'D' OR 'T'. + /ui2/cl_json=>deserialize( + EXPORTING + json = `"` && && `"` + CHANGING + data = ). + WHEN 'C'. + CASE lr_attri->type. + WHEN `ABAP_BOOL` OR `ABAP_BOOLEAN` OR `XSDBOOLEAN`. + = xsdbool( = `true` ). + WHEN OTHERS. + = . + ENDCASE. + WHEN OTHERS. + = . + ENDCASE. ENDCASE. ENDLOOP. @@ -1467,12 +1487,8 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. IF check_gen_data = abap_true. TRY. - - DATA lr_ref2 TYPE REF TO data. - GET REFERENCE OF INTO lr_ref2. - FIELD-SYMBOLS TYPE any. - ASSIGN lr_ref2->* TO . + ASSIGN lr_ref->* TO . lr_ref = CAST data( ). IF lr_attri->gen_type IS INITIAL. FIELD-SYMBOLS TYPE any. @@ -1570,8 +1586,9 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. CONTINUE. ENDIF. - DATA(lo_actual) = COND #( WHEN lr_attri->bind_type = cs_bind_type-one_way THEN r_view_model - ELSE lo_update ). + DATA(lo_actual) = COND #( WHEN lr_attri->bind_type = cs_bind_type-one_way + THEN r_view_model + ELSE lo_update ). FIELD-SYMBOLS TYPE any. DATA(lv_name) = c_prefix && to_upper( lr_attri->name ). @@ -1586,33 +1603,29 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. CASE lr_attri->type_kind. - " WHEN `g` OR `D` OR `T` OR `C`. - " lo_actual->add_attribute( n = lr_attri->name - " v = z2ui5_lcl_utility=>get_abap_2_json( ) - " apos_active = abap_false ). - - " WHEN `P`. - " lo_actual->add_attribute( n = lr_attri->name - " v = /ui2/cl_json=>serialize( ) - " apos_active = abap_false ). - - " WHEN `I`. - " lo_actual->add_attribute( n = lr_attri->name - " " v = - " v = CONV string( ) - " apos_active = abap_false ). - WHEN `h`. lo_actual->add_attribute( n = lr_attri->name v = z2ui5_lcl_utility=>trans_any_2_json( ) apos_active = abap_false ). WHEN OTHERS. - lo_actual->add_attribute( - n = lr_attri->name - v = /ui2/cl_json=>serialize( ) - apos_active = abap_false ). + CASE lr_attri->type. + + WHEN `ABAP_BOOL` OR `ABAP_BOOLEAN` OR `XSDBOOLEAN`. + + lo_actual->add_attribute( + n = lr_attri->name + v = SWITCH #( WHEN abap_true THEN `true` ELSE `false` ) + apos_active = abap_false ). + + WHEN OTHERS. + + lo_actual->add_attribute( + n = lr_attri->name + v = /ui2/cl_json=>serialize( ) + apos_active = abap_false ). + ENDCASE. ENDCASE. ENDLOOP. diff --git a/src/z2ui5_cl_http_handler.clas.testclasses.abap b/src/z2ui5_cl_http_handler.clas.testclasses.abap index 6f7245e3..add982fd 100644 --- a/src/z2ui5_cl_http_handler.clas.testclasses.abap +++ b/src/z2ui5_cl_http_handler.clas.testclasses.abap @@ -10,9 +10,41 @@ CLASS ltcl_unit_01_json DEFINITION FINAL FOR TESTING METHODS test_json_struc FOR TESTING RAISING cx_static_check. METHODS test_json_trans FOR TESTING RAISING cx_static_check. METHODS test_json_trans_gen FOR TESTING RAISING cx_static_check. - METHODS test_utility FOR TESTING RAISING cx_static_check. + METHODS test_util_uuid_session FOR TESTING RAISING cx_static_check. + METHODS test_util_attri_by_ref FOR TESTING RAISING cx_static_check. ENDCLASS. +CLASS ltcl_unit_04_deep_data DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. + + PUBLIC SECTION. + INTERFACES z2ui5_if_app. + + DATA check_initialized TYPE abap_bool. + + TYPES: + BEGIN OF ty_row, + title TYPE string, + value TYPE string, + descr TYPE string, + icon TYPE string, + info TYPE string, + selected TYPE abap_bool, + checkbox TYPE abap_bool, + END OF ty_row. + + CLASS-DATA t_tab TYPE STANDARD TABLE OF ty_row WITH EMPTY KEY. + + CLASS-DATA sv_status TYPE string. + + PRIVATE SECTION. + METHODS test_app_deep_data FOR TESTING RAISING cx_static_check. + METHODS test_app_deep_data_change FOR TESTING RAISING cx_static_check. + METHODS test_app_all FOR TESTING RAISING cx_static_check. +ENDCLASS. + + CLASS ltcl_unit_01_json IMPLEMENTATION. @@ -137,7 +169,27 @@ CLASS ltcl_unit_01_json IMPLEMENTATION. ENDMETHOD. - METHOD test_utility. + METHOD test_util_attri_by_ref. + + DATA(lo_app) = NEW ltcl_unit_04_deep_data( ). + + DATA(lt_attri) = z2ui5_lcl_utility=>get_t_attri_by_ref( lo_app ). + + DATA(lt_test) = VALUE z2ui5_lcl_utility=>ty_t_attri( +( name = `Z2UI5_IF_APP~ID` type_kind = `g` type = `STRING` bind_type = `` data_stringify = `` gen_type_kind = `` gen_type = `` gen_kind = `` ) +( name = `CHECK_INITIALIZED` type_kind = `C` type = `ABAP_BOOL` bind_type = `` data_stringify = `` gen_type_kind = `` gen_type = `` gen_kind = `` ) +( name = `SV_STATUS` type_kind = `g` type = `STRING` bind_type = `` data_stringify = `` gen_type_kind = `` gen_type = `` gen_kind = `` ) +( name = `T_TAB` type_kind = `h` type = `` bind_type = `` data_stringify = `` gen_type_kind = `` gen_type = `` gen_kind = `` ) + ). + + IF lt_test <> lt_attri. + cl_abap_unit_assert=>fail( msg = 'utility - get t_attri table wrong' quit = 5 ). + ENDIF. + + ENDMETHOD. + + + METHOD test_util_uuid_session. DATA(lv_one) = z2ui5_lcl_utility=>get_uuid_session( ). DATA(lv_two) = z2ui5_lcl_utility=>get_uuid_session( ). @@ -860,37 +912,6 @@ CLASS ltcl_unit_03_app_ajax IMPLEMENTATION. ENDCLASS. -CLASS ltcl_unit_04_deep_data DEFINITION FINAL FOR TESTING - DURATION SHORT - RISK LEVEL HARMLESS. - - PUBLIC SECTION. - INTERFACES z2ui5_if_app. - - DATA check_initialized TYPE abap_bool. - - TYPES: - BEGIN OF ty_row, - title TYPE string, - value TYPE string, - descr TYPE string, - icon TYPE string, - info TYPE string, - selected TYPE abap_bool, - checkbox TYPE abap_bool, - END OF ty_row. - - CLASS-DATA t_tab TYPE STANDARD TABLE OF ty_row WITH EMPTY KEY. - - CLASS-DATA sv_status TYPE string. - - PRIVATE SECTION. - METHODS test_app_deep_data FOR TESTING RAISING cx_static_check. - METHODS test_app_deep_data_change FOR TESTING RAISING cx_static_check. - METHODS test_app_all FOR TESTING RAISING cx_static_check. -ENDCLASS. - - CLASS ltcl_unit_04_deep_data IMPLEMENTATION. @@ -1107,4 +1128,5 @@ CLASS ltcl_unit_04_deep_data IMPLEMENTATION. ENDMETHOD. + ENDCLASS.