From c2aee2d4e8dc00097f101a5cbaaefff7c22f782e Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 2 Aug 2016 17:01:17 +0200 Subject: [PATCH] Minor: Replace MockServices with a new class that's in core instead of node, old class becomes MockServiceHubInternal. --- .../com/r3corda/core/node/services/testing/MockServices.kt | 2 +- .../main/kotlin/com/r3corda/core/testing/CoreTestUtils.kt | 6 +++--- .../kotlin/com/r3corda/contracts/BillOfLadingAgreement.kt | 3 +-- .../com/r3corda/contracts/BillOfLadingAgreementTests.kt | 6 +++--- .../services/{MockServices.kt => MockServiceHubInternal.kt} | 2 +- .../com/r3corda/node/services/NodeSchedulerServiceTest.kt | 2 +- .../kotlin/com/r3corda/node/services/WalletWithCashTest.kt | 6 +++--- .../node/services/statemachine/StateMachineManagerTests.kt | 4 ++-- 8 files changed, 15 insertions(+), 16 deletions(-) rename node/src/test/kotlin/com/r3corda/node/services/{MockServices.kt => MockServiceHubInternal.kt} (99%) diff --git a/core/src/main/kotlin/com/r3corda/core/node/services/testing/MockServices.kt b/core/src/main/kotlin/com/r3corda/core/node/services/testing/MockServices.kt index e26671715a..477d55fce0 100644 --- a/core/src/main/kotlin/com/r3corda/core/node/services/testing/MockServices.kt +++ b/core/src/main/kotlin/com/r3corda/core/node/services/testing/MockServices.kt @@ -34,7 +34,7 @@ import javax.annotation.concurrent.ThreadSafe * A singleton utility that only provides a mock identity, key and storage service. However, this is sufficient for * building chains of transactions and verifying them. It isn't sufficient for testing protocols however. */ -open class UnitTestServices(val key: KeyPair = generateKeyPair()) : ServiceHub { +open class MockServices(val key: KeyPair = generateKeyPair()) : ServiceHub { override fun invokeProtocolAsync(logicType: Class>, vararg args: Any?): ListenableFuture { throw UnsupportedOperationException("not implemented") } diff --git a/core/src/main/kotlin/com/r3corda/core/testing/CoreTestUtils.kt b/core/src/main/kotlin/com/r3corda/core/testing/CoreTestUtils.kt index 600dce87c6..952484a335 100644 --- a/core/src/main/kotlin/com/r3corda/core/testing/CoreTestUtils.kt +++ b/core/src/main/kotlin/com/r3corda/core/testing/CoreTestUtils.kt @@ -9,7 +9,7 @@ import com.r3corda.core.contracts.TransactionBuilder import com.r3corda.core.crypto.* import com.r3corda.core.node.ServiceHub import com.r3corda.core.node.services.testing.MockIdentityService -import com.r3corda.core.node.services.testing.UnitTestServices +import com.r3corda.core.node.services.testing.MockServices import java.math.BigInteger import java.net.ServerSocket import java.security.KeyPair @@ -94,10 +94,10 @@ fun freeLocalHostAndPort(): HostAndPort { /** * Creates and tests a ledger built by the passed in dsl. The provided services can be customised, otherwise a default - * of a freshly built [UnitTestServices] is used. + * of a freshly built [MockServices] is used. */ @JvmOverloads fun ledger( - services: ServiceHub = UnitTestServices(), + services: ServiceHub = MockServices(), dsl: LedgerDSL.() -> Unit ): LedgerDSL { val ledgerDsl = LedgerDSL(TestLedgerDSLInterpreter(services)) diff --git a/experimental/src/main/kotlin/com/r3corda/contracts/BillOfLadingAgreement.kt b/experimental/src/main/kotlin/com/r3corda/contracts/BillOfLadingAgreement.kt index c6839ca306..59db2d87f5 100644 --- a/experimental/src/main/kotlin/com/r3corda/contracts/BillOfLadingAgreement.kt +++ b/experimental/src/main/kotlin/com/r3corda/contracts/BillOfLadingAgreement.kt @@ -4,7 +4,6 @@ import com.r3corda.core.contracts.* import com.r3corda.core.crypto.Party import com.r3corda.core.crypto.SecureHash import com.r3corda.core.days -import com.r3corda.core.testing.DUMMY_NOTARY import java.security.PublicKey import java.time.Instant import java.time.LocalDate @@ -112,7 +111,7 @@ class BillOfLadingAgreement : Contract { /** * Returns a transaction that issues a Bill of Lading Agreement */ - fun generateIssue(owner: PublicKey, beneficiary: Party, props: BillOfLadingProperties, notary: Party = DUMMY_NOTARY): TransactionBuilder { + fun generateIssue(owner: PublicKey, beneficiary: Party, props: BillOfLadingProperties, notary: Party): TransactionBuilder { val state = State(owner, beneficiary, props) val builder = TransactionType.General.Builder(notary = notary) builder.setTime(Instant.now(), notary, 1.days) diff --git a/experimental/src/test/kotlin/com/r3corda/contracts/BillOfLadingAgreementTests.kt b/experimental/src/test/kotlin/com/r3corda/contracts/BillOfLadingAgreementTests.kt index 1b81c75cde..4c0c169302 100644 --- a/experimental/src/test/kotlin/com/r3corda/contracts/BillOfLadingAgreementTests.kt +++ b/experimental/src/test/kotlin/com/r3corda/contracts/BillOfLadingAgreementTests.kt @@ -48,7 +48,7 @@ class BillOfLadingAgreementTests { @Test fun issueGenerationMethod() { - val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary,Bill.props).apply { + val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props, DUMMY_NOTARY).apply { signWith(ALICE_KEY) signWith(DUMMY_NOTARY_KEY) } @@ -58,14 +58,14 @@ class BillOfLadingAgreementTests { @Test(expected = IllegalStateException::class) fun issueGenerationMethod_Unsigned() { - val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props) + val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props, DUMMY_NOTARY) val stx = ptx.toSignedTransaction() stx.verifyToLedgerTransaction(MOCK_IDENTITY_SERVICE,attachments) } @Test(expected = IllegalStateException::class) fun issueGenerationMethod_KeyMismatch() { - val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props).apply { + val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary, Bill.props, DUMMY_NOTARY).apply { signWith(BOB_KEY) } val stx = ptx.toSignedTransaction() diff --git a/node/src/test/kotlin/com/r3corda/node/services/MockServices.kt b/node/src/test/kotlin/com/r3corda/node/services/MockServiceHubInternal.kt similarity index 99% rename from node/src/test/kotlin/com/r3corda/node/services/MockServices.kt rename to node/src/test/kotlin/com/r3corda/node/services/MockServiceHubInternal.kt index 4bf957f5d4..251d3652c2 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/MockServices.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/MockServiceHubInternal.kt @@ -19,7 +19,7 @@ import com.r3corda.node.services.statemachine.StateMachineManager import com.r3corda.node.services.wallet.NodeWalletService import java.time.Clock -open class MockServices( +open class MockServiceHubInternal( customWallet: WalletService? = null, val keyManagement: KeyManagementService? = null, val net: MessagingServiceInternal? = null, diff --git a/node/src/test/kotlin/com/r3corda/node/services/NodeSchedulerServiceTest.kt b/node/src/test/kotlin/com/r3corda/node/services/NodeSchedulerServiceTest.kt index c2f20ec8b3..1b298893e9 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/NodeSchedulerServiceTest.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/NodeSchedulerServiceTest.kt @@ -60,7 +60,7 @@ class NodeSchedulerServiceTest : SingletonSerializeAsToken() { init { val kms = MockKeyManagementService(ALICE_KEY) val mockMessagingService = InMemoryMessagingNetwork(false).InMemoryMessaging(false, InMemoryMessagingNetwork.Handle(0, "None")) - val mockServices = object : MockServices(overrideClock = testClock, keyManagement = kms, net = mockMessagingService), TestReference { + val mockServices = object : MockServiceHubInternal(overrideClock = testClock, keyManagement = kms, net = mockMessagingService), TestReference { override val testReference = this@NodeSchedulerServiceTest } services = mockServices diff --git a/node/src/test/kotlin/com/r3corda/node/services/WalletWithCashTest.kt b/node/src/test/kotlin/com/r3corda/node/services/WalletWithCashTest.kt index 290f0988cb..4582b89fa3 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/WalletWithCashTest.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/WalletWithCashTest.kt @@ -8,7 +8,7 @@ import com.r3corda.core.contracts.* import com.r3corda.core.crypto.SecureHash import com.r3corda.core.node.services.WalletService import com.r3corda.core.node.services.testing.MockStorageService -import com.r3corda.core.node.services.testing.UnitTestServices +import com.r3corda.core.node.services.testing.MockServices import com.r3corda.core.testing.* import com.r3corda.core.utilities.BriefLogFormatter import com.r3corda.node.services.wallet.NodeWalletService @@ -23,13 +23,13 @@ import kotlin.test.assertNull // TODO: Move this to the cash contract tests once mock services are further split up. class WalletWithCashTest { - lateinit var services: UnitTestServices + lateinit var services: MockServices val wallet: WalletService get() = services.walletService @Before fun setUp() { BriefLogFormatter.loggingOn(NodeWalletService::class) - services = object : UnitTestServices() { + services = object : MockServices() { override val walletService: WalletService = NodeWalletService(this) override fun recordTransactions(txs: Iterable) { diff --git a/node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt b/node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt index 4fd25015bd..8c9ab91a95 100644 --- a/node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/services/statemachine/StateMachineManagerTests.kt @@ -4,7 +4,7 @@ import co.paralleluniverse.fibers.Fiber import co.paralleluniverse.fibers.Suspendable import com.r3corda.core.messaging.MessagingService import com.r3corda.core.protocols.ProtocolLogic -import com.r3corda.node.services.MockServices +import com.r3corda.node.services.MockServiceHubInternal import com.r3corda.node.services.api.Checkpoint import com.r3corda.node.services.api.CheckpointStorage import com.r3corda.node.services.api.MessagingServiceInternal @@ -45,7 +45,7 @@ class StateMachineManagerTests { assertThat(protocol.lazyTime).isNotNull() } - private fun createManager() = StateMachineManager(object : MockServices() { + private fun createManager() = StateMachineManager(object : MockServiceHubInternal() { override val networkService: MessagingServiceInternal get() = network }, emptyList(), checkpointStorage, AffinityExecutor.SAME_THREAD)