diff --git a/LICENSE b/LICENSE index bbc5bd8d..3de960f0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 oblomov +Copyright (c) 2023 oblomov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/z2ui5_cl_http_handler.clas.locals_imp.abap b/src/z2ui5_cl_http_handler.clas.locals_imp.abap index 25b5b1b6..85ab57be 100644 --- a/src/z2ui5_cl_http_handler.clas.locals_imp.abap +++ b/src/z2ui5_cl_http_handler.clas.locals_imp.abap @@ -645,7 +645,7 @@ CLASS z2ui5_lcl_utility_tree_json DEFINITION. RETURNING VALUE(result) TYPE REF TO z2ui5_lcl_utility_tree_json. - METHODS write_result + METHODS stringify RETURNING VALUE(result) TYPE string. @@ -857,7 +857,7 @@ CLASS z2ui5_lcl_utility_tree_json IMPLEMENTATION. ENDMETHOD. - METHOD write_result. + METHOD stringify. LOOP AT mt_values INTO DATA(lo_attri). @@ -871,7 +871,7 @@ CLASS z2ui5_lcl_utility_tree_json IMPLEMENTATION. IF lo_attri->mt_values IS NOT INITIAL. - result = result && lo_attri->write_result( ). + result = result && lo_attri->stringify( ). ELSE. result = result && quote_json( iv_cond = xsdbool( lo_attri->mv_apost_active = abap_true OR lo_attri->mv_value IS INITIAL ) @@ -1442,7 +1442,7 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. IF ms_next-s_set-check_set_prev_view = abap_true. lo_ui5_model->add_attribute( n = `SET_PREV_VIEW` v = `true` apos_active = abap_false ). ENDIF. - result = lo_ui5_model->get_root( )->write_result( ). + result = lo_ui5_model->get_root( )->stringify( ). z2ui5_lcl_fw_db=>create( id = ms_db-id db = ms_db ). ENDMETHOD. @@ -1547,8 +1547,8 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. DATA(ls_draft) = z2ui5_lcl_fw_db=>read( id = result->ms_db-o_app->id check_load_app = abap_false ). result->ms_db-id_prev_app_stack = ls_draft-uuid_prev_app_stack. - result->ms_db-t_attri = z2ui5_lcl_utility=>get_t_attri_by_ref( result->ms_db-o_app ). - result->ms_db-id = z2ui5_lcl_utility=>get_uuid( ). + result->ms_db-t_attri = z2ui5_lcl_utility=>get_t_attri_by_ref( result->ms_db-o_app ). + result->ms_db-id = z2ui5_lcl_utility=>get_uuid( ). result->ms_db-o_app->id = result->ms_db-id. result->ms_db-id_prev_app = ms_db-id. result->ms_db-id_prev = ms_db-id. @@ -1560,11 +1560,11 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. z2ui5_lcl_fw_db=>create( id = ms_db-id db = ms_db ). result = NEW #( ). - result->ms_db-id = z2ui5_lcl_utility=>get_uuid( ). - result->ms_db-o_app = ms_next-o_call_app. + result->ms_db-id = z2ui5_lcl_utility=>get_uuid( ). + result->ms_db-o_app = ms_next-o_call_app. result->ms_db-o_app->id = result->ms_db-id. - result->ms_db-id_prev_app = ms_db-id. + result->ms_db-id_prev_app = ms_db-id. result->ms_db-id_prev_app_stack = ms_db-id. result->ms_next-t_after = ms_next-t_after. @@ -1599,16 +1599,18 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. DATA(lv_name) = c_prefix && to_upper( lr_attri->name ). ASSIGN (lv_name) TO . z2ui5_lcl_utility=>raise( when = xsdbool( sy-subrc <> 0 ) v = `Attribute in App with name ` && lv_name && ` not found` ). - - DATA lr_ref2 TYPE REF TO data. - GET REFERENCE OF INTO lr_ref2. - " DATA(lr_ref2) = REF #( ). + DATA lr_ref TYPE REF TO data. + GET REFERENCE OF INTO lr_ref. 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 . - DATA(lr_ref) = CAST data( ). + lr_ref = CAST data( ). IF lr_attri->gen_type IS INITIAL. FIELD-SYMBOLS TYPE any. ASSIGN lr_ref->* TO . @@ -1627,8 +1629,6 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION. CATCH cx_root. CONTINUE. ENDTRY. - ELSE. - lr_ref = lr_ref2. ENDIF. IF lr_in = lr_ref. diff --git a/src/z2ui5_cl_http_handler.clas.testclasses.abap b/src/z2ui5_cl_http_handler.clas.testclasses.abap new file mode 100644 index 00000000..5aefcfbc --- /dev/null +++ b/src/z2ui5_cl_http_handler.clas.testclasses.abap @@ -0,0 +1,55 @@ +CLASS ltcl_unit_test DEFINITION FINAL FOR TESTING + DURATION SHORT + RISK LEVEL HARMLESS. + + PRIVATE SECTION. + METHODS test_json_attri FOR TESTING RAISING cx_static_check. + METHODS test_json_object FOR TESTING RAISING cx_static_check. + METHODS test_index_html FOR TESTING RAISING cx_static_check. +ENDCLASS. + + +CLASS ltcl_unit_test IMPLEMENTATION. + + METHOD test_json_attri. + + DATA(lo_tree) = NEW z2ui5_lcl_utility_tree_json( ). + + lo_tree->add_attribute( n = `AAA` v = `BBB` ). + + DATA(lv_result) = lo_tree->stringify( ). + IF `{"AAA":"BBB"}` <> lv_result. + cl_abap_unit_assert=>fail( 'json tree - wrong stringify attributes' ). + ENDIF. + + ENDMETHOD. + + METHOD test_json_object. + + DATA(lo_tree) = NEW z2ui5_lcl_utility_tree_json( ). + + lo_tree->add_attribute_object( `CCC` + )->add_attribute( n = `AAA` v = `BBB` ). + + DATA(lv_result) = lo_tree->stringify( ). + IF `{"CCC":{"AAA":"BBB"}}` <> lv_result. + cl_abap_unit_assert=>fail( 'json tree - wrong stringify object attributes' ). + ENDIF. + + ENDMETHOD. + + METHOD test_index_html. + + z2ui5_cl_http_handler=>client = VALUE #( + t_header = VALUE #( ( name = '~path' value = 'dummy' ) ) + ). + + DATA(lv_index_html) = z2ui5_cl_http_handler=>http_get( ). + + IF lv_index_html IS INITIAL. + cl_abap_unit_assert=>fail( 'HTTP GET - index html initial' ). + ENDIF. + + ENDMETHOD. + +ENDCLASS. diff --git a/src/z2ui5_cl_http_handler.clas.xml b/src/z2ui5_cl_http_handler.clas.xml index 2a406bf4..d4eeb85b 100644 --- a/src/z2ui5_cl_http_handler.clas.xml +++ b/src/z2ui5_cl_http_handler.clas.xml @@ -10,6 +10,7 @@ X X X + X