The Behavior tab

With the Behavior tab, you can add reusable behavioral entities, that is, pre-programmed intelligence, to your stub.

Important: This tab is not displayed when you edit a deterministic stub.

A behavior can act as a source of events that cause a stub to run an operation that is not a reaction to an incoming message from an external system. For example, you might want to create a stub that can proactively publish messages that are not just "responses" to an incoming message.

After you define one or more behaviors on the Behavior tab, you can use them as "events" on the Events tab.

The upper half of the Behavior tab comprises:
  • A window that lists any behaviors that are created for the stub, and buttons to create, modify, and delete behavioral entities.
  • A text box that displays a description for each selected behavior.

The lower half of the tab comprises a Configuration window that displays details about any behavioral entity with custom instance names.

The following table outlines the default behavior-types that are supplied with HCL OneTest API.

Behavior-Type Description
Lifecycle Run certain actions when the currently selected stub starts up or shuts down.

For example, you can set up and later clean up any resources that might be required by the stub.

Timer Set up a timer that schedules a future callback after a specified delay so that the stub receives an event to which it can respond.
Tip: Callback timer settings for a stub can be overridden for each event that is created for the stub (for information, see The Events tab).
Tip: HCL OneTest API provides the means to create more custom behaviors. For more information, see Behaviors for stubs.

The following table describes the buttons on the upper half of the Behavior tab.

Button Description
Add Opens the Add Behavioral Entity dialog.
Add Behavioral Entity dialogThe upper left side of the Add Behavioral Entity dialog displays the available behavior-types. The upper right side of the Add Behavioral Entity dialog displays a description for each selected behavior-type.
The default available behavior-types are as follows:
  • Lifecycle, which you can use to perform certain actions when the stub starts or stops.
  • Timer, which you can use to set a timer for the stub.

The lower half of the Add Behavioral Entity dialog displays the available sample behaviors for the currently selected behavior type. The Instance field is used to refer to the behavioral entity in function actions. This field is optional so that you can create multiple instances of a behavior. Based on the selected behavior, a default instance name is displayed. If required, you can specify a different instance name.

The following sample behaviors are listed:
  • Functions: The functions are indicated with the right arrows functions and can be called within the function script in the business logic view of the stub events. The three functions that can be called within scripts are scheduleTimerEvent, scheduleRepeatingTimerEvent, and cancelTimerEvent.
  • Events: The events are indicated with the left arrows functions and can be selected in the Events tab to perform business logic or send a message when the event occurs. The callback that is named onTimerEvent, provides an event to the stub when a timer runs out.
The following table describes each of the Timer function behaviors that you can use to schedule a single timer event, schedule a repeating timer event, or cancel a timer event.
Function Description
scheduleTimerEvent(timerTaskId, parameter, delay, delayTimeUnit) A single timer event that runs after a specified elapsed time.
timerTaskId
An identifier for the single timer event.
parameter
Any object, for example, a place to record some state, which is returned when the single timer event runs.
delay
A number that in combination with delayTimeUnit defines when the single timer event runs.
delayTimeUnit
The unit type, for example, seconds or hours.
  • java.util.concurrent.TimeUnit.SECONDS
  • java.util.concurrent.TimeUnit.MILLISECONDS
  • java.util.concurrent.TimeUnit.MINUTES

For more information about java.util.concurrent.TimeUnit, see Enum TimeUnit.

scheduleRepeatingTimerEvent(timerTaskId, parameter, delay, period, delayTimeUnit) A repeating timer event that starts after a specified time and repeats.
timerTaskId
An identifier for the repeating timer event.
parameter
Any object, for example, a place to record some state, which is returned when the repeating timer event runs.
delay
A number that in combination with delayTimeUnit defines when the repeating timer event initially runs.
period
A number that in combination with the delayTimeUnit defines when the repeating timer event repeatedly runs.
delayTimeUnit
The unit type, for example, seconds or hours.
  • java.util.concurrent.TimeUnit.SECONDS
  • java.util.concurrent.TimeUnit.MILLISECONDS
  • java.util.concurrent.TimeUnit.MINUTES

For more information about java.util.concurrent.TimeUnit, see Enum TimeUnit.

cancelTimerEvent(timerTaskId) A previously scheduled timer event that you want to cancel.
timerTaskId
An identifier for a previously scheduled timer event.
An example of calling a Function Action from the logon event for setting a timer to log out the user from a session after a specified time period.
logoffTimer.scheduleTimerEvent("logOutSession", tags["SESSION/KEY/sessionID"], 30, java.util.concurrent.TimeUnit.SECONDS)
In this example:
  • logoffTimer is the name of the instance. This instance must be added to the onTimerEvent, which is displayed as logoffTimer.onTimerEvent to the Events tab and runs after the specified time period elapses.
  • The value of tags, ["SESSION/KEY/sessionID"], is evaluated at the point when the timer is started and is passed as the parameter to the event's input tab.
  • logOutSession is the identifier for this timer that is passed to the Input tab of the onTimerEvent event.
  • logOutSession identifier can also be used as a parameter of the cancelTimeEvent function to cancel the timer
For more information about setting a timer behavior, see Adding a timer behavior to a stub.
Tip: To select multiple behaviors for a behavioral entity, hold the Ctrl key and click each behavior after you select a behavior-type on the upper left side of the Add Behavioral Entity dialog.

After you specify the properties of a behavior, click Add to create the behavior and to close the Add Behavioral Entity dialog box.

Tip: Although behavioral entities display on the list window on the upper left side of the Behavior tab, each new behavioral entity also has its events (qualified by the name of the behavior instance) available as values in the Events field on the Events tab for the stub. For more information, see The Events tab.
Edit Opens the Edit Behavioral Entity dialog, so you can modify instance details for the selected behavioral entity.
Delete Deletes any behavioral entities that are selected in the list window on the tab.
Tip: To select multiple behavioral entities for deletion, hold down Ctrl and click each entity.