mirror of
https://github.com/corda/corda.git
synced 2024-12-22 06:17:55 +00:00
CORDA-1862: Allow MockNetwork to create StartedMockNode from UnstartedMockNode. (#3731)
* Allow MockNetwork to create StartedMockNode from UnstartedMockNode. * Reimplement by adding a `started` property to UnstartedMockNode. * Throw IllegalStateException instead of NoSuchElementException. * Add an isStarted property to UnstartedMockNode.
This commit is contained in:
parent
0762a61aca
commit
01d896394a
@ -128,6 +128,18 @@ class UnstartedMockNode private constructor(private val node: InternalMockNetwor
|
|||||||
* @return A [StartedMockNode] object.
|
* @return A [StartedMockNode] object.
|
||||||
*/
|
*/
|
||||||
fun start(): StartedMockNode = StartedMockNode.create(node.start())
|
fun start(): StartedMockNode = StartedMockNode.create(node.start())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [StartedMockNode] object for this running node.
|
||||||
|
* @throws [IllegalStateException] if the node is not running yet.
|
||||||
|
*/
|
||||||
|
val started: StartedMockNode
|
||||||
|
get() = StartedMockNode.create(node.started ?: throw IllegalStateException("Node ID=$id is not running"))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this node has been started yet.
|
||||||
|
*/
|
||||||
|
val isStarted: Boolean get() = node.started != null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A class that represents a started mock node for testing. */
|
/** A class that represents a started mock node for testing. */
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package net.corda.testing.node
|
||||||
|
|
||||||
|
import net.corda.testing.core.*
|
||||||
|
import org.assertj.core.api.Assertions.*
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
|
class MockNetworkTest {
|
||||||
|
private companion object {
|
||||||
|
private const val NODE_ID = 101
|
||||||
|
}
|
||||||
|
private lateinit var mockNetwork: MockNetwork
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
mockNetwork = MockNetwork(cordappPackages = emptyList())
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun done() {
|
||||||
|
mockNetwork.stopNodes()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `with a started node`() {
|
||||||
|
val unstarted = mockNetwork.createUnstartedNode(DUMMY_BANK_A_NAME, forcedID = NODE_ID)
|
||||||
|
assertFalse(unstarted.isStarted)
|
||||||
|
|
||||||
|
mockNetwork.startNodes()
|
||||||
|
assertTrue(unstarted.isStarted)
|
||||||
|
|
||||||
|
val started = unstarted.started
|
||||||
|
assertEquals(NODE_ID, started.id)
|
||||||
|
assertEquals(DUMMY_BANK_A_NAME, started.info.identityFromX500Name(DUMMY_BANK_A_NAME).name)
|
||||||
|
assertFailsWith<IllegalArgumentException> { started.info.identityFromX500Name(DUMMY_BANK_B_NAME) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `with an unstarted node`() {
|
||||||
|
val unstarted = mockNetwork.createUnstartedNode(DUMMY_BANK_A_NAME, forcedID = NODE_ID)
|
||||||
|
val ex = assertFailsWith<IllegalStateException> { unstarted.started }
|
||||||
|
assertThat(ex).hasMessage("Node ID=$NODE_ID is not running")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user