121 lines
3.7 KiB
ABAP
121 lines
3.7 KiB
ABAP
CLASS {{p}}t41_test DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
|
|
PRIVATE SECTION.
|
|
METHODS setup.
|
|
METHODS teardown.
|
|
METHODS insert_dishes.
|
|
METHODS insert_positions
|
|
IMPORTING it_positions TYPE STANDARD TABLE OF {{p}}pos.
|
|
METHODS fee_for
|
|
IMPORTING iv_order_id TYPE string
|
|
RETURNING VALUE(rv_total) TYPE decfloat34.
|
|
|
|
METHODS total_of_order FOR TESTING.
|
|
METHODS distinct_dishes FOR TESTING.
|
|
METHODS discount_from_fifty FOR TESTING.
|
|
METHODS empty_order FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}t41_test IMPLEMENTATION.
|
|
|
|
METHOD setup.
|
|
DELETE FROM {{p}}pos WHERE client = @sy-mandt.
|
|
DELETE FROM {{p}}dish WHERE client = @sy-mandt.
|
|
insert_dishes( ).
|
|
ENDMETHOD.
|
|
|
|
METHOD teardown.
|
|
DELETE FROM {{p}}pos WHERE client = @sy-mandt.
|
|
DELETE FROM {{p}}dish WHERE client = @sy-mandt.
|
|
ENDMETHOD.
|
|
|
|
METHOD insert_dishes.
|
|
DATA lt_dishes TYPE STANDARD TABLE OF {{p}}dish.
|
|
lt_dishes = VALUE #(
|
|
( client = sy-mandt dish_id = 'D001' dish_name = 'Tomato soup' price = '4.50' )
|
|
( client = sy-mandt dish_id = 'D002' dish_name = 'Roast beef' price = '18.00' )
|
|
( client = sy-mandt dish_id = 'D003' dish_name = 'Apple pie' price = '5.25' )
|
|
( client = sy-mandt dish_id = 'D004' dish_name = 'Sparkling water' price = '2.00' )
|
|
( client = sy-mandt dish_id = 'D005' dish_name = 'Bread basket' price = '2.05' )
|
|
).
|
|
INSERT {{p}}dish FROM TABLE @lt_dishes.
|
|
ENDMETHOD.
|
|
|
|
METHOD insert_positions.
|
|
INSERT {{p}}pos FROM TABLE @it_positions.
|
|
ENDMETHOD.
|
|
|
|
METHOD fee_for.
|
|
CALL FUNCTION '{{P}}BANQUET_FEE'
|
|
EXPORTING
|
|
iv_order_id = iv_order_id
|
|
IMPORTING
|
|
ev_total = rv_total
|
|
EXCEPTIONS
|
|
OTHERS = 1.
|
|
|
|
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD total_of_order.
|
|
DATA lt_positions TYPE STANDARD TABLE OF {{p}}pos.
|
|
lt_positions = VALUE #(
|
|
( client = sy-mandt order_id = 'T41A' pos_no = 1 dish_id = 'D001' qty = 2 )
|
|
( client = sy-mandt order_id = 'T41A' pos_no = 2 dish_id = 'D002' qty = 1 ) ).
|
|
insert_positions( lt_positions ).
|
|
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = CONV decfloat34( '27.00' )
|
|
act = fee_for( 'T41A' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD distinct_dishes.
|
|
DATA lt_positions TYPE STANDARD TABLE OF {{p}}pos.
|
|
lt_positions = VALUE #(
|
|
( client = sy-mandt order_id = 'T41A' pos_no = 1 dish_id = 'D001' qty = 2 )
|
|
( client = sy-mandt order_id = 'T41A' pos_no = 2 dish_id = 'D001' qty = 3 )
|
|
( client = sy-mandt order_id = 'T41A' pos_no = 3 dish_id = 'D003' qty = 1 ) ).
|
|
insert_positions( lt_positions ).
|
|
|
|
DATA lv_dishes TYPE i.
|
|
CALL FUNCTION '{{P}}BANQUET_FEE'
|
|
EXPORTING
|
|
iv_order_id = 'T41A'
|
|
IMPORTING
|
|
ev_dishes = lv_dishes
|
|
EXCEPTIONS
|
|
OTHERS = 1.
|
|
|
|
cl_abap_unit_assert=>assert_subrc( exp = 0 ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lv_dishes ).
|
|
ENDMETHOD.
|
|
|
|
METHOD discount_from_fifty.
|
|
DATA lt_positions TYPE STANDARD TABLE OF {{p}}pos.
|
|
lt_positions = VALUE #(
|
|
( client = sy-mandt order_id = 'T41A' pos_no = 1 dish_id = 'D004' qty = 49 )
|
|
( client = sy-mandt order_id = 'T41A' pos_no = 2 dish_id = 'D005' qty = 1 ) ).
|
|
insert_positions( lt_positions ).
|
|
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = CONV decfloat34( '95.05' )
|
|
act = fee_for( 'T41A' ) ).
|
|
ENDMETHOD.
|
|
|
|
METHOD empty_order.
|
|
DATA lv_total TYPE decfloat34.
|
|
CALL FUNCTION '{{P}}BANQUET_FEE'
|
|
EXPORTING
|
|
iv_order_id = 'T41Z'
|
|
IMPORTING
|
|
ev_total = lv_total
|
|
EXCEPTIONS
|
|
no_positions = 1
|
|
OTHERS = 2.
|
|
|
|
cl_abap_unit_assert=>assert_equals( exp = 1 act = sy-subrc ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|