Package cloud.metaapi.sdk.util
Class ServiceProvider
- java.lang.Object
-
- cloud.metaapi.sdk.util.ServiceProvider
-
public class ServiceProvider extends Object
Inner service provider that implements dependency injection (DI) of some SDK classes which are needed to be tested properly. This class creates objects as they are used in normal environment giving opportunity to mock them for testing before they are actually created.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceServiceProvider.MetaApiConnectionProviderInterface for creatingMetaApiConnection.
-
Constructor Summary
Constructors Constructor Description ServiceProvider()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static HistoryFileManagercreateHistoryFileManager(String accountId, HistoryStorage storage)Constructs history file manager with its corresponding constructor or returns a mock if it is set.static MetaApiConnectioncreateMetaApiConnection(MetaApiWebsocketClient websocketClient, MetatraderAccount account, HistoryStorage historyStorage, ConnectionRegistry connectionRegistry)Constructs metaapi connection with its corresponding constructor or returns a mock if it is set.static voidsetHistoryFileManagerMock(HistoryFileManager mock)Sets history file manager mock that will be created by this provider.static voidsetMetApiConnectionMock(MetaApiConnection mock)Sets metaapi connection mock that will be created by this provider.static voidsetMetApiConnectionMock(ServiceProvider.MetaApiConnectionProvider mockProvider)Sets metaapi connection provider that will be used for creating the mock.
-
-
-
Method Detail
-
createHistoryFileManager
public static HistoryFileManager createHistoryFileManager(String accountId, HistoryStorage storage)
Constructs history file manager with its corresponding constructor or returns a mock if it is set.- Parameters:
accountId- account idstorage- storage- Returns:
- normal or mocked history file manager
- See Also:
setHistoryFileManagerMock(HistoryFileManager)
-
setHistoryFileManagerMock
public static void setHistoryFileManagerMock(HistoryFileManager mock)
Sets history file manager mock that will be created by this provider. Ifnullis set, the mock is removed and the object will be created as normal.- Parameters:
mock- mocked history file manager ornull
-
createMetaApiConnection
public static MetaApiConnection createMetaApiConnection(MetaApiWebsocketClient websocketClient, MetatraderAccount account, HistoryStorage historyStorage, ConnectionRegistry connectionRegistry)
Constructs metaapi connection with its corresponding constructor or returns a mock if it is set.- Parameters:
websocketClient- MetaApi websocket clientaccount- MetaTrader account to connect tohistoryStorage- optional local terminal history storage. Use for accounts in user synchronization mode. By default an instance of MemoryHistoryStorage will be used.connectionRegistry- metatrader account connection registry- See Also:
setHistoryFileManagerMock(HistoryFileManager)
-
setMetApiConnectionMock
public static void setMetApiConnectionMock(MetaApiConnection mock)
Sets metaapi connection mock that will be created by this provider. Ifnullis set, the mock is removed and the object will be created as normal.- Parameters:
mock- mocked metaapi connection ornull
-
setMetApiConnectionMock
public static void setMetApiConnectionMock(ServiceProvider.MetaApiConnectionProvider mockProvider)
Sets metaapi connection provider that will be used for creating the mock. Ifnullis set, the mock provider is removed and the object will be created as normal.- Parameters:
mockProvider- mocked metaapi connection ornull
-
-