mirror of
https://github.com/abap2UI5/abap2UI5.git
synced 2025-04-28 18:26:18 +08:00
refactoring and tests (#190)
* Update LICENSE * refactoring * unit tests
This commit is contained in:
parent
4206e559eb
commit
0f20644caf
2
LICENSE
2
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
|
||||
|
|
|
@ -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.
|
||||
|
@ -1599,16 +1599,18 @@ CLASS z2ui5_lcl_fw_handler IMPLEMENTATION.
|
|||
DATA(lv_name) = c_prefix && to_upper( lr_attri->name ).
|
||||
ASSIGN (lv_name) TO <attribute>.
|
||||
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 <attribute> INTO lr_ref2.
|
||||
" DATA(lr_ref2) = REF #( <attribute> ).
|
||||
DATA lr_ref TYPE REF TO data.
|
||||
GET REFERENCE OF <attribute> INTO lr_ref.
|
||||
|
||||
IF check_gen_data = abap_true.
|
||||
TRY.
|
||||
|
||||
DATA lr_ref2 TYPE REF TO data.
|
||||
GET REFERENCE OF <attribute> INTO lr_ref2.
|
||||
|
||||
FIELD-SYMBOLS <field> TYPE any.
|
||||
ASSIGN lr_ref2->* TO <field>.
|
||||
DATA(lr_ref) = CAST data( <field> ).
|
||||
lr_ref = CAST data( <field> ).
|
||||
IF lr_attri->gen_type IS INITIAL.
|
||||
FIELD-SYMBOLS <field2> TYPE any.
|
||||
ASSIGN lr_ref->* TO <field2>.
|
||||
|
@ -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.
|
||||
|
|
55
src/z2ui5_cl_http_handler.clas.testclasses.abap
Normal file
55
src/z2ui5_cl_http_handler.clas.testclasses.abap
Normal file
|
@ -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.
|
|
@ -10,6 +10,7 @@
|
|||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
|
|
Loading…
Reference in New Issue
Block a user