More classes to global
This commit is contained in:
Lars Hvam 2018-02-11 10:07:05 +01:00 committed by GitHub
parent 664b8bb782
commit e9ffa8e642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 956 additions and 2422 deletions

View File

@ -318,3 +318,147 @@ CLASS ltcl_pack IMPLEMENTATION.
ENDMETHOD.
ENDCLASS.
CLASS ltcl_git_pack_decode_commit DEFINITION FOR TESTING
RISK LEVEL HARMLESS DURATION SHORT FINAL.
PUBLIC SECTION.
METHODS:
decode1 FOR TESTING
RAISING zcx_abapgit_exception,
decode2 FOR TESTING
RAISING zcx_abapgit_exception,
decode3 FOR TESTING
RAISING zcx_abapgit_exception.
PRIVATE SECTION.
DATA: ms_raw TYPE zcl_abapgit_git_pack=>ty_commit,
mv_str TYPE string.
METHODS:
setup,
decode
RAISING zcx_abapgit_exception,
add
IMPORTING iv_string TYPE string.
ENDCLASS.
CLASS ltcl_git_pack_decode_commit IMPLEMENTATION.
METHOD setup.
CLEAR ms_raw.
CLEAR mv_str.
ENDMETHOD.
METHOD add.
CONCATENATE mv_str iv_string zif_abapgit_definitions=>gc_newline INTO mv_str.
ENDMETHOD.
METHOD decode.
DATA: lv_xstr TYPE xstring.
lv_xstr = zcl_abapgit_convert=>string_to_xstring_utf8( mv_str ).
ms_raw = zcl_abapgit_git_pack=>decode_commit( lv_xstr ).
ENDMETHOD.
METHOD decode1.
add( 'tree tree' ).
add( 'parent parent1' ).
add( 'parent parent2' ).
add( 'author author' ).
add( 'committer committer' ).
add( '' ).
add( 'comment' ).
decode( ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-tree
exp = 'tree' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-author
exp = 'author' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-committer
exp = 'committer' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-parent
exp = 'parent1' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-parent2
exp = 'parent2' ).
cl_abap_unit_assert=>assert_char_cp(
act = ms_raw-body
exp = 'comment+' ).
ENDMETHOD.
METHOD decode2.
add( 'tree tree' ).
add( 'author author' ).
add( 'committer committer' ).
add( '' ).
add( 'comment' ).
decode( ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-tree
exp = 'tree' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-author
exp = 'author' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-committer
exp = 'committer' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-parent
exp = '' ).
cl_abap_unit_assert=>assert_char_cp(
act = ms_raw-body
exp = 'comment+' ).
ENDMETHOD.
METHOD decode3.
add( 'tree tree' ).
add( 'parent parent1' ).
add( 'author author' ).
add( 'committer committer' ).
add( '' ).
add( 'comment' ).
decode( ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-tree
exp = 'tree' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-author
exp = 'author' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-committer
exp = 'committer' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-parent
exp = 'parent1' ).
cl_abap_unit_assert=>assert_char_cp(
act = ms_raw-body
exp = 'comment+' ).
ENDMETHOD.
ENDCLASS.

View File

@ -0,0 +1,62 @@
CLASS ltcl_test DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS:
repo_host FOR TESTING RAISING zcx_abapgit_exception,
repo_name1 FOR TESTING RAISING zcx_abapgit_exception,
repo_name2 FOR TESTING RAISING zcx_abapgit_exception,
repo_error FOR TESTING.
ENDCLASS. "ltcl_Test
CLASS ltcl_test IMPLEMENTATION.
METHOD repo_error.
TRY.
zcl_abapgit_url=>host( 'not a real url' ). "#EC NOTEXT
cl_abap_unit_assert=>fail( ).
CATCH zcx_abapgit_exception. "#EC NO_HANDLER
ENDTRY.
ENDMETHOD. "repo_error
METHOD repo_host.
DATA: lv_host TYPE string.
lv_host = zcl_abapgit_url=>host( 'https://github.com/larshp/Foobar.git' ).
cl_abap_unit_assert=>assert_equals(
exp = 'https://github.com'
act = lv_host ).
ENDMETHOD. "repo_url
METHOD repo_name1.
DATA: lv_name TYPE string.
lv_name = zcl_abapgit_url=>name( 'https://github.com/larshp/Foobar.git' ).
cl_abap_unit_assert=>assert_equals(
exp = 'Foobar'
act = lv_name ).
ENDMETHOD.
METHOD repo_name2.
DATA: lv_name TYPE string.
lv_name = zcl_abapgit_url=>name( 'https://git.hanatrial.ondemand.com/p12345trial/yay' ).
cl_abap_unit_assert=>assert_equals(
exp = 'yay'
act = lv_name ).
ENDMETHOD.
ENDCLASS.

View File

@ -13,6 +13,7 @@
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@ -41,7 +41,7 @@ CLASS lcl_git_transport DEFINITION FINAL.
CLASS-METHODS branch_list
IMPORTING iv_url TYPE string
iv_service TYPE string
EXPORTING eo_client TYPE REF TO lcl_http_client
EXPORTING eo_client TYPE REF TO zcl_abapgit_http_client
eo_branch_list TYPE REF TO zcl_abapgit_git_branch_list
RAISING zcx_abapgit_exception.
@ -49,7 +49,7 @@ CLASS lcl_git_transport DEFINITION FINAL.
IMPORTING iv_url TYPE string
iv_service TYPE string
iv_branch_name TYPE string
EXPORTING eo_client TYPE REF TO lcl_http_client
EXPORTING eo_client TYPE REF TO zcl_abapgit_http_client
ev_branch TYPE zif_abapgit_definitions=>ty_sha1
RAISING zcx_abapgit_exception.
@ -87,7 +87,7 @@ CLASS lcl_git_transport IMPLEMENTATION.
METHOD branches.
DATA: lo_client TYPE REF TO lcl_http_client.
DATA: lo_client TYPE REF TO zcl_abapgit_http_client.
lcl_git_transport=>branch_list(
@ -121,7 +121,7 @@ CLASS lcl_git_transport IMPLEMENTATION.
METHOD receive_pack.
DATA: lo_client TYPE REF TO lcl_http_client,
DATA: lo_client TYPE REF TO zcl_abapgit_http_client,
lv_cmd_pkt TYPE string,
lv_line TYPE string,
lv_tmp TYPE xstring,
@ -214,7 +214,7 @@ CLASS lcl_git_transport IMPLEMENTATION.
METHOD upload_pack.
DATA: lo_client TYPE REF TO lcl_http_client,
DATA: lo_client TYPE REF TO zcl_abapgit_http_client,
lv_buffer TYPE string,
lv_xstring TYPE xstring,
lv_line TYPE string,

View File

@ -50,167 +50,6 @@ CLASS lcl_proxy_auth IMPLEMENTATION.
ENDCLASS.
CLASS lcl_http_client DEFINITION FINAL.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING ii_client TYPE REF TO if_http_client,
close,
set_digest
IMPORTING io_digest TYPE REF TO zcl_abapgit_http_digest,
send_receive_close
IMPORTING
iv_data TYPE xstring
RETURNING
VALUE(rv_data) TYPE xstring
RAISING zcx_abapgit_exception,
get_cdata
RETURNING VALUE(rv_value) TYPE string,
check_http_200
RAISING zcx_abapgit_exception,
send_receive
RAISING zcx_abapgit_exception,
set_headers
IMPORTING iv_url TYPE string
iv_service TYPE string
RAISING zcx_abapgit_exception.
PRIVATE SECTION.
DATA: mi_client TYPE REF TO if_http_client,
mo_digest TYPE REF TO zcl_abapgit_http_digest.
ENDCLASS.
CLASS lcl_http_client IMPLEMENTATION.
METHOD constructor.
mi_client = ii_client.
ENDMETHOD.
METHOD set_digest.
mo_digest = io_digest.
ENDMETHOD.
METHOD send_receive_close.
* do not use set_cdata as it modifies the Content-Type header field
mi_client->request->set_data( iv_data ).
send_receive( ).
check_http_200( ).
rv_data = mi_client->response->get_data( ).
mi_client->close( ).
ENDMETHOD.
METHOD get_cdata.
rv_value = mi_client->response->get_cdata( ).
ENDMETHOD.
METHOD close.
mi_client->close( ).
ENDMETHOD.
METHOD set_headers.
DATA: lv_value TYPE string.
mi_client->request->set_header_field(
name = '~request_method'
value = 'POST' ).
lv_value = zcl_abapgit_url=>path_name( iv_url ) &&
'/git-' &&
iv_service &&
'-pack'.
mi_client->request->set_header_field(
name = '~request_uri'
value = lv_value ).
lv_value = 'application/x-git-'
&& iv_service && '-pack-request'. "#EC NOTEXT
mi_client->request->set_header_field(
name = 'Content-Type'
value = lv_value ). "#EC NOTEXT
lv_value = 'application/x-git-'
&& iv_service && '-pack-result'. "#EC NOTEXT
mi_client->request->set_header_field(
name = 'Accept'
value = lv_value ). "#EC NOTEXT
IF mo_digest IS BOUND.
mo_digest->run( mi_client ).
ENDIF.
ENDMETHOD. "set_headers
METHOD send_receive.
DATA: lv_text TYPE string,
lv_code TYPE i,
lv_message TYPE string.
mi_client->send( ).
mi_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4 ).
IF sy-subrc <> 0.
" in case of HTTP_COMMUNICATION_FAILURE
" make sure:
" a) SSL is setup properly in STRUST
" b) no firewalls
" check trace file in transaction SMICM
mi_client->get_last_error(
IMPORTING
code = lv_code
message = lv_message ).
lv_text = |HTTP error { lv_code } occured: { lv_message }|.
zcx_abapgit_exception=>raise( lv_text ).
ENDIF.
ENDMETHOD. "send_receive
METHOD check_http_200.
DATA: lv_code TYPE i,
lv_text TYPE string.
mi_client->response->get_status(
IMPORTING
code = lv_code ).
CASE lv_code.
WHEN 200.
RETURN.
WHEN 302.
zcx_abapgit_exception=>raise( 'HTTP redirect, check URL' ).
WHEN 401.
zcx_abapgit_exception=>raise( 'HTTP 401, unauthorized' ).
WHEN 403.
zcx_abapgit_exception=>raise( 'HTTP 403, forbidden' ).
WHEN 404.
zcx_abapgit_exception=>raise( 'HTTP 404, not found' ).
WHEN 415.
zcx_abapgit_exception=>raise( 'HTTP 415, unsupported media type' ).
WHEN OTHERS.
lv_text = mi_client->response->get_cdata( ).
zcx_abapgit_exception=>raise( |HTTP error code: { lv_code }, { lv_text }| ).
ENDCASE.
ENDMETHOD. "http_200
ENDCLASS.
CLASS lcl_http DEFINITION FINAL.
PUBLIC SECTION.
@ -224,7 +63,7 @@ CLASS lcl_http DEFINITION FINAL.
create_by_url
IMPORTING iv_url TYPE string
iv_service TYPE string
RETURNING VALUE(ro_client) TYPE REF TO lcl_http_client
RETURNING VALUE(ro_client) TYPE REF TO zcl_abapgit_http_client
RAISING zcx_abapgit_exception.
PRIVATE SECTION.
@ -238,7 +77,7 @@ CLASS lcl_http DEFINITION FINAL.
RETURNING VALUE(rv_bool) TYPE abap_bool,
acquire_login_details
IMPORTING ii_client TYPE REF TO if_http_client
io_client TYPE REF TO lcl_http_client
io_client TYPE REF TO zcl_abapgit_http_client
iv_url TYPE string
RETURNING VALUE(rv_scheme) TYPE string
RAISING zcx_abapgit_exception.

File diff suppressed because it is too large Load Diff

View File

@ -2,44 +2,4 @@
*& Include zabapgit_skip_objects
*&---------------------------------------------------------------------*
CLASS lcl_skip_objects IMPLEMENTATION.
METHOD skip_sadl_generated_objects.
DATA: ls_tadir_class LIKE LINE OF rt_tadir,
ls_tadir LIKE LINE OF rt_tadir,
lt_lines_to_delete TYPE zif_abapgit_definitions=>ty_tadir_tt.
rt_tadir = it_tadir.
LOOP AT it_tadir INTO ls_tadir WHERE object = 'DDLS'.
LOOP AT rt_tadir INTO ls_tadir_class
WHERE object = 'CLAS' AND obj_name CS ls_tadir-obj_name.
IF has_sadl_superclass( ls_tadir_class ) = abap_true.
APPEND ls_tadir_class TO lt_lines_to_delete.
ENDIF.
ENDLOOP.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM lt_lines_to_delete.
LOOP AT lt_lines_to_delete INTO ls_tadir_class.
DELETE TABLE rt_tadir FROM ls_tadir_class.
IF io_log IS BOUND.
io_log->add(
iv_msg = |{ ls_tadir_class-obj_name } skipped: generated by SADL|
iv_type = 'W' ).
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD has_sadl_superclass.
DATA: lo_oo_functions TYPE REF TO zif_abapgit_oo_object_fnc,
lv_class_name TYPE seoclsname,
lv_superclass TYPE seoclsname.
lo_oo_functions = zcl_abapgit_oo_factory=>make( is_class-object ).
lv_class_name = is_class-obj_name.
lv_superclass = lo_oo_functions->read_superclass( lv_class_name ).
IF lv_superclass = 'CL_SADL_GTK_EXPOSURE_MPC'.
rv_return = abap_true.
ENDIF.
ENDMETHOD.
ENDCLASS.
* todo, include to be deleted

View File

@ -7,23 +7,6 @@
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_skip_objects DEFINITION.
PUBLIC SECTION.
METHODS:
skip_sadl_generated_objects
IMPORTING
it_tadir TYPE zif_abapgit_definitions=>ty_tadir_tt
io_log TYPE REF TO zcl_abapgit_log OPTIONAL
RETURNING
VALUE(rt_tadir) TYPE zif_abapgit_definitions=>ty_tadir_tt.
PRIVATE SECTION.
METHODS:
has_sadl_superclass
IMPORTING
is_class TYPE zif_abapgit_definitions=>ty_tadir
RETURNING
VALUE(rv_return) TYPE abap_bool.
ENDCLASS.
CLASS lcl_tadir DEFINITION FINAL.
@ -161,7 +144,7 @@ CLASS lcl_tadir IMPLEMENTATION.
DATA: lt_tadir TYPE zif_abapgit_definitions=>ty_tadir_tt,
lt_tdevc TYPE STANDARD TABLE OF tdevc,
lv_path TYPE string,
lo_skip_objects TYPE REF TO lcl_skip_objects,
lo_skip_objects TYPE REF TO zcl_abapgit_skip_objects,
lt_excludes TYPE RANGE OF trobjtype,
ls_exclude LIKE LINE OF lt_excludes.

View File

@ -176,81 +176,6 @@ CLASS lcl_transport IMPLEMENTATION.
ENDMETHOD.
ENDCLASS.
CLASS lcl_transport_objects DEFINITION.
"Under test at ltcl_transport_objects
PUBLIC SECTION.
METHODS constructor
IMPORTING
it_transport_objects TYPE scts_tadir.
METHODS to_stage
IMPORTING
io_stage TYPE REF TO zcl_abapgit_stage
is_stage_objects TYPE zif_abapgit_definitions=>ty_stage_files
it_object_statuses TYPE zif_abapgit_definitions=>ty_results_tt
RAISING
zcx_abapgit_exception.
PRIVATE SECTION.
DATA mt_transport_objects TYPE scts_tadir.
ENDCLASS.
CLASS lcl_transport_objects IMPLEMENTATION.
METHOD constructor.
mt_transport_objects = it_transport_objects.
ENDMETHOD.
METHOD to_stage.
DATA: ls_transport_object TYPE tadir,
ls_local_file TYPE zif_abapgit_definitions=>ty_file_item,
ls_object_status TYPE zif_abapgit_definitions=>ty_result.
LOOP AT mt_transport_objects INTO ls_transport_object.
LOOP AT it_object_statuses INTO ls_object_status
WHERE obj_name = ls_transport_object-obj_name
AND obj_type = ls_transport_object-object
AND NOT lstate IS INITIAL.
CASE ls_object_status-lstate.
WHEN zif_abapgit_definitions=>gc_state-added OR zif_abapgit_definitions=>gc_state-modified.
IF ls_transport_object-delflag = abap_true.
zcx_abapgit_exception=>raise( |Object { ls_transport_object-obj_name
} should be added/modified, but has deletion flag in transport| ).
ENDIF.
READ TABLE is_stage_objects-local
INTO ls_local_file
WITH KEY item-obj_name = ls_transport_object-obj_name
item-obj_type = ls_transport_object-object
file-filename = ls_object_status-filename.
IF sy-subrc <> 0.
zcx_abapgit_exception=>raise( |Object { ls_transport_object-obj_name
} not found in the local repository files| ).
ENDIF.
io_stage->add(
iv_path = ls_local_file-file-path
iv_filename = ls_local_file-file-filename
iv_data = ls_local_file-file-data ).
WHEN zif_abapgit_definitions=>gc_state-deleted.
IF ls_transport_object-delflag = abap_false.
zcx_abapgit_exception=>raise( |Object { ls_transport_object-obj_name
} should be removed, but has NO deletion flag in transport| ).
ENDIF.
io_stage->rm(
iv_path = ls_object_status-path
iv_filename = ls_object_status-filename ).
WHEN OTHERS.
ASSERT 0 = 1. "Unexpected state
ENDCASE.
ENDLOOP.
IF sy-subrc <> 0.
zcx_abapgit_exception=>raise( |Object { ls_transport_object-obj_name
} not found in the local repository files| ).
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
CLASS lcl_transport_2_branch DEFINITION.
PUBLIC SECTION.
METHODS:
@ -341,7 +266,7 @@ CLASS lcl_transport_2_branch IMPLEMENTATION.
ENDMETHOD.
METHOD stage_transport_objects.
DATA lo_transport_objects TYPE REF TO lcl_transport_objects.
DATA lo_transport_objects TYPE REF TO zcl_abapgit_transport_objects.
CREATE OBJECT lo_transport_objects
EXPORTING
it_transport_objects = it_transport_objects.

View File

@ -312,78 +312,6 @@ CLASS ltcl_git_porcelain IMPLEMENTATION.
ENDCLASS.
*----------------------------------------------------------------------*
* CLASS ltcl_url DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS ltcl_url DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL.
PRIVATE SECTION.
METHODS:
repo_host FOR TESTING RAISING zcx_abapgit_exception,
repo_name1 FOR TESTING RAISING zcx_abapgit_exception,
repo_name2 FOR TESTING RAISING zcx_abapgit_exception,
repo_error FOR TESTING.
ENDCLASS. "ltcl_url DEFINITION
*----------------------------------------------------------------------*
* CLASS ltcl_url IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS ltcl_url IMPLEMENTATION.
METHOD repo_error.
TRY.
zcl_abapgit_url=>host( 'not a real url' ). "#EC NOTEXT
cl_abap_unit_assert=>fail( ).
CATCH zcx_abapgit_exception. "#EC NO_HANDLER
ENDTRY.
ENDMETHOD. "repo_error
METHOD repo_host.
DATA: lv_host TYPE string.
lv_host = zcl_abapgit_url=>host( 'https://github.com/larshp/Foobar.git' ).
cl_abap_unit_assert=>assert_equals(
exp = 'https://github.com'
act = lv_host ).
ENDMETHOD. "repo_url
METHOD repo_name1.
DATA: lv_name TYPE string.
lv_name = zcl_abapgit_url=>name( 'https://github.com/larshp/Foobar.git' ).
cl_abap_unit_assert=>assert_equals(
exp = 'Foobar'
act = lv_name ).
ENDMETHOD.
METHOD repo_name2.
DATA: lv_name TYPE string.
lv_name = zcl_abapgit_url=>name( 'https://git.hanatrial.ondemand.com/p12345trial/yay' ).
cl_abap_unit_assert=>assert_equals(
exp = 'yay'
act = lv_name ).
ENDMETHOD.
ENDCLASS. "ltcl_url IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS ltcl_object_types DEFINITION
*----------------------------------------------------------------------*
@ -459,150 +387,6 @@ CLASS ltcl_object_types IMPLEMENTATION.
ENDCLASS. "ltcl_object_types IMPLEMENTATION
CLASS ltcl_git_pack_decode_commit DEFINITION FOR TESTING
RISK LEVEL HARMLESS DURATION SHORT FINAL.
PUBLIC SECTION.
METHODS:
decode1 FOR TESTING
RAISING zcx_abapgit_exception,
decode2 FOR TESTING
RAISING zcx_abapgit_exception,
decode3 FOR TESTING
RAISING zcx_abapgit_exception.
PRIVATE SECTION.
DATA: ms_raw TYPE zcl_abapgit_git_pack=>ty_commit,
mv_str TYPE string.
METHODS:
setup,
decode
RAISING zcx_abapgit_exception,
add
IMPORTING iv_string TYPE string.
ENDCLASS.
CLASS ltcl_git_pack_decode_commit IMPLEMENTATION.
METHOD setup.
CLEAR ms_raw.
CLEAR mv_str.
ENDMETHOD.
METHOD add.
CONCATENATE mv_str iv_string zif_abapgit_definitions=>gc_newline INTO mv_str.
ENDMETHOD.
METHOD decode.
DATA: lv_xstr TYPE xstring.
lv_xstr = zcl_abapgit_convert=>string_to_xstring_utf8( mv_str ).
ms_raw = zcl_abapgit_git_pack=>decode_commit( lv_xstr ).
ENDMETHOD.
METHOD decode1.
add( 'tree tree' ).
add( 'parent parent1' ).
add( 'parent parent2' ).
add( 'author author' ).
add( 'committer committer' ).
add( '' ).
add( 'comment' ).
decode( ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-tree
exp = 'tree' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-author
exp = 'author' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-committer
exp = 'committer' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-parent
exp = 'parent1' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-parent2
exp = 'parent2' ).
cl_abap_unit_assert=>assert_char_cp(
act = ms_raw-body
exp = 'comment+' ).
ENDMETHOD.
METHOD decode2.
add( 'tree tree' ).
add( 'author author' ).
add( 'committer committer' ).
add( '' ).
add( 'comment' ).
decode( ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-tree
exp = 'tree' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-author
exp = 'author' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-committer
exp = 'committer' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-parent
exp = '' ).
cl_abap_unit_assert=>assert_char_cp(
act = ms_raw-body
exp = 'comment+' ).
ENDMETHOD.
METHOD decode3.
add( 'tree tree' ).
add( 'parent parent1' ).
add( 'author author' ).
add( 'committer committer' ).
add( '' ).
add( 'comment' ).
decode( ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-tree
exp = 'tree' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-author
exp = 'author' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-committer
exp = 'committer' ).
cl_abap_unit_assert=>assert_equals(
act = ms_raw-parent
exp = 'parent1' ).
cl_abap_unit_assert=>assert_char_cp(
act = ms_raw-body
exp = 'comment+' ).
ENDMETHOD.
ENDCLASS.
*----------------------------------------------------------------------*
* CLASS ltcl_serialize DEFINITION
*----------------------------------------------------------------------*

View File

@ -2,363 +2,4 @@
*& Include ZABAPGIT_UNIT_TEST_TRANSPORT
*&---------------------------------------------------------------------*
CLASS ltcl_transport_objects DEFINITION FOR TESTING.
PRIVATE SECTION.
METHODS:
add_new_to_local_files FOR TESTING RAISING cx_static_check,
modified_to_new_local_files FOR TESTING RAISING cx_static_check,
transport_not_in_repository FOR TESTING RAISING cx_static_check,
object_not_in_local_files FOR TESTING RAISING cx_static_check,
cant_be_added_with_del_flag FOR TESTING RAISING cx_static_check,
cant_be_modified_with_del_flag FOR TESTING RAISING cx_static_check,
deleted_to_removed_files FOR TESTING RAISING cx_static_check,
shouldnt_remove_no_delflag FOR TESTING RAISING cx_static_check,
should_add_all_local_files FOR TESTING RAISING cx_static_check,
should_delete_all_related FOR TESTING RAISING cx_static_check,
setup,
given_the_transport_object
IMPORTING iv_obj_name TYPE string
iv_obj_type TYPE string
iv_delflag TYPE abap_bool OPTIONAL,
given_the_object_status
IMPORTING
iv_obj_name TYPE string OPTIONAL
iv_obj_type TYPE string OPTIONAL
iv_filename TYPE string OPTIONAL
iv_path TYPE string OPTIONAL
iv_lstate TYPE char1,
given_the_local_file
IMPORTING iv_obj_name TYPE string
iv_obj_type TYPE string
iv_filename TYPE string
iv_path TYPE string
iv_data TYPE string
RETURNING VALUE(rs_local_file) TYPE zif_abapgit_definitions=>ty_file_item,
when_staging
RAISING zcx_abapgit_exception,
then_file_should_be_added
IMPORTING
is_local_file TYPE zif_abapgit_definitions=>ty_file_item,
then_it_should_raise_exception
IMPORTING
with_text TYPE string,
then_it_should_remove_at_stage
IMPORTING
iv_filename TYPE string
iv_path TYPE string.
DATA: mo_transport_objects TYPE REF TO lcl_transport_objects,
mt_transport_objects TYPE scts_tadir,
mt_object_statuses TYPE zif_abapgit_definitions=>ty_results_tt,
ms_stage_objects TYPE zif_abapgit_definitions=>ty_stage_files,
mo_stage TYPE REF TO zcl_abapgit_stage.
ENDCLASS.
CLASS ltcl_transport_objects IMPLEMENTATION.
METHOD setup.
CREATE OBJECT mo_stage
EXPORTING
iv_branch_name = 'A_branch_name'
iv_branch_sha1 = 'Branch_SH1'.
ENDMETHOD.
METHOD add_new_to_local_files.
DATA ls_local_file TYPE zif_abapgit_definitions=>ty_file_item.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_lstate = zif_abapgit_definitions=>gc_state-added ).
ls_local_file = given_the_local_file(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/path'
iv_data = 'data' ).
when_staging( ).
then_file_should_be_added( ls_local_file ).
ENDMETHOD.
METHOD modified_to_new_local_files.
DATA ls_local_file TYPE zif_abapgit_definitions=>ty_file_item.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_lstate = zif_abapgit_definitions=>gc_state-modified ).
ls_local_file = given_the_local_file(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/path'
iv_data = 'data' ).
when_staging( ).
then_file_should_be_added( ls_local_file ).
ENDMETHOD.
METHOD should_add_all_local_files.
"Not only .abap, but also .xml and other includes
DATA ls_abap_local_file TYPE zif_abapgit_definitions=>ty_file_item.
DATA ls_xml_local_file TYPE zif_abapgit_definitions=>ty_file_item.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_lstate = zif_abapgit_definitions=>gc_state-modified ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.xml'
iv_lstate = zif_abapgit_definitions=>gc_state-modified ).
ls_abap_local_file = given_the_local_file(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/path'
iv_data = 'data' ).
ls_xml_local_file = given_the_local_file(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.xml'
iv_path = '/path'
iv_data = 'data' ).
when_staging( ).
then_file_should_be_added( ls_abap_local_file ).
then_file_should_be_added( ls_xml_local_file ).
ENDMETHOD.
METHOD transport_not_in_repository.
given_the_transport_object(
iv_obj_name = 'CL_A_CLASS_NOT_IN_REPO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_lstate = zif_abapgit_definitions=>gc_state-added ).
then_it_should_raise_exception(
with_text = 'Object CL_A_CLASS_NOT_IN_REPO not found in the local repository files' ).
ENDMETHOD.
METHOD object_not_in_local_files.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_lstate = zif_abapgit_definitions=>gc_state-added ).
given_the_local_file(
iv_obj_name = 'CL_ANOTHER_LOCAL_FILE'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/path'
iv_data = 'data' ).
then_it_should_raise_exception(
with_text = 'Object CL_FOO not found in the local repository files' ).
ENDMETHOD.
METHOD cant_be_added_with_del_flag.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_true ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_lstate = zif_abapgit_definitions=>gc_state-added ).
then_it_should_raise_exception(
with_text = 'Object CL_FOO should be added/modified, but has deletion flag in transport' ).
ENDMETHOD.
METHOD cant_be_modified_with_del_flag.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_true ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_lstate = zif_abapgit_definitions=>gc_state-modified ).
then_it_should_raise_exception(
with_text = 'Object CL_FOO should be added/modified, but has deletion flag in transport' ).
ENDMETHOD.
METHOD deleted_to_removed_files.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_true ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path'
iv_lstate = zif_abapgit_definitions=>gc_state-deleted ).
when_staging( ).
then_it_should_remove_at_stage(
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path' ).
ENDMETHOD.
METHOD should_delete_all_related.
"i.e. Should also delete the XMLs related to the transport objects
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_true ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path'
iv_lstate = zif_abapgit_definitions=>gc_state-deleted ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.xml'
iv_path = '/a_path'
iv_lstate = zif_abapgit_definitions=>gc_state-deleted ).
when_staging( ).
then_it_should_remove_at_stage(
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path' ).
then_it_should_remove_at_stage(
iv_filename = 'CL_FOO.xml'
iv_path = '/a_path' ).
ENDMETHOD.
METHOD shouldnt_remove_no_delflag.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_false ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path'
iv_lstate = zif_abapgit_definitions=>gc_state-deleted ).
then_it_should_raise_exception(
with_text = 'Object CL_FOO should be removed, but has NO deletion flag in transport' ).
ENDMETHOD.
METHOD given_the_transport_object.
DATA ls_transport_object TYPE tadir.
ls_transport_object-obj_name = iv_obj_name.
ls_transport_object-object = iv_obj_type.
ls_transport_object-delflag = iv_delflag.
APPEND ls_transport_object TO mt_transport_objects.
ENDMETHOD.
METHOD given_the_object_status.
DATA ls_object_status TYPE zif_abapgit_definitions=>ty_result.
ls_object_status-obj_name = iv_obj_name.
ls_object_status-obj_type = iv_obj_type.
ls_object_status-filename = iv_filename.
ls_object_status-path = iv_path.
ls_object_status-lstate = iv_lstate.
APPEND ls_object_status TO mt_object_statuses.
ENDMETHOD.
METHOD given_the_local_file.
rs_local_file-item-obj_name = iv_obj_name.
rs_local_file-item-obj_type = iv_obj_type.
rs_local_file-file-filename = iv_filename.
rs_local_file-file-path = iv_path.
rs_local_file-file-data = iv_data.
APPEND rs_local_file TO ms_stage_objects-local.
ENDMETHOD.
METHOD when_staging.
CREATE OBJECT mo_transport_objects
EXPORTING
it_transport_objects = mt_transport_objects.
mo_transport_objects->to_stage(
io_stage = mo_stage
is_stage_objects = ms_stage_objects
it_object_statuses = mt_object_statuses ).
ENDMETHOD.
METHOD then_file_should_be_added.
DATA: lt_staged_objects TYPE zcl_abapgit_stage=>ty_stage_tt.
lt_staged_objects = mo_stage->get_all( ).
READ TABLE lt_staged_objects TRANSPORTING NO FIELDS
WITH KEY file-filename = is_local_file-file-filename
file-path = is_local_file-file-path
file-data = is_local_file-file-data
method = zcl_abapgit_stage=>c_method-add.
IF sy-subrc <> 0.
cl_abap_unit_assert=>fail( |Object { is_local_file-file-filename } not added to stage| ).
ENDIF.
ENDMETHOD.
METHOD then_it_should_raise_exception.
DATA: lo_exception TYPE REF TO zcx_abapgit_exception.
TRY.
when_staging( ).
cl_abap_unit_assert=>fail( 'Should have raised exception').
CATCH zcx_abapgit_exception INTO lo_exception.
cl_abap_unit_assert=>assert_equals(
act = lo_exception->text
exp = with_text ).
ENDTRY.
ENDMETHOD.
METHOD then_it_should_remove_at_stage.
DATA: lt_staged_objects TYPE zcl_abapgit_stage=>ty_stage_tt.
lt_staged_objects = mo_stage->get_all( ).
READ TABLE lt_staged_objects TRANSPORTING NO FIELDS
WITH KEY file-filename = iv_filename
file-path = iv_path.
IF sy-subrc <> 0.
cl_abap_unit_assert=>fail( |Object { iv_filename } not removed in stage| ).
ENDIF.
ENDMETHOD.
ENDCLASS.
* todo, include to be deleted

View File

@ -0,0 +1,169 @@
CLASS zcl_abapgit_http_client DEFINITION PUBLIC CREATE PUBLIC.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING ii_client TYPE REF TO if_http_client,
close,
set_digest
IMPORTING io_digest TYPE REF TO zcl_abapgit_http_digest,
send_receive_close
IMPORTING
iv_data TYPE xstring
RETURNING
VALUE(rv_data) TYPE xstring
RAISING zcx_abapgit_exception,
get_cdata
RETURNING VALUE(rv_value) TYPE string,
check_http_200
RAISING zcx_abapgit_exception,
send_receive
RAISING zcx_abapgit_exception,
set_headers
IMPORTING iv_url TYPE string
iv_service TYPE string
RAISING zcx_abapgit_exception.
PRIVATE SECTION.
DATA: mi_client TYPE REF TO if_http_client,
mo_digest TYPE REF TO zcl_abapgit_http_digest.
ENDCLASS.
CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
METHOD check_http_200.
DATA: lv_code TYPE i,
lv_text TYPE string.
mi_client->response->get_status(
IMPORTING
code = lv_code ).
CASE lv_code.
WHEN 200.
RETURN.
WHEN 302.
zcx_abapgit_exception=>raise( 'HTTP redirect, check URL' ).
WHEN 401.
zcx_abapgit_exception=>raise( 'HTTP 401, unauthorized' ).
WHEN 403.
zcx_abapgit_exception=>raise( 'HTTP 403, forbidden' ).
WHEN 404.
zcx_abapgit_exception=>raise( 'HTTP 404, not found' ).
WHEN 415.
zcx_abapgit_exception=>raise( 'HTTP 415, unsupported media type' ).
WHEN OTHERS.
lv_text = mi_client->response->get_cdata( ).
zcx_abapgit_exception=>raise( |HTTP error code: { lv_code }, { lv_text }| ).
ENDCASE.
ENDMETHOD. "http_200
METHOD close.
mi_client->close( ).
ENDMETHOD.
METHOD constructor.
mi_client = ii_client.
ENDMETHOD.
METHOD get_cdata.
rv_value = mi_client->response->get_cdata( ).
ENDMETHOD.
METHOD send_receive.
DATA: lv_text TYPE string,
lv_code TYPE i,
lv_message TYPE string.
mi_client->send( ).
mi_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4 ).
IF sy-subrc <> 0.
" in case of HTTP_COMMUNICATION_FAILURE
" make sure:
" a) SSL is setup properly in STRUST
" b) no firewalls
" check trace file in transaction SMICM
mi_client->get_last_error(
IMPORTING
code = lv_code
message = lv_message ).
lv_text = |HTTP error { lv_code } occured: { lv_message }|.
zcx_abapgit_exception=>raise( lv_text ).
ENDIF.
ENDMETHOD. "send_receive
METHOD send_receive_close.
* do not use set_cdata as it modifies the Content-Type header field
mi_client->request->set_data( iv_data ).
send_receive( ).
check_http_200( ).
rv_data = mi_client->response->get_data( ).
mi_client->close( ).
ENDMETHOD.
METHOD set_digest.
mo_digest = io_digest.
ENDMETHOD.
METHOD set_headers.
DATA: lv_value TYPE string.
mi_client->request->set_header_field(
name = '~request_method'
value = 'POST' ).
lv_value = zcl_abapgit_url=>path_name( iv_url ) &&
'/git-' &&
iv_service &&
'-pack'.
mi_client->request->set_header_field(
name = '~request_uri'
value = lv_value ).
lv_value = 'application/x-git-'
&& iv_service && '-pack-request'. "#EC NOTEXT
mi_client->request->set_header_field(
name = 'Content-Type'
value = lv_value ). "#EC NOTEXT
lv_value = 'application/x-git-'
&& iv_service && '-pack-result'. "#EC NOTEXT
mi_client->request->set_header_field(
name = 'Accept'
value = lv_value ). "#EC NOTEXT
IF mo_digest IS BOUND.
mo_digest->run( mi_client ).
ENDIF.
ENDMETHOD. "set_headers
ENDCLASS.

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_ABAPGIT_HTTP_CLIENT</CLSNAME>
<VERSION>1</VERSION>
<LANGU>E</LANGU>
<DESCRIPT>http client</DESCRIPT>
<EXPOSURE>2</EXPOSURE>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,66 @@
CLASS zcl_abapgit_skip_objects DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
METHODS:
skip_sadl_generated_objects
IMPORTING
it_tadir TYPE zif_abapgit_definitions=>ty_tadir_tt
io_log TYPE REF TO zcl_abapgit_log OPTIONAL
RETURNING
VALUE(rt_tadir) TYPE zif_abapgit_definitions=>ty_tadir_tt.
PRIVATE SECTION.
METHODS:
has_sadl_superclass
IMPORTING
is_class TYPE zif_abapgit_definitions=>ty_tadir
RETURNING
VALUE(rv_return) TYPE abap_bool.
ENDCLASS.
CLASS ZCL_ABAPGIT_SKIP_OBJECTS IMPLEMENTATION.
METHOD has_sadl_superclass.
DATA: lo_oo_functions TYPE REF TO zif_abapgit_oo_object_fnc,
lv_class_name TYPE seoclsname,
lv_superclass TYPE seoclsname.
lo_oo_functions = zcl_abapgit_oo_factory=>make( is_class-object ).
lv_class_name = is_class-obj_name.
lv_superclass = lo_oo_functions->read_superclass( lv_class_name ).
IF lv_superclass = 'CL_SADL_GTK_EXPOSURE_MPC'.
rv_return = abap_true.
ENDIF.
ENDMETHOD.
METHOD skip_sadl_generated_objects.
DATA: ls_tadir_class LIKE LINE OF rt_tadir,
ls_tadir LIKE LINE OF rt_tadir,
lt_lines_to_delete TYPE zif_abapgit_definitions=>ty_tadir_tt.
rt_tadir = it_tadir.
LOOP AT it_tadir INTO ls_tadir WHERE object = 'DDLS'.
LOOP AT rt_tadir INTO ls_tadir_class
WHERE object = 'CLAS' AND obj_name CS ls_tadir-obj_name.
IF has_sadl_superclass( ls_tadir_class ) = abap_true.
APPEND ls_tadir_class TO lt_lines_to_delete.
ENDIF.
ENDLOOP.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM lt_lines_to_delete.
LOOP AT lt_lines_to_delete INTO ls_tadir_class.
DELETE TABLE rt_tadir FROM ls_tadir_class.
IF io_log IS BOUND.
io_log->add(
iv_msg = |{ ls_tadir_class-obj_name } skipped: generated by SADL|
iv_type = 'W' ).
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_ABAPGIT_SKIP_OBJECTS</CLSNAME>
<VERSION>1</VERSION>
<LANGU>E</LANGU>
<DESCRIPT>Skip objects</DESCRIPT>
<EXPOSURE>2</EXPOSURE>
<STATE>1</STATE>
<CLSFINAL>X</CLSFINAL>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,83 @@
CLASS zcl_abapgit_transport_objects DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
METHODS constructor
IMPORTING
!it_transport_objects TYPE scts_tadir .
METHODS to_stage
IMPORTING
!io_stage TYPE REF TO zcl_abapgit_stage
!is_stage_objects TYPE zif_abapgit_definitions=>ty_stage_files
!it_object_statuses TYPE zif_abapgit_definitions=>ty_results_tt
RAISING
zcx_abapgit_exception .
PRIVATE SECTION.
DATA mt_transport_objects TYPE scts_tadir.
ENDCLASS.
CLASS ZCL_ABAPGIT_TRANSPORT_OBJECTS IMPLEMENTATION.
METHOD constructor.
mt_transport_objects = it_transport_objects.
ENDMETHOD.
METHOD to_stage.
DATA: ls_transport_object TYPE tadir,
ls_local_file TYPE zif_abapgit_definitions=>ty_file_item,
ls_object_status TYPE zif_abapgit_definitions=>ty_result.
LOOP AT mt_transport_objects INTO ls_transport_object.
LOOP AT it_object_statuses INTO ls_object_status
WHERE obj_name = ls_transport_object-obj_name
AND obj_type = ls_transport_object-object
AND NOT lstate IS INITIAL.
CASE ls_object_status-lstate.
WHEN zif_abapgit_definitions=>gc_state-added OR zif_abapgit_definitions=>gc_state-modified.
IF ls_transport_object-delflag = abap_true.
zcx_abapgit_exception=>raise( |Object { ls_transport_object-obj_name
} should be added/modified, but has deletion flag in transport| ).
ENDIF.
READ TABLE is_stage_objects-local
INTO ls_local_file
WITH KEY item-obj_name = ls_transport_object-obj_name
item-obj_type = ls_transport_object-object
file-filename = ls_object_status-filename.
IF sy-subrc <> 0.
zcx_abapgit_exception=>raise( |Object { ls_transport_object-obj_name
} not found in the local repository files| ).
ENDIF.
io_stage->add(
iv_path = ls_local_file-file-path
iv_filename = ls_local_file-file-filename
iv_data = ls_local_file-file-data ).
WHEN zif_abapgit_definitions=>gc_state-deleted.
IF ls_transport_object-delflag = abap_false.
zcx_abapgit_exception=>raise( |Object { ls_transport_object-obj_name
} should be removed, but has NO deletion flag in transport| ).
ENDIF.
io_stage->rm(
iv_path = ls_object_status-path
iv_filename = ls_object_status-filename ).
WHEN OTHERS.
ASSERT 0 = 1. "Unexpected state
ENDCASE.
ENDLOOP.
IF sy-subrc <> 0.
zcx_abapgit_exception=>raise( |Object { ls_transport_object-obj_name
} not found in the local repository files| ).
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.

View File

@ -0,0 +1,363 @@
CLASS ltcl_transport_objects DEFINITION FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS:
add_new_to_local_files FOR TESTING RAISING cx_static_check,
modified_to_new_local_files FOR TESTING RAISING cx_static_check,
transport_not_in_repository FOR TESTING RAISING cx_static_check,
object_not_in_local_files FOR TESTING RAISING cx_static_check,
cant_be_added_with_del_flag FOR TESTING RAISING cx_static_check,
cant_be_modified_with_del_flag FOR TESTING RAISING cx_static_check,
deleted_to_removed_files FOR TESTING RAISING cx_static_check,
shouldnt_remove_no_delflag FOR TESTING RAISING cx_static_check,
should_add_all_local_files FOR TESTING RAISING cx_static_check,
should_delete_all_related FOR TESTING RAISING cx_static_check,
setup,
given_the_transport_object
IMPORTING iv_obj_name TYPE string
iv_obj_type TYPE string
iv_delflag TYPE abap_bool OPTIONAL,
given_the_object_status
IMPORTING
iv_obj_name TYPE string OPTIONAL
iv_obj_type TYPE string OPTIONAL
iv_filename TYPE string OPTIONAL
iv_path TYPE string OPTIONAL
iv_lstate TYPE char1,
given_the_local_file
IMPORTING iv_obj_name TYPE string
iv_obj_type TYPE string
iv_filename TYPE string
iv_path TYPE string
iv_data TYPE string
RETURNING VALUE(rs_local_file) TYPE zif_abapgit_definitions=>ty_file_item,
when_staging
RAISING zcx_abapgit_exception,
then_file_should_be_added
IMPORTING
is_local_file TYPE zif_abapgit_definitions=>ty_file_item,
then_it_should_raise_exception
IMPORTING
with_text TYPE string,
then_it_should_remove_at_stage
IMPORTING
iv_filename TYPE string
iv_path TYPE string.
DATA: mo_transport_objects TYPE REF TO zcl_abapgit_transport_objects,
mt_transport_objects TYPE scts_tadir,
mt_object_statuses TYPE zif_abapgit_definitions=>ty_results_tt,
ms_stage_objects TYPE zif_abapgit_definitions=>ty_stage_files,
mo_stage TYPE REF TO zcl_abapgit_stage.
ENDCLASS. "ltcl_Transport_Objects
CLASS ltcl_transport_objects IMPLEMENTATION.
METHOD setup.
CREATE OBJECT mo_stage
EXPORTING
iv_branch_name = 'A_branch_name'
iv_branch_sha1 = 'Branch_SH1'.
ENDMETHOD.
METHOD add_new_to_local_files.
DATA ls_local_file TYPE zif_abapgit_definitions=>ty_file_item.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_lstate = zif_abapgit_definitions=>gc_state-added ).
ls_local_file = given_the_local_file(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/path'
iv_data = 'data' ).
when_staging( ).
then_file_should_be_added( ls_local_file ).
ENDMETHOD.
METHOD modified_to_new_local_files.
DATA ls_local_file TYPE zif_abapgit_definitions=>ty_file_item.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_lstate = zif_abapgit_definitions=>gc_state-modified ).
ls_local_file = given_the_local_file(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/path'
iv_data = 'data' ).
when_staging( ).
then_file_should_be_added( ls_local_file ).
ENDMETHOD.
METHOD should_add_all_local_files.
"Not only .abap, but also .xml and other includes
DATA ls_abap_local_file TYPE zif_abapgit_definitions=>ty_file_item.
DATA ls_xml_local_file TYPE zif_abapgit_definitions=>ty_file_item.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_lstate = zif_abapgit_definitions=>gc_state-modified ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.xml'
iv_lstate = zif_abapgit_definitions=>gc_state-modified ).
ls_abap_local_file = given_the_local_file(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/path'
iv_data = 'data' ).
ls_xml_local_file = given_the_local_file(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.xml'
iv_path = '/path'
iv_data = 'data' ).
when_staging( ).
then_file_should_be_added( ls_abap_local_file ).
then_file_should_be_added( ls_xml_local_file ).
ENDMETHOD.
METHOD transport_not_in_repository.
given_the_transport_object(
iv_obj_name = 'CL_A_CLASS_NOT_IN_REPO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_lstate = zif_abapgit_definitions=>gc_state-added ).
then_it_should_raise_exception(
with_text = 'Object CL_A_CLASS_NOT_IN_REPO not found in the local repository files' ).
ENDMETHOD.
METHOD object_not_in_local_files.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS' ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_lstate = zif_abapgit_definitions=>gc_state-added ).
given_the_local_file(
iv_obj_name = 'CL_ANOTHER_LOCAL_FILE'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/path'
iv_data = 'data' ).
then_it_should_raise_exception(
with_text = 'Object CL_FOO not found in the local repository files' ).
ENDMETHOD.
METHOD cant_be_added_with_del_flag.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_true ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_lstate = zif_abapgit_definitions=>gc_state-added ).
then_it_should_raise_exception(
with_text = 'Object CL_FOO should be added/modified, but has deletion flag in transport' ).
ENDMETHOD.
METHOD cant_be_modified_with_del_flag.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_true ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_lstate = zif_abapgit_definitions=>gc_state-modified ).
then_it_should_raise_exception(
with_text = 'Object CL_FOO should be added/modified, but has deletion flag in transport' ).
ENDMETHOD.
METHOD deleted_to_removed_files.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_true ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path'
iv_lstate = zif_abapgit_definitions=>gc_state-deleted ).
when_staging( ).
then_it_should_remove_at_stage(
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path' ).
ENDMETHOD.
METHOD should_delete_all_related.
"i.e. Should also delete the XMLs related to the transport objects
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_true ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path'
iv_lstate = zif_abapgit_definitions=>gc_state-deleted ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.xml'
iv_path = '/a_path'
iv_lstate = zif_abapgit_definitions=>gc_state-deleted ).
when_staging( ).
then_it_should_remove_at_stage(
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path' ).
then_it_should_remove_at_stage(
iv_filename = 'CL_FOO.xml'
iv_path = '/a_path' ).
ENDMETHOD.
METHOD shouldnt_remove_no_delflag.
given_the_transport_object(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_delflag = abap_false ).
given_the_object_status(
iv_obj_name = 'CL_FOO'
iv_obj_type = 'CLAS'
iv_filename = 'CL_FOO.abap'
iv_path = '/a_path'
iv_lstate = zif_abapgit_definitions=>gc_state-deleted ).
then_it_should_raise_exception(
with_text = 'Object CL_FOO should be removed, but has NO deletion flag in transport' ).
ENDMETHOD.
METHOD given_the_transport_object.
DATA ls_transport_object TYPE tadir.
ls_transport_object-obj_name = iv_obj_name.
ls_transport_object-object = iv_obj_type.
ls_transport_object-delflag = iv_delflag.
APPEND ls_transport_object TO mt_transport_objects.
ENDMETHOD.
METHOD given_the_object_status.
DATA ls_object_status TYPE zif_abapgit_definitions=>ty_result.
ls_object_status-obj_name = iv_obj_name.
ls_object_status-obj_type = iv_obj_type.
ls_object_status-filename = iv_filename.
ls_object_status-path = iv_path.
ls_object_status-lstate = iv_lstate.
APPEND ls_object_status TO mt_object_statuses.
ENDMETHOD.
METHOD given_the_local_file.
rs_local_file-item-obj_name = iv_obj_name.
rs_local_file-item-obj_type = iv_obj_type.
rs_local_file-file-filename = iv_filename.
rs_local_file-file-path = iv_path.
rs_local_file-file-data = iv_data.
APPEND rs_local_file TO ms_stage_objects-local.
ENDMETHOD.
METHOD when_staging.
CREATE OBJECT mo_transport_objects
EXPORTING
it_transport_objects = mt_transport_objects.
mo_transport_objects->to_stage(
io_stage = mo_stage
is_stage_objects = ms_stage_objects
it_object_statuses = mt_object_statuses ).
ENDMETHOD.
METHOD then_file_should_be_added.
DATA: lt_staged_objects TYPE zcl_abapgit_stage=>ty_stage_tt.
lt_staged_objects = mo_stage->get_all( ).
READ TABLE lt_staged_objects TRANSPORTING NO FIELDS
WITH KEY file-filename = is_local_file-file-filename
file-path = is_local_file-file-path
file-data = is_local_file-file-data
method = zcl_abapgit_stage=>c_method-add.
IF sy-subrc <> 0.
cl_abap_unit_assert=>fail( |Object { is_local_file-file-filename } not added to stage| ).
ENDIF.
ENDMETHOD.
METHOD then_it_should_raise_exception.
DATA: lo_exception TYPE REF TO zcx_abapgit_exception.
TRY.
when_staging( ).
cl_abap_unit_assert=>fail( 'Should have raised exception').
CATCH zcx_abapgit_exception INTO lo_exception.
cl_abap_unit_assert=>assert_equals(
act = lo_exception->text
exp = with_text ).
ENDTRY.
ENDMETHOD.
METHOD then_it_should_remove_at_stage.
DATA: lt_staged_objects TYPE zcl_abapgit_stage=>ty_stage_tt.
lt_staged_objects = mo_stage->get_all( ).
READ TABLE lt_staged_objects TRANSPORTING NO FIELDS
WITH KEY file-filename = iv_filename
file-path = iv_path.
IF sy-subrc <> 0.
cl_abap_unit_assert=>fail( |Object { iv_filename } not removed in stage| ).
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_ABAPGIT_TRANSPORT_OBJECTS</CLSNAME>
<VERSION>1</VERSION>
<LANGU>E</LANGU>
<DESCRIPT>Transport objects</DESCRIPT>
<EXPOSURE>2</EXPOSURE>
<STATE>1</STATE>
<CLSFINAL>X</CLSFINAL>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>