测试场景创建 + 功能控制 + 按关联创建

ABAP RESTful 应用程序编程模型 › 测试 › 集成测试 › EML 集成测试 › EML 测试:实施测试方法 › 测试场景创建 + 功能控制 + 按关联创建

此集成测试检查实例功能控制实施 get_features 是否阻止对已创建实例执行的按关联创建操作的执行。

测试方法 cba_fc_negative

首先,测试方法填充开始日期和结束日期的变量。

接下来,该方法执行创建差旅实例的 EML 修改创建调用。为确保正确执行创建操作,将为航班日期以及代理和客户标识提供有效数据。由于该方法测试阻止后续按关联创建操作的情况,因此提供整体状态 X。

创建操作应正确运行。因此,该方法断言来自 EML 创建语句的 mapped 响应包含预期内容和差旅标识,并且 failed 和 reported 响应为空。

现在, 方法触发按关联创建操作。

根据 get_features 方法的逻辑,针对总体状态为 X 的差旅实例禁用关联 _booking。因此,该方法断言 mapped 操作的create-by-association 响应为空。此外,该方法断言 failed 响应包含差旅标识,并分别标记关联 _booking。预期不会返回任何消息,因此该方法断言 reported 响应为空。

展开以下代码示例以查看方法 cba_fc_negative 的源代码。

示例代码

METHOD cba_fc_negative.

    begin_date = cl_abap_context_info=>get_system_date( ) + 10.
    end_date   = cl_abap_context_info=>get_system_date( ) + 30.

    " Create a Travel with overall status "Cancelled"
    MODIFY ENTITIES OF /dmo/i_travel_m
    ENTITY travel
      CREATE FIELDS (    agency_id customer_id begin_date end_date description booking_fee currency_code overall_status ) WITH
      VALUE #( (         %cid = cid
                         agency_id      = agency_mock_data[ 1 ]-agency_id
                         customer_id    = customer_mock_data[ 1 ]-customer_id
                         begin_date     = begin_date
                         end_date       = end_date
                         description    = 'TestTravel 1'
                         booking_fee    = '10.5'
                         currency_code  = 'EUR'
                         overall_status = 'X' ) )
    MAPPED DATA(mapped_create)
    FAILED DATA(failed_create)
    REPORTED DATA(reported_create).

    " Travel was created successfully
    cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( mapped_create-travel ) ).
    DATA(key_of_new_travel) = mapped_create-travel[ 1 ].
    cl_abap_unit_assert=>assert_equals( exp = cid act = key_of_new_travel-%cid ).
    cl_abap_unit_assert=>assert_not_initial( act = key_of_new_travel-travel_id ).

    cl_abap_unit_assert=>assert_initial( failed_create ).
    cl_abap_unit_assert=>assert_initial( reported_create ).

    " Create a Booking for the created Travel
    MODIFY ENTITIES OF /dmo/i_travel_m
    ENTITY travel
      CREATE BY \_booking FIELDS ( booking_date customer_id carrier_id connection_id flight_date flight_price currency_code booking_status ) WITH
      VALUE #( (         travel_id = mapped_create-travel[ 1 ]-%tky
                         %target = VALUE #( ( %cid = cid_node
                                              booking_date   = begin_date
                                              customer_id    = customer_mock_data[ 1 ]-customer_id
                                              carrier_id     = '1'
                                              connection_id  = '1'
                                              flight_date    = begin_date
                                              flight_price   = '200'
                                              currency_code  = 'EUR'
                                              booking_status = 'B' ) )
       ) )
    MAPPED DATA(mapped_cba)
    FAILED DATA(failed_cba)
    REPORTED DATA(reported_cba).

    " Booking was not created as overall status of Travel is "Cancelled" (should be "Open" or "Accepted")
    cl_abap_unit_assert=>assert_initial( act = mapped_cba-booking ).

    cl_abap_unit_assert=>assert_equals( act = lines( failed_cba-travel ) exp = 1 ).
    cl_abap_unit_assert=>assert_not_initial( act = failed_cba-travel[ 1 ]-travel_id ).
    cl_abap_unit_assert=>assert_equals( exp = if_abap_behv=>mk-on act = failed_cba-travel[ 1 ]-%assoc-_Booking ).

    cl_abap_unit_assert=>assert_initial( act = reported_cba ).

  ENDMETHOD.

测试方法 cba_fc_positive

第二个测试方法测试使用者创建总体状态为 A 的行程实例的情况。与上面显示的负面情况相反,按关联创建操作的 mapped 响应现在预期包含相应的标识, failed 响应预期为空。

展开以下代码示例以查看方法 cba_fc_positive 的源代码。

示例代码

METHOD cba_fc_positive.

    begin_date = cl_abap_context_info=>get_system_date( ) + 10.
    end_date   = cl_abap_context_info=>get_system_date( ) + 30.

    " Create a Travel with overall status "Accepted"
    MODIFY ENTITIES OF /dmo/i_travel_m
    ENTITY travel
      CREATE FIELDS (    agency_id customer_id begin_date end_date description booking_fee currency_code overall_status ) WITH
      VALUE #( (         %cid = cid
                         agency_id      = agency_mock_data[ 1 ]-agency_id
                         customer_id    = customer_mock_data[ 1 ]-customer_id
                         begin_date     = begin_date
                         end_date       = end_date
                         description    = 'TestTravel 1'
                         booking_fee    = '10.5'
                         currency_code  = 'EUR'
                         overall_status = 'A' ) )
    MAPPED DATA(mapped_create)
    FAILED DATA(failed_create)
    REPORTED DATA(reported_create).

    " Travel was created successfully
    cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( mapped_create-travel ) ).
    DATA(key_of_new_travel) = mapped_create-travel[ 1 ].
    cl_abap_unit_assert=>assert_equals( exp = cid act = key_of_new_travel-%cid ).
    cl_abap_unit_assert=>assert_not_initial( act = key_of_new_travel-travel_id ).

    cl_abap_unit_assert=>assert_initial( failed_create ).
    cl_abap_unit_assert=>assert_initial( reported_create ).

    " Create a Booking for the created Travel
    MODIFY ENTITIES OF /dmo/i_travel_m
    ENTITY travel
      CREATE BY \_booking FIELDS ( booking_date customer_id carrier_id connection_id flight_date flight_price currency_code booking_status ) WITH
      VALUE #( (         travel_id = mapped_create-travel[ 1 ]-%tky
                         %target = VALUE #( ( %cid = cid_node
                                              booking_date   = begin_date
                                              customer_id    = customer_mock_data[ 1 ]-customer_id
                                              carrier_id     = '1'
                                              connection_id  = '1'
                                              flight_date    = begin_date
                                              flight_price   = '200'
                                              currency_code  = 'EUR'
                                              booking_status = 'B' ) )
       ) )
    MAPPED DATA(mapped_cba)
    FAILED DATA(failed_cba)
    REPORTED DATA(reported_cba).

    " Booking was created successfully
    cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( mapped_cba-booking ) ).
    DATA(key_of_new_booking) = mapped_cba-booking[ 1 ].
    cl_abap_unit_assert=>assert_equals( exp = cid_node act = key_of_new_booking-%cid ).
    cl_abap_unit_assert=>assert_not_initial( act = key_of_new_booking-booking_id ).

    cl_abap_unit_assert=>assert_initial( act = failed_cba ).

    cl_abap_unit_assert=>assert_initial( act = reported_cba ).

  ENDMETHOD.

来源:SAP Help Portal · 2025 FPS02 (Oct 2026) · 中文为 SAP 官方机器翻译

← 测试场景创建 + 功能控制 + 操作 · 测试场景创建 + 附加保存 →