
Data provider classes are enabled for unit tests. A data provider (specialization of /IWBEP/CL_MGW_ABS_DATA) requires the request context (a realization of the /IWBEP/IF_MGW_REQ_X interfaces) to be initialized in order to receive the information provided through the consumer request.
An implementation of the request context is available with /IWBEP/CL_MGW_REQUEST_UNITTST which is a subclass of /IWBEP/CL_MGW_REQUEST. The new request context is exposed in the package interface /IWBEP/MGW_GSR_CORE_CNT, hence is accessible for the data provider classes (DPCs). In addition, the new method INIT_DP_FOR_UNIT_TEST has been added to the interface /IWBEP/IF_MGW_CONV_SRV_RUNTIME. This method is used to initialize a data provider instance for the usage in a unit test.
The implementation of the request context can only be used within the unit test, not during usual processing through the SAP NetWeaver Gateway runtime.
data: mo_request_context_object type ref to /iwbep/cl_mgw_request_unittst.
data: ms_request_context_struct type /iwbep/cl_mgw_request_unittst=>ty_s_mgw_request_context_unit.
data: mo_data_provider type ref to <your DPC>.
method setup. * instantiate the Data Provider create object mo_data_provider .
ms_request_context_struct-technical_request-source_entity_type = 'Manager'. ms_request_context_struct-technical_request-target_entity_type = 'Manager'. ms_request_context_struct-technical_request-source_entity_set = 'Managers'. ms_request_context_struct-technical_request-target_entity_set = 'Managers'.
DATA: lo_filter TYPE REF TO /iwbep/if_mgw_req_filter. DATA: ls_converted_keys TYPE REF TO data. DATA: ls_converted_parameters TYPE REF TO data. ms_request_context_struct-technical_request-converted_keys = ls_converted_keys. ms_request_context_struct-technical_request-conv_action_parameters = ls_converted_parameters. ms_request_context_struct-technical_request-filter_object = lo_filter .
mo_request_context_object = mo_data_provider->/iwbep/if_mgw_conv_srv_runtime~init_dp_for_unit_test ( is_request_context = ms_request_context_struct ).
try .
so_data_provider->/iwbep/if_mgw_appl_srv_runtime~get_entityset(
exporting
io_tech_request_context = so_request_context_object
importing
er_entityset = lr_data
es_response_context = ls_response_context
).
catch /iwbep/cx_mgw_busi_exception.
catch /iwbep/cx_mgw_tech_exception.
endtry.
cl_aunit_assert=>assert_not_initial( act = lr_data ).
You can find an example unit test created for the data provider class /IWBEP/CL_TEA_DATA_PROVIDER in the system.