Caplin Trader 4.8.0

Class: module:caplin/trading/testing/TradeMessageFixture

module:caplin/trading/testing/TradeMessageFixture

Constructor

new module:caplin/trading/testing/TradeMessageFixture()

Constructs a caplin.trading.testing.TradeMessageFixture. The TradeMessageFixture serves to create a context for testing trade interactions, through the use of a trade subscriber mock object.

Tests may use the TradeMessageFixture to:

  • trigger mock server events: given(PM is in state A)
    when("trade.eventReceived => 'ExecuteAck|TRADE_CONF_EXECUTE_DATA'")
    then(PM is in state B)
  • trigger mock server's trading status changes: given(PM is in state A)
    when("trade.statusEnabled => false")
    then(PM is in state B)
  • verify that a trade object has sent the expected event: given(PM is in state A)
    when (execute button is pressed)
    then ("trade.eventSent = 'Execute|TRADE_EXECUTE_DATA'")
Implements:

Methods

addNamedValueMap(name, values)

This method enables a FixtureFactory to register a set of record identifiers and corresponding map of mock record field data with this TradeMessageFixture. Tests using the fixture to receive mock messages or verify events sent by the trade are able to refer to record data using property value '|'.
Parameters:
Name Type Description
name String the record identifier.
values Map the record data map from field data to field value.

canHandleProperty()

TradeMessageFixture handles properties 'eventReceived', 'eventSent' and 'statusEnabled'.
Implements:
See:

doGiven(propertyName, value)

This method can be used with the 'eventReceived' or 'statusEnabled' properties to trigger the stub to simulate these events being received from the server. The 'eventReceived' property must be supplied with a trade event name and optional data map id, in the format NAME|DATA, where DATA is the key for one of the name-value pairs already supplied (caplin.trading.testing.TradeMessageFixture.addNamedValueMap).
Parameters:
Name Type Description
propertyName String The property name.
value Variant The value to check.
Implements:
See:

doThen(propertyName, value)

This method can be used to check whether the last trade event 'sent' by the trading stub was the one expected. This method must be used with the property name 'eventSent', while the value is the event name and data expected in the format NAME|DATA.
Parameters:
Name Type Description
propertyName String The property name.
value Variant The value to set.
Implements:
See:

doWhen(propertyName, value)

This method can be used with the 'eventReceived' or 'statusEnabled' properties to trigger the stub to simulate these events being received from the server.
Parameters:
Name Type Description
propertyName String The property name.
value Variant The value to set.
Implements:
See:

setTradeMessageServiceStub(tradeMessageServiceStub)

Sets a TradeMessageServiceStub to be used by this fixture to simulate trade events.
Parameters:
Name Type Description
tradeMessageServiceStub module:caplin/trading/testing/TradeMessageServiceStub the trade subscriber stub.