All files / src/objects/core zcl_abapgit_objects_files.clas.testclasses.abap

100% Statements 219/219
100% Branches 7/7
100% Functions 7/7
100% Lines 219/219

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 2201x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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_objects_files DEFINITION FOR TESTING
  DURATION SHORT RISK LEVEL HARMLESS.
 
  PRIVATE SECTION.
    DATA: mo_cut TYPE REF TO zcl_abapgit_objects_files.
 
    METHODS setup
      RAISING
        zcx_abapgit_exception .
 
    METHODS get_program_data
      IMPORTING
        iv_line_break    TYPE clike
      RETURNING
        VALUE(rv_result) TYPE xstring
      RAISING
        zcx_abapgit_exception .
 
    METHODS get_xml_data
      RETURNING
        VALUE(rv_result) TYPE xstring
      RAISING
        zcx_abapgit_exception .
 
    METHODS get_expected_abap_source
      RETURNING
        VALUE(rt_result) TYPE abaptxt255_tab.
 
    METHODS read_abap FOR TESTING RAISING cx_static_check.
    METHODS read_xml FOR TESTING RAISING cx_static_check.
    METHODS get_file_pattern FOR TESTING.
    METHODS is_json_metadata FOR TESTING.
    METHODS is_not_json_metadata FOR TESTING.
    METHODS read_i18n_files FOR TESTING RAISING cx_static_check.
ENDCLASS.
 
CLASS ltcl_objects_files IMPLEMENTATION.
 
  METHOD setup.
 
    DATA lt_files TYPE zif_abapgit_git_definitions=>ty_files_tt.
    DATA ls_item  TYPE zif_abapgit_definitions=>ty_item.
    FIELD-SYMBOLS: <ls_files> LIKE LINE OF lt_files.
 
    " filenames are lower case
    APPEND INITIAL LINE TO lt_files ASSIGNING <ls_files>.
    <ls_files>-filename = 'zlf.prog.abap'.
    <ls_files>-data = get_program_data( cl_abap_char_utilities=>newline ).
    APPEND INITIAL LINE TO lt_files ASSIGNING <ls_files>.
    <ls_files>-filename = 'zlf.prog.xml'.
    <ls_files>-data = get_xml_data( ).
    APPEND INITIAL LINE TO lt_files ASSIGNING <ls_files>.
    <ls_files>-filename = 'zlf.prog.i18n.de.po'.
    APPEND INITIAL LINE TO lt_files ASSIGNING <ls_files>.
    <ls_files>-filename = 'zlf.prog.i18n.es.po'.
    APPEND INITIAL LINE TO lt_files ASSIGNING <ls_files>.
    <ls_files>-filename = 'zlf.prog.i18n.cs.other'.
 
    " object type and name are upper case
    ls_item-obj_type = 'PROG'.
    ls_item-obj_name = 'ZLF'.
 
    mo_cut = zcl_abapgit_objects_files=>new( ls_item ).
 
    mo_cut->set_files( lt_files ).
 
  ENDMETHOD.
 
  METHOD get_program_data.
    DATA: lv_abap_source TYPE string.
 
    CONCATENATE 'My first program' iv_line_break 'has syntax errors' INTO lv_abap_source.
    rv_result = zcl_abapgit_convert=>string_to_xstring_utf8( lv_abap_source ).
 
  ENDMETHOD.
 
  METHOD get_xml_data.
    DATA: lv_xml_source TYPE string.
 
    lv_xml_source = '<?xml version="1.0" encoding="utf-8"?>' &&
      '<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">' &&
        '<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">' &&
          '<asx:values>' &&
            '<PROGDIR>' &&
              '<NAME>ZLF</NAME>' &&
              '<SUBC>1</SUBC>' &&
              '<RLOAD>E</RLOAD>' &&
              '<FIXPT>X</FIXPT>' &&
              '<UCCHECK>X</UCCHECK>' &&
            '</PROGDIR>' &&
          '</asx:values>' &&
        '</asx:abap>' &&
      '</abapGit>'.
 
    rv_result = zcl_abapgit_convert=>string_to_xstring_utf8( lv_xml_source ).
 
  ENDMETHOD.
 
  METHOD get_expected_abap_source.
 
    APPEND 'My first program' TO rt_result.
    APPEND 'has syntax errors' TO rt_result.
 
  ENDMETHOD.
 
  METHOD read_abap.
 
    cl_abap_unit_assert=>assert_equals( exp = get_expected_abap_source( )
      act = mo_cut->read_abap( ) ).
 
  ENDMETHOD.
 
  METHOD read_xml.
    DATA: BEGIN OF ls_exp_prog_metadata,
            name       TYPE progname VALUE 'ZLF',
            subc(1)    TYPE c VALUE '1',
            rload(1)   TYPE c VALUE 'E',
            fixpt(1)   TYPE c VALUE 'X',
            uccheck(1) TYPE c VALUE 'X',
          END OF ls_exp_prog_metadata,
          ls_act_prog_metadata LIKE ls_exp_prog_metadata,
          ls_exp_metadata      TYPE zif_abapgit_definitions=>ty_metadata,
          li_xml               TYPE REF TO zif_abapgit_xml_input.
 
    ls_exp_metadata-class = 'LCL_OBJECT_PROG'.
    ls_exp_metadata-version = 'v1.0.0'.
 
    li_xml = mo_cut->read_xml( ).
    li_xml->read( EXPORTING iv_name = 'PROGDIR' CHANGING cg_data = ls_act_prog_metadata ).
 
    cl_abap_unit_assert=>assert_equals( exp = ls_exp_prog_metadata
      act = ls_act_prog_metadata ).
    cl_abap_unit_assert=>assert_equals( exp = ls_exp_metadata
      act = mo_cut->read_xml( )->get_metadata( ) ).
 
  ENDMETHOD.
 
  METHOD get_file_pattern.
 
    DATA ls_item TYPE zif_abapgit_definitions=>ty_item.
 
    " filenames are lower case
    cl_abap_unit_assert=>assert_equals(
      exp = 'zlf.prog.*'
      act = mo_cut->get_file_pattern( ) ).
 
    " object type and name are upper case
    ls_item-obj_type = 'PROG'.
    ls_item-obj_name = '/TEST/ZLF'.
 
    mo_cut = zcl_abapgit_objects_files=>new( ls_item ).
 
    " filenames are lower case
    cl_abap_unit_assert=>assert_equals(
      exp = '##test##zlf.prog.*'
      act = mo_cut->get_file_pattern( ) ).
 
  ENDMETHOD.
 
  METHOD is_json_metadata.
 
    DATA ls_item TYPE zif_abapgit_definitions=>ty_item.
    DATA lv_data TYPE xstring.
 
    " object type and name are upper case
    ls_item-obj_type = 'CHKO'.
    ls_item-obj_name = 'Z_AFF_EXAMPLE_CHKO'.
 
    mo_cut = zcl_abapgit_objects_files=>new( ls_item ).
 
    mo_cut->add_raw( iv_data = lv_data
                     iv_ext  = 'json' ).
 
    cl_abap_unit_assert=>assert_equals(
      exp = abap_true
      act = mo_cut->is_json_metadata( ) ).
 
  ENDMETHOD.
 
  METHOD is_not_json_metadata.
 
    " checks PROG ZLF (see setup)
    cl_abap_unit_assert=>assert_equals(
      exp = abap_false
      act = mo_cut->is_json_metadata( ) ).
 
  ENDMETHOD.
 
  METHOD read_i18n_files.
 
    DATA lt_i18n_files TYPE zif_abapgit_i18n_file=>ty_table_of.
    DATA li_f LIKE LINE OF lt_i18n_files.
 
    lt_i18n_files = mo_cut->read_i18n_files( ).
 
    cl_abap_unit_assert=>assert_equals(
      act = lines( lt_i18n_files )
      exp = 2 ).
 
    LOOP AT lt_i18n_files INTO li_f.
      CASE sy-tabix.
        WHEN 1.
          cl_abap_unit_assert=>assert_equals(
            act = li_f->lang( )
            exp = 'de' ).
        WHEN 2.
          cl_abap_unit_assert=>assert_equals(
            act = li_f->lang( )
            exp = 'es' ).
      ENDCASE.
    ENDLOOP.
 
    cl_abap_unit_assert=>assert_equals(
      act = lines( mo_cut->get_accessed_files( ) )
      exp = 2 ).
 
  ENDMETHOD.
 
ENDCLASS.