All files / src/data zcl_abapgit_data_deserializer.clas.testclasses.abap

100% Statements 231/231
100% Branches 4/4
100% Functions 4/4
100% Lines 231/231

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 2321x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS ltcl_test DEFINITION DEFERRED.
CLASS zcl_abapgit_data_deserializer DEFINITION LOCAL FRIENDS ltcl_test.
 
CLASS ltcl_test DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS FINAL.
 
  PRIVATE SECTION.
    METHODS test1 FOR TESTING RAISING cx_static_check.
    METHODS preview_database_changes_ins FOR TESTING RAISING cx_static_check.
    METHODS preview_database_changes_upd FOR TESTING RAISING cx_static_check.
    METHODS preview_database_changes_del FOR TESTING RAISING cx_static_check.
 
ENDCLASS.
 
 
CLASS ltcl_test IMPLEMENTATION.
 
  METHOD test1.
 
    DATA li_cut TYPE REF TO zif_abapgit_data_deserializer.
    DATA li_config TYPE REF TO zif_abapgit_data_config.
    DATA lt_files TYPE zif_abapgit_git_definitions=>ty_files_tt.
    DATA ls_config TYPE zif_abapgit_data_config=>ty_config.
 
    CREATE OBJECT li_cut TYPE zcl_abapgit_data_deserializer.
    CREATE OBJECT li_config TYPE zcl_abapgit_data_config.
 
    ls_config-type = zif_abapgit_data_config=>c_data_type-tabu.
    ls_config-name = 'T100'.
 
    li_config->add_config( ls_config ).
 
    " this does not change the database. it just gives a preview of changes
    li_cut->deserialize(
      ii_config = li_config
      it_files  = lt_files ).
 
  ENDMETHOD.
 
 
  METHOD preview_database_changes_ins.
 
    CONSTANTS: lc_msgnr TYPE c LENGTH 3 VALUE '999'.
 
    DATA: li_cut     TYPE REF TO zcl_abapgit_data_deserializer,
          ls_config  TYPE zif_abapgit_data_config=>ty_config,
          lr_db_data TYPE REF TO data,
          lr_lc_data TYPE REF TO data,
          ls_t100    TYPE t100,
          ls_result  TYPE zif_abapgit_data_deserializer=>ty_result.
 
    FIELD-SYMBOLS: <lt_db_data> TYPE ANY TABLE,
                   <lt_lc_data> TYPE ANY TABLE,
                   <lg_ins>     TYPE ANY TABLE,
                   <ls_ins>     TYPE t100,
                   <lg_upd>     TYPE ANY TABLE,
                   <lg_del>     TYPE ANY TABLE.
 
    ls_config-type = zif_abapgit_data_config=>c_data_type-tabu.
    ls_config-name = 'T100'.
 
    lr_db_data = zcl_abapgit_data_utils=>build_table_itab( ls_config-name ).
    ASSIGN lr_db_data->* TO <lt_db_data>.
    lr_lc_data = zcl_abapgit_data_utils=>build_table_itab( ls_config-name ).
    ASSIGN lr_lc_data->* TO <lt_lc_data>.
 
    " Create test data for INSERT
    ls_t100-sprsl = sy-langu.
    ls_t100-arbgb = 'AUNIT_ABAPGIT'.
    ls_t100-msgnr = lc_msgnr.
    ls_t100-text  = |abapGit aunit test|.
    INSERT ls_t100 INTO TABLE <lt_lc_data>.
 
    CREATE OBJECT li_cut TYPE zcl_abapgit_data_deserializer.
    ls_result = li_cut->preview_database_changes(
      iv_name    = ls_config-name
      ir_db_data = lr_db_data
      ir_lc_data = lr_lc_data ).
 
    ASSIGN ls_result-inserts->* TO <lg_ins>.
    ASSIGN ls_result-updates->* TO <lg_upd>.
    ASSIGN ls_result-deletes->* TO <lg_del>.
 
    cl_abap_unit_assert=>assert_equals(
      exp = 1
      act = lines( <lg_ins> ) ).
    cl_abap_unit_assert=>assert_equals(
      exp = 0
      act = lines( <lg_upd> ) ).
    cl_abap_unit_assert=>assert_equals(
      exp = 0
      act = lines( <lg_del> ) ).
 
    LOOP AT <lg_ins> ASSIGNING <ls_ins>.
      cl_abap_unit_assert=>assert_equals(
        exp = lc_msgnr
        act = <ls_ins>-msgnr ).
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD preview_database_changes_upd.
 
    CONSTANTS: lc_msgnr TYPE c LENGTH 3 VALUE '999'.
 
    DATA: li_cut     TYPE REF TO zcl_abapgit_data_deserializer,
          ls_config  TYPE zif_abapgit_data_config=>ty_config,
          lr_db_data TYPE REF TO data,
          lr_lc_data TYPE REF TO data,
          ls_t100    TYPE t100,
          ls_result  TYPE zif_abapgit_data_deserializer=>ty_result.
 
    FIELD-SYMBOLS: <lt_db_data> TYPE ANY TABLE,
                   <lt_lc_data> TYPE ANY TABLE,
                   <lg_ins>     TYPE ANY TABLE,
                   <lg_upd>     TYPE ANY TABLE,
                   <ls_upd>     TYPE t100,
                   <lg_del>     TYPE ANY TABLE.
 
    ls_config-type = zif_abapgit_data_config=>c_data_type-tabu.
    ls_config-name = 'T100'.
 
    lr_db_data = zcl_abapgit_data_utils=>build_table_itab( ls_config-name ).
    ASSIGN lr_db_data->* TO <lt_db_data>.
    lr_lc_data = zcl_abapgit_data_utils=>build_table_itab( ls_config-name ).
    ASSIGN lr_lc_data->* TO <lt_lc_data>.
 
    " Create test data for UPDATE
    ls_t100-sprsl = sy-langu.
    ls_t100-arbgb = |AUNIT_ABAPGIT|.
    ls_t100-msgnr = lc_msgnr.
    ls_t100-text  = |abapGit aunit test|.
    INSERT ls_t100 INTO TABLE <lt_db_data>.
 
    ls_t100-sprsl = sy-langu.
    ls_t100-arbgb = 'AUNIT_ABAPGIT'.
    ls_t100-msgnr = lc_msgnr.
    ls_t100-text  = |abapGit aunit test UPDATE|.
    INSERT ls_t100 INTO TABLE <lt_lc_data>.
 
    CREATE OBJECT li_cut TYPE zcl_abapgit_data_deserializer.
    ls_result = li_cut->preview_database_changes(
      iv_name    = ls_config-name
      ir_db_data = lr_db_data
      ir_lc_data = lr_lc_data ).
 
    ASSIGN ls_result-inserts->* TO <lg_ins>.
    ASSIGN ls_result-updates->* TO <lg_upd>.
    ASSIGN ls_result-deletes->* TO <lg_del>.
 
    cl_abap_unit_assert=>assert_equals(
      exp = 0
      act = lines( <lg_ins> ) ).
    cl_abap_unit_assert=>assert_equals(
      exp = 1
      act = lines( <lg_upd> ) ).
    cl_abap_unit_assert=>assert_equals(
      exp = 0
      act = lines( <lg_del> ) ).
 
    LOOP AT <lg_upd> ASSIGNING <ls_upd>.
      cl_abap_unit_assert=>assert_equals(
        exp = lc_msgnr
        act = <ls_upd>-msgnr ).
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD preview_database_changes_del.
 
    CONSTANTS: lc_msgnr TYPE c LENGTH 3 VALUE '999'.
 
    DATA: li_cut     TYPE REF TO zcl_abapgit_data_deserializer,
          ls_config  TYPE zif_abapgit_data_config=>ty_config,
          lr_db_data TYPE REF TO data,
          lr_lc_data TYPE REF TO data,
          ls_t100    TYPE t100,
          ls_result  TYPE zif_abapgit_data_deserializer=>ty_result.
 
    FIELD-SYMBOLS: <lt_db_data> TYPE ANY TABLE,
                   <lt_lc_data> TYPE ANY TABLE,
                   <lg_ins>     TYPE ANY TABLE,
                   <lg_upd>     TYPE ANY TABLE,
                   <lg_del>     TYPE ANY TABLE,
                   <ls_del>     TYPE t100.
 
    ls_config-type = zif_abapgit_data_config=>c_data_type-tabu.
    ls_config-name = 'T100'.
 
    lr_db_data = zcl_abapgit_data_utils=>build_table_itab( ls_config-name ).
    ASSIGN lr_db_data->* TO <lt_db_data>.
    lr_lc_data = zcl_abapgit_data_utils=>build_table_itab( ls_config-name ).
    ASSIGN lr_lc_data->* TO <lt_lc_data>.
 
    " Create test data for DELETE
    ls_t100-sprsl = sy-langu.
    ls_t100-arbgb = 'AUNIT_ABAPGIT'.
    ls_t100-msgnr = lc_msgnr.
    ls_t100-text  = |abapGit aunit test DELETE|.
    INSERT ls_t100 INTO TABLE <lt_db_data>.
 
    CREATE OBJECT li_cut TYPE zcl_abapgit_data_deserializer.
    ls_result = li_cut->preview_database_changes(
      iv_name    = ls_config-name
      ir_db_data = lr_db_data
      ir_lc_data = lr_lc_data ).
 
    ASSIGN ls_result-inserts->* TO <lg_ins>.
    ASSIGN ls_result-updates->* TO <lg_upd>.
    ASSIGN ls_result-deletes->* TO <lg_del>.
 
    cl_abap_unit_assert=>assert_equals(
      exp = 0
      act = lines( <lg_ins> ) ).
    cl_abap_unit_assert=>assert_equals(
      exp = 0
      act = lines( <lg_upd> ) ).
    cl_abap_unit_assert=>assert_equals(
      exp = 1
      act = lines( <lg_del> ) ).
 
    LOOP AT <lg_del> ASSIGNING <ls_del>.
      cl_abap_unit_assert=>assert_equals(
        exp = lc_msgnr
        act = <ls_del>-msgnr ).
    ENDLOOP.
 
  ENDMETHOD.
 
ENDCLASS.