Remove popup for XML version mismatch (#5403)

Very unlikely that this error happens. Therefore, the popup was replaced with an exception which makes the case testable.
This commit is contained in:
Marc Bernard 2022-03-24 07:12:24 +01:00 committed by GitHub
parent ac96dbb867
commit 103790eb35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 31 deletions

View File

@ -32,7 +32,7 @@ CLASS zcl_abapgit_xml DEFINITION
!ii_parser TYPE REF TO if_ixml_parser
RAISING
zcx_abapgit_exception .
METHODS display_version_mismatch
METHODS raise_version_mismatch
IMPORTING
!iv_vers TYPE string
RAISING
@ -56,31 +56,6 @@ CLASS zcl_abapgit_xml IMPLEMENTATION.
ENDMETHOD.
METHOD display_version_mismatch.
DATA lv_text TYPE string.
lv_text = |The XML versions do not match, expected: { zif_abapgit_version=>c_xml_version }, actual: { iv_vers }|.
IF mv_filename IS NOT INITIAL.
lv_text = lv_text && |, file: { mv_filename }|.
ENDIF.
lv_text = lv_text && | (see https://docs.abapgit.org/other-xml-mismatch.html)|.
zcl_abapgit_ui_factory=>get_popups( )->popup_to_confirm(
iv_titlebar = 'abapGit XML Version Mismatch'
iv_text_question = lv_text ).
IF mv_filename IS INITIAL.
zcx_abapgit_exception=>raise( 'abapGit XML version mismatch' ).
ELSE.
zcx_abapgit_exception=>raise( |abapGit XML version mismatch in file { mv_filename }| ).
ENDIF.
ENDMETHOD.
METHOD error.
IF ii_parser->num_errors( ) <> 0.
@ -125,7 +100,7 @@ CLASS zcl_abapgit_xml IMPLEMENTATION.
li_version = li_element->if_ixml_node~get_attributes(
)->get_named_item_ns( c_attr_version ).
IF li_version->get_value( ) <> zif_abapgit_version=>c_xml_version.
display_version_mismatch( li_version->get_value( ) ).
raise_version_mismatch( li_version->get_value( ) ).
ENDIF.
* buffer serializer metadata. Git node will be removed lateron
@ -151,6 +126,23 @@ CLASS zcl_abapgit_xml IMPLEMENTATION.
ENDMETHOD.
METHOD raise_version_mismatch.
DATA lv_text TYPE string.
lv_text = |The XML versions do not match, expected: { zif_abapgit_version=>c_xml_version }, actual: { iv_vers }|.
IF mv_filename IS NOT INITIAL.
lv_text = lv_text && |, file: { mv_filename }|.
ENDIF.
lv_text = lv_text && | (see https://docs.abapgit.org/other-xml-mismatch.html)|.
zcx_abapgit_exception=>raise( lv_text ).
ENDMETHOD.
METHOD to_xml.
* will render to codepage UTF-16

View File

@ -16,8 +16,8 @@ CLASS ltcl_xml DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
METHODS setup.
METHODS:
space_leading_trailing FOR TESTING
RAISING zcx_abapgit_exception,
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:
@ -61,7 +61,6 @@ CLASS ltcl_xml IMPLEMENTATION.
DATA: lv_from_xml TYPE string,
lv_to_xml TYPE string.
lv_from_xml = `<FOO> A </FOO>`.
parse_xml( lv_from_xml ).
@ -90,11 +89,35 @@ CLASS ltcl_xml IMPLEMENTATION.
ENDMETHOD.
METHOD bad_xml_raises_exc.
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( iv_xml = 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 }">|