Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
104 lines
4.1 KiB
ABAP
104 lines
4.1 KiB
ABAP
CLASS {{p}}t20_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
CLASS-DATA go_env TYPE REF TO if_cds_test_environment.
|
|
CLASS-METHODS class_setup.
|
|
CLASS-METHODS class_teardown.
|
|
METHODS setup.
|
|
METHODS one_row_per_play FOR TESTING.
|
|
METHODS performance_count FOR TESTING.
|
|
METHODS total_tickets FOR TESTING.
|
|
METHODS total_revenue FOR TESTING.
|
|
METHODS play_without_perf FOR TESTING.
|
|
METHODS title_shown FOR TESTING.
|
|
METHODS single_performance FOR TESTING.
|
|
METHODS decimals FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t20_hidden IMPLEMENTATION.
|
|
METHOD class_setup.
|
|
go_env = cl_cds_test_environment=>create( i_for_entity = '{{P}}I_PLAY_STATS' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD class_teardown.
|
|
go_env->destroy( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD setup.
|
|
DATA lt_play TYPE STANDARD TABLE OF {{p}}play WITH EMPTY KEY.
|
|
DATA lt_perf TYPE STANDARD TABLE OF {{p}}perf WITH EMPTY KEY.
|
|
go_env->clear_doubles( ).
|
|
lt_play = VALUE #( ( play_id = 'P1' title = 'HAMLET' genre = 'DRAMA' director = 'A' )
|
|
( play_id = 'P2' title = 'CARMEN' genre = 'OPERA' director = 'B' )
|
|
( play_id = 'P3' title = 'ROMEO' genre = 'DRAMA' director = 'C' )
|
|
( play_id = 'P4' title = 'TOSCA' genre = 'OPERA' director = 'D' ) ).
|
|
lt_perf = VALUE #( ( play_id = 'P1' perf_no = 1 tickets_sold = 100 revenue = '1000.00' )
|
|
( play_id = 'P1' perf_no = 2 tickets_sold = 150 revenue = '1500.00' )
|
|
( play_id = 'P1' perf_no = 3 tickets_sold = 50 revenue = '500.00' )
|
|
( play_id = 'P2' perf_no = 1 tickets_sold = 200 revenue = '4000.00' )
|
|
( play_id = 'P4' perf_no = 1 tickets_sold = 10 revenue = '10.10' )
|
|
( play_id = 'P4' perf_no = 2 tickets_sold = 1 revenue = '0.05' ) ).
|
|
go_env->insert_test_data( lt_play ).
|
|
go_env->insert_test_data( lt_perf ).
|
|
ENDMETHOD.
|
|
|
|
METHOD one_row_per_play.
|
|
SELECT COUNT(*) FROM {{p}}i_play_stats INTO @DATA(lv_rows).
|
|
cl_abap_unit_assert=>assert_equals( exp = 3 act = lv_rows ).
|
|
ENDMETHOD.
|
|
|
|
METHOD performance_count.
|
|
SELECT SINGLE performance_count FROM {{p}}i_play_stats
|
|
WHERE play_id = 'P1' INTO @DATA(lv_count).
|
|
cl_abap_unit_assert=>assert_equals( exp = 3 act = lv_count ).
|
|
ENDMETHOD.
|
|
|
|
METHOD total_tickets.
|
|
SELECT SINGLE total_tickets FROM {{p}}i_play_stats
|
|
WHERE play_id = 'P1' INTO @DATA(lv_tickets).
|
|
cl_abap_unit_assert=>assert_equals( exp = 300 act = lv_tickets ).
|
|
ENDMETHOD.
|
|
|
|
METHOD total_revenue.
|
|
SELECT SINGLE total_revenue FROM {{p}}i_play_stats
|
|
WHERE play_id = 'P1' INTO @DATA(lv_revenue).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = CONV decfloat34( '3000.00' )
|
|
act = CONV decfloat34( lv_revenue ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD play_without_perf.
|
|
SELECT COUNT(*) FROM {{p}}i_play_stats
|
|
WHERE play_id = 'P3' INTO @DATA(lv_rows).
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = lv_rows ).
|
|
ENDMETHOD.
|
|
|
|
METHOD title_shown.
|
|
SELECT SINGLE title FROM {{p}}i_play_stats
|
|
WHERE play_id = 'P1' INTO @DATA(lv_title).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'HAMLET' act = lv_title ).
|
|
ENDMETHOD.
|
|
|
|
METHOD single_performance.
|
|
SELECT SINGLE performance_count, total_tickets, total_revenue
|
|
FROM {{p}}i_play_stats
|
|
WHERE play_id = 'P2' INTO @DATA(ls_row).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = ls_row-performance_count ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 200 act = ls_row-total_tickets ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = CONV decfloat34( '4000.00' )
|
|
act = CONV decfloat34( ls_row-total_revenue ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD decimals.
|
|
SELECT SINGLE total_tickets, total_revenue
|
|
FROM {{p}}i_play_stats
|
|
WHERE play_id = 'P4' INTO @DATA(ls_row).
|
|
cl_abap_unit_assert=>assert_equals( exp = 11 act = ls_row-total_tickets ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = CONV decfloat34( '10.15' )
|
|
act = CONV decfloat34( ls_row-total_revenue ) ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|