148 lines
6.9 KiB
ABAP
148 lines
6.9 KiB
ABAP
CLASS {{p}}t16_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
|
|
PRIVATE SECTION.
|
|
CLASS-DATA gt_fields TYPE ddfields.
|
|
CLASS-DATA go_env TYPE REF TO if_osql_test_environment.
|
|
|
|
CLASS-METHODS class_setup.
|
|
CLASS-METHODS class_teardown.
|
|
METHODS setup.
|
|
|
|
METHODS all_fields_present FOR TESTING.
|
|
METHODS key_fields FOR TESTING.
|
|
METHODS text_lengths FOR TESTING.
|
|
METHODS date_and_count_types FOR TESTING.
|
|
METHODS rate_decimals FOR TESTING.
|
|
METHODS insert_and_read FOR TESTING.
|
|
METHODS multiple_rows_stored FOR TESTING.
|
|
METHODS numc_keeps_leading_zeros FOR TESTING.
|
|
|
|
CLASS-METHODS get_field
|
|
IMPORTING iv_name TYPE fieldname
|
|
RETURNING VALUE(rs_field) TYPE dfies.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t16_hidden IMPLEMENTATION.
|
|
|
|
METHOD class_setup.
|
|
DATA(lo_struct) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_name( '{{P}}PITCH' ) ).
|
|
gt_fields = lo_struct->get_ddic_field_list( ).
|
|
go_env = cl_osql_test_environment=>create( i_dependency_list = VALUE #( ( '{{P}}PITCH' ) ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD class_teardown.
|
|
IF go_env IS BOUND.
|
|
go_env->destroy( ).
|
|
ENDIF.
|
|
ENDMETHOD.
|
|
|
|
METHOD setup.
|
|
go_env->clear_doubles( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD get_field.
|
|
READ TABLE gt_fields INTO rs_field WITH KEY fieldname = iv_name.
|
|
cl_abap_unit_assert=>assert_equals( exp = 0 act = sy-subrc
|
|
msg = |Field { iv_name } is missing| ).
|
|
ENDMETHOD.
|
|
|
|
METHOD all_fields_present.
|
|
cl_abap_unit_assert=>assert_equals( exp = 9 act = lines( gt_fields ) ).
|
|
get_field( 'CLIENT' ).
|
|
get_field( 'BOOKING_ID' ).
|
|
get_field( 'PITCH_NO' ).
|
|
get_field( 'GUEST_NAME' ).
|
|
get_field( 'ARRIVAL_DATE' ).
|
|
get_field( 'DEPARTURE_DATE' ).
|
|
get_field( 'PERSONS' ).
|
|
get_field( 'POWER_HOOKUP' ).
|
|
get_field( 'RATE_PER_NIGHT' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD key_fields.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'X' act = get_field( 'CLIENT' )-keyflag ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'X' act = get_field( 'BOOKING_ID' )-keyflag ).
|
|
cl_abap_unit_assert=>assert_equals( exp = ' ' act = get_field( 'PITCH_NO' )-keyflag ).
|
|
cl_abap_unit_assert=>assert_equals( exp = ' ' act = get_field( 'GUEST_NAME' )-keyflag ).
|
|
cl_abap_unit_assert=>assert_equals( exp = ' ' act = get_field( 'ARRIVAL_DATE' )-keyflag ).
|
|
cl_abap_unit_assert=>assert_equals( exp = ' ' act = get_field( 'DEPARTURE_DATE' )-keyflag ).
|
|
cl_abap_unit_assert=>assert_equals( exp = ' ' act = get_field( 'PERSONS' )-keyflag ).
|
|
cl_abap_unit_assert=>assert_equals( exp = ' ' act = get_field( 'POWER_HOOKUP' )-keyflag ).
|
|
cl_abap_unit_assert=>assert_equals( exp = ' ' act = get_field( 'RATE_PER_NIGHT' )-keyflag ).
|
|
ENDMETHOD.
|
|
|
|
METHOD text_lengths.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'C' act = get_field( 'CLIENT' )-inttype ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 3 act = get_field( 'CLIENT' )-leng ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'C' act = get_field( 'BOOKING_ID' )-inttype ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 10 act = get_field( 'BOOKING_ID' )-leng ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'N' act = get_field( 'PITCH_NO' )-inttype ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 4 act = get_field( 'PITCH_NO' )-leng ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'C' act = get_field( 'GUEST_NAME' )-inttype ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 30 act = get_field( 'GUEST_NAME' )-leng ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'C' act = get_field( 'POWER_HOOKUP' )-inttype ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = get_field( 'POWER_HOOKUP' )-leng ).
|
|
ENDMETHOD.
|
|
|
|
METHOD date_and_count_types.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'D' act = get_field( 'ARRIVAL_DATE' )-inttype ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 8 act = get_field( 'ARRIVAL_DATE' )-leng ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'D' act = get_field( 'DEPARTURE_DATE' )-inttype ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 8 act = get_field( 'DEPARTURE_DATE' )-leng ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'I' act = get_field( 'PERSONS' )-inttype ).
|
|
ENDMETHOD.
|
|
|
|
METHOD rate_decimals.
|
|
cl_abap_unit_assert=>assert_equals( exp = 'P' act = get_field( 'RATE_PER_NIGHT' )-inttype ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 9 act = get_field( 'RATE_PER_NIGHT' )-leng ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = get_field( 'RATE_PER_NIGHT' )-decimals ).
|
|
ENDMETHOD.
|
|
|
|
METHOD insert_and_read.
|
|
DATA lt_rows TYPE STANDARD TABLE OF {{p}}pitch WITH EMPTY KEY.
|
|
lt_rows = VALUE #(
|
|
( client = sy-mandt booking_id = 'B0001' pitch_no = '0001' guest_name = 'MUELLER'
|
|
arrival_date = '20250601' departure_date = '20250608' persons = 4
|
|
power_hookup = 'X' rate_per_night = '12.50' ) ).
|
|
INSERT {{p}}pitch FROM TABLE @lt_rows.
|
|
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
|
SELECT SINGLE guest_name, pitch_no, persons, power_hookup, departure_date, rate_per_night
|
|
FROM {{p}}pitch WHERE booking_id = 'B0001' INTO @DATA(ls_row).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'MUELLER' act = ls_row-guest_name ).
|
|
cl_abap_unit_assert=>assert_equals( exp = '0001' act = ls_row-pitch_no ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 4 act = ls_row-persons ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 'X' act = ls_row-power_hookup ).
|
|
cl_abap_unit_assert=>assert_equals( exp = '20250608' act = ls_row-departure_date ).
|
|
cl_abap_unit_assert=>assert_equals( exp = CONV decfloat34( '12.50' )
|
|
act = CONV decfloat34( ls_row-rate_per_night ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD multiple_rows_stored.
|
|
DATA lt_rows TYPE STANDARD TABLE OF {{p}}pitch WITH EMPTY KEY.
|
|
lt_rows = VALUE #(
|
|
( client = sy-mandt booking_id = 'C0001' pitch_no = '0003' arrival_date = '20250601'
|
|
departure_date = '20250602' persons = 1 rate_per_night = '9.00' )
|
|
( client = sy-mandt booking_id = 'C0002' pitch_no = '0004' arrival_date = '20250601'
|
|
departure_date = '20250602' persons = 2 rate_per_night = '9.00' )
|
|
( client = sy-mandt booking_id = 'C0003' pitch_no = '0005' arrival_date = '20250601'
|
|
departure_date = '20250602' persons = 3 rate_per_night = '9.00' ) ).
|
|
INSERT {{p}}pitch FROM TABLE @lt_rows.
|
|
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
|
SELECT COUNT(*) FROM {{p}}pitch INTO @DATA(lv_count).
|
|
cl_abap_unit_assert=>assert_equals( exp = 3 act = lv_count ).
|
|
ENDMETHOD.
|
|
|
|
METHOD numc_keeps_leading_zeros.
|
|
DATA lt_rows TYPE STANDARD TABLE OF {{p}}pitch WITH EMPTY KEY.
|
|
lt_rows = VALUE #(
|
|
( client = sy-mandt booking_id = 'D0001' pitch_no = '0123' arrival_date = '20250601'
|
|
departure_date = '20250602' persons = 2 rate_per_night = '10.00' ) ).
|
|
INSERT {{p}}pitch FROM TABLE @lt_rows.
|
|
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
|
SELECT SINGLE pitch_no FROM {{p}}pitch WHERE booking_id = 'D0001' INTO @DATA(lv_pitch).
|
|
cl_abap_unit_assert=>assert_equals( exp = '0123' act = lv_pitch ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|