SAP CL_CRM_BOL_ENTITY单元测试方法 CRMSAPSAP云平台SAP Cloud PlatformSAP成都研究院
In SAP standard development it is very important to use unit test to cover those changes on legacy code to try to avoid side effect. As type reference CL_CRM_BOL_ENTITY is widely used in UI component code, I would like to find a way to construct its reference by sample data.
The normal way we get instance of CL_CRM_BOL_ENTITY is, to use query or dquery method provided in class CL_CRM_BOL_CORE, which return a BOL collection list and then we can get each bol entity from by iterating that collection. However, both of these methods will perform database scan and return found data – such behavior is not appropriate for unit test. I have gone through all public methods in CL_CRM_BOL_CORE and do not find a useful method to construct bol entity based on sample data, so I write a small piece of code:
I create a class which inherits CL_CRM_BOL_ENTITY:
Create a static private attribute:
And initialize it in class_constructor:
METHOD class_constructor.
so_bol_core = cl_crm_bol_core=>get_instance( ).
so_bol_core->load_component_set( 'PROD_ALL' ).
ENDMETHOD.
The signature and source code are listed below:
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PROD_UNIT_TEST_TOOL=>GET_FAKE_BOL_ENTITY
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_DATA TYPE ANY
* | [--->] IV_BOL_NAME TYPE CRMT_EXT_OBJ_NAME
* | [--->] IV_KEY TYPE CRMT_OBJECT_GUID
* | [<-()] RO_RESULT TYPE REF TO CL_CRM_BOL_ENTITY
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_fake_bol_entity.
DATA: lr_cast TYPE REF TO cl_crm_genil_container_object,
lr_entity TYPE REF TO crmt_bol_entity_line.
DATA(lv_root_list) = cl_crm_genil_container_tools=>get_new_cont_root_list( ).
DATA(lr_root_object) = lv_root_list->add_object(
iv_object_name = iv_bol_name
is_object_key = iv_key
iv_attr_req = abap_false ).
lr_root_object->set_attributes( is_data ).
lr_cast ?= lr_root_object.
CREATE DATA lr_entity.
lr_entity->instance = lr_cast->data_ref->instance.
ro_result = NEW cl_crm_bol_entity( iv_cont_proxy = lr_cast
iv_manager_entry = lr_entity ).
ENDMETHOD.
And below is an example how to construct BOL entity using this utility method:
CONSTANTS: cv_prod_guid TYPE crmt_object_guid VALUE '0123456789123456'.
DATA(ls_prod_header) = VALUE comt_product_ui( product_guid = cv_prod_guid
product_id = 'I042416' product_type = '01' ).
DATA(ro_entity) = zcl_prod_unit_test_tool=>get_fake_bol_entity(
iv_bol_name = 'Product'
is_data = ls_prod_header
iv_key = cv_prod_guid ).
DATA(lv_type) = ro_entity->get_property_as_string( 'PRODUCT_TYPE' ).
DATA(lv_guid) = ro_entity->get_property_as_string( 'PRODUCT_GUID' ).
DATA(lv_id) = ro_entity->get_property_as_string( 'PRODUCT_ID' ).
WRITE: / lv_type.
WRITE: / lv_guid.
WRITE: / lv_id.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
推荐阅读
-
wordpress插件上传的失败原因和处理方案 WordPressSAP成都研究院SAP Cloud PlatformSAP云平台SAP
-
使用SAP CRM中间件XIF(External Interface)一步步创建服务订单 SAP成都研究院SAP Cloud PlatformSAP云平台SAPABAP
-
Product settype在CRM WebClient UI架构中的地位 SAPCRMSAP成都研究院SAP Cloud PlatformSAP云平台
-
SAP Cloud for Customer ABSL的一些优化 C4CCloud for CustomerSAP成都研究院SAP Cloud PlatformSAP云平台
-
Account group in ERP and its mapping relationship with CRM partner group ERPCRMSAP成都研究院SAP Cloud PlatformSAP云平台
-
SAP CRM中间件下载时数据库表CRMATAB为空的处理方法 SAP成都研究院SAP Cloud PlatformSAP云平台CRM中间件
-
错误消息sales area is not assigned forheader product SAP成都研究院SAP Cloud PlatformSAP云平台SAPABAP
-
SAP CRM里产品主数据的文本模型设计 SAP成都研究院SAP Cloud PlatformSAP云平台SAPFiori
-
如何关闭SAP CRM中间件的delta download方式 CRM中间件SAP成都研究院SAP Cloud PlatformSAP云平台
-
How to test Delta download in CRM Side CRM中间件SAP成都研究院SAP Cloud PlatformSAP云平台