All files / src/xml zcl_abapgit_xml.clas.testclasses.abap

66.19% Statements 94/142
100% Branches 2/2
40% Functions 2/5
66.19% Lines 94/142

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 1431x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                       1x 1x                               1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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_xml DEFINITION DEFERRED.
 
CLASS ltcl_xml_concrete DEFINITION FOR TESTING
    FINAL
    INHERITING FROM zcl_abapgit_xml
    FRIENDS ltcl_xml.
ENDCLASS.
 
CLASS ltcl_xml_concrete IMPLEMENTATION.
ENDCLASS.
 
CLASS ltcl_xml DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
 
  PRIVATE SECTION.
 
    METHODS setup.
 
    METHODS:
      space_leading_trailing FOR TESTING RAISING zcx_abapgit_exception,
      bad_version_raises_exc FOR TESTING RAISING cx_static_check,
      bad_xml_raises_exc FOR TESTING RAISING cx_static_check.
 
    METHODS:
      parse_xml
        IMPORTING
          iv_xml TYPE csequence
        RAISING
          zcx_abapgit_exception,
      render_xml
        RETURNING
          VALUE(rv_xml) TYPE string.
 
    DATA mo_xml TYPE REF TO ltcl_xml_concrete.
 
ENDCLASS.
 
 
CLASS ltcl_xml IMPLEMENTATION.
 
  METHOD setup.
    CREATE OBJECT mo_xml.
  ENDMETHOD.
 
  METHOD parse_xml.

    DATA lv_xml TYPE string.

    lv_xml = |<?xml version="1.0"?>|
          && |<{ mo_xml->c_abapgit_tag } { mo_xml->c_attr_version }="{ zif_abapgit_version=>c_xml_version }">|
          && iv_xml
          && |</{ mo_xml->c_abapgit_tag }>|.

    mo_xml->parse( lv_xml ).

  ENDMETHOD.
 
  METHOD space_leading_trailing.

    DATA: lv_from_xml TYPE string,
          lv_to_xml   TYPE string.

    lv_from_xml = `<FOO> A </FOO>`.

    parse_xml( lv_from_xml ).

    lv_to_xml = render_xml( ).

    cl_abap_unit_assert=>assert_char_cp(
      act = lv_to_xml
      exp = |*{ lv_from_xml }*| ).

  ENDMETHOD.
 
  METHOD render_xml.
 
* this code replicates the functionality in ZCL_ABAPGIT_XML_OUTPUT,
 
    DATA: li_ostream       TYPE REF TO if_ixml_ostream,
          li_renderer      TYPE REF TO if_ixml_renderer,
          li_streamfactory TYPE REF TO if_ixml_stream_factory.
 
    li_streamfactory = mo_xml->mi_ixml->create_stream_factory( ).
 
    li_ostream = li_streamfactory->create_ostream_cstring( rv_xml ).
 
    li_renderer = mo_xml->mi_ixml->create_renderer(
      ostream  = li_ostream
      document = mo_xml->mi_xml_doc ).
 
    li_renderer->render( ).
 
  ENDMETHOD.
 
  METHOD bad_version_raises_exc.
 
    DATA: lv_xml   TYPE string,
          lo_error TYPE REF TO zcx_abapgit_exception,
          lv_text  TYPE string.
 
    lv_xml = |<?xml version="1.0"?>|
          && |<{ mo_xml->c_abapgit_tag } { mo_xml->c_attr_version }="v9.8.7">|
          && |<TEST>data</TEST>|
          && |</{ mo_xml->c_abapgit_tag }>|.
 
    TRY.
        mo_xml->parse( lv_xml ).
        cl_abap_unit_assert=>fail( msg = 'Exception not raised' ).
 
      CATCH zcx_abapgit_exception INTO lo_error.
        lv_text = lo_error->get_text( ).
        cl_abap_unit_assert=>assert_char_cp(
            act              = lv_text
            exp              = '*XML version*' ).
    ENDTRY.
 
  ENDMETHOD.
 
  METHOD bad_xml_raises_exc.

    DATA: lv_xml   TYPE string,
          lo_error TYPE REF TO zcx_abapgit_exception,
          lv_text  TYPE string.

    lv_xml = |<?xml version="1.0"?>|
          && |<{ mo_xml->c_abapgit_tag } { mo_xml->c_attr_version }="{ zif_abapgit_version=>c_xml_version }">|
          && |<open_tag>|
          && |</{ mo_xml->c_abapgit_tag }>|.

    TRY.
        mo_xml->parse( lv_xml ).
        cl_abap_unit_assert=>fail( msg = 'Exception not raised' ).

      CATCH zcx_abapgit_exception INTO lo_error.
        lv_text = lo_error->get_text( ).
        cl_abap_unit_assert=>assert_char_cp(
            act              = lv_text
            exp              = '*open_tag*' ).
    ENDTRY.

  ENDMETHOD.
 
ENDCLASS.