diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-07-24 11:48:12 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-03 09:41:09 +0200 |
commit | fc6ab3e5fee2bc3e607848caa665b166d6f38dd6 (patch) | |
tree | c54a032ef0093f7024cff963addca163b0dcf98e /hv-collector-xnf-simulator/src/test | |
parent | 53dbf8e66ad83c2d5f06279a0d7446e5e8be68e8 (diff) |
Rework argument configuration
- Unify names of argument configuration classes in
DCAE APP simulator, XNF simualtor and VES HV Collector
- Make some of the arguments required
- Adjust docker-compose and Dockerfiles
- Adjust test cases and error handling
Closes ONAP-683
Change-Id: I4a9d43791cced9dcb52eb83e2f7956462e8712d9
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-xnf-simulator/src/test')
-rw-r--r-- | hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt (renamed from hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt) | 77 |
1 files changed, 64 insertions, 13 deletions
diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt index 04d81c74..e3a20c70 100644 --- a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt +++ b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgXnfSimulatorConfiurationTest.kt @@ -20,6 +20,7 @@ package org.onap.dcae.collectors.veshv.main.config import arrow.core.identity +import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.describe @@ -27,22 +28,25 @@ 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.simulators.xnf.config.ArgConfigurationProvider -import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgConfigurationProvider.DefaultValues +import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration +import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgXnfSimulatorConfiguration.DefaultValues import org.onap.dcae.collectors.veshv.simulators.xnf.config.SimulatorConfiguration +import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError import java.nio.file.Paths import kotlin.test.assertTrue -object ArgConfigurationProviderTest : Spek({ - lateinit var cut: ArgConfigurationProvider - val vesHost = "localhosting" +object ArgXnfSimulatorConfiurationTest : Spek({ + lateinit var cut: ArgXnfSimulatorConfiguration + val listenPort = "4321" + val vesHost = "localhost" + val vesPort = "1234" val pk = Paths.get("/", "etc", "ves", "pk.pem") val cert = Paths.get("/", "etc", "ssl", "certs", "ca-bundle.crt") val trustCert = Paths.get("/", "etc", "ves", "trusted.crt") beforeEachTest { - cut = ArgConfigurationProvider() + cut = ArgXnfSimulatorConfiguration() } fun parse(vararg cmdLine: String): SimulatorConfiguration = @@ -51,6 +55,12 @@ object ArgConfigurationProviderTest : Spek({ ::identity ) + fun parseExpectingFailure(vararg cmdLine: String) = + cut.parse(cmdLine).fold( + ::identity, + { throw AssertionError("parsing should have failed") } + ) + describe("parsing arguments") { lateinit var result: SimulatorConfiguration @@ -58,15 +68,24 @@ object ArgConfigurationProviderTest : Spek({ beforeEachTest { result = parse("--ssl-disable", - "--ves-port", "6969", + "--listen-port", listenPort, "--ves-host", vesHost, + "--ves-port", vesPort, "--private-key-file", pk.toFile().absolutePath, "--cert-file", cert.toFile().absolutePath, "--trust-cert-file", trustCert.toFile().absolutePath) } - it("should set proper port") { - assertThat(result.vesPort).isEqualTo(6969) + it("should set proper listen port") { + assertThat(result.listenPort).isEqualTo(listenPort.toInt()) + } + + it("should set proper ves host") { + assertThat(result.vesHost).isEqualTo(vesHost) + } + + it("should set proper ves port") { + assertThat(result.vesPort).isEqualTo(vesPort.toInt()) } it("should set proper security configuration") { @@ -79,18 +98,26 @@ object ArgConfigurationProviderTest : Spek({ given("some parameters are present in the short form") { beforeEachTest { - result = parse("-h", "ves-hv", "--ves-port", "666") + result = parse("-p", listenPort, "-h", vesHost, "--ves-port", vesPort) + } + + it("should set proper listen port") { + assertThat(result.listenPort).isEqualTo(listenPort.toInt()) + } + + it("should set proper ves host") { + assertThat(result.vesHost).isEqualTo(vesHost) } - it("should set proper port") { - assertThat(result.vesPort).isEqualTo(666) + it("should set proper ves port") { + assertThat(result.vesPort).isEqualTo(vesPort.toInt()) } } given("all optional parameters are absent") { beforeEachTest { - result = parse("-h", "ves-hv", "-v", "666") + result = parse("-p", listenPort, "-h", vesHost, "-v", vesPort) } on("security config") { @@ -113,6 +140,7 @@ object ArgConfigurationProviderTest : Spek({ given("disabled ssl certs together with all other parameters") { beforeEachTest { result = parse("--ssl-disable", + "--listen-port", listenPort, "--ves-port", "888", "--ves-host", vesHost, "--private-key-file", pk.toFile().absolutePath, @@ -138,5 +166,28 @@ object ArgConfigurationProviderTest : Spek({ } } } + + describe("required parameter is absent") { + given("ves port is missing") { + it("should throw exception") { + assertThat(parseExpectingFailure("-p", listenPort, "-h", vesHost)) + .isInstanceOf(WrongArgumentError::class.java) + } + } + + given("ves host is missing") { + it("should throw exception") { + assertThat(parseExpectingFailure("-p", listenPort, "-v", vesPort)) + .isInstanceOf(WrongArgumentError::class.java) + } + } + + given("listen port is missing") { + it("should throw exception") { + assertThat(parseExpectingFailure("-h", vesHost, "-v", vesPort)) + .isInstanceOf(WrongArgumentError::class.java) + } + } + } } }) |