Caplin Trader 5.0.0

Class: module:ct-trading/testing/TOBOUserServiceStub

module:ct-trading/testing/TOBOUserServiceStub()

The TOBOUserServiceStub class provides a stub implementation of the module:ct-trading/service/TOBOUserService to provide the TOBO user list and accounts for a system-under-test. This class also provides additional methods to set such properties where external sub-systems (such as permissioning) are missing in the testing environment.

The initial state of the TOBOUserServiceStub is as follows:

  • User cannot trade on behalf of other users
  • The TOBOUserService is unlocked and TOBOUserService state values can be modified
  • There are no TOBO Users/Accounts or selected TOBO user/account which the user can trade on behalf of

Constructor

new module:ct-trading/testing/TOBOUserServiceStub()

Constructs an instance of TOBOUserServiceStub.

Extends:
Implements:

Extends

Methods

addListener(oListener)

Adds a listener which will be notified when the TOBOUserService state is changed. The listener must be an instance of module:ct-trading/service/TOBOUserServiceListener.

Parameters:
Name Type Description
oListener module:ct-trading/service/TOBOUserServiceListener

Listener object.

Implements:

addObserver(observer)

Adds the specified observer to the list of those to be called when module:br-util/Observable#notifyObservers is invoked. This method will not prevent a particular observer from being added multiple times. The module:br-util/Observable#addUniqueObserver method should be used for this behaviour. If an observer is added multiple times it will receive every notification once for each time it has been registered.

Parameters:
Name Type Description
observer Object

The object to be added as an observer.

Inherited From:
Throws:

if the specified observer is not an Object, or if it is a native JavaScript String, Number, Boolean or Function.

Type
Error

addUniqueObserver(observer) → {Boolean}

Adds the specified observer to the list of those to be called when module:br-util/Observable#notifyObservers is invoked. This method prevents a observer that has already been added to an Observable from being added again. The module:br-util/Observable#addObserver method should be used if duplicates are allowed.

Parameters:
Name Type Description
observer Object

The object to be added as an observer.

Inherited From:
Throws:

if the specified observer is not an Object, or if it is a native JavaScript String, Number, Boolean or Function.

Type
Error
Returns:

true if the observer was successfully added or false if it failed because it had already been added before.

Type
Boolean

canPerformTrade()

This method can be used to query whether the logged-in user can perform a trade on behalf of the currently TOBO user.

Implements:

canTradeOnBehalfOf()

This method can be used to query whether the logged-in user can trade on behalf of other users.

Implements:

getAccount()

Returns the account of the currently selected TOBO user which is being used by the logged-in user.

Implements:

getAllObservers() → {Array}

Gets a list of all the observers that have been registered with this Observable.

Inherited From:
Returns:

A list of the observers that have been registered.

Type
Array

getCount()

Gets the number of listeners within the observer.

Inherited From:
Returns:

The number of listeners within the observer.

getTradeOnBehalfOfUser()

Returns the TOBO user whom the logged-in user is trading on behalf of.

Implements:

getUserType()

Returns the user type of the logged-in user. Used to query whether the user is a trader or a user who is allowed to trade on behalf of other users.

Implements:

notify(methodName)

Invokes the specified method with specified parameters on each of the observers that have been added to this Observable. Please note that this method does not attempt to catch any exceptions that may be thrown by the caller. It is recommended that before adding an observer to the Observable, it should be tested to ensure it conforms to the expected interface, and if not it should be rejected.

Parameters:
Name Type Description
methodName String

The method to be invoked on each of the registered observers.

\{...\}

(Optional) Additional parameters are passed to the observer.

Inherited From:

notifyObservers(methodName, (Optional))

Invokes the specified method with specified array of parameters on each of the observers that have been added to this Observable. Please note that this method does not attempt to catch any exceptions that may be thrown by the caller. If this is an issue then the module:br-util/Observable#notifyObserversWithTryCatch method should be used instead. It is recommended that before adding an observer to the Observable, it should be tested to ensure it conforms to the expected interface, and if not it should be rejected.

Parameters:
Name Type Description
methodName String

The method to be invoked on each of the registered observers.

(Optional) Array

parameters An array of the parameters to be passed into the specified method. The first element of the array will be the first parameter in the callback method, the second element the second parameter, and so on.

Inherited From:

notifyObserversWithTryCatch(methodName, parameters, throwExceptions) → {Array}

Invokes the specified method with a specified array of parameters on each of the observers that have been added to this Observable. This method wraps each call to the observer in a try..catch block so that if any observer throws an exception it will get caught and the execution will continue to the remaining observers. When exceptions occur, they are wrapped in module:br-util/Observable/FailedNotification and an array of these are returned to the caller.

Parameters:
Name Type Description
methodName String

The method to be invoked on each of the registered observers.

parameters Array

An array of the parameters to be passed into the specified method. The first element of the array will be the first parameter in the callback method, the second element the second parameter, and so on.

throwExceptions boolean

(optional) You can use this parameter if you wish the exception array to be thrown rather than returned. If no exceptions occur then nothing will be thrown and the method will return normally.

Inherited From:
See:
  • Observable#notifyObservers to notify without guarding against exceptions.
Returns:

The list of Observable.FailedNotifications that occured or an empty array if no exceptions occurred.

Type
Array

removeAllObservers()

Removes all observers from this Observable. They will no longer be informed of any events that are raised on it.

Inherited From:

removeListener(oListener)

Removes a listener on the TOBOUserService.

Parameters:
Name Type Description
oListener module:ct-trading/service/TOBOUserServiceListener

Listener object.

Implements:

removeObserver(observer) → {Boolean}

Removes the specified observer from the list of registered observers. It will no longer be notified of any events that are raised on this Observable.

Parameters:
Name Type Description
observer Object

The observer to be removed.

Inherited From:
Returns:

true if the observer has been removed, otherwise false, which indicates that the observer was not registered.

Type
Boolean

setAccount()

Called to set the current TOBO user's account to be used for trading by the logged-in user.

Implements:

setAccountList(pAccounts)

This method is called by a mock permission service to set the list of the selected TOBO user's accounts that the user of the system-user-test is allowed to trade upon.

Parameters:
Name Type Description
pAccounts Array

List of account names.

setTOBOLocked(bLocked)

This method is called to lock the TOBO User Service; i.e. to trigger a signal to all listeners that the TOBO user/account cannot be changed.

Parameters:
Name Type Description
bLocked boolean

if TRUE the user/account cannot be changed.

setTOBOUserList(pTOBOUsers)

This method is called by a mock permission service to set the list of TOBO users that the user of the system-user-test is allowed to trade on behalf of.

Parameters:
Name Type Description
pTOBOUsers Array

List of TOBO users' names.

setTradeOnBehalfOfUser()

Called to set the TOBO user whom the logged-in user wishes to trade on behalf of.

Implements:

setUserCanTradeOnBehalfOf(bCanTradeOnBehalfOf)

This method is called by a mock permission service to adjust whether or not the current user of the system-under-test can trade on behalf of other users, or not.

Parameters:
Name Type Description
bCanTradeOnBehalfOf Boolean

True if the user is allowed to trade on behalf of other users; false otherwise.

setUserType(sUserType)

This method is called by a mock permission service to set the user type of the user of the system-under-test.

Parameters:
Name Type Description
sUserType String

User type.

tradeFinished()

This method is called by the trading components to notify the TOBOUserService when a trade has finished.

Implements:

tradeStarted()

This method is called by the trading components to notify the TOBOUserService when a trade has started.

Implements: