All files / src/env zcl_abapgit_abap_language_vers.clas.testclasses.abap

78.54% Statements 377/480
92.85% Branches 13/14
81.25% Functions 13/16
78.54% Lines 377/480

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 4811x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 30x 30x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 20x 20x 20x 20x 20x 20x 20x 1x 1x 30x 30x 1x 1x 4x 4x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x                                         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                                             1x 1x 1x                                                                                         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
* Helper to toggle (cloud) enviroment
CLASS lcl_environment DEFINITION.
 
  PUBLIC SECTION.
    INTERFACES zif_abapgit_environment.
 
    DATA mv_is_cloud TYPE abap_bool.
 
    METHODS set_cloud
      IMPORTING
        iv_is_cloud TYPE abap_bool.
 
ENDCLASS.
 
CLASS lcl_environment IMPLEMENTATION.
 
  METHOD set_cloud.
    mv_is_cloud = iv_is_cloud.
  ENDMETHOD.
 
  METHOD zif_abapgit_environment~is_sap_cloud_platform.
    rv_result = mv_is_cloud.
  ENDMETHOD.
 
  METHOD zif_abapgit_environment~compare_with_inactive.
  ENDMETHOD.
  METHOD zif_abapgit_environment~get_basis_release.
  ENDMETHOD.
  METHOD zif_abapgit_environment~get_system_language_filter.
  ENDMETHOD.
  METHOD zif_abapgit_environment~is_merged.
  ENDMETHOD.
  METHOD zif_abapgit_environment~is_repo_object_changes_allowed.
  ENDMETHOD.
  METHOD zif_abapgit_environment~is_restart_required.
  ENDMETHOD.
  METHOD zif_abapgit_environment~is_sap_object_allowed.
  ENDMETHOD.
  METHOD zif_abapgit_environment~is_variant_maintenance.
  ENDMETHOD.
  METHOD zif_abapgit_environment~init_parallel_processing.
  ENDMETHOD.
 
ENDCLASS.
 
* Helper to toggle experimental features
CLASS lcl_persist_settings DEFINITION.
 
  PUBLIC SECTION.
    INTERFACES zif_abapgit_persist_settings.
 
    DATA mo_settings TYPE REF TO zcl_abapgit_settings.
 
    METHODS constructor.
 
ENDCLASS.
 
CLASS lcl_persist_settings IMPLEMENTATION.
 
  METHOD constructor.
    CREATE OBJECT mo_settings.
  ENDMETHOD.
 
  METHOD zif_abapgit_persist_settings~modify.
  ENDMETHOD.
 
  METHOD zif_abapgit_persist_settings~read.
    ro_settings = mo_settings.
  ENDMETHOD.
 
ENDCLASS.
 
* Test cases
CLASS ltcl_abap_language_version DEFINITION FOR TESTING RISK LEVEL HARMLESS
  DURATION SHORT FINAL.
 
  PRIVATE SECTION.
    " Cloud package hardcoded in cl_abap_language_version
    CONSTANTS c_cloud_package TYPE devclass VALUE 'TEST_LANGUAGE_VERSION_SCP'.
 
    DATA:
      mt_versions          TYPE string_table,
      mv_has_cloud_package TYPE abap_bool,
      mo_environment       TYPE REF TO lcl_environment,
      mi_persistency       TYPE REF TO zif_abapgit_persist_settings,
      mo_dot_abapgit       TYPE REF TO zcl_abapgit_dot_abapgit,
      mo_cut               TYPE REF TO zcl_abapgit_abap_language_vers.
 
    METHODS:
      setup,
      init
        IMPORTING
          iv_abap_language_version TYPE string,
      set_environment
        IMPORTING
          iv_is_cloud TYPE abap_bool,
      set_features
        IMPORTING
          iv_features TYPE string,
      repo_setting_test
        IMPORTING
          iv_version TYPE string
          iv_exp     TYPE zif_abapgit_aff_types_v1=>ty_abap_language_version,
      object_type_test
        IMPORTING
          iv_version      TYPE string
          iv_standard     TYPE zif_abapgit_aff_types_v1=>ty_abap_language_version
          iv_standard_src TYPE zif_abapgit_aff_types_v1=>ty_abap_language_version
          iv_cloud        TYPE zif_abapgit_aff_types_v1=>ty_abap_language_version
          iv_cloud_src    TYPE zif_abapgit_aff_types_v1=>ty_abap_language_version,
      is_import_allowed_test
        IMPORTING
          iv_version  TYPE string
          iv_standard TYPE abap_bool
          iv_cloud    TYPE abap_bool
          iv_new      TYPE abap_bool.
 
    METHODS:
      repo_setting_feature_off FOR TESTING,
      repo_setting_feature_on FOR TESTING,
      object_type_feature_off FOR TESTING,
      object_type_feature_on FOR TESTING,
      is_import_allowed FOR TESTING,
      check_abap_language_vers_same FOR TESTING RAISING zcx_abapgit_exception,
      check_abap_language_vers_diff FOR TESTING.
 
ENDCLASS.
 
CLASS ltcl_abap_language_version IMPLEMENTATION.
 
  METHOD setup.
    CREATE OBJECT mo_environment.
    zcl_abapgit_injector=>set_environment( mo_environment ).
 
    CREATE OBJECT mi_persistency TYPE lcl_persist_settings.
    zcl_abapgit_persist_injector=>set_settings( mi_persistency ).
 
    APPEND zif_abapgit_dot_abapgit=>c_abap_language_version-undefined TO mt_versions.
    APPEND zif_abapgit_dot_abapgit=>c_abap_language_version-ignore TO mt_versions.
    APPEND zif_abapgit_dot_abapgit=>c_abap_language_version-standard TO mt_versions.
    APPEND zif_abapgit_dot_abapgit=>c_abap_language_version-key_user TO mt_versions.
    APPEND zif_abapgit_dot_abapgit=>c_abap_language_version-cloud_development TO mt_versions.
 
    mv_has_cloud_package = zcl_abapgit_factory=>get_sap_package( c_cloud_package )->exists( ).
  ENDMETHOD.
 
  METHOD init.
    mo_dot_abapgit = zcl_abapgit_dot_abapgit=>build_default( ).
    mo_dot_abapgit->set_abap_language_version( iv_abap_language_version ).
 
    CREATE OBJECT mo_cut
      EXPORTING
        io_dot_abapgit = mo_dot_abapgit.
  ENDMETHOD.
 
  METHOD set_environment.
    mo_environment->set_cloud( iv_is_cloud ).
  ENDMETHOD.
 
  METHOD set_features.
    mi_persistency->read( )->set_experimental_features( iv_features ).
  ENDMETHOD.
 
  METHOD repo_setting_test.
 
    init( iv_version ).
 
    " Assume on-prem (no cloud)
    set_environment( abap_false ).
 
    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->get_repo_abap_language_version( )
      exp = iv_exp
      msg = |ABAP Language Version: { iv_version }, On-prem| ).
 
    " Assume cloud platform
    set_environment( abap_true ).
 
    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->get_repo_abap_language_version( )
      exp = iv_exp
      msg = |ABAP Language Version: { iv_version }, Cloud| ).
 
  ENDMETHOD.
 
  METHOD repo_setting_feature_off.
 
    DATA lv_version TYPE string.
 
    " If experimental feature is off, repo setting is not taken into consideration
    set_features( '' ).
 
    LOOP AT mt_versions INTO lv_version.
 
      repo_setting_test(
        iv_version = lv_version
        iv_exp     = zcl_abapgit_abap_language_vers=>c_any_abap_language_version ).
 
    ENDLOOP.
 
  ENDMETHOD.
 
  METHOD repo_setting_feature_on.
 
    DATA lv_version TYPE string.
 
    " If experimental feature is on, repo setting is returned
    set_features( zcl_abapgit_abap_language_vers=>c_feature_flag ).
 
    LOOP AT mt_versions INTO lv_version.
 
      CASE lv_version.
        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-undefined.
 
          repo_setting_test(
            iv_version = lv_version
            iv_exp     = zcl_abapgit_abap_language_vers=>c_any_abap_language_version ).
 
        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-ignore.
 
          repo_setting_test(
            iv_version = lv_version
            iv_exp     = zcl_abapgit_abap_language_vers=>c_no_abap_language_version ).
 
        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-standard.
 
          repo_setting_test(
            iv_version = lv_version
            iv_exp     = zif_abapgit_aff_types_v1=>co_abap_language_version_src-standard ).
 
        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-key_user.
 
          repo_setting_test(
            iv_version = lv_version
            iv_exp     = zif_abapgit_aff_types_v1=>co_abap_language_version_src-key_user ).
 
        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-cloud_development.
 
          repo_setting_test(
            iv_version = lv_version
            iv_exp     = zif_abapgit_aff_types_v1=>co_abap_language_version_src-cloud_development ).
 
      ENDCASE.
 
    ENDLOOP.
 
  ENDMETHOD.
 
  METHOD object_type_test.
 
    init( iv_version ).
 
    " Assume on-prem (no cloud)
    set_environment( abap_false ).
 
    " source code
    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->get_abap_language_vers_by_objt(
              iv_object_type = 'INTF'
              iv_package     = '$TMP' )
      exp = iv_standard_src
      msg = |ABAP Language Version: { iv_version }, On-prem| ).
 
    " non-source code
    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->get_abap_language_vers_by_objt(
              iv_object_type = 'TABL'
              iv_package     = '$TMP' )
      exp = iv_standard
      msg = |ABAP Language Version: { iv_version }, On-prem| ).
 
    " Assume cloud platform
    IF mv_has_cloud_package = abap_false.
      RETURN.
    ENDIF.

    set_environment( abap_true ).

    " source code
    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->get_abap_language_vers_by_objt(
              iv_object_type = 'INTF'
              iv_package     = c_cloud_package )
      exp = iv_cloud_src
      msg = |ABAP Language Version: { iv_version }, Cloud| ).

    " non-source code
    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->get_abap_language_vers_by_objt(
              iv_object_type = 'TABL'
              iv_package     = c_cloud_package )
      exp = iv_cloud
      msg = |ABAP Language Version: { iv_version }, Cloud| ).

  ENDMETHOD.
 
  METHOD object_type_feature_off.
 
    DATA lv_version TYPE string.
 
    " If experimental feature is off, repo setting is ignored
    set_features( '' ).
 
    LOOP AT mt_versions INTO lv_version.
 
      object_type_test(
        iv_version      = lv_version
        iv_standard     = zcl_abapgit_abap_language_vers=>c_any_abap_language_version
        iv_standard_src = zcl_abapgit_abap_language_vers=>c_any_abap_language_version
        iv_cloud        = zcl_abapgit_abap_language_vers=>c_any_abap_language_version
        iv_cloud_src    = zcl_abapgit_abap_language_vers=>c_any_abap_language_version ).
 
    ENDLOOP.
 
  ENDMETHOD.
 
  METHOD object_type_feature_on.
 
    DATA lv_version TYPE string.
 
    " If experimental feature is on, repo setting is ignored but package setting is returned
    set_features( zcl_abapgit_abap_language_vers=>c_feature_flag ).
 
    LOOP AT mt_versions INTO lv_version.
 
      CASE lv_version.
        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-undefined.
 
          object_type_test(
            iv_version      = lv_version
            iv_standard     = zcl_abapgit_abap_language_vers=>c_any_abap_language_version
            iv_standard_src = zcl_abapgit_abap_language_vers=>c_any_abap_language_version
            iv_cloud        = zcl_abapgit_abap_language_vers=>c_any_abap_language_version
            iv_cloud_src    = zcl_abapgit_abap_language_vers=>c_any_abap_language_version ).
 
        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-ignore.
 
          object_type_test(
            iv_version      = lv_version
            iv_standard     = zcl_abapgit_abap_language_vers=>c_no_abap_language_version
            iv_standard_src = zcl_abapgit_abap_language_vers=>c_no_abap_language_version
            iv_cloud        = zcl_abapgit_abap_language_vers=>c_no_abap_language_version
            iv_cloud_src    = zcl_abapgit_abap_language_vers=>c_no_abap_language_version ).
 
        WHEN OTHERS.
 
          object_type_test(
            iv_version      = lv_version
            iv_standard     = zif_abapgit_aff_types_v1=>co_abap_language_version-standard
            iv_standard_src = zif_abapgit_aff_types_v1=>co_abap_language_version_src-standard
            iv_cloud        = zif_abapgit_aff_types_v1=>co_abap_language_version-cloud_development
            iv_cloud_src    = zif_abapgit_aff_types_v1=>co_abap_language_version_src-cloud_development ).
 
      ENDCASE.
 
    ENDLOOP.
 
  ENDMETHOD.
 
  METHOD is_import_allowed_test.

    init( iv_version ).

    " Assume on-prem (no cloud)
    set_environment( abap_false ).

    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->is_import_allowed( '$TMP' ) " existing standard package
      exp = iv_standard ).

    IF mv_has_cloud_package = abap_true.
      cl_abap_unit_assert=>assert_equals(
        act = mo_cut->is_import_allowed( c_cloud_package ) " existing cloud package
        exp = iv_cloud ).
    ENDIF.

    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->is_import_allowed( 'Z_FOO_BAR' ) " non-existing package
      exp = iv_new ).

    " Assume cloud platform
    set_environment( abap_true ).

    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->is_import_allowed( '$TMP' ) " existing standard package
      exp = iv_standard ).

    IF mv_has_cloud_package = abap_true.
      cl_abap_unit_assert=>assert_equals(
        act = mo_cut->is_import_allowed( c_cloud_package ) " existing cloud package
        exp = iv_cloud ).
    ENDIF.

    cl_abap_unit_assert=>assert_equals(
      act = mo_cut->is_import_allowed( 'Z_FOO_BAR' ) " non-existing package
      exp = iv_new ).

  ENDMETHOD.
 
 
  METHOD is_import_allowed.

    DATA lv_version TYPE string.

    LOOP AT mt_versions INTO lv_version.

      CASE lv_version.
        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-undefined
          OR zif_abapgit_dot_abapgit=>c_abap_language_version-ignore.

          is_import_allowed_test(
            iv_version  = lv_version
            iv_standard = abap_true
            iv_cloud    = abap_true
            iv_new      = abap_true ).

        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-standard.

          is_import_allowed_test(
            iv_version  = lv_version
            iv_standard = abap_true
            iv_cloud    = abap_false
            iv_new      = abap_true ).

        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-key_user.

          is_import_allowed_test(
            iv_version  = lv_version
            iv_standard = abap_false
            iv_cloud    = abap_false
            iv_new      = abap_true ).

        WHEN zif_abapgit_dot_abapgit=>c_abap_language_version-cloud_development.

          is_import_allowed_test(
            iv_version  = lv_version
            iv_standard = abap_false
            iv_cloud    = abap_true
            iv_new      = abap_true ).

      ENDCASE.

    ENDLOOP.

  ENDMETHOD.
 
  METHOD check_abap_language_vers_same.
 
    DATA ls_item TYPE zif_abapgit_definitions=>ty_item.
 
    ls_item-obj_type              = 'CLAS'.
    ls_item-obj_name              = 'ZCL_FOO_BAR'.
    ls_item-abap_language_version = zif_abapgit_aff_types_v1=>co_abap_language_version-standard.
 
    " Does not throw
    zcl_abapgit_abap_language_vers=>check_abap_language_version(
      iv_abap_language_version = zif_abapgit_aff_types_v1=>co_abap_language_version-standard
      is_item                  = ls_item ).
 
  ENDMETHOD.
 
  METHOD check_abap_language_vers_diff.
 
    DATA ls_item TYPE zif_abapgit_definitions=>ty_item.
 
    ls_item-obj_type              = 'CLAS'.
    ls_item-obj_name              = 'ZCL_FOO_BAR'.
    ls_item-abap_language_version = zif_abapgit_aff_types_v1=>co_abap_language_version_src-standard.
 
    TRY.
        zcl_abapgit_abap_language_vers=>check_abap_language_version(
          iv_abap_language_version = zif_abapgit_aff_types_v1=>co_abap_language_version_src-cloud_development
          is_item                  = ls_item ).
        cl_abap_unit_assert=>fail( ).
      CATCH zcx_abapgit_exception ##NO_HANDLER.
    ENDTRY.
 
  ENDMETHOD.
 
ENDCLASS.