open class MockServices
An implementation of ServiceHub that is designed for in-memory unit tests of contract validation logic. It has enough functionality to do tests of code that queries the vault, inserts to the vault, and constructs/checks transactions. However it isn't enough to test flows and other aspects of an app that require a network. For that you should investigate MockNetwork.
There are a variety of constructors that can be used to supply enough data to simulate a node. Each mock service hub must have at least an identity of its own. The other components have defaults that work in most situations.
MockServices(cordappPackages: Iterable<String>, initialIdentity: <ERROR CLASS>, identityService: <ERROR CLASS> = makeTestIdentityService(), vararg moreKeys: KeyPair) MockServices(cordappPackages: Iterable<String>, initialIdentityName: <ERROR CLASS>, identityService: <ERROR CLASS> = makeTestIdentityService(), key: KeyPair, vararg moreKeys: KeyPair)
Create a mock ServiceHub that looks for app code in the given package names, uses the provided identity service (you can get one from makeTestIdentityService) and represents the given identity. MockServices(cordappPackages: Iterable<String>, initialIdentity: <ERROR CLASS>, identityService: <ERROR CLASS>, networkParameters: <ERROR CLASS>, vararg moreKeys: KeyPair) MockServices(cordappPackages: Iterable<String>, initialIdentity: <ERROR CLASS>, identityService: <ERROR CLASS>, networkParameters: <ERROR CLASS>, vararg moreKeys: KeyPair, keyManagementService: <ERROR CLASS>) MockServices(cordappPackages: List<String>, initialIdentityName: <ERROR CLASS>, identityService: <ERROR CLASS>, networkParameters: <ERROR CLASS>) MockServices(cordappPackages: List<String>, initialIdentityName: <ERROR CLASS>, identityService: <ERROR CLASS>, networkParameters: <ERROR CLASS>, key: KeyPair) MockServices(firstIdentity: <ERROR CLASS>, networkParameters: <ERROR CLASS>, vararg moreIdentities: <ERROR CLASS>) MockServices(cordappPackages: List<String>, firstIdentity: <ERROR CLASS>, vararg moreIdentities: <ERROR CLASS>) MockServices(cordappPackages: List<String>, firstIdentity: <ERROR CLASS>, networkParameters: <ERROR CLASS>, vararg moreIdentities: <ERROR CLASS>) MockServices(cordappPackages: Iterable<String>, initialIdentityName: <ERROR CLASS>, identityService: <ERROR CLASS> = makeTestIdentityService())
Create a mock ServiceHub that can't load CorDapp code, which uses the provided identity service (you can get one from makeTestIdentityService) and which represents the given identity. MockServices(cordappPackages: Iterable<String>)
Create a mock ServiceHub that can't load CorDapp code, and which uses a default service identity. MockServices(initialIdentityName: <ERROR CLASS>, identityService: <ERROR CLASS> = makeTestIdentityService(), key: KeyPair, vararg moreKeys: KeyPair)
Create a mock ServiceHub which uses the package of the caller to find CorDapp code. It uses the provided identity service (you can get one from makeTestIdentityService) and which represents the given identity. MockServices(initialIdentityName: <ERROR CLASS>, identityService: <ERROR CLASS> = makeTestIdentityService())
Create a mock ServiceHub which uses the package of the caller to find CorDapp code. It uses the provided identity service (you can get one from makeTestIdentityService) and which represents the given identity. It has no keys. MockServices(firstIdentity: <ERROR CLASS>, vararg moreIdentities: <ERROR CLASS>)
A helper constructor that requires at least one test identity to be registered, and which takes the package of the caller as the package in which to find app code. This is the most convenient constructor and the one that is normally worth using. The first identity is the identity of this service hub, the rest are identities that it is aware of. MockServices()
Create a mock ServiceHub which uses the package of the caller to find CorDapp code. It uses a default service identity. |
val attachments: MockAttachmentStorage |
|
open val clock: TestClock |
|
open val contractUpgradeService: <ERROR CLASS> |
|
val cordappClassloader: ClassLoader
Returns the classloader containing all jar deployed in the 'cordapps' folder. |
|
open val cordappProvider: <ERROR CLASS> |
|
open val diagnosticsService: <ERROR CLASS> |
|
open val identityService: <ERROR CLASS> |
|
open val keyManagementService: <ERROR CLASS> |
|
open val myInfo: <ERROR CLASS> |
|
open val networkMapCache: <ERROR CLASS> |
|
open val networkParameters: <ERROR CLASS> |
|
open var networkParametersService: <ERROR CLASS> |
|
val servicesForResolution: <ERROR CLASS> |
|
open val transactionVerifierService: <ERROR CLASS> |
|
open val validatedTransactions: <ERROR CLASS> |
|
open val vaultService: <ERROR CLASS> |
fun addMockCordapp(contractClassName: <ERROR CLASS>): Unit
Add the given package name to the list of packages which will be scanned for cordapp contract verification code |
|
open fun <T> cordaService(type: Class<T>): T |
|
open fun jdbcSession(): Connection |
|
open fun loadContractAttachment(stateRef: <ERROR CLASS>): <ERROR CLASS>
Returns a dummy Attachment, in context of signature constrains non-downgrade rule this default to contract class version |
|
open fun loadState(stateRef: <ERROR CLASS>): <ERROR CLASS> |
|
open fun loadStates(stateRefs: Set<<ERROR CLASS>>): <ERROR CLASS> |
|
open fun recordTransactions(statesToRecord: <ERROR CLASS>, txs: Iterable<<ERROR CLASS>>): Unit |
|
open fun registerUnloadHandler(runOnStop: () -> Unit): Nothing |
|
open fun <T> withEntityManager(block: <ERROR CLASS>.() -> T): T open fun withEntityManager(block: Consumer<<ERROR CLASS>>): Unit |
fun makeTestDataSourceProperties(nodeName: String = SecureHash.randomSHA256().toString()): Properties fun makeTestDataSourceProperties(nodeName: String = SecureHash.randomSHA256().toString(), inMemory: Boolean = false): Properties
Make properties appropriate for creating a DataSource for unit tests. Defaults configuration of on-disk H2 instance. If 'databaseProvider' system property is set then creates a config from the relevant config file is present in resources folder (used to parametrize test to run against a remote database). |
|
fun makeTestDatabaseAndMockServices(cordappPackages: List<String>, identityService: <ERROR CLASS>, initialIdentity: <ERROR CLASS>, networkParameters: <ERROR CLASS> = testNetworkParameters(modifiedTime = Instant.MIN), vararg moreKeys: KeyPair, softLockingSqlInClauseSize: Int = NodeVaultService.DEFAULT_SOFT_LOCKING_SQL_IN_CLAUSE_SIZE): <ERROR CLASS><<ERROR CLASS>, MockServices>
Makes database and mock services appropriate for unit tests. |
|
fun makeTestDatabaseAndPersistentServices(cordappPackages: List<String>, initialIdentity: <ERROR CLASS>, networkParameters: <ERROR CLASS> = testNetworkParameters(modifiedTime = Instant.MIN), moreKeys: Set<KeyPair>, moreIdentities: Set<<ERROR CLASS>>, cacheFactory: TestingNamedCacheFactory = TestingNamedCacheFactory()): <ERROR CLASS><<ERROR CLASS>, MockServices>
Makes database and persistent services appropriate for unit tests which require persistence across the vault, identity service and key managment service. |