194 lines
7.1 KiB
ABAP
194 lines
7.1 KiB
ABAP
CLASS {{p}}svc_job_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
|
|
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
|
PRIVATE SECTION.
|
|
CLASS-DATA go_job TYPE REF TO cl_abap_structdescr.
|
|
CLASS-DATA go_base TYPE REF TO cl_abap_structdescr.
|
|
CLASS-DATA gt_job TYPE ddfields.
|
|
CLASS-DATA gt_base TYPE ddfields.
|
|
CLASS-METHODS class_setup.
|
|
METHODS assert_job_field
|
|
IMPORTING iv_index TYPE i
|
|
iv_name TYPE string
|
|
iv_type TYPE string
|
|
iv_leng TYPE i
|
|
iv_dec TYPE i.
|
|
METHODS assert_base_field
|
|
IMPORTING iv_index TYPE i
|
|
iv_name TYPE string
|
|
iv_type TYPE string
|
|
iv_leng TYPE i
|
|
iv_dec TYPE i.
|
|
METHODS structure_exists FOR TESTING.
|
|
METHODS base_structure_exists FOR TESTING.
|
|
METHODS component_order FOR TESTING.
|
|
METHODS base_component_order FOR TESTING.
|
|
METHODS base_created_by_type FOR TESTING.
|
|
METHODS base_created_on_type FOR TESTING.
|
|
METHODS char_fields FOR TESTING.
|
|
METHODS numeric_fields FOR TESTING.
|
|
METHODS date_fields FOR TESTING.
|
|
ENDCLASS.
|
|
|
|
|
|
CLASS {{p}}svc_job_hidden IMPLEMENTATION.
|
|
METHOD class_setup.
|
|
TRY.
|
|
go_job ?= cl_abap_typedescr=>describe_by_name( '{{P}}SVC_JOB' ).
|
|
gt_job = go_job->get_ddic_field_list( ).
|
|
CATCH cx_root.
|
|
CLEAR go_job.
|
|
CLEAR gt_job.
|
|
ENDTRY.
|
|
TRY.
|
|
go_base ?= cl_abap_typedescr=>describe_by_name( '{{P}}SVC_BASE' ).
|
|
gt_base = go_base->get_ddic_field_list( ).
|
|
CATCH cx_root.
|
|
CLEAR go_base.
|
|
CLEAR gt_base.
|
|
ENDTRY.
|
|
DELETE gt_job WHERE fieldname CP '.*'.
|
|
DELETE gt_base WHERE fieldname CP '.*'.
|
|
ENDMETHOD.
|
|
|
|
METHOD assert_job_field.
|
|
DATA ls_field TYPE dfies.
|
|
cl_abap_unit_assert=>assert_bound( act = go_job
|
|
msg = 'Structure {{P}}SVC_JOB is not available' ).
|
|
READ TABLE gt_job INTO ls_field INDEX iv_index.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_name
|
|
act = CONV string( ls_field-fieldname )
|
|
msg = |Wrong field name at position { iv_index } of SVC_JOB| ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_type
|
|
act = CONV string( ls_field-datatype )
|
|
msg = |Wrong data type of field { iv_name }| ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_leng
|
|
act = ls_field-leng
|
|
msg = |Wrong length of field { iv_name }| ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_dec
|
|
act = ls_field-decimals
|
|
msg = |Wrong number of decimals of field { iv_name }| ).
|
|
ENDMETHOD.
|
|
|
|
METHOD assert_base_field.
|
|
DATA ls_field TYPE dfies.
|
|
cl_abap_unit_assert=>assert_bound( act = go_base
|
|
msg = 'Structure {{P}}SVC_BASE is not available' ).
|
|
READ TABLE gt_base INTO ls_field INDEX iv_index.
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_name
|
|
act = CONV string( ls_field-fieldname )
|
|
msg = |Wrong field name at position { iv_index } of SVC_BASE| ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_type
|
|
act = CONV string( ls_field-datatype )
|
|
msg = |Wrong data type of base field { iv_name }| ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_leng
|
|
act = ls_field-leng
|
|
msg = |Wrong length of base field { iv_name }| ).
|
|
cl_abap_unit_assert=>assert_equals(
|
|
exp = iv_dec
|
|
act = ls_field-decimals
|
|
msg = |Wrong number of decimals of base field { iv_name }| ).
|
|
ENDMETHOD.
|
|
|
|
METHOD structure_exists.
|
|
DATA lo_descr TYPE REF TO cl_abap_typedescr.
|
|
TRY.
|
|
lo_descr = cl_abap_typedescr=>describe_by_name( '{{P}}SVC_JOB' ).
|
|
CATCH cx_root.
|
|
CLEAR lo_descr.
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_bound( act = lo_descr
|
|
msg = 'Structure {{P}}SVC_JOB does not exist' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD base_structure_exists.
|
|
DATA lo_descr TYPE REF TO cl_abap_typedescr.
|
|
TRY.
|
|
lo_descr = cl_abap_typedescr=>describe_by_name( '{{P}}SVC_BASE' ).
|
|
CATCH cx_root.
|
|
CLEAR lo_descr.
|
|
ENDTRY.
|
|
cl_abap_unit_assert=>assert_bound( act = lo_descr
|
|
msg = 'Structure {{P}}SVC_BASE does not exist' ).
|
|
ENDMETHOD.
|
|
|
|
METHOD component_order.
|
|
cl_abap_unit_assert=>assert_bound( act = go_job
|
|
msg = 'Structure {{P}}SVC_JOB is not available' ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 10 act = lines( gt_job )
|
|
msg = 'Structure {{P}}SVC_JOB must have exactly 10 fields' ).
|
|
assert_job_field( iv_index = 1 iv_name = `CREATED_BY` iv_type = `CHAR`
|
|
iv_leng = 12 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 2 iv_name = `CREATED_ON` iv_type = `DATS`
|
|
iv_leng = 8 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 3 iv_name = `JOB_ID` iv_type = `CHAR`
|
|
iv_leng = 10 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 4 iv_name = `WORK_HOURS` iv_type = `DEC`
|
|
iv_leng = 5 iv_dec = 2 ).
|
|
assert_job_field( iv_index = 5 iv_name = `CALC_MODE` iv_type = `CHAR`
|
|
iv_leng = 2 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 6 iv_name = `ORDER_REF` iv_type = `CHAR`
|
|
iv_leng = 12 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 7 iv_name = `SERVICE_DATE` iv_type = `DATS`
|
|
iv_leng = 8 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 8 iv_name = `PART_COUNT` iv_type = `INT4`
|
|
iv_leng = 10 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 9 iv_name = `GROUP_CODE` iv_type = `CHAR`
|
|
iv_leng = 4 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 10 iv_name = `NET_VALUE` iv_type = `DEC`
|
|
iv_leng = 13 iv_dec = 2 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD base_component_order.
|
|
cl_abap_unit_assert=>assert_bound( act = go_base
|
|
msg = 'Structure {{P}}SVC_BASE is not available' ).
|
|
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( gt_base )
|
|
msg = 'Structure {{P}}SVC_BASE must have exactly 2 fields' ).
|
|
assert_base_field( iv_index = 1 iv_name = `CREATED_BY` iv_type = `CHAR`
|
|
iv_leng = 12 iv_dec = 0 ).
|
|
assert_base_field( iv_index = 2 iv_name = `CREATED_ON` iv_type = `DATS`
|
|
iv_leng = 8 iv_dec = 0 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD base_created_by_type.
|
|
assert_base_field( iv_index = 1 iv_name = `CREATED_BY` iv_type = `CHAR`
|
|
iv_leng = 12 iv_dec = 0 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD base_created_on_type.
|
|
assert_base_field( iv_index = 2 iv_name = `CREATED_ON` iv_type = `DATS`
|
|
iv_leng = 8 iv_dec = 0 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD char_fields.
|
|
assert_job_field( iv_index = 3 iv_name = `JOB_ID` iv_type = `CHAR`
|
|
iv_leng = 10 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 5 iv_name = `CALC_MODE` iv_type = `CHAR`
|
|
iv_leng = 2 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 6 iv_name = `ORDER_REF` iv_type = `CHAR`
|
|
iv_leng = 12 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 9 iv_name = `GROUP_CODE` iv_type = `CHAR`
|
|
iv_leng = 4 iv_dec = 0 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD numeric_fields.
|
|
assert_job_field( iv_index = 4 iv_name = `WORK_HOURS` iv_type = `DEC`
|
|
iv_leng = 5 iv_dec = 2 ).
|
|
assert_job_field( iv_index = 8 iv_name = `PART_COUNT` iv_type = `INT4`
|
|
iv_leng = 10 iv_dec = 0 ).
|
|
assert_job_field( iv_index = 10 iv_name = `NET_VALUE` iv_type = `DEC`
|
|
iv_leng = 13 iv_dec = 2 ).
|
|
ENDMETHOD.
|
|
|
|
METHOD date_fields.
|
|
assert_job_field( iv_index = 7 iv_name = `SERVICE_DATE` iv_type = `DATS`
|
|
iv_leng = 8 iv_dec = 0 ).
|
|
ENDMETHOD.
|
|
ENDCLASS.
|