All files / src/objects zcl_abapgit_objects.clas.testclasses.abap

45.21% Statements 236/522
100% Branches 0/0
0% Functions 0/29
45.21% Lines 236/522

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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 5231x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                             1x 1x                                                     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                     1x 1x                     1x 1x                     1x 1x                     1x 1x                     1x 1x                   1x 1x 1x                                                                               1x 1x                     1x 1x                     1x 1x                     1x 1x                     1x 1x                     1x 1x                     1x 1x                     1x 1x                         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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_object_types DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL.
 
  PRIVATE SECTION.
    METHODS:
      type_supported FOR TESTING RAISING zcx_abapgit_exception,
      not_exist FOR TESTING RAISING zcx_abapgit_exception.
 
ENDCLASS.
 
CLASS ltcl_object_types IMPLEMENTATION.
 
  METHOD type_supported.

    cl_abap_unit_assert=>assert_equals(
      act  = zcl_abapgit_objects=>is_type_supported( 'PROG' )
      exp  = abap_true ).

    cl_abap_unit_assert=>assert_equals(
      act  = zcl_abapgit_objects=>is_type_supported( 'ZXYZ' )
      exp  = abap_false ).

    cl_abap_unit_assert=>assert_equals(
      act  = zcl_abapgit_objects=>is_type_supported( '' )
      exp  = abap_false ).

  ENDMETHOD.
 
  METHOD not_exist.

    DATA: ls_item   TYPE zif_abapgit_definitions=>ty_item,
          lv_exists TYPE abap_bool,
          lt_types  TYPE zcl_abapgit_objects=>ty_types_tt.

    FIELD-SYMBOLS: <lv_type> LIKE LINE OF lt_types.


    lt_types = zcl_abapgit_objects=>supported_list( ).

    cl_abap_unit_assert=>assert_not_initial( lt_types ).

    LOOP AT lt_types ASSIGNING <lv_type>.
      CLEAR ls_item.
      ls_item-obj_name = 'ZABAPGIT_FOOBAR'.
      ls_item-obj_type = <lv_type>.
      lv_exists = zcl_abapgit_objects=>exists( ls_item ).

      cl_abap_unit_assert=>assert_equals(
        act  = lv_exists
        exp  = abap_false
        msg  = ls_item-obj_type
        quit = if_aunit_constants=>no ).
    ENDLOOP.

  ENDMETHOD.
 
ENDCLASS.
 
 
CLASS lcl_settings_with_features DEFINITION.
  PUBLIC SECTION.
    INTERFACES zif_abapgit_persist_settings.
    METHODS: constructor
      IMPORTING iv_features TYPE string.
  PRIVATE SECTION.
    DATA mv_features TYPE string.
ENDCLASS.
 
CLASS lcl_settings_with_features IMPLEMENTATION.
 
  METHOD zif_abapgit_persist_settings~modify.
    RETURN.
  ENDMETHOD.
 
  METHOD zif_abapgit_persist_settings~read.
 
    CREATE OBJECT ro_settings.
    ro_settings->set_experimental_features( mv_features ).
 
  ENDMETHOD.
 
  METHOD constructor.
    mv_features = iv_features.
  ENDMETHOD.
 
ENDCLASS.
 
 
*----------------------------------------------------------------------*
*       CLASS ltcl_serialize DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS ltcl_serialize DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL.
 
  PRIVATE SECTION.
 
    METHODS:
      check
        IMPORTING is_item TYPE zif_abapgit_definitions=>ty_item
        RAISING   zcx_abapgit_exception,
      serialize_tabl FOR TESTING RAISING zcx_abapgit_exception,
      serialize_shlp FOR TESTING RAISING zcx_abapgit_exception,
      serialize_view FOR TESTING RAISING zcx_abapgit_exception,
      serialize_auth FOR TESTING RAISING zcx_abapgit_exception,
      serialize_clas FOR TESTING RAISING zcx_abapgit_exception,
      serialize_intf FOR TESTING RAISING zcx_abapgit_exception,
      serialize_doma FOR TESTING RAISING zcx_abapgit_exception,
      serialize_dtel FOR TESTING RAISING zcx_abapgit_exception,
      serialize_fugr FOR TESTING RAISING zcx_abapgit_exception,
      serialize_msag FOR TESTING RAISING zcx_abapgit_exception,
      serialize_prog FOR TESTING RAISING zcx_abapgit_exception,
      serialize_tran FOR TESTING RAISING zcx_abapgit_exception,
      serialize_ttyp FOR TESTING RAISING zcx_abapgit_exception,
      serialize_intf_aff_translate FOR TESTING RAISING cx_static_check.
 
ENDCLASS.
 
*----------------------------------------------------------------------*
*       CLASS ltcl_serialize IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS ltcl_serialize IMPLEMENTATION.
 
  METHOD serialize_shlp.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'SHLP'.
    ls_item-obj_name = 'USER_LOGON'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_view.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'VIEW'.
    ls_item-obj_name = 'VUSR02_HEADER'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_tabl.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'TABL'.
    ls_item-obj_name = 'USR02'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_auth.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'AUTH'.
    ls_item-obj_name = 'AREA'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_clas.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'CLAS'.
    ls_item-obj_name = 'CL_GUI_FRONTEND_SERVICES'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_intf.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.

    ls_item-obj_type = 'INTF'.
    ls_item-obj_name = 'IF_BADI_TADIR_CHANGED'.

    check( ls_item ).

  ENDMETHOD.
 
 
  METHOD serialize_intf_aff_translate.

    DATA: ls_item           TYPE zif_abapgit_definitions=>ty_item,
          lo_settings       TYPE REF TO lcl_settings_with_features,
          ls_act            TYPE zif_abapgit_objects=>ty_serialization,
          ls_translation_de TYPE zif_abapgit_git_definitions=>ty_file,
          lt_target_langu   TYPE zif_abapgit_definitions=>ty_languages,
          lo_i18n_params    TYPE REF TO zcl_abapgit_i18n_params,
          lv_features       TYPE string,
          lv_filename       TYPE string.

    ls_item-obj_type = 'INTF'.
    ls_item-obj_name = 'IF_BADI_TADIR_CHANGED'.

    lv_features = |{ zcl_abapgit_aff_registry=>c_aff_feature }, { zcl_abapgit_properties_file=>c_properties_feature }|.
    CREATE OBJECT lo_settings
      EXPORTING
        iv_features = lv_features.

    zcl_abapgit_persist_injector=>set_settings( lo_settings ).

    APPEND `DE` TO lt_target_langu.
    lo_i18n_params = zcl_abapgit_i18n_params=>new( iv_main_language     = zif_abapgit_definitions=>c_english
                                                   it_translation_langs = lt_target_langu
                                                   iv_use_lxe           = abap_true ).
    ls_act = zcl_abapgit_objects=>serialize(
      is_item        = ls_item
      io_i18n_params = lo_i18n_params ).

    cl_abap_unit_assert=>assert_not_initial( ls_act-files ).
    cl_abap_unit_assert=>assert_equals( act = ls_act-item
                                        exp = ls_item ).


    lv_filename = 'if_badi_tadir_changed.intf.i18n.de.properties'.
    READ TABLE ls_act-files WITH KEY file COMPONENTS filename = lv_filename INTO ls_translation_de.

    cl_abap_unit_assert=>assert_not_initial( ls_translation_de ).

  ENDMETHOD.
 
  METHOD serialize_doma.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'DOMA'.
    ls_item-obj_name = 'PGMID'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_dtel.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'DTEL'.
    ls_item-obj_name = 'PGMID'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_fugr.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'FUGR'.
    ls_item-obj_name = 'SRFC'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_msag.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'MSAG'.
    ls_item-obj_name = '00'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_prog.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'PROG'.
    ls_item-obj_name = 'SAPLWBABAP'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_tran.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'TRAN'.
    ls_item-obj_name = 'SE38'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD serialize_ttyp.

    DATA: ls_item  TYPE zif_abapgit_definitions=>ty_item.


    ls_item-obj_type = 'TTYP'.
    ls_item-obj_name = 'ABAPPROG'.

    check( ls_item ).

  ENDMETHOD.
 
  METHOD check.

    DATA: ls_files_item TYPE zif_abapgit_objects=>ty_serialization.

    ls_files_item = zcl_abapgit_objects=>serialize(
      is_item        = is_item
      io_i18n_params = zcl_abapgit_i18n_params=>new( iv_main_language = zif_abapgit_definitions=>c_english ) ).

    cl_abap_unit_assert=>assert_not_initial( ls_files_item-files ).
    cl_abap_unit_assert=>assert_equals( act = ls_files_item-item
                                        exp = is_item ).

  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltcl_object_tabl_mock DEFINITION INHERITING FROM zcl_abapgit_objects_super FOR TESTING.
 
  PUBLIC SECTION.
    INTERFACES zif_abapgit_object.
 
ENDCLASS.
 
CLASS ltcl_object_tabl_mock IMPLEMENTATION.
 
  METHOD zif_abapgit_object~is_locked.
 
    CASE ms_item-obj_name.
      WHEN 'Z_TEST_TABL'.
 
        rv_is_locked = abap_true.
 
      WHEN 'Z_TEST_TABL_2'.
 
        rv_is_locked = abap_false.
 
    ENDCASE.
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~get_deserialize_steps. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~get_deserialize_order. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~changed_by. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~get_comparator. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~delete. "##needed

  ENDMETHOD.
 
  METHOD zif_abapgit_object~deserialize. "##needed

  ENDMETHOD.
 
  METHOD zif_abapgit_object~exists. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~get_metadata. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~jump. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~serialize. "##needed

  ENDMETHOD.
 
  METHOD zif_abapgit_object~is_active. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~map_filename_to_object. "##needed
 
  ENDMETHOD.
 
  METHOD zif_abapgit_object~map_object_to_filename. "##needed
 
  ENDMETHOD.
 
ENDCLASS.
 
CLASS ltcl_check_objects_locked DEFINITION FINAL FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.
 
  PRIVATE SECTION.
    DATA:
      mt_given_items    TYPE zif_abapgit_definitions=>ty_items_tt,
      mv_exception_text TYPE string.
 
    METHODS:
      throw_excp_if_object_is_locked FOR TESTING RAISING cx_static_check,
      no_excp_if_obj_is_not_locked FOR TESTING RAISING cx_static_check,
      given_locked_object,
      when_check_objects_locked,
      then_exception_shd_be_raised,
      given_not_locked_object,
      then_no_exception_shd_occur,
      given_object
        IMPORTING
          iv_object_name TYPE string.
 
ENDCLASS.
 
CLASS zcl_abapgit_objects DEFINITION LOCAL FRIENDS ltcl_check_objects_locked.
 
CLASS ltcl_check_objects_locked IMPLEMENTATION.
 
  METHOD throw_excp_if_object_is_locked.

    given_locked_object( ).
    when_check_objects_locked( ).
    then_exception_shd_be_raised( ).

  ENDMETHOD.
 
  METHOD no_excp_if_obj_is_not_locked.

    given_not_locked_object( ).
    when_check_objects_locked( ).
    then_no_exception_shd_occur( ).

  ENDMETHOD.
 
  METHOD given_locked_object.

    given_object( 'Z_TEST_TABL' ).

  ENDMETHOD.
 
 
  METHOD when_check_objects_locked.

    DATA: lx_error TYPE REF TO zcx_abapgit_exception.

    TRY.
        zcl_abapgit_objects=>check_objects_locked( mt_given_items ).
      CATCH zcx_abapgit_exception INTO lx_error.
        mv_exception_text = lx_error->get_text( ).
    ENDTRY.

  ENDMETHOD.
 
 
  METHOD then_exception_shd_be_raised.

    cl_abap_unit_assert=>assert_equals(
      exp = |Object TABL Z_TEST_TABL is locked. Action not possible.|
      act = mv_exception_text ).

  ENDMETHOD.
 
 
  METHOD given_not_locked_object.

    given_object( 'Z_TEST_TABL_2' ).

  ENDMETHOD.
 
 
  METHOD then_no_exception_shd_occur.

    cl_abap_unit_assert=>assert_initial( mv_exception_text ).

  ENDMETHOD.
 
 
  METHOD given_object.

    CONSTANTS:
      lc_obj_type TYPE string VALUE 'TABL'.

    DATA:
      ls_item               LIKE LINE OF mt_given_items,
      ls_obj_serializer_map LIKE LINE OF zcl_abapgit_objects=>gt_obj_serializer_map.

    ls_item-obj_type = lc_obj_type.
    ls_item-obj_name = iv_object_name.
    INSERT ls_item INTO TABLE mt_given_items.

    ls_obj_serializer_map-item-obj_type = lc_obj_type.
    ls_obj_serializer_map-item-obj_name = iv_object_name.
    ls_obj_serializer_map-metadata-class = '\CLASS-POOL=ZCL_ABAPGIT_OBJECTS\CLASS=LTCL_OBJECT_TABL_MOCK'.
    INSERT ls_obj_serializer_map INTO TABLE zcl_abapgit_objects=>gt_obj_serializer_map.

  ENDMETHOD.
 
ENDCLASS.