Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1abee71
commit f2d9347
Showing
12 changed files
with
476 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,57 @@ | ||
CLASS LHC_SPEAKER DEFINITION INHERITING FROM CL_ABAP_BEHAVIOR_HANDLER. | ||
"! Local Test Class for Speaker entity | ||
CLASS ltc_speaker DEFINITION DEFERRED FOR TESTING. | ||
CLASS lhc_speaker DEFINITION INHERITING FROM cl_abap_behavior_handler FRIENDS ltc_speaker. | ||
PRIVATE SECTION. | ||
METHODS: | ||
CALCULATESPEAKERUUID FOR DETERMINE ON SAVE | ||
IMPORTING | ||
KEYS FOR Speaker~CalculateSpeakerUUID . | ||
METHODS calculatespeakeruuid FOR DETERMINE ON SAVE | ||
IMPORTING | ||
keys FOR Speaker~CalculateSpeakerUUID. | ||
|
||
METHODS autoTwitterHandle FOR DETERMINE ON MODIFY | ||
IMPORTING keys FOR Speaker~autoTwitterHandle. | ||
ENDCLASS. | ||
|
||
CLASS LHC_SPEAKER IMPLEMENTATION. | ||
METHOD CALCULATESPEAKERUUID. | ||
|
||
CLASS lhc_speaker IMPLEMENTATION. | ||
METHOD calculatespeakeruuid. | ||
ENDMETHOD. | ||
|
||
METHOD autoTwitterHandle. | ||
DATA twitter_handle TYPE ze_abapconf_speaker_socialmed. | ||
|
||
" Read travel instances of the transferred keys | ||
READ ENTITIES OF zr_ac_sessiontp IN LOCAL MODE | ||
ENTITY Speaker | ||
FIELDS ( speakerwebpage socialmed ) | ||
WITH CORRESPONDING #( keys ) | ||
RESULT DATA(speakers) | ||
" TODO: variable is assigned but never used (ABAP cleaner) | ||
FAILED DATA(read_failed). | ||
|
||
" Check if Social Media Handle is already set | ||
DELETE speakers WHERE Socialmed IS NOT INITIAL. | ||
IF speakers IS INITIAL. | ||
RETURN. | ||
ENDIF. | ||
|
||
LOOP AT speakers INTO DATA(speaker). | ||
|
||
" Check if Webpage is a Twitter Profile | ||
IF speaker-SpeakerWebpage CA 'twitter.com/'. | ||
|
||
twitter_handle = |@{ match( val = speaker-SpeakerWebpage | ||
regex = '([^\/]+$)' ) }|. | ||
MODIFY ENTITIES OF zr_ac_sessiontp IN LOCAL MODE | ||
ENTITY Speaker | ||
UPDATE SET FIELDS | ||
WITH VALUE #( ( %tky = speaker-%tky Socialmed = twitter_handle ) ) | ||
REPORTED DATA(update_reported). | ||
|
||
" Set the changing parameter | ||
reported = CORRESPONDING #( DEEP update_reported ). | ||
|
||
ENDIF. | ||
|
||
ENDLOOP. | ||
|
||
ENDMETHOD. | ||
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
CLASS ltc_speaker DEFINITION FINAL FOR TESTING | ||
DURATION SHORT | ||
RISK LEVEL HARMLESS. | ||
|
||
PRIVATE SECTION. | ||
CLASS-DATA: class_under_test TYPE REF TO lhc_speaker, | ||
cds_test_environment TYPE REF TO if_cds_test_environment. | ||
|
||
CLASS-METHODS: | ||
"! Instantiate class under test and setup test double frameworks | ||
class_setup, | ||
|
||
"! Destroy test environments and test doubles | ||
class_teardown. | ||
|
||
METHODS: | ||
"! Reset test doubles | ||
setup, | ||
|
||
"! Reset transactional buffer | ||
teardown, | ||
|
||
"! Test Auto Twitter Handle | ||
autoTwitterHandle FOR TESTING. | ||
|
||
ENDCLASS. | ||
|
||
CLASS ltc_speaker IMPLEMENTATION. | ||
|
||
METHOD class_setup. | ||
CREATE OBJECT class_under_test FOR TESTING. | ||
cds_test_environment = cl_cds_test_environment=>create_for_multiple_cds( | ||
i_for_entities = VALUE #( ( i_for_entity = 'ZR_AC_SeSSIONTP' ) | ||
( i_for_entity = 'ZR_AC_SPEAKERTP' ) ) | ||
). | ||
ENDMETHOD. | ||
|
||
METHOD setup. | ||
cds_test_environment->clear_doubles( ). | ||
ENDMETHOD. | ||
|
||
METHOD teardown. | ||
ROLLBACK ENTITIES. | ||
ENDMETHOD. | ||
|
||
METHOD class_teardown. | ||
cds_test_environment->destroy( ). | ||
ENDMETHOD. | ||
|
||
METHOD autotwitterhandle. | ||
" Fill in test data | ||
DATA speaker_mock_data TYPE STANDARD TABLE OF zzt_ac_speaker. | ||
|
||
DATA(speaker_uuid) = cl_system_uuid=>if_system_uuid_static~create_uuid_x16( ). | ||
speaker_mock_data = VALUE #( ( speaker_uuid = speaker_uuid speaker_webpage = 'twitter.com/wachtersascha' ) ). | ||
cds_test_environment->insert_test_data( speaker_mock_data ). | ||
|
||
" Declare required table and structures | ||
DATA reported TYPE RESPONSE FOR REPORTED LATE zr_ac_sessiontp. | ||
|
||
" Call the method to be tested | ||
class_under_test->autotwitterhandle( | ||
EXPORTING keys = CORRESPONDING #( speaker_mock_data MAPPING SpeakerUUID = speaker_uuid ) | ||
CHANGING reported = reported ). | ||
|
||
" Check for content in reported | ||
cl_abap_unit_assert=>assert_initial( msg = 'reported' act = reported ). | ||
|
||
READ ENTITIES OF zr_ac_sessiontp IN LOCAL MODE | ||
ENTITY Speaker | ||
FIELDS ( socialmed ) | ||
WITH VALUE #( ( SpeakerUUID = speaker_uuid ) ) | ||
RESULT DATA(speakers) | ||
" TODO: variable is assigned but never used (ABAP cleaner) | ||
FAILED DATA(read_failed). | ||
|
||
cl_abap_unit_assert=>assert_equals( msg = 'action result' exp = '@wachtersascha' act = speakers[ 1 ]-Socialmed ). | ||
ENDMETHOD. | ||
|
||
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.