diff options
author | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-06-06 11:47:54 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-01 10:37:18 +0200 |
commit | f895b8628fbc9cde4013dcf68607b4e18a8ce85b (patch) | |
tree | f6bbb19cea606860ce4f83424292c5ccb6e41c55 /hv-collector-main/src | |
parent | e74c9e1c95d4e6a83e7a668df9a9835328245d5e (diff) |
Missing unit tests for argument parser
Change-Id: Ib093b41f60efc089f47bb636e659c91ca385a437
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-main/src')
-rw-r--r-- | hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt | 102 |
1 files changed, 61 insertions, 41 deletions
diff --git a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt index 4c0224e3..b10e3597 100644 --- a/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt +++ b/hv-collector-main/src/test/kotlin/org/onap/dcae/collectors/veshv/main/ArgBasedServerConfigurationTest.kt @@ -21,8 +21,10 @@ package org.onap.dcae.collectors.veshv.main import org.assertj.core.api.Assertions.assertThat import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it +import org.jetbrains.spek.api.dsl.on import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration import org.onap.dcae.collectors.veshv.domain.ServerConfiguration import java.nio.file.Paths @@ -44,62 +46,80 @@ object ArgBasedServerConfigurationTest : Spek({ fun parse(vararg cmdLine: String) = cut.parse(cmdLine) - given("all parameters are present in the long form") { - lateinit var result: ServerConfiguration + describe("parsing arguments") { + given("all parameters are present in the long form") { + lateinit var result: ServerConfiguration - beforeEachTest { - result = parse("--listen-port", "6969", - "--config-url", configurationUrl, - "--private-key-file", pk.toFile().absolutePath, - "--cert-file", cert.toFile().absolutePath, - "--trust-cert-file", trustCert.toFile().absolutePath) - } + beforeEachTest { + result = parse("--listen-port", "6969", + "--config-url", configurationUrl, + "--private-key-file", pk.toFile().absolutePath, + "--cert-file", cert.toFile().absolutePath, + "--trust-cert-file", trustCert.toFile().absolutePath) + } - it("should set proper port") { - assertThat(result.port).isEqualTo(6969) - } + it("should set proper port") { + assertThat(result.port).isEqualTo(6969) + } - it("should set proper config url") { - assertThat(result.configurationUrl).isEqualTo(configurationUrl) - } + it("should set proper config url") { + assertThat(result.configurationUrl).isEqualTo(configurationUrl) + } - it("should set proper security configuration") { - assertThat(result.securityConfiguration).isEqualTo( - SecurityConfiguration(pk, cert, trustCert) - ) + it("should set proper security configuration") { + assertThat(result.securityConfiguration).isEqualTo( + SecurityConfiguration(pk, cert, trustCert) + ) + } } - } - given("some parameters are present in the short form") { - lateinit var result: ServerConfiguration + given("some parameters are present in the short form") { + lateinit var result: ServerConfiguration - beforeEachTest { - result = parse("-p", "666", "-c", configurationUrl) - } + beforeEachTest { + result = parse("-p", "666", "-c", configurationUrl) + } - it("should set proper port") { - assertThat(result.port).isEqualTo(666) - } + it("should set proper port") { + assertThat(result.port).isEqualTo(666) + } - it("should set proper config url") { - assertThat(result.configurationUrl).isEqualTo(configurationUrl) + it("should set proper config url") { + assertThat(result.configurationUrl).isEqualTo(configurationUrl) + } } - } - given("all optional parameters are absent") { - lateinit var result: ServerConfiguration + given("all optional parameters are absent") { + lateinit var result: ServerConfiguration - beforeEachTest { - result = parse() - } + beforeEachTest { + result = parse() + } - it("should set default port") { - assertThat(result.port).isEqualTo(DefaultValues.PORT) - } + it("should set default port") { + assertThat(result.port).isEqualTo(DefaultValues.PORT) + } + + it("should set default config url") { + assertThat(result.configurationUrl).isEqualTo(DefaultValues.CONFIG_URL) + } + + on("security config") { + val secConf = result.securityConfiguration + + it("should set default trust cert file") { + assertThat(secConf.trustedCert.toString()).isEqualTo(DefaultValues.TRUST_CERT_FILE) + } + + it("should set default server cert file") { + assertThat(secConf.cert.toString()).isEqualTo(DefaultValues.CERT_FILE) + } - it("should set default config url") { - assertThat(result.configurationUrl).isEqualTo(DefaultValues.CONFIG_URL) + it("should set default private key file") { + assertThat(secConf.privateKey.toString()).isEqualTo(DefaultValues.PRIVATE_KEY_FILE) + } + } } } }) |