All files / src/objects/rules zcl_abapgit_field_rules.clas.testclasses.abap

99.3% Statements 287/289
92.3% Branches 12/13
100% Functions 11/11
99.3% Lines 287/289

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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 2901x 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 9x 9x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 2x 2x 7x 7x 7x 7x 7x 7x 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_field_rules DEFINITION FOR TESTING RISK LEVEL HARMLESS
  DURATION SHORT FINAL.
 
  PRIVATE SECTION.
 
    CONSTANTS:
      c_package TYPE devclass VALUE '$TMP',
      c_table   TYPE tabname VALUE 'ZTEST'.
 
    TYPES:
      BEGIN OF ty_test,
        key  TYPE i,
        user TYPE sy-uname,
        date TYPE d,
        time TYPE t,
        ts   TYPE timestamp,
        tl   TYPE timestampl,
      END OF ty_test.
 
    DATA mo_cut TYPE REF TO zcl_abapgit_field_rules.
 
    METHODS:
      setup,
      fill_value
        IMPORTING
          iv_rule TYPE zif_abapgit_field_rules=>ty_fill_rule
          iv_exp  TYPE string
          iv_len  TYPE i OPTIONAL,
      fill1 FOR TESTING,
      fill2 FOR TESTING,
      fill3 FOR TESTING,
      fill4 FOR TESTING,
      fill5 FOR TESTING,
      fill6 FOR TESTING,
      fill7 FOR TESTING,
      get_rules
        RETURNING
          VALUE(ri_rules) TYPE REF TO zif_abapgit_field_rules,
      apply_clear_logic FOR TESTING,
      apply_fill_logic FOR TESTING,
      get_utc_timestamp
        RETURNING
          VALUE(rv_timestamp) TYPE timestamp.
 
ENDCLASS.
 
CLASS zcl_abapgit_field_rules DEFINITION LOCAL FRIENDS ltcl_field_rules.
 
CLASS ltcl_field_rules IMPLEMENTATION.
 
  METHOD setup.
    CREATE OBJECT mo_cut.
  ENDMETHOD.
 
  METHOD fill_value.
 
    DATA lv_act TYPE string.
 
    mo_cut->fill_value(
      EXPORTING
        iv_rule    = iv_rule
        iv_package = c_package
      CHANGING
        cv_value   = lv_act ).
 
    IF iv_len IS NOT INITIAL.
      lv_act = lv_act(iv_len).
    ENDIF.
 
    cl_abap_unit_assert=>assert_equals(
      act = lv_act
      exp = iv_exp ).
 
  ENDMETHOD.
 
  METHOD fill1.
    fill_value(
      iv_rule = zif_abapgit_field_rules=>c_fill_rule-date
      iv_exp  = |{ sy-datum }| ).
  ENDMETHOD.
 
  METHOD fill2.
    fill_value(
      iv_rule = zif_abapgit_field_rules=>c_fill_rule-time
      iv_len  = 2
      iv_exp  = |{ sy-uzeit(2) }| ). " avoid comparing minutes
  ENDMETHOD.
 
  METHOD fill3.
    DATA lv_timestamp TYPE timestamp.
    lv_timestamp = get_utc_timestamp( ).
    fill_value(
      iv_rule = zif_abapgit_field_rules=>c_fill_rule-timestamp
      iv_len  = 10
      iv_exp  = |{ lv_timestamp DIV 10000 }| ). " avoid comparing minutes
  ENDMETHOD.
 
  METHOD fill4.
    fill_value(
      iv_rule = zif_abapgit_field_rules=>c_fill_rule-user
      iv_exp  = |{ sy-uname }| ).
  ENDMETHOD.
 
  METHOD fill5.
    fill_value(
      iv_rule = zif_abapgit_field_rules=>c_fill_rule-client
      iv_exp  = |{ sy-mandt }| ).
  ENDMETHOD.
 
  METHOD fill6.
    fill_value(
      iv_rule = zif_abapgit_field_rules=>c_fill_rule-package
      iv_exp  = |{ c_package }| ).
  ENDMETHOD.
 
  METHOD fill7.
    fill_value(
      iv_rule = 'XY'
      iv_exp  = '' ).
  ENDMETHOD.
 
  METHOD get_rules.
 
    ri_rules = zcl_abapgit_field_rules=>create( )->add(
      iv_table     = c_table
      iv_field     = 'USER'
      iv_fill_rule = zif_abapgit_field_rules=>c_fill_rule-user
    )->add(
      iv_table     = c_table
      iv_field     = 'DATE'
      iv_fill_rule = zif_abapgit_field_rules=>c_fill_rule-date
    )->add(
      iv_table     = c_table
      iv_field     = 'TIME'
      iv_fill_rule = zif_abapgit_field_rules=>c_fill_rule-time
    )->add(
      iv_table     = c_table
      iv_field     = 'TS'
      iv_fill_rule = zif_abapgit_field_rules=>c_fill_rule-timestamp
    )->add(
      iv_table     = c_table
      iv_field     = 'TL'
      iv_fill_rule = zif_abapgit_field_rules=>c_fill_rule-timestamp ).
 
  ENDMETHOD.
 
  METHOD apply_clear_logic.
 
    DATA:
      li_rules TYPE REF TO zif_abapgit_field_rules,
      ls_act   TYPE ty_test,
      lt_act   TYPE STANDARD TABLE OF ty_test.
 
    ls_act-key  = 1.
    ls_act-user = 'MARC'.
    ls_act-date = '19720101'.
    ls_act-time = '123456'.
    ls_act-ts   = '19720101123456'.
    ls_act-tl   = '19720101123456.123456'.
    INSERT ls_act INTO TABLE lt_act.
    ls_act-key  = 2.
    ls_act-user = 'FRANK'.
    ls_act-date = '20230101'.
    ls_act-time = '000001'.
    INSERT ls_act INTO TABLE lt_act.
 
    li_rules = get_rules( ).
 
    li_rules->apply_clear_logic(
      EXPORTING
        iv_table = c_table
      CHANGING
        ct_data  = lt_act ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lines( lt_act )
      exp = 2 ).
 
    READ TABLE lt_act INTO ls_act INDEX 1.
 
    cl_abap_unit_assert=>assert_not_initial( ls_act-key ).
    cl_abap_unit_assert=>assert_initial( ls_act-user ).
    cl_abap_unit_assert=>assert_initial( ls_act-date ).
    cl_abap_unit_assert=>assert_initial( ls_act-time ).
    cl_abap_unit_assert=>assert_initial( ls_act-ts ).
    cl_abap_unit_assert=>assert_initial( ls_act-tl ).
 
    READ TABLE lt_act INTO ls_act INDEX 2.
 
    cl_abap_unit_assert=>assert_not_initial( ls_act-key ).
    cl_abap_unit_assert=>assert_initial( ls_act-user ).
    cl_abap_unit_assert=>assert_initial( ls_act-date ).
    cl_abap_unit_assert=>assert_initial( ls_act-time ).
    cl_abap_unit_assert=>assert_initial( ls_act-ts ).
    cl_abap_unit_assert=>assert_initial( ls_act-tl ).
 
  ENDMETHOD.
 
  METHOD apply_fill_logic.
 
    DATA:
      li_rules     TYPE REF TO zif_abapgit_field_rules,
      ls_act       TYPE ty_test,
      lt_act       TYPE STANDARD TABLE OF ty_test,
      lv_ts        TYPE string,
      lv_timestamp TYPE timestamp.
 
    ls_act-key  = 1.
    INSERT ls_act INTO TABLE lt_act.
    ls_act-key  = 2.
    ls_act-user = 'XYZ'.
    ls_act-date = ''.
    ls_act-time = '123456'.
    INSERT ls_act INTO TABLE lt_act.
 
    li_rules = get_rules( ).
 
    li_rules->apply_fill_logic(
      EXPORTING
        iv_table   = c_table
        iv_package = c_package
      CHANGING
        ct_data    = lt_act ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lines( lt_act )
      exp = 2 ).
 
    READ TABLE lt_act INTO ls_act INDEX 1.
 
    cl_abap_unit_assert=>assert_equals(
      act = ls_act-key
      exp = 1 ).
    cl_abap_unit_assert=>assert_equals(
      act = ls_act-user
      exp = sy-uname ).
    cl_abap_unit_assert=>assert_equals(
      act = ls_act-date
      exp = sy-datum ).
    cl_abap_unit_assert=>assert_equals(
      act = ls_act-time(4)
      exp = sy-uzeit(4) ). " avoid comparing seconds
 
    lv_timestamp = get_utc_timestamp( ).
    lv_ts = ls_act-ts.
    lv_ts = lv_ts(12).
    cl_abap_unit_assert=>assert_equals(
      act = lv_ts
      exp = |{ lv_timestamp DIV 100 }| ). " avoid comparing second
    lv_ts = ls_act-tl.
    lv_ts = lv_ts(12).
    cl_abap_unit_assert=>assert_equals(
      act = lv_ts
      exp = |{ lv_timestamp DIV 100 }| ). " avoid comparing seconds
 
    READ TABLE lt_act INTO ls_act INDEX 2.
 
    cl_abap_unit_assert=>assert_equals(
      act = ls_act-key
      exp = 2 ).
    cl_abap_unit_assert=>assert_equals(
      act = ls_act-user
      exp = sy-uname ).
    cl_abap_unit_assert=>assert_equals(
      act = ls_act-date
      exp = sy-datum ).
    cl_abap_unit_assert=>assert_equals(
      act = ls_act-time(4)
      exp = sy-uzeit(4) ). " avoid comparing seconds
 
  ENDMETHOD.
 
  METHOD get_utc_timestamp.
    DATA lv_syst_timezone TYPE timezone.
    CALL FUNCTION 'GET_SYSTEM_TIMEZONE'
      IMPORTING
        timezone            = lv_syst_timezone
      EXCEPTIONS
        customizing_missing = 1
        OTHERS              = 2.
    IF sy-subrc <> 0.
      cl_abap_unit_assert=>fail( 'Could not get system timezone' ).
    ENDIF.
 
    CONVERT DATE sy-datum TIME sy-uzeit
      INTO TIME STAMP rv_timestamp
      TIME ZONE lv_syst_timezone.
  ENDMETHOD.
ENDCLASS.