From d474a48cdba7f0b03898aacd7b996881931bd6f6 Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Mon, 12 Dec 2016 17:33:41 +0100 Subject: [PATCH 1/9] Isolating creation dependencies --- src/zabapgit_object_clas.prog.abap | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index 5549a80c8..635050282 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -7,6 +7,91 @@ *----------------------------------------------------------------------* * *----------------------------------------------------------------------* +INTERFACE lif_object_oriented_object. + METHODS: + create + IMPORTING + iv_package TYPE devclass + iv_overwrite TYPE seox_boolean DEFAULT seox_true + CHANGING + is_properties TYPE any + RAISING + lcx_exception. +ENDINTERFACE. + +CLASS lcl_object_oriented_class DEFINITION. + PUBLIC SECTION. + INTERFACES: lif_object_oriented_object. +ENDCLASS. +CLASS lcl_object_oriented_class IMPLEMENTATION. + METHOD lif_object_oriented_object~create. + CALL FUNCTION 'SEO_CLASS_CREATE_COMPLETE' + EXPORTING + devclass = iv_package + overwrite = iv_overwrite + CHANGING + class = is_properties + EXCEPTIONS + existing = 1 + is_interface = 2 + db_error = 3 + component_error = 4 + no_access = 5 + other = 6 + OTHERS = 7. + IF sy-subrc <> 0. + lcx_exception=>raise( 'error from SEO_CLASS_CREATE_COMPLETE' ). + ENDIF. + ENDMETHOD. +ENDCLASS. + +CLASS lcl_object_oriented_interface DEFINITION. + PUBLIC SECTION. + INTERFACES: lif_object_oriented_object. +ENDCLASS. + +CLASS lcl_object_oriented_interface IMPLEMENTATION. + METHOD lif_object_oriented_object~create. + CALL FUNCTION 'SEO_INTERFACE_CREATE_COMPLETE' + EXPORTING + devclass = iv_package + overwrite = iv_overwrite + CHANGING + interface = is_properties + EXCEPTIONS + existing = 1 + is_class = 2 + db_error = 3 + component_error = 4 + no_access = 5 + other = 6 + OTHERS = 7. + IF sy-subrc <> 0. + lcx_exception=>raise( 'Error from SEO_INTERFACE_CREATE_COMPLETE' ). + ENDIF. + ENDMETHOD. +ENDCLASS. + +CLASS lcl_object_oriented_factory DEFINITION. + PUBLIC SECTION. + CLASS-METHODS: + create + IMPORTING + iv_object_type TYPE tadir-object + RETURNING + VALUE(ro_object_oriented_object) TYPE REF TO lif_object_oriented_object. +ENDCLASS. +CLASS lcl_object_oriented_factory IMPLEMENTATION. + METHOD create. + IF iv_object_type = 'CLAS'. + CREATE OBJECT ro_object_oriented_object TYPE lcl_object_oriented_class. + ELSEIF iv_object_type = 'INTF'. + CREATE OBJECT ro_object_oriented_object TYPE lcl_object_oriented_interface. + ENDIF. + ENDMETHOD. +ENDCLASS. + + CLASS lcl_object_clas DEFINITION INHERITING FROM lcl_objects_program. PUBLIC SECTION. From e763228fc53287e3e66f702ffc20d2753eb53447 Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Wed, 21 Dec 2016 10:30:23 +0100 Subject: [PATCH 2/9] Tests dependency isolation for creation --- src/zabapgit_object_clas.prog.abap | 216 ++++++++++++++++++++++++----- src/zabapgit_objects.prog.abap | 2 +- 2 files changed, 181 insertions(+), 37 deletions(-) diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index 635050282..de70546aa 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -17,6 +17,24 @@ INTERFACE lif_object_oriented_object. is_properties TYPE any RAISING lcx_exception. +* generate_locals +* CALL FUNCTION 'SEO_CLASS_GENERATE_LOCALS' +* EXPORTING +* clskey = ls_clskey +* force = seox_true +* locals_def = lt_locals_def +* locals_imp = lt_locals_imp +* locals_mac = lt_locals_mac +* locals_testclasses = lt_testclasses +* EXCEPTIONS +* not_existing = 1 +* model_only = 2 +* locals_not_generated = 3 +* locals_not_initialised = 4 +* OTHERS = 5. +* IF sy-subrc <> 0. +* lcx_exception=>raise( 'error from generate_locals' ). +* ENDIF. ENDINTERFACE. CLASS lcl_object_oriented_class DEFINITION. @@ -72,17 +90,27 @@ CLASS lcl_object_oriented_interface IMPLEMENTATION. ENDMETHOD. ENDCLASS. -CLASS lcl_object_oriented_factory DEFINITION. +CLASS lth_oo_factory_injector DEFINITION DEFERRED. + +CLASS lcl_object_oriented_factory DEFINITION + FRIENDS lth_oo_factory_injector. PUBLIC SECTION. CLASS-METHODS: - create + make IMPORTING iv_object_type TYPE tadir-object RETURNING VALUE(ro_object_oriented_object) TYPE REF TO lif_object_oriented_object. + PRIVATE SECTION. + CLASS-DATA: + go_object_oriented_object TYPE REF TO lif_object_oriented_object. ENDCLASS. CLASS lcl_object_oriented_factory IMPLEMENTATION. - METHOD create. + METHOD make. + IF go_object_oriented_object IS BOUND. + ro_object_oriented_object = go_object_oriented_object. + RETURN. + ENDIF. IF iv_object_type = 'CLAS'. CREATE OBJECT ro_object_oriented_object TYPE lcl_object_oriented_class. ELSEIF iv_object_type = 'INTF'. @@ -91,6 +119,18 @@ CLASS lcl_object_oriented_factory IMPLEMENTATION. ENDMETHOD. ENDCLASS. +CLASS lth_oo_factory_injector DEFINITION FOR TESTING. + PUBLIC SECTION. + CLASS-METHODS: + inject + IMPORTING + io_object_oriented_object TYPE REF TO lif_object_oriented_object. +ENDCLASS. +CLASS lth_oo_factory_injector IMPLEMENTATION. + METHOD inject. + lcl_object_oriented_factory=>go_object_oriented_object = io_object_oriented_object. + ENDMETHOD. +ENDCLASS. CLASS lcl_object_clas DEFINITION INHERITING FROM lcl_objects_program. @@ -1004,51 +1044,32 @@ CLASS lcl_object_clas IMPLEMENTATION. ls_clskey-clsname = ms_item-obj_name. + DATA lo_object_oriented_object TYPE REF TO lif_object_oriented_object. + lo_object_oriented_object = lcl_object_oriented_factory=>make( iv_object_type = ms_item-obj_type ). + CASE ms_item-obj_type. WHEN 'CLAS'. io_xml->read( EXPORTING iv_name = 'VSEOCLASS' CHANGING cg_data = ls_vseoclass ). - CALL FUNCTION 'SEO_CLASS_CREATE_COMPLETE' + lo_object_oriented_object->create( EXPORTING - devclass = iv_package - overwrite = seox_true + iv_package = iv_package CHANGING - class = ls_vseoclass - EXCEPTIONS - existing = 1 - is_interface = 2 - db_error = 3 - component_error = 4 - no_access = 5 - other = 6 - OTHERS = 7. - IF sy-subrc <> 0. - lcx_exception=>raise( 'error from SEO_CLASS_CREATE_COMPLETE' ). - ENDIF. + is_properties = ls_vseoclass + ). WHEN 'INTF'. io_xml->read( EXPORTING iv_name = 'VSEOINTERF' CHANGING cg_data = ls_vseointerf ). - CALL FUNCTION 'SEO_INTERFACE_CREATE_COMPLETE' - EXPORTING - devclass = iv_package - overwrite = seox_true - CHANGING - interface = ls_vseointerf - EXCEPTIONS - existing = 1 - is_class = 2 - db_error = 3 - component_error = 4 - no_access = 5 - other = 6 - OTHERS = 7. - IF sy-subrc <> 0. - lcx_exception=>raise( 'Error from SEO_INTERFACE_CREATE_COMPLETE' ). - ENDIF. + lo_object_oriented_object->create( + EXPORTING + iv_package = iv_package + CHANGING + is_properties = ls_vseointerf + ). WHEN OTHERS. ASSERT 0 = 1. @@ -1158,4 +1179,127 @@ CLASS lcl_object_clas IMPLEMENTATION. CREATE OBJECT ro_comparison_result TYPE lcl_null_comparison_result. ENDMETHOD. -ENDCLASS. "lcl_object_CLAS IMPLEMENTATION \ No newline at end of file +ENDCLASS. "lcl_object_CLAS IMPLEMENTATION + +CLASS ltd_spy_oo_object DEFINITION FOR TESTING. + PUBLIC SECTION. + INTERFACES: lif_object_oriented_object. + DATA: + mv_package TYPE devclass, + mv_overwrite TYPE seox_boolean, + mr_properties TYPE REF TO data. +ENDCLASS. +CLASS ltd_spy_oo_object IMPLEMENTATION. + METHOD lif_object_oriented_object~create. + FIELD-SYMBOLS: TYPE any. + ASSIGN is_properties to . + " = is_properties. + GET reference of into mr_properties. + mv_package = iv_package. + mv_overwrite = iv_overwrite. + ENDMETHOD. +ENDCLASS. + +CLASS ltd_fake_object_files DEFINITION FOR TESTING + INHERITING FROM lcl_objects_files. + PUBLIC SECTION. + METHODS constructor. + METHODS read_abap REDEFINITION. + DATA: + lt_sources TYPE seop_source_string, + lt_local_definitions TYPE seop_source_string, + lt_local_implementations TYPE seop_source_string, + lt_local_macros TYPE seop_source_string, + lt_test_classes TYPE seop_source_string. +ENDCLASS. +CLASS ltd_fake_object_files IMPLEMENTATION. + METHOD read_abap. + CASE iv_extra. + WHEN 'locals_def'. + rt_abap = lt_local_definitions. + WHEN 'locals_imp'. + rt_abap = lt_local_implementations. + WHEN 'macros'. + rt_abap = lt_local_macros. + WHEN 'testclasses'. + rt_abap = lt_test_classes. + WHEN OTHERS. + rt_abap = lt_sources. + RETURN. + ENDCASE. + + cl_abap_unit_assert=>assert_false( iv_error ). + ENDMETHOD. + METHOD constructor. + DATA ls_empty_item TYPE ty_item. + super->constructor( ls_empty_item ). + APPEND 'source' TO me->lt_sources. + APPEND 'definition' TO me->lt_local_definitions. + APPEND 'implementation' TO me->lt_local_implementations. + APPEND 'macro' TO me->lt_local_macros. + APPEND 'test' TO me->lt_test_classes. + ENDMETHOD. + +ENDCLASS. + +CLASS ltc_class_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. + PRIVATE SECTION. + METHODS: + create FOR TESTING RAISING cx_static_check. +ENDCLASS. + +CLASS ltc_class_deserialization IMPLEMENTATION. + + METHOD create. + DATA spy_oo_object TYPE REF TO ltd_spy_oo_object. + DATA fake_object_files TYPE REF TO ltd_fake_object_files. + CREATE OBJECT fake_object_files. + CREATE OBJECT spy_oo_object. + + lth_oo_factory_injector=>inject( spy_oo_object ). + + DATA lo_class TYPE REF TO lif_object. + CREATE OBJECT lo_class TYPE lcl_object_clas + EXPORTING + is_item = VALUE #( devclass = 'CLAS' obj_name = 'zclass' obj_type = 'CLAS' ) + iv_language = sy-langu. + lo_class->mo_files = fake_object_files. + + DATA xml_input TYPE REF TO lcl_xml_input. + DATA xml_out TYPE REF TO lcl_xml_output. + DATA: ls_class_properties TYPE vseoclass. + ls_class_properties-clsname = 'class_name'. + CREATE OBJECT xml_out. + xml_out->add( + EXPORTING + iv_name = 'VSEOCLASS' + ig_data = ls_class_properties + ). + + CREATE OBJECT xml_input + EXPORTING + iv_xml = xml_out->render( ). + lo_class->deserialize( + iv_package = 'package_name' + io_xml = xml_input + ). + + lcl_objects_activation=>clear( ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mr_properties + exp = ls_class_properties + ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mv_overwrite + exp = abap_true + ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mv_package + exp = 'package_name' + ). + ENDMETHOD. + +ENDCLASS. \ No newline at end of file diff --git a/src/zabapgit_objects.prog.abap b/src/zabapgit_objects.prog.abap index 30887800b..a76058992 100644 --- a/src/zabapgit_objects.prog.abap +++ b/src/zabapgit_objects.prog.abap @@ -187,7 +187,7 @@ ENDCLASS. "lcl_objects_activation IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* -CLASS lcl_objects_files DEFINITION FINAL. +CLASS lcl_objects_files DEFINITION . PUBLIC SECTION. METHODS: From 9ade177c49aefd83d34b45fb8ded87c282f19aef Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Wed, 21 Dec 2016 14:18:18 +0100 Subject: [PATCH 3/9] class_abap_deserializing --- src/zabapgit_definitions.prog.abap | 2 + src/zabapgit_object_clas.prog.abap | 433 ++++++++++++++++++++++------- 2 files changed, 334 insertions(+), 101 deletions(-) diff --git a/src/zabapgit_definitions.prog.abap b/src/zabapgit_definitions.prog.abap index 139849bfe..5f0b0e1bd 100644 --- a/src/zabapgit_definitions.prog.abap +++ b/src/zabapgit_definitions.prog.abap @@ -114,6 +114,8 @@ TYPES: ty_results_tt TYPE STANDARD TABLE OF ty_result WITH DEFAULT KEY. TYPES: ty_sval_tt TYPE STANDARD TABLE OF sval WITH DEFAULT KEY. +TYPES: ty_seocompotx_tt TYPE STANDARD TABLE OF seocompotx WITH DEFAULT KEY. + CONSTANTS: BEGIN OF gc_state, " https://git-scm.com/docs/git-status unchanged TYPE char1 VALUE '', added TYPE char1 VALUE 'A', diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index de70546aa..0fe33e381 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -15,31 +15,150 @@ INTERFACE lif_object_oriented_object. iv_overwrite TYPE seox_boolean DEFAULT seox_true CHANGING is_properties TYPE any + RAISING + lcx_exception, + generate_locals + IMPORTING + is_key TYPE seoclskey + iv_force TYPE seox_boolean DEFAULT seox_true + it_local_definitions TYPE seop_source_string OPTIONAL + it_local_implementations TYPE seop_source_string OPTIONAL + it_local_macros TYPE seop_source_string OPTIONAL + it_local_test_classes TYPE seop_source_string OPTIONAL + RAISING + lcx_exception, + deserialize_source + IMPORTING + is_key TYPE seoclskey + it_source TYPE ty_string_tt + RAISING + lcx_exception + cx_sy_dyn_call_error, + update_descriptions + IMPORTING + is_key TYPE seoclskey + it_descriptions TYPE ty_seocompotx_tt, + add_to_activation_list + IMPORTING + is_item TYPE ty_item RAISING lcx_exception. -* generate_locals -* CALL FUNCTION 'SEO_CLASS_GENERATE_LOCALS' -* EXPORTING -* clskey = ls_clskey -* force = seox_true -* locals_def = lt_locals_def -* locals_imp = lt_locals_imp -* locals_mac = lt_locals_mac -* locals_testclasses = lt_testclasses -* EXCEPTIONS -* not_existing = 1 -* model_only = 2 -* locals_not_generated = 3 -* locals_not_initialised = 4 -* OTHERS = 5. -* IF sy-subrc <> 0. -* lcx_exception=>raise( 'error from generate_locals' ). -* ENDIF. ENDINTERFACE. -CLASS lcl_object_oriented_class DEFINITION. +CLASS lcl_object_oriented_base DEFINITION ABSTRACT. PUBLIC SECTION. INTERFACES: lif_object_oriented_object. + PRIVATE SECTION. + METHODS deserialize_abap_source_old + IMPORTING is_clskey TYPE seoclskey + it_source TYPE ty_string_tt + RAISING lcx_exception. + + METHODS deserialize_abap_source_new + IMPORTING is_clskey TYPE seoclskey + it_source TYPE ty_string_tt + RAISING lcx_exception + cx_sy_dyn_call_error. +ENDCLASS. + +CLASS lcl_object_oriented_base IMPLEMENTATION. + + METHOD lif_object_oriented_object~create. + "Subclass responsibility + RETURN. + ENDMETHOD. + + METHOD lif_object_oriented_object~deserialize_source. + TRY. + deserialize_abap_source_new( + is_clskey = is_key + it_source = it_source ). + CATCH cx_sy_dyn_call_error. + deserialize_abap_source_old( + is_clskey = is_key + it_source = it_source ). + ENDTRY. + ENDMETHOD. + + METHOD lif_object_oriented_object~generate_locals. + "Subclass responsibility + RETURN. + ENDMETHOD. + + METHOD deserialize_abap_source_old. + "for backwards compatability down to 702 + + DATA: lo_source TYPE REF TO cl_oo_source. + + CREATE OBJECT lo_source + EXPORTING + clskey = is_clskey + EXCEPTIONS + class_not_existing = 1 + OTHERS = 2. + IF sy-subrc <> 0. + lcx_exception=>raise( 'error from CL_OO_SOURCE' ). + ENDIF. + + TRY. + lo_source->access_permission( seok_access_modify ). + lo_source->set_source( it_source ). + lo_source->save( ). + lo_source->access_permission( seok_access_free ). + CATCH cx_oo_access_permission. + lcx_exception=>raise( 'permission error' ). + CATCH cx_oo_source_save_failure. + lcx_exception=>raise( 'save failure' ). + ENDTRY. + + ENDMETHOD. + + METHOD deserialize_abap_source_new. + DATA: lo_factory TYPE REF TO object, + lo_source TYPE REF TO object. + + CALL METHOD ('CL_OO_FACTORY')=>('CREATE_INSTANCE') + RECEIVING + result = lo_factory. + + CALL METHOD lo_factory->('CREATE_CLIF_SOURCE') + EXPORTING + clif_name = is_clskey-clsname + RECEIVING + result = lo_source. + + TRY. + CALL METHOD lo_source->('IF_OO_CLIF_SOURCE~LOCK'). + CATCH cx_oo_access_permission. + lcx_exception=>raise( 'source_new, access permission exception' ). + ENDTRY. + + CALL METHOD lo_source->('IF_OO_CLIF_SOURCE~SET_SOURCE') + EXPORTING + source = it_source. + + CALL METHOD lo_source->('IF_OO_CLIF_SOURCE~SAVE'). + + CALL METHOD lo_source->('IF_OO_CLIF_SOURCE~UNLOCK'). + + ENDMETHOD. + METHOD lif_object_oriented_object~add_to_activation_list. + lcl_objects_activation=>add_item( is_item ). + ENDMETHOD. + + METHOD lif_object_oriented_object~update_descriptions. + DELETE FROM seocompotx WHERE clsname = is_key-clsname. + INSERT seocompotx FROM TABLE it_descriptions. + ENDMETHOD. +ENDCLASS. + + +CLASS lcl_object_oriented_class DEFINITION + INHERITING FROM lcl_object_oriented_base. + PUBLIC SECTION. + METHODS: + lif_object_oriented_object~create REDEFINITION, + lif_object_oriented_object~generate_locals REDEFINITION. ENDCLASS. CLASS lcl_object_oriented_class IMPLEMENTATION. METHOD lif_object_oriented_object~create. @@ -61,11 +180,32 @@ CLASS lcl_object_oriented_class IMPLEMENTATION. lcx_exception=>raise( 'error from SEO_CLASS_CREATE_COMPLETE' ). ENDIF. ENDMETHOD. + METHOD lif_object_oriented_object~generate_locals. + CALL FUNCTION 'SEO_CLASS_GENERATE_LOCALS' + EXPORTING + clskey = is_key + force = iv_force + locals_def = it_local_definitions + locals_imp = it_local_implementations + locals_mac = it_local_macros + locals_testclasses = it_local_test_classes + EXCEPTIONS + not_existing = 1 + model_only = 2 + locals_not_generated = 3 + locals_not_initialised = 4 + OTHERS = 5. + IF sy-subrc <> 0. + lcx_exception=>raise( 'error from generate_locals' ). + ENDIF. + ENDMETHOD. ENDCLASS. -CLASS lcl_object_oriented_interface DEFINITION. +CLASS lcl_object_oriented_interface DEFINITION + INHERITING FROM lcl_object_oriented_base. PUBLIC SECTION. - INTERFACES: lif_object_oriented_object. + METHODS: + lif_object_oriented_object~create REDEFINITION. ENDCLASS. CLASS lcl_object_oriented_interface IMPLEMENTATION. @@ -146,7 +286,7 @@ CLASS lcl_object_clas DEFINITION INHERITING FROM lcl_objects_program. TYPES: ty_sotr_tt TYPE STANDARD TABLE OF ty_sotr WITH DEFAULT KEY. - TYPES: ty_seocompotx_tt TYPE STANDARD TABLE OF seocompotx WITH DEFAULT KEY. + DATA mv_skip_testclass TYPE abap_bool. @@ -861,13 +1001,6 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDMETHOD. "serialize_xml METHOD lif_object~deserialize. - -* function group SEOK -* function group SEOQ -* function group SEOP -* class CL_OO_CLASSNAME_SERVICE -* class CL_OO_SOURCE - deserialize_abap( io_xml = io_xml iv_package = iv_package ). @@ -879,7 +1012,6 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDIF. deserialize_docu( io_xml ). - ENDMETHOD. "deserialize METHOD deserialize_sotr. @@ -1076,42 +1208,30 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDCASE. IF ms_item-obj_type = 'CLAS'. - CALL FUNCTION 'SEO_CLASS_GENERATE_LOCALS' - EXPORTING - clskey = ls_clskey - force = seox_true - locals_def = lt_locals_def - locals_imp = lt_locals_imp - locals_mac = lt_locals_mac - locals_testclasses = lt_testclasses - EXCEPTIONS - not_existing = 1 - model_only = 2 - locals_not_generated = 3 - locals_not_initialised = 4 - OTHERS = 5. - IF sy-subrc <> 0. - lcx_exception=>raise( 'error from generate_locals' ). - ENDIF. + lo_object_oriented_object->generate_locals( + is_key = ls_clskey + iv_force = seox_true + it_local_definitions = lt_locals_def + it_local_implementations = lt_locals_imp + it_local_macros = lt_locals_mac + it_local_test_classes = lt_testclasses + ). ENDIF. - TRY. - deserialize_abap_source_new( - is_clskey = ls_clskey - it_source = lt_source ). - CATCH cx_sy_dyn_call_error. - deserialize_abap_source_old( - is_clskey = ls_clskey - it_source = lt_source ). - ENDTRY. + lo_object_oriented_object->deserialize_source( + is_key = ls_clskey + it_source = lt_source + ). io_xml->read( EXPORTING iv_name = 'DESCRIPTIONS' CHANGING cg_data = lt_descriptions ). - DELETE FROM seocompotx WHERE clsname = ls_clskey-clsname. - INSERT seocompotx FROM TABLE lt_descriptions. - lcl_objects_activation=>add_item( ms_item ). + lo_object_oriented_object->update_descriptions( + is_key = ls_clskey + it_descriptions = lt_descriptions + ). + lo_object_oriented_object->add_to_activation_list( is_item = ms_item ). ENDMETHOD. "deserialize METHOD deserialize_abap_source_old. @@ -1185,19 +1305,55 @@ CLASS ltd_spy_oo_object DEFINITION FOR TESTING. PUBLIC SECTION. INTERFACES: lif_object_oriented_object. DATA: - mv_package TYPE devclass, - mv_overwrite TYPE seox_boolean, - mr_properties TYPE REF TO data. + mv_package TYPE devclass, + mv_overwrite TYPE seox_boolean, + ms_interface_properties TYPE vseointerf, + ms_class_properties TYPE vseoclass, + ms_locals_key TYPE seoclskey, + mt_local_definitions TYPE rswsourcet, + mt_local_implementations TYPE rswsourcet, + mt_local_macros TYPE rswsourcet, + mt_local_test_classes TYPE rswsourcet, + mv_force TYPE seoflag, + ms_deserialize_key TYPE seoclskey, + mt_source TYPE ty_string_tt, + ms_item_to_activate TYPE ty_item, + mt_descriptions TYPE ty_seocompotx_tt, + ms_description_key TYPE seoclskey. ENDCLASS. CLASS ltd_spy_oo_object IMPLEMENTATION. METHOD lif_object_oriented_object~create. - FIELD-SYMBOLS: TYPE any. - ASSIGN is_properties to . - " = is_properties. - GET reference of into mr_properties. - mv_package = iv_package. - mv_overwrite = iv_overwrite. + IF cl_abap_typedescr=>describe_by_data( is_properties )->absolute_name = cl_abap_typedescr=>describe_by_data( ms_interface_properties )->absolute_name. + ms_interface_properties = is_properties. + ELSE. + ms_class_properties = is_properties. + ENDIF. + mv_package = iv_package. + mv_overwrite = iv_overwrite. ENDMETHOD. + METHOD lif_object_oriented_object~generate_locals. + ms_locals_key = is_key. + mt_local_definitions = it_local_definitions. + mt_local_implementations = it_local_implementations. + mt_local_macros = it_local_macros. + mt_local_test_classes = it_local_test_classes. + mv_force = iv_force. + ENDMETHOD. + + METHOD lif_object_oriented_object~deserialize_source. + ms_deserialize_key = is_key. + mt_source = it_source. + ENDMETHOD. + + METHOD lif_object_oriented_object~add_to_activation_list. + ms_item_to_activate = is_item. + ENDMETHOD. + + METHOD lif_object_oriented_object~update_descriptions. + ms_description_key = is_key. + mt_descriptions = it_descriptions. + ENDMETHOD. + ENDCLASS. CLASS ltd_fake_object_files DEFINITION FOR TESTING @@ -1206,25 +1362,25 @@ CLASS ltd_fake_object_files DEFINITION FOR TESTING METHODS constructor. METHODS read_abap REDEFINITION. DATA: - lt_sources TYPE seop_source_string, - lt_local_definitions TYPE seop_source_string, - lt_local_implementations TYPE seop_source_string, - lt_local_macros TYPE seop_source_string, - lt_test_classes TYPE seop_source_string. + mt_sources TYPE seop_source_string, + mt_local_definitions TYPE seop_source_string, + mt_local_implementations TYPE seop_source_string, + mt_local_macros TYPE seop_source_string, + mt_local_test_classes TYPE seop_source_string. ENDCLASS. CLASS ltd_fake_object_files IMPLEMENTATION. METHOD read_abap. CASE iv_extra. WHEN 'locals_def'. - rt_abap = lt_local_definitions. + rt_abap = mt_local_definitions. WHEN 'locals_imp'. - rt_abap = lt_local_implementations. + rt_abap = mt_local_implementations. WHEN 'macros'. - rt_abap = lt_local_macros. + rt_abap = mt_local_macros. WHEN 'testclasses'. - rt_abap = lt_test_classes. + rt_abap = mt_local_test_classes. WHEN OTHERS. - rt_abap = lt_sources. + rt_abap = mt_sources. RETURN. ENDCASE. @@ -1233,11 +1389,11 @@ CLASS ltd_fake_object_files IMPLEMENTATION. METHOD constructor. DATA ls_empty_item TYPE ty_item. super->constructor( ls_empty_item ). - APPEND 'source' TO me->lt_sources. - APPEND 'definition' TO me->lt_local_definitions. - APPEND 'implementation' TO me->lt_local_implementations. - APPEND 'macro' TO me->lt_local_macros. - APPEND 'test' TO me->lt_test_classes. + APPEND 'source' TO me->mt_sources. + APPEND 'definition' TO me->mt_local_definitions. + APPEND 'implementation' TO me->mt_local_implementations. + APPEND 'macro' TO me->mt_local_macros. + APPEND 'test' TO me->mt_local_test_classes. ENDMETHOD. ENDCLASS. @@ -1245,35 +1401,48 @@ ENDCLASS. CLASS ltc_class_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. PRIVATE SECTION. METHODS: - create FOR TESTING RAISING cx_static_check. + deserialize FOR TESTING RAISING cx_static_check. ENDCLASS. CLASS ltc_class_deserialization IMPLEMENTATION. - METHOD create. + METHOD deserialize. DATA spy_oo_object TYPE REF TO ltd_spy_oo_object. DATA fake_object_files TYPE REF TO ltd_fake_object_files. + DATA xml_input TYPE REF TO lcl_xml_input. + DATA xml_out TYPE REF TO lcl_xml_output. + DATA: ls_class_properties TYPE vseoclass. + DATA lo_class TYPE REF TO lif_object. + DATA ls_description TYPE seocompotx. + DATA lt_descriptions TYPE TABLE OF seocompotx. + CREATE OBJECT fake_object_files. CREATE OBJECT spy_oo_object. lth_oo_factory_injector=>inject( spy_oo_object ). - DATA lo_class TYPE REF TO lif_object. + DATA(ls_item) = VALUE ty_item( devclass = 'package_name' obj_name = 'zcl_class' obj_type = 'CLAS' ). + CREATE OBJECT lo_class TYPE lcl_object_clas EXPORTING - is_item = VALUE #( devclass = 'CLAS' obj_name = 'zclass' obj_type = 'CLAS' ) + is_item = ls_item iv_language = sy-langu. lo_class->mo_files = fake_object_files. - DATA xml_input TYPE REF TO lcl_xml_input. - DATA xml_out TYPE REF TO lcl_xml_output. - DATA: ls_class_properties TYPE vseoclass. - ls_class_properties-clsname = 'class_name'. + + ls_class_properties-clsname = 'zcl_class'. CREATE OBJECT xml_out. xml_out->add( - EXPORTING - iv_name = 'VSEOCLASS' - ig_data = ls_class_properties + iv_name = 'VSEOCLASS' + ig_data = ls_class_properties + ). + + ls_description-clsname = 'zcl_class'. + ls_description-cmpname = 'a_method'. + APPEND ls_description TO lt_descriptions. + xml_out->add( + iv_name = 'DESCRIPTIONS' + ig_data = lt_descriptions ). CREATE OBJECT xml_input @@ -1284,22 +1453,84 @@ CLASS ltc_class_deserialization IMPLEMENTATION. io_xml = xml_input ). - lcl_objects_activation=>clear( ). - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mr_properties + act = spy_oo_object->ms_class_properties exp = ls_class_properties ). - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mv_overwrite - exp = abap_true - ). + cl_abap_unit_assert=>assert_true( spy_oo_object->mv_overwrite ). cl_abap_unit_assert=>assert_equals( act = spy_oo_object->mv_package exp = 'package_name' ). + + "Local generation + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->ms_locals_key + exp = 'zcl_class' + ). + cl_abap_unit_assert=>assert_true( spy_oo_object->mv_force ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mt_local_definitions + exp = fake_object_files->mt_local_definitions + ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mt_local_implementations + exp = fake_object_files->mt_local_implementations + ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mt_local_macros + exp = fake_object_files->mt_local_macros + ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mt_local_test_classes + exp = fake_object_files->mt_local_test_classes + ). + + "Deserialization source + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mt_source + exp = fake_object_files->mt_sources + ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->ms_deserialize_key + exp = 'zcl_class' + ). + + "Update descriptions + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mt_descriptions + exp = lt_descriptions + ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->ms_description_key + exp = 'zcl_class' + ). + + "Descriptions + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->mt_descriptions + exp = lt_descriptions + ). + + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->ms_description_key + exp = 'zcl_class' + ). + + "Activation + cl_abap_unit_assert=>assert_equals( + act = spy_oo_object->ms_item_to_activate + exp = ls_item + ). + ENDMETHOD. ENDCLASS. \ No newline at end of file From c0cb1f2a9556844881cd8d3477138160f7772fdd Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Wed, 21 Dec 2016 15:29:27 +0100 Subject: [PATCH 4/9] Breaking into several tests --- src/zabapgit_object_clas.prog.abap | 295 ++++++++++++++++++----------- 1 file changed, 187 insertions(+), 108 deletions(-) diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index 0fe33e381..29562e8d7 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -1401,136 +1401,215 @@ ENDCLASS. CLASS ltc_class_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. PRIVATE SECTION. METHODS: - deserialize FOR TESTING RAISING cx_static_check. + setup, + given_a_class_properties + RAISING + lcx_exception, + when_deserializing + RAISING + lcx_exception, + then_should_create_class, + then_it_should_generate_locals, + then_should_deserialize_source, + given_the_descriptions + IMPORTING + it_descriptions TYPE ty_seocompotx_tt + RAISING + lcx_exception, + then_shuld_update_descriptions + IMPORTING + it_descriptions TYPE ty_seocompotx_tt, + then_it_should_add_activation, + should_create_class FOR TESTING RAISING cx_static_check, + should_generate_locals FOR TESTING RAISING cx_static_check, + should_deserialize_source FOR TESTING RAISING cx_static_check, + should_update_descriptions FOR TESTING RAISING cx_static_check, + should_add_to_activation FOR TESTING RAISING cx_static_check. + + DATA: + mo_spy_oo_object TYPE REF TO ltd_spy_oo_object, + mo_fake_object_files TYPE REF TO ltd_fake_object_files, + mo_xml_input TYPE REF TO lcl_xml_input, + mo_xml_out TYPE REF TO lcl_xml_output, + mo_class TYPE REF TO lif_object, + ms_class_properties TYPE vseoclass, + ls_item TYPE ty_item. ENDCLASS. CLASS ltc_class_deserialization IMPLEMENTATION. + METHOD setup. + CREATE OBJECT mo_fake_object_files. + CREATE OBJECT mo_spy_oo_object. + CREATE OBJECT mo_xml_out. + lth_oo_factory_injector=>inject( mo_spy_oo_object ). - METHOD deserialize. - DATA spy_oo_object TYPE REF TO ltd_spy_oo_object. - DATA fake_object_files TYPE REF TO ltd_fake_object_files. - DATA xml_input TYPE REF TO lcl_xml_input. - DATA xml_out TYPE REF TO lcl_xml_output. - DATA: ls_class_properties TYPE vseoclass. - DATA lo_class TYPE REF TO lif_object. - DATA ls_description TYPE seocompotx. - DATA lt_descriptions TYPE TABLE OF seocompotx. + ls_item-devclass = 'package_name'. + ls_item-obj_name = 'zcl_class'. + ls_item-obj_type = 'CLAS'. - CREATE OBJECT fake_object_files. - CREATE OBJECT spy_oo_object. - - lth_oo_factory_injector=>inject( spy_oo_object ). - - DATA(ls_item) = VALUE ty_item( devclass = 'package_name' obj_name = 'zcl_class' obj_type = 'CLAS' ). - - CREATE OBJECT lo_class TYPE lcl_object_clas + CREATE OBJECT mo_class TYPE lcl_object_clas EXPORTING is_item = ls_item iv_language = sy-langu. - lo_class->mo_files = fake_object_files. + mo_class->mo_files = mo_fake_object_files. + ENDMETHOD. + METHOD should_create_class. + ms_class_properties-clsname = ls_item-obj_name. - ls_class_properties-clsname = 'zcl_class'. - CREATE OBJECT xml_out. - xml_out->add( - iv_name = 'VSEOCLASS' - ig_data = ls_class_properties - ). + given_a_class_properties( ). - ls_description-clsname = 'zcl_class'. + when_deserializing( ). + + then_should_create_class( ). + ENDMETHOD. + + METHOD should_generate_locals. + given_a_class_properties( ). + + when_deserializing( ). + + then_it_should_generate_locals( ). + ENDMETHOD. + + METHOD should_deserialize_source. + given_a_class_properties( ). + + when_deserializing( ). + + then_should_deserialize_source( ). + ENDMETHOD. + + METHOD should_update_descriptions. + DATA: + ls_description TYPE seocompotx, + lt_descriptions TYPE ty_seocompotx_tt. + + given_a_class_properties( ). + + ls_description-clsname = ls_item-obj_name. ls_description-cmpname = 'a_method'. APPEND ls_description TO lt_descriptions. - xml_out->add( - iv_name = 'DESCRIPTIONS' - ig_data = lt_descriptions - ). + given_the_descriptions( lt_descriptions ). - CREATE OBJECT xml_input - EXPORTING - iv_xml = xml_out->render( ). - lo_class->deserialize( - iv_package = 'package_name' - io_xml = xml_input - ). + when_deserializing( ). - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->ms_class_properties - exp = ls_class_properties - ). + then_shuld_update_descriptions( lt_descriptions ). + ENDMETHOD. - cl_abap_unit_assert=>assert_true( spy_oo_object->mv_overwrite ). + METHOD should_add_to_activation. + given_a_class_properties( ). - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mv_package - exp = 'package_name' - ). - - "Local generation - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->ms_locals_key - exp = 'zcl_class' - ). - cl_abap_unit_assert=>assert_true( spy_oo_object->mv_force ). - - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mt_local_definitions - exp = fake_object_files->mt_local_definitions - ). - - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mt_local_implementations - exp = fake_object_files->mt_local_implementations - ). - - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mt_local_macros - exp = fake_object_files->mt_local_macros - ). - - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mt_local_test_classes - exp = fake_object_files->mt_local_test_classes - ). - - "Deserialization source - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mt_source - exp = fake_object_files->mt_sources - ). - - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->ms_deserialize_key - exp = 'zcl_class' - ). - - "Update descriptions - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mt_descriptions - exp = lt_descriptions - ). - - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->ms_description_key - exp = 'zcl_class' - ). - - "Descriptions - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->mt_descriptions - exp = lt_descriptions - ). - - cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->ms_description_key - exp = 'zcl_class' - ). + when_deserializing( ). "Activation +then_it_should_add_activation( ). + ENDMETHOD. + + METHOD given_a_class_properties. + mo_xml_out->add( + iv_name = 'VSEOCLASS' + ig_data = ms_class_properties + ). + ENDMETHOD. + + + METHOD when_deserializing. + CREATE OBJECT mo_xml_input + EXPORTING + iv_xml = mo_xml_out->render( ). + mo_class->deserialize( + iv_package = 'package_name' + io_xml = mo_xml_input + ). + ENDMETHOD. + + + METHOD then_should_create_class. + cl_abap_unit_assert=>assert_equals( - act = spy_oo_object->ms_item_to_activate - exp = ls_item + act = mo_spy_oo_object->ms_class_properties + exp = ms_class_properties + ). + + cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_package + exp = 'package_name' ). ENDMETHOD. + + METHOD then_it_should_generate_locals. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_locals_key + exp = ls_item-obj_name + ). + cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_force ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_local_definitions + exp = mo_fake_object_files->mt_local_definitions + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_local_implementations + exp = mo_fake_object_files->mt_local_implementations + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_local_macros + exp = mo_fake_object_files->mt_local_macros + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_local_test_classes + exp = mo_fake_object_files->mt_local_test_classes + ). + ENDMETHOD. + + + METHOD then_should_deserialize_source. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_source + exp = mo_fake_object_files->mt_sources + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_deserialize_key + exp = ls_item-obj_name + ). + ENDMETHOD. + + + METHOD given_the_descriptions. + mo_xml_out->add( + iv_name = 'DESCRIPTIONS' + ig_data = it_descriptions + ). + ENDMETHOD. + + + METHOD then_shuld_update_descriptions. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_descriptions + exp = it_descriptions + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_description_key + exp = ls_item-obj_name + ). + ENDMETHOD. + + + METHOD then_it_should_add_activation. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_item_to_activate + exp = ls_item + ). + ENDMETHOD. + ENDCLASS. \ No newline at end of file From 56675067e49cc296a15ecd7257d4c50b13e3a92e Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Wed, 21 Dec 2016 16:03:27 +0100 Subject: [PATCH 5/9] added interface tests --- src/zabapgit_object_clas.prog.abap | 259 ++++++++++++++++++++--------- 1 file changed, 178 insertions(+), 81 deletions(-) diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index 29562e8d7..feba06bc0 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -1398,42 +1398,98 @@ CLASS ltd_fake_object_files IMPLEMENTATION. ENDCLASS. -CLASS ltc_class_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. - PRIVATE SECTION. - METHODS: - setup, - given_a_class_properties - RAISING - lcx_exception, - when_deserializing - RAISING - lcx_exception, - then_should_create_class, - then_it_should_generate_locals, +CLASS ltc_oo_test DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT . + PROTECTED SECTION. + DATA: + mo_spy_oo_object TYPE REF TO ltd_spy_oo_object, + mo_fake_object_files TYPE REF TO ltd_fake_object_files, + mo_xml_input TYPE REF TO lcl_xml_input, + mo_xml_out TYPE REF TO lcl_xml_output, + mo_oo_object TYPE REF TO lif_object, + ms_item TYPE ty_item. + METHODS: when_deserializing + RAISING + lcx_exception, then_should_deserialize_source, given_the_descriptions IMPORTING it_descriptions TYPE ty_seocompotx_tt RAISING lcx_exception, - then_shuld_update_descriptions - IMPORTING + then_shuld_update_descriptions + IMPORTING it_descriptions TYPE ty_seocompotx_tt, - then_it_should_add_activation, + then_it_should_add_activation. + +ENDCLASS. +CLASS ltc_oo_test IMPLEMENTATION. + + METHOD then_it_should_add_activation. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_item_to_activate + exp = ms_item + ). + ENDMETHOD. + + METHOD then_shuld_update_descriptions. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_descriptions + exp = it_descriptions + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_description_key + exp = ms_item-obj_name + ). + ENDMETHOD. + + METHOD given_the_descriptions. + mo_xml_out->add( + iv_name = 'DESCRIPTIONS' + ig_data = it_descriptions + ). + ENDMETHOD. + + METHOD then_should_deserialize_source. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_source + exp = mo_fake_object_files->mt_sources + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_deserialize_key + exp = ms_item-obj_name + ). + ENDMETHOD. + + METHOD when_deserializing. + CREATE OBJECT mo_xml_input + EXPORTING + iv_xml = mo_xml_out->render( ). + mo_oo_object->deserialize( + iv_package = 'package_name' + io_xml = mo_xml_input + ). + ENDMETHOD. +ENDCLASS. + +CLASS ltc_class_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT +INHERITING FROM ltc_oo_test. + PRIVATE SECTION. + METHODS: + setup, + given_a_class_properties + RAISING + lcx_exception, + then_should_create_class, + then_it_should_generate_locals, should_create_class FOR TESTING RAISING cx_static_check, should_generate_locals FOR TESTING RAISING cx_static_check, should_deserialize_source FOR TESTING RAISING cx_static_check, should_update_descriptions FOR TESTING RAISING cx_static_check, should_add_to_activation FOR TESTING RAISING cx_static_check. - DATA: - mo_spy_oo_object TYPE REF TO ltd_spy_oo_object, - mo_fake_object_files TYPE REF TO ltd_fake_object_files, - mo_xml_input TYPE REF TO lcl_xml_input, - mo_xml_out TYPE REF TO lcl_xml_output, - mo_class TYPE REF TO lif_object, - ms_class_properties TYPE vseoclass, - ls_item TYPE ty_item. + ms_class_properties TYPE vseoclass. ENDCLASS. CLASS ltc_class_deserialization IMPLEMENTATION. @@ -1443,19 +1499,19 @@ CLASS ltc_class_deserialization IMPLEMENTATION. CREATE OBJECT mo_xml_out. lth_oo_factory_injector=>inject( mo_spy_oo_object ). - ls_item-devclass = 'package_name'. - ls_item-obj_name = 'zcl_class'. - ls_item-obj_type = 'CLAS'. + ms_item-devclass = 'package_name'. + ms_item-obj_name = 'zcl_class'. + ms_item-obj_type = 'CLAS'. - CREATE OBJECT mo_class TYPE lcl_object_clas + CREATE OBJECT mo_oo_object TYPE lcl_object_clas EXPORTING - is_item = ls_item + is_item = ms_item iv_language = sy-langu. - mo_class->mo_files = mo_fake_object_files. + mo_oo_object->mo_files = mo_fake_object_files. ENDMETHOD. METHOD should_create_class. - ms_class_properties-clsname = ls_item-obj_name. + ms_class_properties-clsname = ms_item-obj_name. given_a_class_properties( ). @@ -1487,14 +1543,14 @@ CLASS ltc_class_deserialization IMPLEMENTATION. given_a_class_properties( ). - ls_description-clsname = ls_item-obj_name. + ls_description-clsname = ms_item-obj_name. ls_description-cmpname = 'a_method'. APPEND ls_description TO lt_descriptions. given_the_descriptions( lt_descriptions ). when_deserializing( ). - then_shuld_update_descriptions( lt_descriptions ). + then_shuld_update_descriptions( lt_descriptions ). ENDMETHOD. METHOD should_add_to_activation. @@ -1502,8 +1558,7 @@ CLASS ltc_class_deserialization IMPLEMENTATION. when_deserializing( ). - "Activation -then_it_should_add_activation( ). + then_it_should_add_activation( ). ENDMETHOD. METHOD given_a_class_properties. @@ -1513,24 +1568,11 @@ then_it_should_add_activation( ). ). ENDMETHOD. - - METHOD when_deserializing. - CREATE OBJECT mo_xml_input - EXPORTING - iv_xml = mo_xml_out->render( ). - mo_class->deserialize( - iv_package = 'package_name' - io_xml = mo_xml_input - ). - ENDMETHOD. - - METHOD then_should_create_class. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_class_properties - exp = ms_class_properties - ). + act = mo_spy_oo_object->ms_class_properties + exp = ms_class_properties + ). cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). @@ -1538,14 +1580,13 @@ then_it_should_add_activation( ). act = mo_spy_oo_object->mv_package exp = 'package_name' ). - ENDMETHOD. METHOD then_it_should_generate_locals. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_locals_key - exp = ls_item-obj_name + exp = ms_item-obj_name ). cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_force ). @@ -1569,46 +1610,102 @@ then_it_should_add_activation( ). exp = mo_fake_object_files->mt_local_test_classes ). ENDMETHOD. +ENDCLASS. +CLASS ltc_interface_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT +INHERITING FROM ltc_oo_test. + PRIVATE SECTION. + METHODS: + setup, + given_an_interface_properties + RAISING + lcx_exception, + then_should_create_interface, + create_interface FOR TESTING RAISING cx_static_check, + update_descriptions FOR TESTING RAISING cx_static_check, + add_to_activation FOR TESTING RAISING cx_static_check, + deserialize_source FOR TESTING RAISING cx_static_check. + DATA: + ms_interface_properties TYPE vseointerf. +ENDCLASS. +CLASS ltc_interface_deserialization IMPLEMENTATION. + METHOD setup. + CREATE OBJECT mo_fake_object_files. + CREATE OBJECT mo_spy_oo_object. + CREATE OBJECT mo_xml_out. + lth_oo_factory_injector=>inject( mo_spy_oo_object ). - METHOD then_should_deserialize_source. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_source - exp = mo_fake_object_files->mt_sources - ). + ms_item-devclass = 'package_name'. + ms_item-obj_name = 'zif_interface'. + ms_item-obj_type = 'INTF'. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_deserialize_key - exp = ls_item-obj_name - ). + CREATE OBJECT mo_oo_object TYPE lcl_object_intf + EXPORTING + is_item = ms_item + iv_language = sy-langu. + mo_oo_object->mo_files = mo_fake_object_files. ENDMETHOD. + METHOD create_interface. + ms_interface_properties-clsname = ms_item-obj_name. + given_an_interface_properties( ). - METHOD given_the_descriptions. + when_deserializing( ). + + then_should_create_interface( ). + ENDMETHOD. + + METHOD update_descriptions. + DATA: + ls_description TYPE seocompotx, + lt_descriptions TYPE ty_seocompotx_tt. + + given_an_interface_properties( ). + + ls_description-clsname = ms_item-obj_name. + ls_description-cmpname = 'a_method'. + APPEND ls_description TO lt_descriptions. + given_the_descriptions( lt_descriptions ). + + when_deserializing( ). + + then_shuld_update_descriptions( lt_descriptions ). + ENDMETHOD. + + METHOD add_to_activation. + given_an_interface_properties( ). + + when_deserializing( ). + + then_it_should_add_activation( ). + ENDMETHOD. + + METHOD deserialize_source. + given_an_interface_properties( ). + + when_deserializing( ). + + then_should_deserialize_source( ). + ENDMETHOD. + + METHOD given_an_interface_properties. mo_xml_out->add( - iv_name = 'DESCRIPTIONS' - ig_data = it_descriptions - ). - ENDMETHOD. - - - METHOD then_shuld_update_descriptions. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_descriptions - exp = it_descriptions - ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_description_key - exp = ls_item-obj_name + iv_name = 'VSEOINTERF' + ig_data = ms_interface_properties ). ENDMETHOD. - - METHOD then_it_should_add_activation. + METHOD then_should_create_interface. cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_item_to_activate - exp = ls_item + act = mo_spy_oo_object->ms_interface_properties + exp = ms_interface_properties + ). + + cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_package + exp = 'package_name' ). ENDMETHOD. From dd23247095ccb89ead51cf90f2bc1b57acd38601 Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Thu, 22 Dec 2016 16:07:25 +0100 Subject: [PATCH 6/9] Sotr TextPool Docu --- src/zabapgit_definitions.prog.abap | 114 ++++---- src/zabapgit_object_clas.prog.abap | 416 +++++++++++++++++++++-------- src/zabapgit_objects.prog.abap | 7 - 3 files changed, 370 insertions(+), 167 deletions(-) diff --git a/src/zabapgit_definitions.prog.abap b/src/zabapgit_definitions.prog.abap index 5f0b0e1bd..3bfde6835 100644 --- a/src/zabapgit_definitions.prog.abap +++ b/src/zabapgit_definitions.prog.abap @@ -18,8 +18,8 @@ TYPES: ty_file_signatures_tt TYPE STANDARD TABLE OF ty_file_signature WITH DEFAU TYPES: ty_file_signatures_ts TYPE SORTED TABLE OF ty_file_signature WITH UNIQUE KEY path filename. TYPES: BEGIN OF ty_file. - INCLUDE TYPE ty_file_signature. -TYPES: data TYPE xstring, + INCLUDE TYPE ty_file_signature. +TYPES: data TYPE xstring, END OF ty_file. TYPES: ty_files_tt TYPE STANDARD TABLE OF ty_file WITH DEFAULT KEY. @@ -61,11 +61,11 @@ TYPES: BEGIN OF ty_web_asset, TYPES tt_web_assets TYPE STANDARD TABLE OF ty_web_asset WITH DEFAULT KEY. TYPES: BEGIN OF ty_repo_file, - path TYPE string, - filename TYPE string, - is_changed TYPE abap_bool, - rstate TYPE char1, - lstate TYPE char1, + path TYPE string, + filename TYPE string, + is_changed TYPE abap_bool, + rstate TYPE char1, + lstate TYPE char1, END OF ty_repo_file. TYPES tt_repo_files TYPE STANDARD TABLE OF ty_repo_file WITH DEFAULT KEY. @@ -101,14 +101,14 @@ TYPES: BEGIN OF ty_tadir, TYPES: ty_tadir_tt TYPE STANDARD TABLE OF ty_tadir WITH DEFAULT KEY. TYPES: BEGIN OF ty_result, - obj_type TYPE tadir-object, - obj_name TYPE tadir-obj_name, - path TYPE string, - filename TYPE string, - package TYPE devclass, - match TYPE sap_bool, - lstate TYPE char1, - rstate TYPE char1, + obj_type TYPE tadir-object, + obj_name TYPE tadir-obj_name, + path TYPE string, + filename TYPE string, + package TYPE devclass, + match TYPE sap_bool, + lstate TYPE char1, + rstate TYPE char1, END OF ty_result. TYPES: ty_results_tt TYPE STANDARD TABLE OF ty_result WITH DEFAULT KEY. @@ -116,6 +116,20 @@ TYPES: ty_sval_tt TYPE STANDARD TABLE OF sval WITH DEFAULT KEY. TYPES: ty_seocompotx_tt TYPE STANDARD TABLE OF seocompotx WITH DEFAULT KEY. +TYPES: BEGIN OF ty_tpool. + INCLUDE TYPE textpool. +TYPES: split TYPE c LENGTH 8. +TYPES: END OF ty_tpool. + +TYPES: ty_tpool_tt TYPE STANDARD TABLE OF ty_tpool WITH DEFAULT KEY. + +TYPES: BEGIN OF ty_sotr, + header TYPE sotr_head, + entries TYPE sotr_text_tt, + END OF ty_sotr. + +TYPES: ty_sotr_tt TYPE STANDARD TABLE OF ty_sotr WITH DEFAULT KEY. + CONSTANTS: BEGIN OF gc_state, " https://git-scm.com/docs/git-status unchanged TYPE char1 VALUE '', added TYPE char1 VALUE 'A', @@ -172,43 +186,43 @@ CONSTANTS: BEGIN OF gc_action, repo_refresh_checksums TYPE string VALUE 'repo_refresh_checksums', repo_toggle_fav TYPE string VALUE 'repo_toggle_fav', - abapgit_home TYPE string VALUE 'abapgit_home', - abapgit_wiki TYPE string VALUE 'abapgit_wiki', - abapgit_install TYPE string VALUE 'abapgit_install', - abapgit_install_pi TYPE string VALUE 'abapgit_install_pi', + abapgit_home TYPE string VALUE 'abapgit_home', + abapgit_wiki TYPE string VALUE 'abapgit_wiki', + abapgit_install TYPE string VALUE 'abapgit_install', + abapgit_install_pi TYPE string VALUE 'abapgit_install_pi', - zip_import TYPE string VALUE 'zip_import', - zip_export TYPE string VALUE 'zip_export', - zip_package TYPE string VALUE 'zip_package', - zip_transport TYPE string VALUE 'zip_transport', - zip_object TYPE string VALUE 'zip_object', + zip_import TYPE string VALUE 'zip_import', + zip_export TYPE string VALUE 'zip_export', + zip_package TYPE string VALUE 'zip_package', + zip_transport TYPE string VALUE 'zip_transport', + zip_object TYPE string VALUE 'zip_object', - git_pull TYPE string VALUE 'git_pull', - git_reset TYPE string VALUE 'git_reset', - git_branch_create TYPE string VALUE 'git_branch_create', - git_branch_switch TYPE string VALUE 'git_branch_switch', - git_branch_delete TYPE string VALUE 'git_branch_delete', - git_commit TYPE string VALUE 'git_commit', + git_pull TYPE string VALUE 'git_pull', + git_reset TYPE string VALUE 'git_reset', + git_branch_create TYPE string VALUE 'git_branch_create', + git_branch_switch TYPE string VALUE 'git_branch_switch', + git_branch_delete TYPE string VALUE 'git_branch_delete', + git_commit TYPE string VALUE 'git_commit', - db_delete TYPE string VALUE 'db_delete', - db_update TYPE string VALUE 'db_update', - db_display TYPE string VALUE 'db_display', - db_edit TYPE string VALUE 'db_edit', - bg_update TYPE string VALUE 'bg_update', + db_delete TYPE string VALUE 'db_delete', + db_update TYPE string VALUE 'db_update', + db_display TYPE string VALUE 'db_display', + db_edit TYPE string VALUE 'db_edit', + bg_update TYPE string VALUE 'bg_update', - go_main TYPE string VALUE 'go_main', - go_explore TYPE string VALUE 'go_explore', - go_db TYPE string VALUE 'go_db', - go_background TYPE string VALUE 'go_background', - go_background_run TYPE string VALUE 'go_background_run', - go_diff TYPE string VALUE 'go_diff', - go_stage TYPE string VALUE 'go_stage', - go_commit TYPE string VALUE 'go_commit', - go_branch_overview TYPE string VALUE 'go_branch_overview', - go_playground TYPE string VALUE 'go_playground', - go_debuginfo TYPE string VALUE 'go_debuginfo', - go_settings TYPE STRING VALUE 'go_settings', - go_tutorial TYPE STRING VALUE 'go_tutorial', - jump TYPE string VALUE 'jump', - jump_pkg TYPE string VALUE 'jump_pkg', + go_main TYPE string VALUE 'go_main', + go_explore TYPE string VALUE 'go_explore', + go_db TYPE string VALUE 'go_db', + go_background TYPE string VALUE 'go_background', + go_background_run TYPE string VALUE 'go_background_run', + go_diff TYPE string VALUE 'go_diff', + go_stage TYPE string VALUE 'go_stage', + go_commit TYPE string VALUE 'go_commit', + go_branch_overview TYPE string VALUE 'go_branch_overview', + go_playground TYPE string VALUE 'go_playground', + go_debuginfo TYPE string VALUE 'go_debuginfo', + go_settings TYPE string VALUE 'go_settings', + go_tutorial TYPE string VALUE 'go_tutorial', + jump TYPE string VALUE 'jump', + jump_pkg TYPE string VALUE 'jump_pkg', END OF gc_action. \ No newline at end of file diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index feba06bc0..b055c09ee 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -34,6 +34,13 @@ INTERFACE lif_object_oriented_object. RAISING lcx_exception cx_sy_dyn_call_error, + insert_text_pool + IMPORTING + iv_class_name TYPE seoclsname + it_text_pool TYPE textpool_table + iv_language TYPE spras + RAISING + lcx_exception, update_descriptions IMPORTING is_key TYPE seoclskey @@ -41,6 +48,19 @@ INTERFACE lif_object_oriented_object. add_to_activation_list IMPORTING is_item TYPE ty_item + RAISING + lcx_exception, + create_sotr + IMPORTING + iv_package TYPE devclass + it_sotr TYPE ty_sotr_tt + RAISING + lcx_exception, + create_documentation + IMPORTING + it_lines TYPE tlinetab + iv_object_name TYPE dokhl-object + iv_language TYPE spras RAISING lcx_exception. ENDINTERFACE. @@ -150,6 +170,20 @@ CLASS lcl_object_oriented_base IMPLEMENTATION. DELETE FROM seocompotx WHERE clsname = is_key-clsname. INSERT seocompotx FROM TABLE it_descriptions. ENDMETHOD. + METHOD lif_object_oriented_object~insert_text_pool. + "Subclass responsibility + RETURN. + ENDMETHOD. + + METHOD lif_object_oriented_object~create_sotr. + "Subclass responsibility + RETURN. + ENDMETHOD. + + METHOD lif_object_oriented_object~create_documentation. + + ENDMETHOD. + ENDCLASS. @@ -158,7 +192,10 @@ CLASS lcl_object_oriented_class DEFINITION PUBLIC SECTION. METHODS: lif_object_oriented_object~create REDEFINITION, - lif_object_oriented_object~generate_locals REDEFINITION. + lif_object_oriented_object~generate_locals REDEFINITION, + lif_object_oriented_object~insert_text_pool REDEFINITION, + lif_object_oriented_object~create_sotr REDEFINITION. + ENDCLASS. CLASS lcl_object_oriented_class IMPLEMENTATION. METHOD lif_object_oriented_object~create. @@ -199,6 +236,83 @@ CLASS lcl_object_oriented_class IMPLEMENTATION. lcx_exception=>raise( 'error from generate_locals' ). ENDIF. ENDMETHOD. + METHOD lif_object_oriented_object~insert_text_pool. + DATA: lv_cp TYPE program. + + lv_cp = cl_oo_classname_service=>get_classpool_name( iv_class_name ). + + INSERT TEXTPOOL lv_cp + FROM it_text_pool + LANGUAGE iv_language + STATE 'I'. + IF sy-subrc <> 0. + lcx_exception=>raise( 'error from INSERT TEXTPOOL' ). + ENDIF. + + lcl_objects_activation=>add( iv_type = 'REPT' + iv_name = lv_cp ). + ENDMETHOD. + + METHOD lif_object_oriented_object~create_sotr. + DATA: lt_sotr TYPE ty_sotr_tt, + lt_objects TYPE sotr_objects, + ls_paket TYPE sotr_pack, + lv_object LIKE LINE OF lt_objects. + + FIELD-SYMBOLS: LIKE LINE OF lt_sotr. + + LOOP AT it_sotr ASSIGNING . + CALL FUNCTION 'SOTR_OBJECT_GET_OBJECTS' + EXPORTING + object_vector = -header-objid_vec + IMPORTING + objects = lt_objects + EXCEPTIONS + object_not_found = 1 + OTHERS = 2. + IF sy-subrc <> 0. + lcx_exception=>raise( 'error from SOTR_OBJECT_GET_OBJECTS' ). + ENDIF. + + READ TABLE lt_objects INDEX 1 INTO lv_object. + ASSERT sy-subrc = 0. + + ls_paket-paket = iv_package. + + CALL FUNCTION 'SOTR_CREATE_CONCEPT' + EXPORTING + paket = ls_paket + crea_lan = -header-crea_lan + alias_name = -header-alias_name + object = lv_object + entries = -entries + concept_default = -header-concept + EXCEPTIONS + package_missing = 1 + crea_lan_missing = 2 + object_missing = 3 + paket_does_not_exist = 4 + alias_already_exist = 5 + object_type_not_found = 6 + langu_missing = 7 + identical_context_not_allowed = 8 + text_too_long = 9 + error_in_update = 10 + no_master_langu = 11 + error_in_concept_id = 12 + alias_not_allowed = 13 + tadir_entry_creation_failed = 14 + internal_error = 15 + error_in_correction = 16 + user_cancelled = 17 + no_entry_found = 18 + OTHERS = 19. + IF sy-subrc <> 0. + lcx_exception=>raise( 'error from SOTR_CREATE_CONCEPT' ). + ENDIF. + ENDLOOP. + ENDMETHOD. + ENDCLASS. CLASS lcl_object_oriented_interface DEFINITION @@ -279,16 +393,8 @@ CLASS lcl_object_clas DEFINITION INHERITING FROM lcl_objects_program. ALIASES mo_files FOR lif_object~mo_files. PRIVATE SECTION. - TYPES: BEGIN OF ty_sotr, - header TYPE sotr_head, - entries TYPE sotr_text_tt, - END OF ty_sotr. - - TYPES: ty_sotr_tt TYPE STANDARD TABLE OF ty_sotr WITH DEFAULT KEY. - - - DATA mv_skip_testclass TYPE abap_bool. + DATA mo_object_oriented_object TYPE REF TO lif_object_oriented_object. METHODS deserialize_abap IMPORTING io_xml TYPE REF TO lcl_xml_input @@ -1001,6 +1107,9 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDMETHOD. "serialize_xml METHOD lif_object~deserialize. + + mo_object_oriented_object = lcl_object_oriented_factory=>make( iv_object_type = ms_item-obj_type ). + deserialize_abap( io_xml = io_xml iv_package = iv_package ). @@ -1015,7 +1124,7 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDMETHOD. "deserialize METHOD deserialize_sotr. - + "OTR stands for Online Text Repository DATA: lt_sotr TYPE ty_sotr_tt, lt_objects TYPE sotr_objects, ls_paket TYPE sotr_pack, @@ -1031,65 +1140,16 @@ CLASS lcl_object_clas IMPLEMENTATION. RETURN. ENDIF. - LOOP AT lt_sotr ASSIGNING . - CALL FUNCTION 'SOTR_OBJECT_GET_OBJECTS' - EXPORTING - object_vector = -header-objid_vec - IMPORTING - objects = lt_objects - EXCEPTIONS - object_not_found = 1 - OTHERS = 2. - IF sy-subrc <> 0. - lcx_exception=>raise( 'error from SOTR_OBJECT_GET_OBJECTS' ). - ENDIF. - - READ TABLE lt_objects INDEX 1 INTO lv_object. - ASSERT sy-subrc = 0. - - ls_paket-paket = iv_package. - - CALL FUNCTION 'SOTR_CREATE_CONCEPT' - EXPORTING - paket = ls_paket - crea_lan = -header-crea_lan - alias_name = -header-alias_name - object = lv_object - entries = -entries - concept_default = -header-concept - EXCEPTIONS - package_missing = 1 - crea_lan_missing = 2 - object_missing = 3 - paket_does_not_exist = 4 - alias_already_exist = 5 - object_type_not_found = 6 - langu_missing = 7 - identical_context_not_allowed = 8 - text_too_long = 9 - error_in_update = 10 - no_master_langu = 11 - error_in_concept_id = 12 - alias_not_allowed = 13 - tadir_entry_creation_failed = 14 - internal_error = 15 - error_in_correction = 16 - user_cancelled = 17 - no_entry_found = 18 - OTHERS = 19. - IF sy-subrc <> 0. - lcx_exception=>raise( 'error from SOTR_CREATE_CONCEPT' ). - ENDIF. - - ENDLOOP. - + mo_object_oriented_object->create_sotr( + iv_package = iv_package + it_sotr = lt_sotr + ). ENDMETHOD. METHOD deserialize_docu. DATA: lt_lines TYPE tlinetab, - lv_object TYPE dokhl-object. - + lv_object type dokhl-object. io_xml->read( EXPORTING iv_name = 'LINES' CHANGING cg_data = lt_lines ). @@ -1099,20 +1159,11 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDIF. lv_object = ms_item-obj_name. - CALL FUNCTION 'DOCU_UPD' - EXPORTING - id = 'CL' - langu = mv_language - object = lv_object - TABLES - line = lt_lines - EXCEPTIONS - ret_code = 1 - OTHERS = 2. - IF sy-subrc <> 0. - lcx_exception=>raise( 'error from DOCU_UPD' ). - ENDIF. + mo_object_oriented_object->create_documentation( + it_lines = lt_lines + iv_object_name = lv_object + iv_language = mv_language ). ENDMETHOD. "deserialize_doku METHOD deserialize_textpool. @@ -1132,19 +1183,12 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDIF. lv_clsname = ms_item-obj_name. - lv_cp = cl_oo_classname_service=>get_classpool_name( lv_clsname ). - - INSERT TEXTPOOL lv_cp - FROM lt_tpool - LANGUAGE mv_language - STATE 'I'. - IF sy-subrc <> 0. - lcx_exception=>raise( 'error from INSERT TEXTPOOL' ). - ENDIF. - - lcl_objects_activation=>add( iv_type = 'REPT' - iv_name = lv_cp ). + mo_object_oriented_object->insert_text_pool( + iv_class_name = lv_clsname + it_text_pool = lt_tpool + iv_language = mv_language + ). ENDMETHOD. "deserialize_textpool METHOD deserialize_abap. @@ -1176,16 +1220,12 @@ CLASS lcl_object_clas IMPLEMENTATION. ls_clskey-clsname = ms_item-obj_name. - DATA lo_object_oriented_object TYPE REF TO lif_object_oriented_object. - lo_object_oriented_object = lcl_object_oriented_factory=>make( iv_object_type = ms_item-obj_type ). - - CASE ms_item-obj_type. WHEN 'CLAS'. io_xml->read( EXPORTING iv_name = 'VSEOCLASS' CHANGING cg_data = ls_vseoclass ). - lo_object_oriented_object->create( + mo_object_oriented_object->create( EXPORTING iv_package = iv_package CHANGING @@ -1196,7 +1236,7 @@ CLASS lcl_object_clas IMPLEMENTATION. io_xml->read( EXPORTING iv_name = 'VSEOINTERF' CHANGING cg_data = ls_vseointerf ). - lo_object_oriented_object->create( + mo_object_oriented_object->create( EXPORTING iv_package = iv_package CHANGING @@ -1208,7 +1248,7 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDCASE. IF ms_item-obj_type = 'CLAS'. - lo_object_oriented_object->generate_locals( + mo_object_oriented_object->generate_locals( is_key = ls_clskey iv_force = seox_true it_local_definitions = lt_locals_def @@ -1218,7 +1258,7 @@ CLASS lcl_object_clas IMPLEMENTATION. ). ENDIF. - lo_object_oriented_object->deserialize_source( + mo_object_oriented_object->deserialize_source( is_key = ls_clskey it_source = lt_source ). @@ -1226,12 +1266,12 @@ CLASS lcl_object_clas IMPLEMENTATION. io_xml->read( EXPORTING iv_name = 'DESCRIPTIONS' CHANGING cg_data = lt_descriptions ). - lo_object_oriented_object->update_descriptions( + mo_object_oriented_object->update_descriptions( is_key = ls_clskey it_descriptions = lt_descriptions ). - lo_object_oriented_object->add_to_activation_list( is_item = ms_item ). + mo_object_oriented_object->add_to_activation_list( is_item = ms_item ). ENDMETHOD. "deserialize METHOD deserialize_abap_source_old. @@ -1319,7 +1359,16 @@ CLASS ltd_spy_oo_object DEFINITION FOR TESTING. mt_source TYPE ty_string_tt, ms_item_to_activate TYPE ty_item, mt_descriptions TYPE ty_seocompotx_tt, - ms_description_key TYPE seoclskey. + ms_description_key TYPE seoclskey, + mv_text_pool_class_name TYPE seoclsname, + mt_text_pool TYPE textpool_table, + mv_text_pool_inserted TYPE abap_bool, + mt_sotr TYPE ty_sotr_tt, + mt_sotr_package TYPE devclass, + mv_docu_object_name TYPE dokhl-object, + mv_docu_language TYPE spras, + mt_docu_lines TYPE tlinetab. + ENDCLASS. CLASS ltd_spy_oo_object IMPLEMENTATION. METHOD lif_object_oriented_object~create. @@ -1354,6 +1403,27 @@ CLASS ltd_spy_oo_object IMPLEMENTATION. mt_descriptions = it_descriptions. ENDMETHOD. + METHOD lif_object_oriented_object~insert_text_pool. + mv_text_pool_inserted = abap_true. + mv_text_pool_class_name = iv_class_name. + mt_text_pool = it_text_pool. + cl_abap_unit_assert=>assert_equals( + act = iv_language + exp = sy-langu + ). + ENDMETHOD. + + METHOD lif_object_oriented_object~create_sotr. + mt_sotr = it_sotr. + mt_sotr_package = iv_package. + ENDMETHOD. + + METHOD lif_object_oriented_object~create_documentation. + mv_docu_object_name = iv_object_name. + mv_docu_language = iv_language. + mt_docu_lines = it_lines. + ENDMETHOD. + ENDCLASS. CLASS ltd_fake_object_files DEFINITION FOR TESTING @@ -1419,11 +1489,43 @@ CLASS ltc_oo_test DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT . then_shuld_update_descriptions IMPORTING it_descriptions TYPE ty_seocompotx_tt, - then_it_should_add_activation. + then_it_should_add_activation, + given_documentation_in_xml_as + IMPORTING + it_lines TYPE tlinetab + RAISING + lcx_exception, + then_docu_should_be_created + IMPORTING + it_lines TYPE tlinetab. ENDCLASS. CLASS ltc_oo_test IMPLEMENTATION. + METHOD then_docu_should_be_created. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_docu_lines + exp = it_lines + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_docu_object_name + exp = ms_item-obj_name + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_docu_language + exp = sy-langu + ). + ENDMETHOD. + + METHOD given_documentation_in_xml_as. + mo_xml_out->add( + iv_name = 'LINES' + ig_data = it_lines + ). + ENDMETHOD. + METHOD then_it_should_add_activation. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_item_to_activate @@ -1433,9 +1535,9 @@ CLASS ltc_oo_test IMPLEMENTATION. METHOD then_shuld_update_descriptions. cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_descriptions - exp = it_descriptions - ). + act = mo_spy_oo_object->mt_descriptions + exp = it_descriptions + ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_description_key @@ -1487,7 +1589,11 @@ INHERITING FROM ltc_oo_test. should_generate_locals FOR TESTING RAISING cx_static_check, should_deserialize_source FOR TESTING RAISING cx_static_check, should_update_descriptions FOR TESTING RAISING cx_static_check, - should_add_to_activation FOR TESTING RAISING cx_static_check. + should_add_to_activation FOR TESTING RAISING cx_static_check, + no_text_pool_no_insert FOR TESTING RAISING cx_static_check, + insert_text_pool FOR TESTING RAISING cx_static_check, + create_stor_from_xml FOR TESTING RAISING cx_static_check, + create_documentation FOR TESTING RAISING cx_static_check. DATA: ms_class_properties TYPE vseoclass. ENDCLASS. @@ -1610,6 +1716,80 @@ CLASS ltc_class_deserialization IMPLEMENTATION. exp = mo_fake_object_files->mt_local_test_classes ). ENDMETHOD. + METHOD no_text_pool_no_insert. + given_a_class_properties( ). + + when_deserializing( ). + + cl_abap_unit_assert=>assert_false( mo_spy_oo_object->mv_text_pool_inserted ). + ENDMETHOD. + + METHOD insert_text_pool. + given_a_class_properties( ). + + DATA lt_pool_external TYPE textpool_table. + DATA ls_pool_external TYPE ty_tpool. + ls_pool_external-id = 'ID'. + ls_pool_external-key = 'KEY'. + APPEND ls_pool_external TO lt_pool_external. + mo_xml_out->add( + iv_name = 'TPOOL' + ig_data = lt_pool_external + ). + + when_deserializing( ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_text_pool + exp = lt_pool_external + ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_text_pool_class_name + exp = 'zcl_class' + ). + ENDMETHOD. + + METHOD create_stor_from_xml. + DATA: + lt_sotr TYPE ty_sotr_tt, + ls_sotr LIKE LINE OF lt_sotr. + + given_a_class_properties( ). + + ls_sotr-header-concept = 'HEADER'. + APPEND ls_sotr TO lt_sotr. + mo_xml_out->add( + iv_name = 'SOTR' + ig_data = lt_sotr + ). + + when_deserializing( ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_sotr + exp = lt_sotr + ). + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_sotr_package + exp = 'package_name' + ). + ENDMETHOD. + + METHOD create_documentation. + DATA: lt_lines TYPE tlinetab, + ls_line TYPE LINE OF tlinetab. + ls_line-tdline = 'Class Line Doc'. + APPEND ls_line TO lt_lines. + + given_a_class_properties( ). + + given_documentation_in_xml_as( lt_lines ). + + when_deserializing( ). + + then_docu_should_be_created( lt_lines ). + ENDMETHOD. ENDCLASS. CLASS ltc_interface_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT @@ -1624,7 +1804,8 @@ INHERITING FROM ltc_oo_test. create_interface FOR TESTING RAISING cx_static_check, update_descriptions FOR TESTING RAISING cx_static_check, add_to_activation FOR TESTING RAISING cx_static_check, - deserialize_source FOR TESTING RAISING cx_static_check. + deserialize_source FOR TESTING RAISING cx_static_check, + create_documentation FOR TESTING RAISING cx_static_check. DATA: ms_interface_properties TYPE vseointerf. ENDCLASS. @@ -1697,9 +1878,9 @@ CLASS ltc_interface_deserialization IMPLEMENTATION. METHOD then_should_create_interface. cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_interface_properties - exp = ms_interface_properties - ). + act = mo_spy_oo_object->ms_interface_properties + exp = ms_interface_properties + ). cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). @@ -1709,4 +1890,19 @@ CLASS ltc_interface_deserialization IMPLEMENTATION. ). ENDMETHOD. + METHOD create_documentation. + DATA: lt_lines TYPE tlinetab, + ls_line TYPE LINE OF tlinetab. + ls_line-tdline = 'Interface Line Doc'. + APPEND ls_line TO lt_lines. + + given_an_interface_properties( ). + + given_documentation_in_xml_as( lt_lines ). + + when_deserializing( ). + + then_docu_should_be_created( lt_lines ). + ENDMETHOD. + ENDCLASS. \ No newline at end of file diff --git a/src/zabapgit_objects.prog.abap b/src/zabapgit_objects.prog.abap index a76058992..37f534e4d 100644 --- a/src/zabapgit_objects.prog.abap +++ b/src/zabapgit_objects.prog.abap @@ -859,13 +859,6 @@ CLASS lcl_objects_program DEFINITION INHERITING FROM lcl_objects_super. TYPES: ty_spaces_tt TYPE STANDARD TABLE OF i WITH DEFAULT KEY. - TYPES: BEGIN OF ty_tpool. - INCLUDE TYPE textpool. - TYPES: split TYPE c LENGTH 8. - TYPES: END OF ty_tpool. - - TYPES: ty_tpool_tt TYPE STANDARD TABLE OF ty_tpool WITH DEFAULT KEY. - TYPES: BEGIN OF ty_dynpro, header TYPE rpy_dyhead, containers TYPE dycatt_tab, From 7fdcf7aa73b5dda70e7952d6d217cafbc120d5da Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Thu, 22 Dec 2016 16:23:40 +0100 Subject: [PATCH 7/9] Refactoring into INTF class since we have tests --- src/zabapgit_object_clas.prog.abap | 163 +++++++++++++++++------------ 1 file changed, 95 insertions(+), 68 deletions(-) diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index b055c09ee..20525d7cc 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -391,21 +391,20 @@ CLASS lcl_object_clas DEFINITION INHERITING FROM lcl_objects_program. PUBLIC SECTION. INTERFACES lif_object. ALIASES mo_files FOR lif_object~mo_files. - - PRIVATE SECTION. - DATA mv_skip_testclass TYPE abap_bool. - DATA mo_object_oriented_object TYPE REF TO lif_object_oriented_object. - + PROTECTED SECTION. METHODS deserialize_abap IMPORTING io_xml TYPE REF TO lcl_xml_input iv_package TYPE devclass RAISING lcx_exception. - METHODS deserialize_textpool + METHODS deserialize_docu IMPORTING io_xml TYPE REF TO lcl_xml_input RAISING lcx_exception. + DATA mo_object_oriented_object TYPE REF TO lif_object_oriented_object. + PRIVATE SECTION. + DATA mv_skip_testclass TYPE abap_bool. - METHODS deserialize_docu + METHODS deserialize_textpool IMPORTING io_xml TYPE REF TO lcl_xml_input RAISING lcx_exception. @@ -480,16 +479,6 @@ CLASS lcl_object_clas DEFINITION INHERITING FROM lcl_objects_program. ENDCLASS. "lcl_object_dtel DEFINITION -*----------------------------------------------------------------------* -* CLASS lcl_object_intf DEFINITION -*----------------------------------------------------------------------* -* -*----------------------------------------------------------------------* -CLASS lcl_object_intf DEFINITION INHERITING FROM lcl_object_clas FINAL. -* todo, CLAS + INTF to be refactored, see: -* https://github.com/larshp/abapGit/issues/21 -ENDCLASS. "lcl_object_intf DEFINITION - *----------------------------------------------------------------------* * CLASS lcl_object_clas IMPLEMENTATION *----------------------------------------------------------------------* @@ -1113,12 +1102,10 @@ CLASS lcl_object_clas IMPLEMENTATION. deserialize_abap( io_xml = io_xml iv_package = iv_package ). - IF ms_item-obj_type = 'CLAS'. - deserialize_textpool( io_xml ). + deserialize_textpool( io_xml ). - deserialize_sotr( io_xml = io_xml - iv_package = iv_package ). - ENDIF. + deserialize_sotr( io_xml = io_xml + iv_package = iv_package ). deserialize_docu( io_xml ). ENDMETHOD. "deserialize @@ -1149,7 +1136,7 @@ CLASS lcl_object_clas IMPLEMENTATION. METHOD deserialize_docu. DATA: lt_lines TYPE tlinetab, - lv_object type dokhl-object. + lv_object TYPE dokhl-object. io_xml->read( EXPORTING iv_name = 'LINES' CHANGING cg_data = lt_lines ). @@ -1194,7 +1181,6 @@ CLASS lcl_object_clas IMPLEMENTATION. METHOD deserialize_abap. DATA: ls_vseoclass TYPE vseoclass, - ls_vseointerf TYPE vseointerf, lt_source TYPE seop_source_string, lt_locals_def TYPE seop_source_string, lt_locals_imp TYPE seop_source_string, @@ -1220,43 +1206,23 @@ CLASS lcl_object_clas IMPLEMENTATION. ls_clskey-clsname = ms_item-obj_name. - CASE ms_item-obj_type. - WHEN 'CLAS'. - io_xml->read( EXPORTING iv_name = 'VSEOCLASS' - CHANGING cg_data = ls_vseoclass ). + io_xml->read( EXPORTING iv_name = 'VSEOCLASS' + CHANGING cg_data = ls_vseoclass ). - mo_object_oriented_object->create( - EXPORTING - iv_package = iv_package - CHANGING - is_properties = ls_vseoclass - ). - - WHEN 'INTF'. - io_xml->read( EXPORTING iv_name = 'VSEOINTERF' - CHANGING cg_data = ls_vseointerf ). - - mo_object_oriented_object->create( - EXPORTING - iv_package = iv_package - CHANGING - is_properties = ls_vseointerf - ). - - WHEN OTHERS. - ASSERT 0 = 1. - ENDCASE. - - IF ms_item-obj_type = 'CLAS'. - mo_object_oriented_object->generate_locals( - is_key = ls_clskey - iv_force = seox_true - it_local_definitions = lt_locals_def - it_local_implementations = lt_locals_imp - it_local_macros = lt_locals_mac - it_local_test_classes = lt_testclasses - ). - ENDIF. + mo_object_oriented_object->create( + EXPORTING + iv_package = iv_package + CHANGING + is_properties = ls_vseoclass + ). + mo_object_oriented_object->generate_locals( + is_key = ls_clskey + iv_force = seox_true + it_local_definitions = lt_locals_def + it_local_implementations = lt_locals_imp + it_local_macros = lt_locals_mac + it_local_test_classes = lt_testclasses + ). mo_object_oriented_object->deserialize_source( is_key = ls_clskey @@ -1341,6 +1307,67 @@ CLASS lcl_object_clas IMPLEMENTATION. ENDCLASS. "lcl_object_CLAS IMPLEMENTATION +*----------------------------------------------------------------------* +* CLASS lcl_object_intf DEFINITION +*----------------------------------------------------------------------* +* +*----------------------------------------------------------------------* +CLASS lcl_object_intf DEFINITION INHERITING FROM lcl_object_clas FINAL. +* todo, CLAS + INTF to be refactored, see: +* https://github.com/larshp/abapGit/issues/21 + PUBLIC SECTION. + METHODS: + lif_object~deserialize REDEFINITION. + PROTECTED SECTION. + METHODS: + deserialize_abap REDEFINITION. +ENDCLASS. "lcl_object_intf DEFINITION +CLASS lcl_object_intf IMPLEMENTATION. + METHOD lif_object~deserialize. + mo_object_oriented_object = lcl_object_oriented_factory=>make( iv_object_type = ms_item-obj_type ). + + deserialize_abap( io_xml = io_xml + iv_package = iv_package ). + + deserialize_docu( io_xml ). + ENDMETHOD. + METHOD deserialize_abap. + DATA: ls_vseointerf TYPE vseointerf, + lt_source TYPE seop_source_string, + lt_descriptions TYPE ty_seocompotx_tt, + ls_clskey TYPE seoclskey. + ls_clskey-clsname = ms_item-obj_name. + + lt_source = mo_files->read_abap( ). + + io_xml->read( EXPORTING iv_name = 'VSEOINTERF' + CHANGING cg_data = ls_vseointerf ). + + mo_object_oriented_object->create( + EXPORTING + iv_package = iv_package + CHANGING + is_properties = ls_vseointerf + ). + + mo_object_oriented_object->deserialize_source( + is_key = ls_clskey + it_source = lt_source + ). + + io_xml->read( EXPORTING iv_name = 'DESCRIPTIONS' + CHANGING cg_data = lt_descriptions ). + + mo_object_oriented_object->update_descriptions( + is_key = ls_clskey + it_descriptions = lt_descriptions + ). + + mo_object_oriented_object->add_to_activation_list( is_item = ms_item ). + ENDMETHOD. +ENDCLASS. + + CLASS ltd_spy_oo_object DEFINITION FOR TESTING. PUBLIC SECTION. INTERFACES: lif_object_oriented_object. @@ -1490,14 +1517,14 @@ CLASS ltc_oo_test DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT . IMPORTING it_descriptions TYPE ty_seocompotx_tt, then_it_should_add_activation, - given_documentation_in_xml_as - IMPORTING - it_lines TYPE tlinetab - RAISING - lcx_exception, - then_docu_should_be_created - IMPORTING - it_lines TYPE tlinetab. + given_documentation_in_xml_as + IMPORTING + it_lines TYPE tlinetab + RAISING + lcx_exception, + then_docu_should_be_created + IMPORTING + it_lines TYPE tlinetab. ENDCLASS. CLASS ltc_oo_test IMPLEMENTATION. From eae228744923741d24c538e6d500b3f5631f2e3f Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Thu, 22 Dec 2016 16:40:22 +0100 Subject: [PATCH 8/9] Final cleanup --- src/zabapgit_object_clas.prog.abap | 261 +++++++++-------------------- 1 file changed, 83 insertions(+), 178 deletions(-) diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index 20525d7cc..49c2b8edf 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -181,7 +181,19 @@ CLASS lcl_object_oriented_base IMPLEMENTATION. ENDMETHOD. METHOD lif_object_oriented_object~create_documentation. - + CALL FUNCTION 'DOCU_UPD' + EXPORTING + id = 'CL' + langu = iv_language + object = iv_object_name + TABLES + line = it_lines + EXCEPTIONS + ret_code = 1 + OTHERS = 2. + IF sy-subrc <> 0. + lcx_exception=>raise( 'error from DOCU_UPD' ). + ENDIF. ENDMETHOD. ENDCLASS. @@ -418,17 +430,6 @@ CLASS lcl_object_clas DEFINITION INHERITING FROM lcl_objects_program. RETURNING VALUE(rt_source) TYPE ty_string_tt RAISING lcx_exception. - METHODS deserialize_abap_source_old - IMPORTING is_clskey TYPE seoclskey - it_source TYPE ty_string_tt - RAISING lcx_exception. - - METHODS deserialize_abap_source_new - IMPORTING is_clskey TYPE seoclskey - it_source TYPE ty_string_tt - RAISING lcx_exception - cx_sy_dyn_call_error. - METHODS serialize_abap_new IMPORTING is_clskey TYPE seoclskey RETURNING VALUE(rt_source) TYPE ty_string_tt @@ -1129,8 +1130,7 @@ CLASS lcl_object_clas IMPLEMENTATION. mo_object_oriented_object->create_sotr( iv_package = iv_package - it_sotr = lt_sotr - ). + it_sotr = lt_sotr ). ENDMETHOD. METHOD deserialize_docu. @@ -1174,37 +1174,36 @@ CLASS lcl_object_clas IMPLEMENTATION. mo_object_oriented_object->insert_text_pool( iv_class_name = lv_clsname it_text_pool = lt_tpool - iv_language = mv_language - ). + iv_language = mv_language ). ENDMETHOD. "deserialize_textpool METHOD deserialize_abap. - DATA: ls_vseoclass TYPE vseoclass, - lt_source TYPE seop_source_string, - lt_locals_def TYPE seop_source_string, - lt_locals_imp TYPE seop_source_string, - lt_locals_mac TYPE seop_source_string, - lt_testclasses TYPE seop_source_string, - lt_descriptions TYPE ty_seocompotx_tt, - ls_clskey TYPE seoclskey. + DATA: ls_vseoclass TYPE vseoclass, + lt_source TYPE seop_source_string, + lt_local_definitions TYPE seop_source_string, + lt_local_implementations TYPE seop_source_string, + lt_local_macros TYPE seop_source_string, + lt_test_classes TYPE seop_source_string, + lt_descriptions TYPE ty_seocompotx_tt, + ls_class_key TYPE seoclskey. lt_source = mo_files->read_abap( ). - lt_locals_def = mo_files->read_abap( iv_extra = 'locals_def' - iv_error = abap_false ). "#EC NOTEXT + lt_local_definitions = mo_files->read_abap( iv_extra = 'locals_def' + iv_error = abap_false ). "#EC NOTEXT - lt_locals_imp = mo_files->read_abap( iv_extra = 'locals_imp' - iv_error = abap_false ). "#EC NOTEXT + lt_local_implementations = mo_files->read_abap( iv_extra = 'locals_imp' + iv_error = abap_false ). "#EC NOTEXT - lt_locals_mac = mo_files->read_abap( iv_extra = 'macros' - iv_error = abap_false ). "#EC NOTEXT + lt_local_macros = mo_files->read_abap( iv_extra = 'macros' + iv_error = abap_false ). "#EC NOTEXT - lt_testclasses = mo_files->read_abap( iv_extra = 'testclasses' - iv_error = abap_false ). "#EC NOTEXT + lt_test_classes = mo_files->read_abap( iv_extra = 'testclasses' + iv_error = abap_false ). "#EC NOTEXT - ls_clskey-clsname = ms_item-obj_name. + ls_class_key-clsname = ms_item-obj_name. io_xml->read( EXPORTING iv_name = 'VSEOCLASS' CHANGING cg_data = ls_vseoclass ). @@ -1213,94 +1212,29 @@ CLASS lcl_object_clas IMPLEMENTATION. EXPORTING iv_package = iv_package CHANGING - is_properties = ls_vseoclass - ). + is_properties = ls_vseoclass ). mo_object_oriented_object->generate_locals( - is_key = ls_clskey + is_key = ls_class_key iv_force = seox_true - it_local_definitions = lt_locals_def - it_local_implementations = lt_locals_imp - it_local_macros = lt_locals_mac - it_local_test_classes = lt_testclasses - ). + it_local_definitions = lt_local_definitions + it_local_implementations = lt_local_implementations + it_local_macros = lt_local_macros + it_local_test_classes = lt_test_classes ). mo_object_oriented_object->deserialize_source( - is_key = ls_clskey - it_source = lt_source - ). + is_key = ls_class_key + it_source = lt_source ). io_xml->read( EXPORTING iv_name = 'DESCRIPTIONS' CHANGING cg_data = lt_descriptions ). mo_object_oriented_object->update_descriptions( - is_key = ls_clskey - it_descriptions = lt_descriptions - ). + is_key = ls_class_key + it_descriptions = lt_descriptions ). mo_object_oriented_object->add_to_activation_list( is_item = ms_item ). ENDMETHOD. "deserialize - METHOD deserialize_abap_source_old. -* for backwards compatability down to 702 - - DATA: lo_source TYPE REF TO cl_oo_source. - - - CREATE OBJECT lo_source - EXPORTING - clskey = is_clskey - EXCEPTIONS - class_not_existing = 1 - OTHERS = 2. - IF sy-subrc <> 0. - lcx_exception=>raise( 'error from CL_OO_SOURCE' ). - ENDIF. - - TRY. - lo_source->access_permission( seok_access_modify ). - lo_source->set_source( it_source ). - lo_source->save( ). - lo_source->access_permission( seok_access_free ). - CATCH cx_oo_access_permission. - lcx_exception=>raise( 'permission error' ). - CATCH cx_oo_source_save_failure. - lcx_exception=>raise( 'save failure' ). - ENDTRY. - - ENDMETHOD. - - METHOD deserialize_abap_source_new. - - DATA: lo_factory TYPE REF TO object, - lo_source TYPE REF TO object. - - - CALL METHOD ('CL_OO_FACTORY')=>('CREATE_INSTANCE') - RECEIVING - result = lo_factory. - - CALL METHOD lo_factory->('CREATE_CLIF_SOURCE') - EXPORTING - clif_name = is_clskey-clsname - RECEIVING - result = lo_source. - - TRY. - CALL METHOD lo_source->('IF_OO_CLIF_SOURCE~LOCK'). - CATCH cx_oo_access_permission. - lcx_exception=>raise( 'source_new, access permission exception' ). - ENDTRY. - - CALL METHOD lo_source->('IF_OO_CLIF_SOURCE~SET_SOURCE') - EXPORTING - source = it_source. - - CALL METHOD lo_source->('IF_OO_CLIF_SOURCE~SAVE'). - - CALL METHOD lo_source->('IF_OO_CLIF_SOURCE~UNLOCK'). - - ENDMETHOD. - METHOD lif_object~compare_to_remote_version. CREATE OBJECT ro_comparison_result TYPE lcl_null_comparison_result. ENDMETHOD. @@ -1347,23 +1281,20 @@ CLASS lcl_object_intf IMPLEMENTATION. EXPORTING iv_package = iv_package CHANGING - is_properties = ls_vseointerf - ). + is_properties = ls_vseointerf ). mo_object_oriented_object->deserialize_source( is_key = ls_clskey - it_source = lt_source - ). + it_source = lt_source ). io_xml->read( EXPORTING iv_name = 'DESCRIPTIONS' CHANGING cg_data = lt_descriptions ). mo_object_oriented_object->update_descriptions( is_key = ls_clskey - it_descriptions = lt_descriptions - ). + it_descriptions = lt_descriptions ). - mo_object_oriented_object->add_to_activation_list( is_item = ms_item ). + mo_object_oriented_object->add_to_activation_list( is_item = ms_item ). ENDMETHOD. ENDCLASS. @@ -1399,7 +1330,9 @@ CLASS ltd_spy_oo_object DEFINITION FOR TESTING. ENDCLASS. CLASS ltd_spy_oo_object IMPLEMENTATION. METHOD lif_object_oriented_object~create. - IF cl_abap_typedescr=>describe_by_data( is_properties )->absolute_name = cl_abap_typedescr=>describe_by_data( ms_interface_properties )->absolute_name. + DATA lv_properties_structure_name TYPE string. + lv_properties_structure_name = cl_abap_typedescr=>describe_by_data( is_properties )->absolute_name. + IF lv_properties_structure_name = cl_abap_typedescr=>describe_by_data( ms_interface_properties )->absolute_name. ms_interface_properties = is_properties. ELSE. ms_class_properties = is_properties. @@ -1436,8 +1369,7 @@ CLASS ltd_spy_oo_object IMPLEMENTATION. mt_text_pool = it_text_pool. cl_abap_unit_assert=>assert_equals( act = iv_language - exp = sy-langu - ). + exp = sy-langu ). ENDMETHOD. METHOD lif_object_oriented_object~create_sotr. @@ -1532,63 +1464,53 @@ CLASS ltc_oo_test IMPLEMENTATION. METHOD then_docu_should_be_created. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_docu_lines - exp = it_lines - ). + exp = it_lines ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mv_docu_object_name - exp = ms_item-obj_name - ). + exp = ms_item-obj_name ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mv_docu_language - exp = sy-langu - ). + exp = sy-langu ). ENDMETHOD. METHOD given_documentation_in_xml_as. mo_xml_out->add( iv_name = 'LINES' - ig_data = it_lines - ). + ig_data = it_lines ). ENDMETHOD. METHOD then_it_should_add_activation. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_item_to_activate - exp = ms_item - ). + exp = ms_item ). ENDMETHOD. METHOD then_shuld_update_descriptions. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_descriptions - exp = it_descriptions - ). + exp = it_descriptions ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_description_key - exp = ms_item-obj_name - ). + exp = ms_item-obj_name ). ENDMETHOD. METHOD given_the_descriptions. mo_xml_out->add( iv_name = 'DESCRIPTIONS' - ig_data = it_descriptions - ). + ig_data = it_descriptions ). ENDMETHOD. METHOD then_should_deserialize_source. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_source - exp = mo_fake_object_files->mt_sources - ). + exp = mo_fake_object_files->mt_sources ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_deserialize_key - exp = ms_item-obj_name - ). + exp = ms_item-obj_name ). ENDMETHOD. METHOD when_deserializing. @@ -1597,8 +1519,7 @@ CLASS ltc_oo_test IMPLEMENTATION. iv_xml = mo_xml_out->render( ). mo_oo_object->deserialize( iv_package = 'package_name' - io_xml = mo_xml_input - ). + io_xml = mo_xml_input ). ENDMETHOD. ENDCLASS. @@ -1697,51 +1618,43 @@ CLASS ltc_class_deserialization IMPLEMENTATION. METHOD given_a_class_properties. mo_xml_out->add( iv_name = 'VSEOCLASS' - ig_data = ms_class_properties - ). + ig_data = ms_class_properties ). ENDMETHOD. METHOD then_should_create_class. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_class_properties - exp = ms_class_properties - ). + exp = ms_class_properties ). cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mv_package - exp = 'package_name' - ). + exp = 'package_name' ). ENDMETHOD. METHOD then_it_should_generate_locals. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_locals_key - exp = ms_item-obj_name - ). + exp = ms_item-obj_name ). cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_force ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_local_definitions - exp = mo_fake_object_files->mt_local_definitions - ). + exp = mo_fake_object_files->mt_local_definitions ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_local_implementations - exp = mo_fake_object_files->mt_local_implementations - ). + exp = mo_fake_object_files->mt_local_implementations ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_local_macros - exp = mo_fake_object_files->mt_local_macros - ). + exp = mo_fake_object_files->mt_local_macros ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_local_test_classes - exp = mo_fake_object_files->mt_local_test_classes - ). + exp = mo_fake_object_files->mt_local_test_classes ). ENDMETHOD. METHOD no_text_pool_no_insert. given_a_class_properties( ). @@ -1752,29 +1665,27 @@ CLASS ltc_class_deserialization IMPLEMENTATION. ENDMETHOD. METHOD insert_text_pool. - given_a_class_properties( ). - - DATA lt_pool_external TYPE textpool_table. - DATA ls_pool_external TYPE ty_tpool. + DATA: lt_pool_external TYPE textpool_table, + ls_pool_external TYPE ty_tpool. ls_pool_external-id = 'ID'. ls_pool_external-key = 'KEY'. APPEND ls_pool_external TO lt_pool_external. + + given_a_class_properties( ). + mo_xml_out->add( iv_name = 'TPOOL' - ig_data = lt_pool_external - ). + ig_data = lt_pool_external ). when_deserializing( ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_text_pool - exp = lt_pool_external - ). + exp = lt_pool_external ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mv_text_pool_class_name - exp = 'zcl_class' - ). + exp = 'zcl_class' ). ENDMETHOD. METHOD create_stor_from_xml. @@ -1788,19 +1699,16 @@ CLASS ltc_class_deserialization IMPLEMENTATION. APPEND ls_sotr TO lt_sotr. mo_xml_out->add( iv_name = 'SOTR' - ig_data = lt_sotr - ). + ig_data = lt_sotr ). when_deserializing( ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_sotr - exp = lt_sotr - ). + exp = lt_sotr ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mt_sotr_package - exp = 'package_name' - ). + exp = 'package_name' ). ENDMETHOD. METHOD create_documentation. @@ -1899,22 +1807,19 @@ CLASS ltc_interface_deserialization IMPLEMENTATION. METHOD given_an_interface_properties. mo_xml_out->add( iv_name = 'VSEOINTERF' - ig_data = ms_interface_properties - ). + ig_data = ms_interface_properties ). ENDMETHOD. METHOD then_should_create_interface. cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->ms_interface_properties - exp = ms_interface_properties - ). + exp = ms_interface_properties ). cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). cl_abap_unit_assert=>assert_equals( act = mo_spy_oo_object->mv_package - exp = 'package_name' - ). + exp = 'package_name' ). ENDMETHOD. METHOD create_documentation. From 8384bd8994215ed3bc0b7969da9b9d36220fe35f Mon Sep 17 00:00:00 2001 From: eduardocopat Date: Fri, 23 Dec 2016 11:19:03 +0100 Subject: [PATCH 9/9] code review --- src/zabapgit_object_clas.prog.abap | 541 ----------------------------- src/zabapgit_unit_test.prog.abap | 540 ++++++++++++++++++++++++++++ 2 files changed, 540 insertions(+), 541 deletions(-) diff --git a/src/zabapgit_object_clas.prog.abap b/src/zabapgit_object_clas.prog.abap index 49c2b8edf..f2f27ef32 100644 --- a/src/zabapgit_object_clas.prog.abap +++ b/src/zabapgit_object_clas.prog.abap @@ -1296,545 +1296,4 @@ CLASS lcl_object_intf IMPLEMENTATION. mo_object_oriented_object->add_to_activation_list( is_item = ms_item ). ENDMETHOD. -ENDCLASS. - - -CLASS ltd_spy_oo_object DEFINITION FOR TESTING. - PUBLIC SECTION. - INTERFACES: lif_object_oriented_object. - DATA: - mv_package TYPE devclass, - mv_overwrite TYPE seox_boolean, - ms_interface_properties TYPE vseointerf, - ms_class_properties TYPE vseoclass, - ms_locals_key TYPE seoclskey, - mt_local_definitions TYPE rswsourcet, - mt_local_implementations TYPE rswsourcet, - mt_local_macros TYPE rswsourcet, - mt_local_test_classes TYPE rswsourcet, - mv_force TYPE seoflag, - ms_deserialize_key TYPE seoclskey, - mt_source TYPE ty_string_tt, - ms_item_to_activate TYPE ty_item, - mt_descriptions TYPE ty_seocompotx_tt, - ms_description_key TYPE seoclskey, - mv_text_pool_class_name TYPE seoclsname, - mt_text_pool TYPE textpool_table, - mv_text_pool_inserted TYPE abap_bool, - mt_sotr TYPE ty_sotr_tt, - mt_sotr_package TYPE devclass, - mv_docu_object_name TYPE dokhl-object, - mv_docu_language TYPE spras, - mt_docu_lines TYPE tlinetab. - -ENDCLASS. -CLASS ltd_spy_oo_object IMPLEMENTATION. - METHOD lif_object_oriented_object~create. - DATA lv_properties_structure_name TYPE string. - lv_properties_structure_name = cl_abap_typedescr=>describe_by_data( is_properties )->absolute_name. - IF lv_properties_structure_name = cl_abap_typedescr=>describe_by_data( ms_interface_properties )->absolute_name. - ms_interface_properties = is_properties. - ELSE. - ms_class_properties = is_properties. - ENDIF. - mv_package = iv_package. - mv_overwrite = iv_overwrite. - ENDMETHOD. - METHOD lif_object_oriented_object~generate_locals. - ms_locals_key = is_key. - mt_local_definitions = it_local_definitions. - mt_local_implementations = it_local_implementations. - mt_local_macros = it_local_macros. - mt_local_test_classes = it_local_test_classes. - mv_force = iv_force. - ENDMETHOD. - - METHOD lif_object_oriented_object~deserialize_source. - ms_deserialize_key = is_key. - mt_source = it_source. - ENDMETHOD. - - METHOD lif_object_oriented_object~add_to_activation_list. - ms_item_to_activate = is_item. - ENDMETHOD. - - METHOD lif_object_oriented_object~update_descriptions. - ms_description_key = is_key. - mt_descriptions = it_descriptions. - ENDMETHOD. - - METHOD lif_object_oriented_object~insert_text_pool. - mv_text_pool_inserted = abap_true. - mv_text_pool_class_name = iv_class_name. - mt_text_pool = it_text_pool. - cl_abap_unit_assert=>assert_equals( - act = iv_language - exp = sy-langu ). - ENDMETHOD. - - METHOD lif_object_oriented_object~create_sotr. - mt_sotr = it_sotr. - mt_sotr_package = iv_package. - ENDMETHOD. - - METHOD lif_object_oriented_object~create_documentation. - mv_docu_object_name = iv_object_name. - mv_docu_language = iv_language. - mt_docu_lines = it_lines. - ENDMETHOD. - -ENDCLASS. - -CLASS ltd_fake_object_files DEFINITION FOR TESTING - INHERITING FROM lcl_objects_files. - PUBLIC SECTION. - METHODS constructor. - METHODS read_abap REDEFINITION. - DATA: - mt_sources TYPE seop_source_string, - mt_local_definitions TYPE seop_source_string, - mt_local_implementations TYPE seop_source_string, - mt_local_macros TYPE seop_source_string, - mt_local_test_classes TYPE seop_source_string. -ENDCLASS. -CLASS ltd_fake_object_files IMPLEMENTATION. - METHOD read_abap. - CASE iv_extra. - WHEN 'locals_def'. - rt_abap = mt_local_definitions. - WHEN 'locals_imp'. - rt_abap = mt_local_implementations. - WHEN 'macros'. - rt_abap = mt_local_macros. - WHEN 'testclasses'. - rt_abap = mt_local_test_classes. - WHEN OTHERS. - rt_abap = mt_sources. - RETURN. - ENDCASE. - - cl_abap_unit_assert=>assert_false( iv_error ). - ENDMETHOD. - METHOD constructor. - DATA ls_empty_item TYPE ty_item. - super->constructor( ls_empty_item ). - APPEND 'source' TO me->mt_sources. - APPEND 'definition' TO me->mt_local_definitions. - APPEND 'implementation' TO me->mt_local_implementations. - APPEND 'macro' TO me->mt_local_macros. - APPEND 'test' TO me->mt_local_test_classes. - ENDMETHOD. - -ENDCLASS. - -CLASS ltc_oo_test DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT . - PROTECTED SECTION. - DATA: - mo_spy_oo_object TYPE REF TO ltd_spy_oo_object, - mo_fake_object_files TYPE REF TO ltd_fake_object_files, - mo_xml_input TYPE REF TO lcl_xml_input, - mo_xml_out TYPE REF TO lcl_xml_output, - mo_oo_object TYPE REF TO lif_object, - ms_item TYPE ty_item. - METHODS: when_deserializing - RAISING - lcx_exception, - then_should_deserialize_source, - given_the_descriptions - IMPORTING - it_descriptions TYPE ty_seocompotx_tt - RAISING - lcx_exception, - then_shuld_update_descriptions - IMPORTING - it_descriptions TYPE ty_seocompotx_tt, - then_it_should_add_activation, - given_documentation_in_xml_as - IMPORTING - it_lines TYPE tlinetab - RAISING - lcx_exception, - then_docu_should_be_created - IMPORTING - it_lines TYPE tlinetab. - -ENDCLASS. -CLASS ltc_oo_test IMPLEMENTATION. - - METHOD then_docu_should_be_created. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_docu_lines - exp = it_lines ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mv_docu_object_name - exp = ms_item-obj_name ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mv_docu_language - exp = sy-langu ). - ENDMETHOD. - - METHOD given_documentation_in_xml_as. - mo_xml_out->add( - iv_name = 'LINES' - ig_data = it_lines ). - ENDMETHOD. - - METHOD then_it_should_add_activation. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_item_to_activate - exp = ms_item ). - ENDMETHOD. - - METHOD then_shuld_update_descriptions. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_descriptions - exp = it_descriptions ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_description_key - exp = ms_item-obj_name ). - ENDMETHOD. - - METHOD given_the_descriptions. - mo_xml_out->add( - iv_name = 'DESCRIPTIONS' - ig_data = it_descriptions ). - ENDMETHOD. - - METHOD then_should_deserialize_source. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_source - exp = mo_fake_object_files->mt_sources ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_deserialize_key - exp = ms_item-obj_name ). - ENDMETHOD. - - METHOD when_deserializing. - CREATE OBJECT mo_xml_input - EXPORTING - iv_xml = mo_xml_out->render( ). - mo_oo_object->deserialize( - iv_package = 'package_name' - io_xml = mo_xml_input ). - ENDMETHOD. -ENDCLASS. - -CLASS ltc_class_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT -INHERITING FROM ltc_oo_test. - PRIVATE SECTION. - METHODS: - setup, - given_a_class_properties - RAISING - lcx_exception, - then_should_create_class, - then_it_should_generate_locals, - should_create_class FOR TESTING RAISING cx_static_check, - should_generate_locals FOR TESTING RAISING cx_static_check, - should_deserialize_source FOR TESTING RAISING cx_static_check, - should_update_descriptions FOR TESTING RAISING cx_static_check, - should_add_to_activation FOR TESTING RAISING cx_static_check, - no_text_pool_no_insert FOR TESTING RAISING cx_static_check, - insert_text_pool FOR TESTING RAISING cx_static_check, - create_stor_from_xml FOR TESTING RAISING cx_static_check, - create_documentation FOR TESTING RAISING cx_static_check. - DATA: - ms_class_properties TYPE vseoclass. -ENDCLASS. - -CLASS ltc_class_deserialization IMPLEMENTATION. - METHOD setup. - CREATE OBJECT mo_fake_object_files. - CREATE OBJECT mo_spy_oo_object. - CREATE OBJECT mo_xml_out. - lth_oo_factory_injector=>inject( mo_spy_oo_object ). - - ms_item-devclass = 'package_name'. - ms_item-obj_name = 'zcl_class'. - ms_item-obj_type = 'CLAS'. - - CREATE OBJECT mo_oo_object TYPE lcl_object_clas - EXPORTING - is_item = ms_item - iv_language = sy-langu. - mo_oo_object->mo_files = mo_fake_object_files. - ENDMETHOD. - - METHOD should_create_class. - ms_class_properties-clsname = ms_item-obj_name. - - given_a_class_properties( ). - - when_deserializing( ). - - then_should_create_class( ). - ENDMETHOD. - - METHOD should_generate_locals. - given_a_class_properties( ). - - when_deserializing( ). - - then_it_should_generate_locals( ). - ENDMETHOD. - - METHOD should_deserialize_source. - given_a_class_properties( ). - - when_deserializing( ). - - then_should_deserialize_source( ). - ENDMETHOD. - - METHOD should_update_descriptions. - DATA: - ls_description TYPE seocompotx, - lt_descriptions TYPE ty_seocompotx_tt. - - given_a_class_properties( ). - - ls_description-clsname = ms_item-obj_name. - ls_description-cmpname = 'a_method'. - APPEND ls_description TO lt_descriptions. - given_the_descriptions( lt_descriptions ). - - when_deserializing( ). - - then_shuld_update_descriptions( lt_descriptions ). - ENDMETHOD. - - METHOD should_add_to_activation. - given_a_class_properties( ). - - when_deserializing( ). - - then_it_should_add_activation( ). - ENDMETHOD. - - METHOD given_a_class_properties. - mo_xml_out->add( - iv_name = 'VSEOCLASS' - ig_data = ms_class_properties ). - ENDMETHOD. - - METHOD then_should_create_class. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_class_properties - exp = ms_class_properties ). - - cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mv_package - exp = 'package_name' ). - ENDMETHOD. - - - METHOD then_it_should_generate_locals. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_locals_key - exp = ms_item-obj_name ). - cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_force ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_local_definitions - exp = mo_fake_object_files->mt_local_definitions ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_local_implementations - exp = mo_fake_object_files->mt_local_implementations ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_local_macros - exp = mo_fake_object_files->mt_local_macros ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_local_test_classes - exp = mo_fake_object_files->mt_local_test_classes ). - ENDMETHOD. - METHOD no_text_pool_no_insert. - given_a_class_properties( ). - - when_deserializing( ). - - cl_abap_unit_assert=>assert_false( mo_spy_oo_object->mv_text_pool_inserted ). - ENDMETHOD. - - METHOD insert_text_pool. - DATA: lt_pool_external TYPE textpool_table, - ls_pool_external TYPE ty_tpool. - ls_pool_external-id = 'ID'. - ls_pool_external-key = 'KEY'. - APPEND ls_pool_external TO lt_pool_external. - - given_a_class_properties( ). - - mo_xml_out->add( - iv_name = 'TPOOL' - ig_data = lt_pool_external ). - - when_deserializing( ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_text_pool - exp = lt_pool_external ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mv_text_pool_class_name - exp = 'zcl_class' ). - ENDMETHOD. - - METHOD create_stor_from_xml. - DATA: - lt_sotr TYPE ty_sotr_tt, - ls_sotr LIKE LINE OF lt_sotr. - - given_a_class_properties( ). - - ls_sotr-header-concept = 'HEADER'. - APPEND ls_sotr TO lt_sotr. - mo_xml_out->add( - iv_name = 'SOTR' - ig_data = lt_sotr ). - - when_deserializing( ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_sotr - exp = lt_sotr ). - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mt_sotr_package - exp = 'package_name' ). - ENDMETHOD. - - METHOD create_documentation. - DATA: lt_lines TYPE tlinetab, - ls_line TYPE LINE OF tlinetab. - ls_line-tdline = 'Class Line Doc'. - APPEND ls_line TO lt_lines. - - given_a_class_properties( ). - - given_documentation_in_xml_as( lt_lines ). - - when_deserializing( ). - - then_docu_should_be_created( lt_lines ). - ENDMETHOD. -ENDCLASS. - -CLASS ltc_interface_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT -INHERITING FROM ltc_oo_test. - PRIVATE SECTION. - METHODS: - setup, - given_an_interface_properties - RAISING - lcx_exception, - then_should_create_interface, - create_interface FOR TESTING RAISING cx_static_check, - update_descriptions FOR TESTING RAISING cx_static_check, - add_to_activation FOR TESTING RAISING cx_static_check, - deserialize_source FOR TESTING RAISING cx_static_check, - create_documentation FOR TESTING RAISING cx_static_check. - DATA: - ms_interface_properties TYPE vseointerf. -ENDCLASS. -CLASS ltc_interface_deserialization IMPLEMENTATION. - METHOD setup. - CREATE OBJECT mo_fake_object_files. - CREATE OBJECT mo_spy_oo_object. - CREATE OBJECT mo_xml_out. - lth_oo_factory_injector=>inject( mo_spy_oo_object ). - - ms_item-devclass = 'package_name'. - ms_item-obj_name = 'zif_interface'. - ms_item-obj_type = 'INTF'. - - CREATE OBJECT mo_oo_object TYPE lcl_object_intf - EXPORTING - is_item = ms_item - iv_language = sy-langu. - mo_oo_object->mo_files = mo_fake_object_files. - ENDMETHOD. - - METHOD create_interface. - ms_interface_properties-clsname = ms_item-obj_name. - given_an_interface_properties( ). - - when_deserializing( ). - - then_should_create_interface( ). - ENDMETHOD. - - METHOD update_descriptions. - DATA: - ls_description TYPE seocompotx, - lt_descriptions TYPE ty_seocompotx_tt. - - given_an_interface_properties( ). - - ls_description-clsname = ms_item-obj_name. - ls_description-cmpname = 'a_method'. - APPEND ls_description TO lt_descriptions. - given_the_descriptions( lt_descriptions ). - - when_deserializing( ). - - then_shuld_update_descriptions( lt_descriptions ). - ENDMETHOD. - - METHOD add_to_activation. - given_an_interface_properties( ). - - when_deserializing( ). - - then_it_should_add_activation( ). - ENDMETHOD. - - METHOD deserialize_source. - given_an_interface_properties( ). - - when_deserializing( ). - - then_should_deserialize_source( ). - ENDMETHOD. - - METHOD given_an_interface_properties. - mo_xml_out->add( - iv_name = 'VSEOINTERF' - ig_data = ms_interface_properties ). - ENDMETHOD. - - METHOD then_should_create_interface. - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->ms_interface_properties - exp = ms_interface_properties ). - - cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). - - cl_abap_unit_assert=>assert_equals( - act = mo_spy_oo_object->mv_package - exp = 'package_name' ). - ENDMETHOD. - - METHOD create_documentation. - DATA: lt_lines TYPE tlinetab, - ls_line TYPE LINE OF tlinetab. - ls_line-tdline = 'Interface Line Doc'. - APPEND ls_line TO lt_lines. - - given_an_interface_properties( ). - - given_documentation_in_xml_as( lt_lines ). - - when_deserializing( ). - - then_docu_should_be_created( lt_lines ). - ENDMETHOD. - ENDCLASS. \ No newline at end of file diff --git a/src/zabapgit_unit_test.prog.abap b/src/zabapgit_unit_test.prog.abap index dd6c4a514..40318dec2 100644 --- a/src/zabapgit_unit_test.prog.abap +++ b/src/zabapgit_unit_test.prog.abap @@ -2205,4 +2205,544 @@ CLASS ltcl_persistence_settings IMPLEMENTATION. ENDMETHOD. +ENDCLASS. + + +CLASS ltd_spy_oo_object DEFINITION FOR TESTING. + PUBLIC SECTION. + INTERFACES: lif_object_oriented_object. + DATA: + mv_package TYPE devclass, + mv_overwrite TYPE seox_boolean, + ms_interface_properties TYPE vseointerf, + ms_class_properties TYPE vseoclass, + ms_locals_key TYPE seoclskey, + mt_local_definitions TYPE rswsourcet, + mt_local_implementations TYPE rswsourcet, + mt_local_macros TYPE rswsourcet, + mt_local_test_classes TYPE rswsourcet, + mv_force TYPE seoflag, + ms_deserialize_key TYPE seoclskey, + mt_source TYPE ty_string_tt, + ms_item_to_activate TYPE ty_item, + mt_descriptions TYPE ty_seocompotx_tt, + ms_description_key TYPE seoclskey, + mv_text_pool_class_name TYPE seoclsname, + mt_text_pool TYPE textpool_table, + mv_text_pool_inserted TYPE abap_bool, + mt_sotr TYPE ty_sotr_tt, + mt_sotr_package TYPE devclass, + mv_docu_object_name TYPE dokhl-object, + mv_docu_language TYPE spras, + mt_docu_lines TYPE tlinetab. + +ENDCLASS. +CLASS ltd_spy_oo_object IMPLEMENTATION. + METHOD lif_object_oriented_object~create. + DATA lv_properties_structure_name TYPE string. + lv_properties_structure_name = cl_abap_typedescr=>describe_by_data( is_properties )->absolute_name. + IF lv_properties_structure_name = cl_abap_typedescr=>describe_by_data( ms_interface_properties )->absolute_name. + ms_interface_properties = is_properties. + ELSE. + ms_class_properties = is_properties. + ENDIF. + mv_package = iv_package. + mv_overwrite = iv_overwrite. + ENDMETHOD. + METHOD lif_object_oriented_object~generate_locals. + ms_locals_key = is_key. + mt_local_definitions = it_local_definitions. + mt_local_implementations = it_local_implementations. + mt_local_macros = it_local_macros. + mt_local_test_classes = it_local_test_classes. + mv_force = iv_force. + ENDMETHOD. + + METHOD lif_object_oriented_object~deserialize_source. + ms_deserialize_key = is_key. + mt_source = it_source. + ENDMETHOD. + + METHOD lif_object_oriented_object~add_to_activation_list. + ms_item_to_activate = is_item. + ENDMETHOD. + + METHOD lif_object_oriented_object~update_descriptions. + ms_description_key = is_key. + mt_descriptions = it_descriptions. + ENDMETHOD. + + METHOD lif_object_oriented_object~insert_text_pool. + mv_text_pool_inserted = abap_true. + mv_text_pool_class_name = iv_class_name. + mt_text_pool = it_text_pool. + cl_abap_unit_assert=>assert_equals( + act = iv_language + exp = sy-langu ). + ENDMETHOD. + + METHOD lif_object_oriented_object~create_sotr. + mt_sotr = it_sotr. + mt_sotr_package = iv_package. + ENDMETHOD. + + METHOD lif_object_oriented_object~create_documentation. + mv_docu_object_name = iv_object_name. + mv_docu_language = iv_language. + mt_docu_lines = it_lines. + ENDMETHOD. + +ENDCLASS. + +CLASS ltd_fake_object_files DEFINITION FOR TESTING + INHERITING FROM lcl_objects_files. + PUBLIC SECTION. + METHODS constructor. + METHODS read_abap REDEFINITION. + DATA: + mt_sources TYPE seop_source_string, + mt_local_definitions TYPE seop_source_string, + mt_local_implementations TYPE seop_source_string, + mt_local_macros TYPE seop_source_string, + mt_local_test_classes TYPE seop_source_string. +ENDCLASS. +CLASS ltd_fake_object_files IMPLEMENTATION. + METHOD read_abap. + CASE iv_extra. + WHEN 'locals_def'. + rt_abap = mt_local_definitions. + WHEN 'locals_imp'. + rt_abap = mt_local_implementations. + WHEN 'macros'. + rt_abap = mt_local_macros. + WHEN 'testclasses'. + rt_abap = mt_local_test_classes. + WHEN OTHERS. + rt_abap = mt_sources. + RETURN. + ENDCASE. + + cl_abap_unit_assert=>assert_false( iv_error ). + ENDMETHOD. + METHOD constructor. + DATA ls_empty_item TYPE ty_item. + super->constructor( ls_empty_item ). + APPEND 'source' TO me->mt_sources. + APPEND 'definition' TO me->mt_local_definitions. + APPEND 'implementation' TO me->mt_local_implementations. + APPEND 'macro' TO me->mt_local_macros. + APPEND 'test' TO me->mt_local_test_classes. + ENDMETHOD. + +ENDCLASS. + +CLASS ltc_oo_test DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT . + PROTECTED SECTION. + DATA: + mo_spy_oo_object TYPE REF TO ltd_spy_oo_object, + mo_fake_object_files TYPE REF TO ltd_fake_object_files, + mo_xml_input TYPE REF TO lcl_xml_input, + mo_xml_out TYPE REF TO lcl_xml_output, + mo_oo_object TYPE REF TO lif_object, + ms_item TYPE ty_item. + METHODS: when_deserializing + RAISING + lcx_exception, + then_should_deserialize_source, + given_the_descriptions + IMPORTING + it_descriptions TYPE ty_seocompotx_tt + RAISING + lcx_exception, + then_shuld_update_descriptions + IMPORTING + it_descriptions TYPE ty_seocompotx_tt, + then_it_should_add_activation, + given_documentation_in_xml_as + IMPORTING + it_lines TYPE tlinetab + RAISING + lcx_exception, + then_docu_should_be_created + IMPORTING + it_lines TYPE tlinetab. + +ENDCLASS. +CLASS ltc_oo_test IMPLEMENTATION. + + METHOD then_docu_should_be_created. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_docu_lines + exp = it_lines ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_docu_object_name + exp = ms_item-obj_name ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_docu_language + exp = sy-langu ). + ENDMETHOD. + + METHOD given_documentation_in_xml_as. + mo_xml_out->add( + iv_name = 'LINES' + ig_data = it_lines ). + ENDMETHOD. + + METHOD then_it_should_add_activation. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_item_to_activate + exp = ms_item ). + ENDMETHOD. + + METHOD then_shuld_update_descriptions. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_descriptions + exp = it_descriptions ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_description_key + exp = ms_item-obj_name ). + ENDMETHOD. + + METHOD given_the_descriptions. + mo_xml_out->add( + iv_name = 'DESCRIPTIONS' + ig_data = it_descriptions ). + ENDMETHOD. + + METHOD then_should_deserialize_source. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_source + exp = mo_fake_object_files->mt_sources ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_deserialize_key + exp = ms_item-obj_name ). + ENDMETHOD. + + METHOD when_deserializing. + CREATE OBJECT mo_xml_input + EXPORTING + iv_xml = mo_xml_out->render( ). + mo_oo_object->deserialize( + iv_package = 'package_name' + io_xml = mo_xml_input ). + ENDMETHOD. +ENDCLASS. + +CLASS ltcl_class_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT +INHERITING FROM ltc_oo_test. + PRIVATE SECTION. + METHODS: + setup, + given_a_class_properties + RAISING + lcx_exception, + then_should_create_class, + then_it_should_generate_locals, + should_create_class FOR TESTING RAISING cx_static_check, + should_generate_locals FOR TESTING RAISING cx_static_check, + should_deserialize_source FOR TESTING RAISING cx_static_check, + should_update_descriptions FOR TESTING RAISING cx_static_check, + should_add_to_activation FOR TESTING RAISING cx_static_check, + no_text_pool_no_insert FOR TESTING RAISING cx_static_check, + insert_text_pool FOR TESTING RAISING cx_static_check, + create_stor_from_xml FOR TESTING RAISING cx_static_check, + create_documentation FOR TESTING RAISING cx_static_check. + DATA: + ms_class_properties TYPE vseoclass. +ENDCLASS. + +CLASS ltcl_class_deserialization IMPLEMENTATION. + METHOD setup. + CREATE OBJECT mo_fake_object_files. + CREATE OBJECT mo_spy_oo_object. + CREATE OBJECT mo_xml_out. + lth_oo_factory_injector=>inject( mo_spy_oo_object ). + + ms_item-devclass = 'package_name'. + ms_item-obj_name = 'zcl_class'. + ms_item-obj_type = 'CLAS'. + + CREATE OBJECT mo_oo_object TYPE lcl_object_clas + EXPORTING + is_item = ms_item + iv_language = sy-langu. + mo_oo_object->mo_files = mo_fake_object_files. + ENDMETHOD. + + METHOD should_create_class. + ms_class_properties-clsname = ms_item-obj_name. + + given_a_class_properties( ). + + when_deserializing( ). + + then_should_create_class( ). + ENDMETHOD. + + METHOD should_generate_locals. + given_a_class_properties( ). + + when_deserializing( ). + + then_it_should_generate_locals( ). + ENDMETHOD. + + METHOD should_deserialize_source. + given_a_class_properties( ). + + when_deserializing( ). + + then_should_deserialize_source( ). + ENDMETHOD. + + METHOD should_update_descriptions. + DATA: + ls_description TYPE seocompotx, + lt_descriptions TYPE ty_seocompotx_tt. + + given_a_class_properties( ). + + ls_description-clsname = ms_item-obj_name. + ls_description-cmpname = 'a_method'. + APPEND ls_description TO lt_descriptions. + given_the_descriptions( lt_descriptions ). + + when_deserializing( ). + + then_shuld_update_descriptions( lt_descriptions ). + ENDMETHOD. + + METHOD should_add_to_activation. + given_a_class_properties( ). + + when_deserializing( ). + + then_it_should_add_activation( ). + ENDMETHOD. + + METHOD given_a_class_properties. + mo_xml_out->add( + iv_name = 'VSEOCLASS' + ig_data = ms_class_properties ). + ENDMETHOD. + + METHOD then_should_create_class. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_class_properties + exp = ms_class_properties ). + + cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_package + exp = 'package_name' ). + ENDMETHOD. + + + METHOD then_it_should_generate_locals. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_locals_key + exp = ms_item-obj_name ). + cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_force ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_local_definitions + exp = mo_fake_object_files->mt_local_definitions ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_local_implementations + exp = mo_fake_object_files->mt_local_implementations ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_local_macros + exp = mo_fake_object_files->mt_local_macros ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_local_test_classes + exp = mo_fake_object_files->mt_local_test_classes ). + ENDMETHOD. + METHOD no_text_pool_no_insert. + given_a_class_properties( ). + + when_deserializing( ). + + cl_abap_unit_assert=>assert_false( mo_spy_oo_object->mv_text_pool_inserted ). + ENDMETHOD. + + METHOD insert_text_pool. + DATA: lt_pool_external TYPE textpool_table, + ls_pool_external TYPE ty_tpool. + ls_pool_external-id = 'ID'. + ls_pool_external-key = 'KEY'. + APPEND ls_pool_external TO lt_pool_external. + + given_a_class_properties( ). + + mo_xml_out->add( + iv_name = 'TPOOL' + ig_data = lt_pool_external ). + + when_deserializing( ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_text_pool + exp = lt_pool_external ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_text_pool_class_name + exp = 'zcl_class' ). + ENDMETHOD. + + METHOD create_stor_from_xml. + DATA: + lt_sotr TYPE ty_sotr_tt, + ls_sotr LIKE LINE OF lt_sotr. + + given_a_class_properties( ). + + ls_sotr-header-concept = 'HEADER'. + APPEND ls_sotr TO lt_sotr. + mo_xml_out->add( + iv_name = 'SOTR' + ig_data = lt_sotr ). + + when_deserializing( ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_sotr + exp = lt_sotr ). + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mt_sotr_package + exp = 'package_name' ). + ENDMETHOD. + + METHOD create_documentation. + DATA: lt_lines TYPE tlinetab, + ls_line TYPE LINE OF tlinetab. + ls_line-tdline = 'Class Line Doc'. + APPEND ls_line TO lt_lines. + + given_a_class_properties( ). + + given_documentation_in_xml_as( lt_lines ). + + when_deserializing( ). + + then_docu_should_be_created( lt_lines ). + ENDMETHOD. +ENDCLASS. + +CLASS ltcl_interface_deserialization DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT +INHERITING FROM ltc_oo_test. + PRIVATE SECTION. + METHODS: + setup, + given_an_interface_properties + RAISING + lcx_exception, + then_should_create_interface, + create_interface FOR TESTING RAISING cx_static_check, + update_descriptions FOR TESTING RAISING cx_static_check, + add_to_activation FOR TESTING RAISING cx_static_check, + deserialize_source FOR TESTING RAISING cx_static_check, + create_documentation FOR TESTING RAISING cx_static_check. + DATA: + ms_interface_properties TYPE vseointerf. +ENDCLASS. +CLASS ltcl_interface_deserialization IMPLEMENTATION. + METHOD setup. + CREATE OBJECT mo_fake_object_files. + CREATE OBJECT mo_spy_oo_object. + CREATE OBJECT mo_xml_out. + lth_oo_factory_injector=>inject( mo_spy_oo_object ). + + ms_item-devclass = 'package_name'. + ms_item-obj_name = 'zif_interface'. + ms_item-obj_type = 'INTF'. + + CREATE OBJECT mo_oo_object TYPE lcl_object_intf + EXPORTING + is_item = ms_item + iv_language = sy-langu. + mo_oo_object->mo_files = mo_fake_object_files. + ENDMETHOD. + + METHOD create_interface. + ms_interface_properties-clsname = ms_item-obj_name. + given_an_interface_properties( ). + + when_deserializing( ). + + then_should_create_interface( ). + ENDMETHOD. + + METHOD update_descriptions. + DATA: + ls_description TYPE seocompotx, + lt_descriptions TYPE ty_seocompotx_tt. + + given_an_interface_properties( ). + + ls_description-clsname = ms_item-obj_name. + ls_description-cmpname = 'a_method'. + APPEND ls_description TO lt_descriptions. + given_the_descriptions( lt_descriptions ). + + when_deserializing( ). + + then_shuld_update_descriptions( lt_descriptions ). + ENDMETHOD. + + METHOD add_to_activation. + given_an_interface_properties( ). + + when_deserializing( ). + + then_it_should_add_activation( ). + ENDMETHOD. + + METHOD deserialize_source. + given_an_interface_properties( ). + + when_deserializing( ). + + then_should_deserialize_source( ). + ENDMETHOD. + + METHOD given_an_interface_properties. + mo_xml_out->add( + iv_name = 'VSEOINTERF' + ig_data = ms_interface_properties ). + ENDMETHOD. + + METHOD then_should_create_interface. + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->ms_interface_properties + exp = ms_interface_properties ). + + cl_abap_unit_assert=>assert_true( mo_spy_oo_object->mv_overwrite ). + + cl_abap_unit_assert=>assert_equals( + act = mo_spy_oo_object->mv_package + exp = 'package_name' ). + ENDMETHOD. + + METHOD create_documentation. + DATA: lt_lines TYPE tlinetab, + ls_line TYPE LINE OF tlinetab. + ls_line-tdline = 'Interface Line Doc'. + APPEND ls_line TO lt_lines. + + given_an_interface_properties( ). + + given_documentation_in_xml_as( lt_lines ). + + when_deserializing( ). + + then_docu_should_be_created( lt_lines ). + ENDMETHOD. ENDCLASS. \ No newline at end of file