Creating basic stubs

A basic stub is a stub that always returns the same response. You can create a basic (hardcoded) stub from recorded events.

About this task

The stub does not execute any other operations, such as performing calculations, looking up data, or making decisions.

Procedure

To create a basic (hardcoded) stub from recorded events, do the following steps:

  1. In the HCL OneTest™ API Recording Studio perspective, select one or more recorded events on 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 create appropriate operations. Thus, a stub created in HCL OneTest API can simulate more than one operation.
    Note: For information about using the Recording Studio perspective to record events, see Using the Recording Studio.
    Note: For information about using the Events View window, including searching recorded events, see Specifying the display options in the Events view.
  2. Click the Save Stub from selected events button () on the Events View toolbar.

    Alternatively, right-click the messages and click Save Stub on the shortcut menu.

    Note: The first and second pages of the Recorded Events wizard are the Resource Type and Data Storage pages. The pages are displayed only if you click the Save button () or press CTRL+S. Click the Save Stub from selected events button () to bypass the Resource Type and Data Storage pages.
    The Operation Assignment page of the Recorded Events wizard is displayed.
    Events are displayed on the left side of the screen, the message on the right.
  3. On the Operation Assignment page, modify the operation and the events associated with the stub.

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

    To... Do this...
    Define names of operations from recorded message 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 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 to close the Select a Resource dialog.
    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 Recorded Events wizard.
    3. Click Rename.
    4. If you have not selected all the events displayed on the Operation Assignment page for assignment to the new operation, you are prompted to confirm whether you want any non-selected events on the page to be assigned to the new operation.
    Apply a different schema to a recorded event
    1. On the left side of the screen, select the event that you want to modify.
    2. On the right side of the screen, click the Body or Header tab (as appropriate).
    3. Select a field.
    4. Click Add Schema to display the Schema Selector window. For information about selecting message schemas, see Applying schemas and formats to messages.
    5. Click Finish in the Schema Selector window and confirm that you want to apply the selected schema to the selected event.
    Note: If you are creating a stub for multiple operations, HCL OneTest API attempts to verity that all selected recorded events are associated with the correct operations.

    Click Next when you are finished.

    The Transaction Assignment page is displayed.
  4. On the Transaction Assignment page, group events into transactions. A transaction can consist of request-reply or a series of events.

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

    To... Do this...
    Group two or more recorded events into a single transaction
    1. On the left side of the screen, 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 screen, select the events that you want to ungroup.
    2. Click Ungroup. The Group# field of the selected events changes.
    Add one or more key fields to one or more selected events displayed on the screen.
    1. On the left side of the screen, select the event that you want to modify.
    2. On the right side of the screen, click the Body and/or Header tab (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 screen, the Define Key dialog box is displayed. Otherwise, an error message is displayed.
    5. On the Define Key dialog box, clear the check boxes of any other events that do not have the same logical value as the field you selected.
    6. Optional: In the Save as a Field Type called field, enter a comment for the key field. Any comment you enter will be displayed in the Rule Cache view of the Architecture School perspective.
    7. Click OK to save your changes and to close the Define Key dialog box.

    Any messages on the screen that are not already grouped into transactions and that contain the key field that you have defined are grouped.

    Apply a different schema to a recorded event
    1. On the left side of the screen, select the event that you want to modify.
    2. On the right side of the screen, click the Body and/or Header tab (as appropriate).
    3. Select a field.
    4. Click Add Schema to display the Schema Selector window. For information about selecting message schemas, see Applying schemas and formats to messages.
    5. Click Finish in the Schema Selector window, then confirm that you want to apply the selected schema to the selected event.

    Click Next when you are finished.

    The Header Transformation page is displayed.
  5. On the Header Transformation page, 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. Change any of these assignments if necessary, and click Next. The Summary page is displayed.
  6. On the Summary page, review the configuration of the stub and save it.

    The following table describes how to use the Summary page.

    To... Do this...
    Open the stub in the Stub Editor after you save 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, then click Finish.

Results

After clicking Finish on the Summary page:

  • The HCL OneTest API Test Factory perspective 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 on the Summary page, the stub is opened in the Stub Editor. For more information, see Modifying message-based stubs.
Feedback