Minor: auto-format of module: test-utils

This commit is contained in:
Mike Hearn
2017-04-11 12:48:56 +02:00
parent 9948815df1
commit cda04b0e7b
12 changed files with 38 additions and 21 deletions

View File

@ -68,6 +68,7 @@ inline fun <reified E : Any> expect(
* @param expectations The pieces of DSL that should run sequentially when events arrive.
*/
fun <E> sequence(vararg expectations: ExpectCompose<E>): ExpectCompose<E> = ExpectCompose.Sequential(listOf(*expectations))
fun <E> sequence(expectations: List<ExpectCompose<E>>): ExpectCompose<E> = ExpectCompose.Sequential(expectations)
/**
@ -76,6 +77,7 @@ fun <E> sequence(expectations: List<ExpectCompose<E>>): ExpectCompose<E> = Expec
* @param expectations The pieces of DSL all of which should run but in an unspecified order depending on what sequence events arrive.
*/
fun <E> parallel(vararg expectations: ExpectCompose<E>): ExpectCompose<E> = ExpectCompose.Parallel(listOf(*expectations))
fun <E> parallel(expectations: List<ExpectCompose<E>>): ExpectCompose<E> = ExpectCompose.Parallel(expectations)
/**
@ -202,6 +204,7 @@ private sealed class ExpectComposeState<E : Any> {
override fun nextState(event: E) = null
override fun getExpectedEvents(): List<Class<E>> = listOf()
}
class Single<E : Any, T : E>(val single: ExpectCompose.Single<E, T>) : ExpectComposeState<E>() {
override fun nextState(event: E): Pair<() -> Unit, ExpectComposeState<E>>? =
if (single.expect.clazz.isAssignableFrom(event.javaClass)) {
@ -215,6 +218,7 @@ private sealed class ExpectComposeState<E : Any> {
} else {
null
}
override fun getExpectedEvents() = listOf(single.expect.clazz)
}
@ -266,6 +270,7 @@ private sealed class ExpectComposeState<E : Any> {
}
return null
}
override fun getExpectedEvents() = states.flatMap { it.getExpectedEvents() }
}

View File

@ -1,6 +1,8 @@
package net.corda.testing
import net.corda.core.contracts.*
import net.corda.core.contracts.ContractState
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.TransactionState
import net.corda.core.crypto.SecureHash
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.transactions.WireTransaction
@ -132,6 +134,7 @@ class LedgerDSL<out T : TransactionDSLInterpreter, out L : LedgerDSLInterpreter<
fun transaction(label: String? = null, transactionBuilder: TransactionBuilder = TransactionBuilder(notary = DUMMY_NOTARY),
dsl: TransactionDSL<TransactionDSLInterpreter>.() -> EnforceVerifyOrFail) =
_transaction(label, transactionBuilder, dsl)
/**
* @see LedgerDSLInterpreter._unverifiedTransaction
*/

View File

@ -4,8 +4,8 @@ import com.google.common.net.HostAndPort
import java.io.IOException
import java.io.InputStreamReader
import java.net.ConnectException
import java.net.SocketException
import java.net.HttpURLConnection
import java.net.SocketException
import java.net.URL
import kotlin.test.assertEquals

View File

@ -1,5 +1,6 @@
package net.corda.testing
import net.corda.testing.TestTimestamp.Companion.timestamp
import java.text.SimpleDateFormat
import java.util.*

View File

@ -84,6 +84,7 @@ class TransactionDSL<out T : TransactionDSLInterpreter>(val interpreter: T) : Tr
}
input(transaction.outRef<ContractState>(0).ref)
}
fun input(stateClosure: () -> ContractState) = input(stateClosure())
/**
@ -92,6 +93,7 @@ class TransactionDSL<out T : TransactionDSLInterpreter>(val interpreter: T) : Tr
@JvmOverloads
fun output(label: String? = null, notary: Party = DUMMY_NOTARY, encumbrance: Int? = null, contractStateClosure: () -> ContractState) =
_output(label, notary, encumbrance, contractStateClosure())
/**
* @see TransactionDSLInterpreter._output
*/
@ -106,6 +108,7 @@ class TransactionDSL<out T : TransactionDSLInterpreter>(val interpreter: T) : Tr
*/
fun command(vararg signers: CompositeKey, commandDataClosure: () -> CommandData) =
_command(listOf(*signers), commandDataClosure())
/**
* @see TransactionDSLInterpreter._command
*/

View File

@ -1,6 +1,5 @@
package net.corda.testing.http
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.common.net.HostAndPort
import java.net.URL
@ -11,6 +10,7 @@ class HttpApi(val root: URL) {
* @param data String values are assumed to be valid JSON. All other values will be mapped to JSON.
*/
fun putJson(path: String, data: Any = Unit) = HttpUtils.putJson(URL(root, path), toJson(data))
/**
* Send a POST with a payload to the path on the API specified.
*

View File

@ -85,7 +85,10 @@ class MockIdentityService(val identities: List<Party>) : IdentityService, Single
private val nameToParties: Map<String, Party>
get() = synchronized(identities) { identities.associateBy { it.name } }
override fun registerIdentity(party: Party) { throw UnsupportedOperationException() }
override fun registerIdentity(party: Party) {
throw UnsupportedOperationException()
}
override fun getAllIdentities(): Iterable<Party> = ArrayList(keyToParties.values)
override fun partyFromAnonymous(party: AnonymousParty): Party? = keyToParties[party.owningKey]
override fun partyFromAnonymous(partyRef: PartyAndReference): Party? = partyFromAnonymous(partyRef.party)

View File

@ -6,8 +6,8 @@ import com.google.common.util.concurrent.SettableFuture
import net.corda.core.crypto.composite
import net.corda.core.crypto.generateKeyPair
import net.corda.core.messaging.RPCOps
import net.corda.testing.MOCK_NODE_VERSION_INFO
import net.corda.node.services.RPCUserServiceImpl
import net.corda.node.services.api.MonitoringService
import net.corda.node.services.config.NodeConfiguration
import net.corda.node.services.messaging.ArtemisMessagingServer
import net.corda.node.services.messaging.NodeMessagingClient
@ -15,12 +15,12 @@ import net.corda.node.services.network.InMemoryNetworkMapCache
import net.corda.node.utilities.AffinityExecutor.ServiceAffinityExecutor
import net.corda.node.utilities.configureDatabase
import net.corda.node.utilities.databaseTransaction
import net.corda.testing.MOCK_NODE_VERSION_INFO
import net.corda.testing.freeLocalHostAndPort
import org.jetbrains.exposed.sql.Database
import java.io.Closeable
import java.security.KeyPair
import kotlin.concurrent.thread
import net.corda.node.services.api.MonitoringService
/**
* This is a bare-bones node which can only send and receive messages. It doesn't register with a network map service or
@ -51,7 +51,9 @@ class SimpleNode(val config: NodeConfiguration, val address: HostAndPort = freeL
fun start() {
broker.start()
net.start(
object : RPCOps { override val protocolVersion = 0 },
object : RPCOps {
override val protocolVersion = 0
},
userService)
thread(name = config.myLegalName) {
net.run()