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的原创文章,请关注公众号"汪子熙":
相关推荐
Genil bol browser 获取组件集的查询服务名 query service name ; Genil model browser 获取组件集的关系 relation name 组件的属性结构
if lv_related_entity is bound. lv_related_entity->set_property( iv_attr_name = 'SHORT_TEXT' iv_value = 'IP 0000001' ). lv_related_entity->set_property( iv_attr_name = 'LANGU' iv_value = '1' )."有...
SQL2005数据库软件在网上很难找到,因此我找了很久才下载到,欢迎大家使用!
WebUI BOL programming
用于双基地声纳定位BOL算法的实现,分别测得收发基站的角度,拟合直线,交点坐标即为目标位置。
简单爬虫 抓取电商网站bol.com 的产品信息 还在持续更新中
Material for SAP CRM BOL development
bol
CRM BSP复杂查询开发
开源项目-schollz-bol.zip,Command-line and web journal that stays synchronized and encrypted across devices
python库。 资源全名:python-bol-api-latest-0.8.1b0.tar.gz
BoL-Launcher_Server
BoL_Scripts 你最喜欢的智利人的大剧本
搜索bol.com是唯一提供了从BOL .com产品非常简单的镀Chrome扩展搜索。 BOL.com拥有广泛的450万产品,是荷兰最大的网上商店之一。 各种项目,如荷兰和国际书籍,CD,DVD,软件,游戏,电子设备,家用设备和玩具,并...
Vul je rekening op met de de handige Rekeningopvuller voor Bol.com Kom je enkele centen tekort om te genieten van gratis verzending? Vul je rekening op met de de handige Rekeningopvuller voor Bol.com...
FM处理BP与BOl建立的函数处理BP数据
BOL数字IP网络广播产品手册.pptx