mirror of
https://github.com/corda/corda.git
synced 2025-02-01 16:58:27 +00:00
Refactor DemoBench's configuration classes (#429)
* Reuse User class from :node-api module. * Test that DemoBench can understand the node's configuration file. * Add return type to User.toMap().
This commit is contained in:
parent
bb74f0ca34
commit
cec4e20bc8
@ -48,12 +48,8 @@ dependencies {
|
|||||||
// Controls FX: more java FX components http://fxexperience.com/controlsfx/
|
// Controls FX: more java FX components http://fxexperience.com/controlsfx/
|
||||||
compile "org.controlsfx:controlsfx:$controlsfx_version"
|
compile "org.controlsfx:controlsfx:$controlsfx_version"
|
||||||
|
|
||||||
compile (project(':client:rpc')) {
|
compile project(':client:rpc')
|
||||||
exclude module: 'junit'
|
compile project(':finance')
|
||||||
}
|
|
||||||
compile (project(':finance')) {
|
|
||||||
exclude module: 'junit'
|
|
||||||
}
|
|
||||||
|
|
||||||
compile "com.h2database:h2:$h2_version"
|
compile "com.h2database:h2:$h2_version"
|
||||||
compile "net.java.dev.jna:jna-platform:$jna_version"
|
compile "net.java.dev.jna:jna-platform:$jna_version"
|
||||||
@ -73,6 +69,8 @@ dependencies {
|
|||||||
compile ':jediterm-terminal-2.5'
|
compile ':jediterm-terminal-2.5'
|
||||||
compile ':pty4j-0.7.2'
|
compile ':pty4j-0.7.2'
|
||||||
|
|
||||||
|
testCompile project(':node')
|
||||||
|
|
||||||
testCompile "junit:junit:$junit_version"
|
testCompile "junit:junit:$junit_version"
|
||||||
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,12 @@ class Explorer internal constructor(private val explorerController: ExplorerCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
val user = config.users.elementAt(0)
|
||||||
val p = explorerController.process(
|
val p = explorerController.process(
|
||||||
"--host=localhost",
|
"--host=localhost",
|
||||||
"--port=${config.rpcPort}",
|
"--port=${config.rpcPort}",
|
||||||
"--username=${config.users[0].user}",
|
"--username=${user.username}",
|
||||||
"--password=${config.users[0].password}")
|
"--password=${user.password}")
|
||||||
.directory(explorerDir)
|
.directory(explorerDir)
|
||||||
.start()
|
.start()
|
||||||
process = p
|
process = p
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
import com.typesafe.config.*
|
import com.typesafe.config.*
|
||||||
|
import net.corda.nodeapi.User
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
|
@file:JvmName("User")
|
||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
data class User(val user: String, val password: String, val permissions: List<String>) {
|
import net.corda.nodeapi.User
|
||||||
fun toMap() = mapOf(
|
import java.util.*
|
||||||
"user" to user,
|
|
||||||
"password" to password,
|
fun User.toMap(): Map<String, Any> = mapOf(
|
||||||
"permissions" to permissions
|
"user" to username,
|
||||||
)
|
"password" to password,
|
||||||
}
|
"permissions" to permissions
|
||||||
|
)
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun toUser(map: Map<String, Any>) = User(
|
fun toUser(map: Map<String, Any>) = User(
|
||||||
map.getOrElse("user", { "none" }) as String,
|
map.getOrElse("user", { "none" }) as String,
|
||||||
map.getOrElse("password", { "none" }) as String,
|
map.getOrElse("password", { "none" }) as String,
|
||||||
map.getOrElse("permissions", { emptyList<String>() }) as List<String>
|
LinkedHashSet<String>(map.getOrElse("permissions", { emptyList<String>() }) as Collection<String>)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun user(name: String) = User(name, "letmein", listOf("ALL"))
|
fun user(name: String) = User(name, "letmein", setOf("ALL"))
|
||||||
|
@ -22,7 +22,8 @@ class NodeRPC(config: NodeConfig, start: () -> Unit, invoke: (CordaRPCOps) -> Un
|
|||||||
val setupTask = object : TimerTask() {
|
val setupTask = object : TimerTask() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
try {
|
try {
|
||||||
rpcClient.start(config.users[0].user, config.users[0].password)
|
val user = config.users.elementAt(0)
|
||||||
|
rpcClient.start(user.username, user.password)
|
||||||
val ops = rpcClient.proxy()
|
val ops = rpcClient.proxy()
|
||||||
|
|
||||||
// Cancel the "setup" task now that we've created the RPC client.
|
// Cancel the "setup" task now that we've created the RPC client.
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
|
import com.google.common.net.HostAndPort
|
||||||
|
import net.corda.node.internal.NetworkMapInfo
|
||||||
|
import net.corda.node.services.config.FullNodeConfiguration
|
||||||
|
import net.corda.nodeapi.User
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
import java.util.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
@ -158,6 +163,33 @@ class NodeConfigTest {
|
|||||||
+ "}", config.toText().stripWhitespace())
|
+ "}", config.toText().stripWhitespace())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `reading node configuration`() {
|
||||||
|
val config = createConfig(
|
||||||
|
legalName = "My Name",
|
||||||
|
nearestCity = "Stockholm",
|
||||||
|
p2pPort = 10001,
|
||||||
|
rpcPort = 40002,
|
||||||
|
webPort = 20001,
|
||||||
|
h2Port = 30001,
|
||||||
|
services = listOf("my.service"),
|
||||||
|
users = listOf(user("jenny"))
|
||||||
|
)
|
||||||
|
config.networkMap = NetworkMapConfig("Notary", 12345)
|
||||||
|
|
||||||
|
val fullConfig = FullNodeConfiguration(Paths.get("."), config.toFileConfig())
|
||||||
|
|
||||||
|
assertEquals("My Name", fullConfig.myLegalName)
|
||||||
|
assertEquals("Stockholm", fullConfig.nearestCity)
|
||||||
|
assertEquals(localPort(20001), fullConfig.webAddress)
|
||||||
|
assertEquals(localPort(40002), fullConfig.rpcAddress)
|
||||||
|
assertEquals(localPort(10001), fullConfig.p2pAddress)
|
||||||
|
assertEquals(listOf("my.service"), fullConfig.extraAdvertisedServiceIds)
|
||||||
|
assertEquals(listOf(user("jenny")), fullConfig.rpcUsers)
|
||||||
|
assertEquals(NetworkMapInfo(localPort(12345), "Notary"), fullConfig.networkMapService)
|
||||||
|
assertTrue(fullConfig.useTestClock)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test moving`() {
|
fun `test moving`() {
|
||||||
val config = createConfig(legalName = "My Name")
|
val config = createConfig(legalName = "My Name")
|
||||||
@ -190,4 +222,5 @@ class NodeConfigTest {
|
|||||||
users = users
|
users = users
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private fun localPort(port: Int) = HostAndPort.fromParts("localhost", port)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
|
import net.corda.nodeapi.User
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
|
import net.corda.nodeapi.User
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
@ -8,9 +9,9 @@ class UserTest {
|
|||||||
@Test
|
@Test
|
||||||
fun createFromEmptyMap() {
|
fun createFromEmptyMap() {
|
||||||
val user = toUser(emptyMap())
|
val user = toUser(emptyMap())
|
||||||
assertEquals("none", user.user)
|
assertEquals("none", user.username)
|
||||||
assertEquals("none", user.password)
|
assertEquals("none", user.password)
|
||||||
assertEquals(emptyList<String>(), user.permissions)
|
assertEquals(emptySet<String>(), user.permissions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -21,26 +22,26 @@ class UserTest {
|
|||||||
"permissions" to listOf("Flow.MyFlow")
|
"permissions" to listOf("Flow.MyFlow")
|
||||||
)
|
)
|
||||||
val user = toUser(map)
|
val user = toUser(map)
|
||||||
assertEquals("MyName", user.user)
|
assertEquals("MyName", user.username)
|
||||||
assertEquals("MyPassword", user.password)
|
assertEquals("MyPassword", user.password)
|
||||||
assertEquals(listOf("Flow.MyFlow"), user.permissions)
|
assertEquals(setOf("Flow.MyFlow"), user.permissions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun userToMap() {
|
fun userToMap() {
|
||||||
val user = User("MyName", "MyPassword", listOf("Flow.MyFlow"))
|
val user = User("MyName", "MyPassword", setOf("Flow.MyFlow"))
|
||||||
val map = user.toMap()
|
val map = user.toMap()
|
||||||
assertEquals("MyName", map["user"])
|
assertEquals("MyName", map["user"])
|
||||||
assertEquals("MyPassword", map["password"])
|
assertEquals("MyPassword", map["password"])
|
||||||
assertEquals(listOf("Flow.MyFlow"), map["permissions"])
|
assertEquals(setOf("Flow.MyFlow"), map["permissions"])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `default user`() {
|
fun `default user`() {
|
||||||
val user = user("guest")
|
val user = user("guest")
|
||||||
assertEquals("guest", user.user)
|
assertEquals("guest", user.username)
|
||||||
assertEquals("letmein", user.password)
|
assertEquals("letmein", user.password)
|
||||||
assertEquals(listOf("ALL"), user.permissions)
|
assertEquals(setOf("ALL"), user.permissions)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user