From 42a6a8302cd876c3ec728548bb809df722eedd10 Mon Sep 17 00:00:00 2001 From: Patrick Kuo Date: Wed, 8 Mar 2017 14:19:03 +0000 Subject: [PATCH] address PR issues --- .../com/r3/corda/doorman/DoormanParameters.kt | 2 +- .../main/kotlin/com/r3/corda/doorman/Main.kt | 2 +- .../r3/corda/doorman/OptionParserUtilities.kt | 2 +- .../r3/corda/doorman/DoormanParametersTest.kt | 27 +++++++++++-------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/doorman/src/main/kotlin/com/r3/corda/doorman/DoormanParameters.kt b/doorman/src/main/kotlin/com/r3/corda/doorman/DoormanParameters.kt index 9f06dc997e..9d4e2f167c 100644 --- a/doorman/src/main/kotlin/com/r3/corda/doorman/DoormanParameters.kt +++ b/doorman/src/main/kotlin/com/r3/corda/doorman/DoormanParameters.kt @@ -10,7 +10,7 @@ import net.corda.node.services.config.getValue import java.nio.file.Path import java.util.* -class DoormanParameters(args: Array) { +class DoormanParameters(vararg args: String) { private val argConfig = args.toConfigWithOptions { accepts("basedir", "Overriding configuration filepath, default to current directory.").withRequiredArg().defaultsTo(".").describedAs("filepath") accepts("configFile", "Overriding configuration file, default to <>/node.conf.").withRequiredArg().describedAs("filepath") diff --git a/doorman/src/main/kotlin/com/r3/corda/doorman/Main.kt b/doorman/src/main/kotlin/com/r3/corda/doorman/Main.kt index 93e0b6ec89..4c50804601 100644 --- a/doorman/src/main/kotlin/com/r3/corda/doorman/Main.kt +++ b/doorman/src/main/kotlin/com/r3/corda/doorman/Main.kt @@ -201,7 +201,7 @@ private fun DoormanParameters.startDoorman() { fun main(args: Array) { try { // TODO : Remove config overrides and solely use config file after testnet is finalized. - DoormanParameters(args).run { + DoormanParameters(*args).run { when (mode) { DoormanParameters.Mode.ROOT_KEYGEN -> generateRootKeyPair() DoormanParameters.Mode.CA_KEYGEN -> generateCAKeyPair() diff --git a/doorman/src/main/kotlin/com/r3/corda/doorman/OptionParserUtilities.kt b/doorman/src/main/kotlin/com/r3/corda/doorman/OptionParserUtilities.kt index 54847f9407..f421a03d75 100644 --- a/doorman/src/main/kotlin/com/r3/corda/doorman/OptionParserUtilities.kt +++ b/doorman/src/main/kotlin/com/r3/corda/doorman/OptionParserUtilities.kt @@ -9,7 +9,7 @@ import joptsimple.OptionParser * Convert commandline arguments to [Config] object will allow us to use kotlin delegate with [ConfigHelper]. */ object OptionParserHelper { - fun Array.toConfigWithOptions(registerOptions: OptionParser.() -> Unit): Config { + fun Array.toConfigWithOptions(registerOptions: OptionParser.() -> Unit): Config { val parser = OptionParser() val helpOption = parser.acceptsAll(listOf("h", "?", "help"), "show help").forHelp(); registerOptions(parser) diff --git a/doorman/src/test/kotlin/com/r3/corda/doorman/DoormanParametersTest.kt b/doorman/src/test/kotlin/com/r3/corda/doorman/DoormanParametersTest.kt index 70fe824aab..4da48fe6f3 100644 --- a/doorman/src/test/kotlin/com/r3/corda/doorman/DoormanParametersTest.kt +++ b/doorman/src/test/kotlin/com/r3/corda/doorman/DoormanParametersTest.kt @@ -3,6 +3,7 @@ package com.r3.corda.doorman import com.typesafe.config.ConfigException import org.junit.Test import java.io.File +import java.nio.file.Paths import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -10,23 +11,27 @@ class DoormanParametersTest { private val testDummyPath = ".${File.separator}testDummyPath.jks" @Test - fun `parse arg correctly`() { - val ref = javaClass.getResource("/node.conf") - val params = DoormanParameters(arrayOf("--keygen", "--keystorePath", testDummyPath, "--configFile", ref.path)) - assertEquals(DoormanParameters.Mode.CA_KEYGEN, params.mode) - assertEquals(testDummyPath, params.keystorePath.toString()) - assertEquals(8080, params.port) + fun `parse mode flag arg correctly`() { + assertEquals(DoormanParameters.Mode.CA_KEYGEN, DoormanParameters("--keygen").mode) + assertEquals(DoormanParameters.Mode.ROOT_KEYGEN, DoormanParameters("--rootKeygen").mode) + assertEquals(DoormanParameters.Mode.DOORMAN, DoormanParameters().mode) + } - val params2 = DoormanParameters(arrayOf("--keystorePath", testDummyPath, "--port", "1000")) - assertEquals(DoormanParameters.Mode.DOORMAN, params2.mode) - assertEquals(testDummyPath, params2.keystorePath.toString()) - assertEquals(1000, params2.port) + @Test + fun `command line arg should override config file`() { + val params = DoormanParameters("--keystorePath", testDummyPath, "--port", "1000", "--configFile", javaClass.getResource("/node.conf").path) + assertEquals(testDummyPath, params.keystorePath.toString()) + assertEquals(1000, params.port) + + val params2 = DoormanParameters("--configFile", javaClass.getResource("/node.conf").path) + assertEquals(Paths.get("/opt/doorman/certificates/caKeystore.jks"), params2.keystorePath) + assertEquals(8080, params2.port) } @Test fun `should fail when config missing`() { // dataSourceProperties is missing from node_fail.conf and it should fail when accessed, and shouldn't use default from reference.conf. - val params = DoormanParameters(arrayOf("--keygen", "--keystorePath", testDummyPath, "--configFile", javaClass.getResource("/node_fail.conf").path)) + val params = DoormanParameters("--keygen", "--keystorePath", testDummyPath, "--configFile", javaClass.getResource("/node_fail.conf").path) assertFailsWith { params.dataSourceProperties } } }