All files / src/ui/core zcl_abapgit_gui_asset_manager.clas.testclasses.abap

100% Statements 168/168
100% Branches 6/6
100% Functions 6/6
100% Lines 168/168

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 1691x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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_abapgit_gui_asset_manager DEFINITION
  FOR TESTING
  DURATION SHORT
  RISK LEVEL HARMLESS.
 
  PRIVATE SECTION.
 
    METHODS get_inline_asset FOR TESTING RAISING zcx_abapgit_exception.
    METHODS get_text_asset FOR TESTING RAISING zcx_abapgit_exception.
    METHODS get_mime_asset FOR TESTING RAISING zcx_abapgit_exception.
    METHODS get_base64_asset FOR TESTING RAISING zcx_abapgit_exception.
    METHODS get_all FOR TESTING RAISING zcx_abapgit_exception.
    METHODS register_and_overwrite FOR TESTING RAISING zcx_abapgit_exception.
ENDCLASS.
 
CLASS ltcl_abapgit_gui_asset_manager IMPLEMENTATION.
 
  METHOD get_inline_asset.
 
    DATA li_assetman TYPE REF TO zif_abapgit_gui_asset_manager.
    DATA ls_asset TYPE zif_abapgit_gui_asset_manager=>ty_web_asset.
 
    li_assetman = zcl_abapgit_gui_asset_manager=>create( ).
 
    li_assetman->register_asset(
      iv_url       = 'css/common.css'
      iv_type      = 'text/css'
      iv_inline    = 'ABC' ).
 
    ls_asset = li_assetman->get_asset( 'css/common.css' ).
 
    cl_abap_unit_assert=>assert_equals( act = ls_asset-type
                                        exp = 'text' ).
    cl_abap_unit_assert=>assert_equals( act = ls_asset-subtype
                                        exp = 'css' ).
    cl_abap_unit_assert=>assert_equals(
      act = zcl_abapgit_convert=>xstring_to_string_utf8( ls_asset-content )
      exp = 'ABC' ).
 
  ENDMETHOD.
 
  METHOD get_text_asset.
 
    DATA li_assetman TYPE REF TO zif_abapgit_gui_asset_manager.
 
    li_assetman = zcl_abapgit_gui_asset_manager=>create( ).
 
    li_assetman->register_asset(
      iv_url       = 'css/common.css'
      iv_type      = 'text/css'
      iv_inline    = 'ABC' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = li_assetman->get_text_asset( 'css/common.css' )
      exp = 'ABC' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = li_assetman->get_text_asset(
        iv_url = 'css/common.css'
        iv_assert_subtype = 'css' )
      exp = 'ABC' ).
 
    TRY.
        li_assetman->get_text_asset(
          iv_url = 'css/common.css'
          iv_assert_subtype = 'xyz' ).
        cl_abap_unit_assert=>fail( ).
      CATCH zcx_abapgit_exception.
        " no futher check
    ENDTRY.
 
    li_assetman->register_asset(
      iv_url       = 'css/common.xyz'
      iv_type      = 'nottext/bin'
      iv_inline    = 'XYZ' ).
 
    TRY.
        li_assetman->get_text_asset( 'css/common.xyz' ).
        cl_abap_unit_assert=>fail( ).
      CATCH zcx_abapgit_exception.
        " no futher check
    ENDTRY.
 
  ENDMETHOD.
 
  METHOD get_mime_asset.
 
    DATA li_assetman TYPE REF TO zif_abapgit_gui_asset_manager.
 
    li_assetman = zcl_abapgit_gui_asset_manager=>create( ).
 
    li_assetman->register_asset(
      iv_url       = 'css/common.css'
      iv_type      = 'text/css'
      iv_mime_name = 'ZABAPGIT_CSS_COMMON' ).
 
    cl_abap_unit_assert=>assert_char_cp(
      act = li_assetman->get_text_asset( 'css/common.css' )
      exp = '*ABAPGIT COMMON CSS*' ).
 
  ENDMETHOD.
 
  METHOD get_base64_asset.
 
    DATA li_assetman TYPE REF TO zif_abapgit_gui_asset_manager.
 
    li_assetman = zcl_abapgit_gui_asset_manager=>create( ).
 
    li_assetman->register_asset(
      iv_url    = 'css/common.css'
      iv_type   = 'text/css'
      iv_base64 = 'QEE=' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = li_assetman->get_text_asset( 'css/common.css' )
      exp = '@A' ).
 
  ENDMETHOD.
 
  METHOD get_all.
 
    DATA li_assetman TYPE REF TO zif_abapgit_gui_asset_manager.
 
    li_assetman = zcl_abapgit_gui_asset_manager=>create( ).
 
    li_assetman->register_asset(
      iv_url    = 'css/common.css'
      iv_type   = 'text/css'
      iv_base64 = 'QEE=' ).
 
    li_assetman->register_asset(
      iv_url    = 'css/common2.css'
      iv_type   = 'text/css'
      iv_inline = 'ABC' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lines( li_assetman->get_all_assets( ) )
      exp = 2 ).
 
  ENDMETHOD.
 
  METHOD register_and_overwrite.
 
    DATA li_assetman TYPE REF TO zif_abapgit_gui_asset_manager.
 
    li_assetman = zcl_abapgit_gui_asset_manager=>create( ).
 
    li_assetman->register_asset(
      iv_url    = 'css/common.css'
      iv_type   = 'text/css'
      iv_inline = 'XYZ' ).
 
    li_assetman->register_asset(
      iv_url    = 'css/common.css'
      iv_type   = 'text/css'
      iv_inline = 'ABC' ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lines( li_assetman->get_all_assets( ) )
      exp = 1 ).
 
    cl_abap_unit_assert=>assert_equals(
      act = li_assetman->get_text_asset( 'css/common.css' )
      exp = 'ABC' ).
 
  ENDMETHOD.
 
ENDCLASS.