Creating basic stubs

A basic stub, also called a hardcoded stub, is a stub that always returns the same response. You can create a basic stub from recorded events by using the Recorded Events wizard from the Recording Studio perspective.

About this task

You can use the Recorded Events wizard to create a basic stub by selecting the events that you want to simulate in the stub and assign operations to the stub. You can group the messages or events into transactions. You can choose to either persist the global rules, disable the global rules, or delete the temporary rules from impacting the grouping in the current wizard session. You can define keys and allow them to persist beyond the current wizard session. You can choose to modify the headers. You can then review the created stub and save it.
Restriction: The basic stub does not execute any other operations, such as performing calculations, looking-up data, or making decisions.

Procedure

  1. In the HCL OneTest API Recording Studio perspective, select one or more recorded events in the Events View window.

    Select events that represent the message exchanges that you want to simulate. You can choose multiple message exchanges because HCL OneTest API can distinguish among them and can create appropriate operations. Thus, a stub created in HCL OneTest API can simulate more than one operation.

  2. Click the Save Stub from selected events icon on the Events View toolbar.

    Alternatively, right-click the messages and click Save Stub from the menu displayed.

    Important: The first and second windows of the Recorded Events wizard are the Resource Type and Data Storage windows. These windows are displayed only if you click the Save icon or press the CTRL+S keys.
  3. Click the Save Stub from selected events icon to bypass the Resource Type and Data Storage windows.

    The Operation Assignment window of the Recorded Events wizard is displayed.

    Events are displayed on the left side of the screen, the message on the right.
  4. In the Operation Assignment window, modify the operation and the events to be associated with the stub.

    The following table describes how to use the Operation Assignment window.

    Task Steps
    Define names of operations from recorded messages payloads.
    1. Select a message that contains a field with the value that must be used as the name of the operation.
    2. On the Body tab, select the relevant field.
    3. Click Define Operation.

    The location of the field within the message is used to define the operation names for all selected messages or all messages if only a single message is selected.

    Select a different operation in the current HCL OneTest API project.
    1. Click Browse to open the Select a Resource dialog.
    2. Select a different operation.
    3. Click OK.
    Select a different operation that is not in the current project.
    1. Click Clear. Alternatively, replace the existing text in the Operation field.
    2. In the Operation field, enter the name of a new operation. The operation is created after you complete the actions in the Recorded Events wizard.
    3. Click Rename.
    4. If you have not selected all the events displayed on the Operation Assignment window for assignment to the new operation, you are prompted to confirm whether you want any non-selected events on the window to be assigned to the new operation.
    Apply a different schema to a recorded event.
    1. On the left side of the window, select the event that you want to modify.
    2. On the right side of the window, click the Body or the Header tab (as appropriate).
    3. Select a field.
    4. Click Add Schema to display the Schema Selector window.
    5. Click OK in the Schema Selector window.
    6. Click Yes to confirm and apply the selected schema to the selected event.
    Tip: If you are creating a stub for multiple operations, HCL OneTest API attempts to verify that all selected recorded events are associated with the correct operations.
  5. Click Next.
    The Transaction Assignment window is displayed.
  6. In the Transaction Assignment window, group events into transactions.

    A transaction can consist of request-reply messages or a series of events.

    The following table describes how to use the Transaction Assignment window.

    Task Steps
    Group two or more recorded events into a single transaction.
    1. On the left side of the window, select the events that you want to group into a transaction.
    2. Click Group. The Group# field of the selected events changes.
    Ungroup a transaction.
    1. On the left side of the window, select the events that you want to ungroup.
    2. Click Ungroup. The Group# field of the selected events changes.
    Delete temporary rules that have affected the grouping in the current Recorded Events wizard session. Click Delete Temporary Keys.
    Disable global rules that have affected the grouping in the current Recorded Events wizard session. Clear the Enable Persisted Keys check box.
    Important: The Enable Persisted Keys check box is checked by default if there are rules which might have changed the way in which the events are grouped.
    Add one or more key fields to one or more selected events displayed on the window.
    1. On the left side of the window, select the event that you want to modify.
    2. On the right side of the window, click the Body tab, the Header tab, or both (as appropriate).
    3. Select a field.
    4. Click Define Key.

      If the value of the field is also displayed in any other fields for other events displayed on the window, the Define Key dialog box is displayed. Otherwise, an error message is displayed.

      Restriction: The key defined is applied only to the current Recorded Events wizard session.
      1. In the Define Key dialog, clear the check boxes of any other events that do not have the same logical value as the field you selected.
      2. Optionally, select the Save as a Field Type called check box and enter a comment for the key field.
        Attention: Selecting this check box enables you to persist the defined key beyond the current Recorded Events wizard session. You can view any comment that you enter in the key field from the Rule Cache view of the Architecture School perspective.
    5. Click OK to save your changes and close the Define Key dialog.
    Messages are grouped based on the following criteria:
    • Messages in the window that are not already grouped into transactions.
    • Messages that contain the key field that you have defined.
    Apply a different schema to a recorded event.
    1. On the left side of the window, select the event that you want to modify.
    2. On the right side of the window, click the Body tab, the Header tab, or both (as appropriate).
    3. Select a field.
    4. Click Add Schema to display the Schema Selector window.
    5. Click OK in the Schema Selector window.
    6. Click Yes to confirm and apply the selected schema to the selected event.
  7. Click Next.

    The Header Transformation window is displayed.

    In the Header Transformation window, all HTTP headers that were identified in the recorded traffic are displayed. Only those headers that are useful in distinguishing one operation from another are enabled. The remaining headers are disabled to make the message or messages more generic.

  8. Change any of these assignments if necessary and click Next.
    The Summary window is displayed.
  9. In the Summary window, review the configuration of the stub and save it.

    The following table describes how to use the Summary window.

    Task Steps
    Open the stub in the Stub Editor after you have saved it and quit the Recorded Events wizard. Select the Open resource after finish check box.
    Save your stub. In the Stub name field, enter a name for the stub, and then click Finish.

Results

The Test Factory perspective of HCL OneTest API is displayed and the newly created stub is displayed under the relevant logical resource on the Test Factory component tree. If you created a stub for multiple operations, the stub is displayed under each applicable operation.

If you selected the Open resource after finish check box in the Summary window, the stub is opened in the Stub Editor.