aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-configuration/src/test
diff options
context:
space:
mode:
authorkjaniak <kornel.janiak@nokia.com>2019-03-28 10:43:59 +0100
committerKornel Janiak <kornel.janiak@nokia.com>2019-03-29 08:17:14 +0000
commit4281a12d8e892f46f5f2226ee0f8aee8b862b177 (patch)
treececcc8eb35d669afdee1d250b0b3c50ee0d9a940 /sources/hv-collector-configuration/src/test
parent4f5d73f18a7952379505a4995b6afe22acf31c11 (diff)
Read HV-VES healthcheck api port from cmd line
Change-Id: I6b4680a62512ef6ba15a0454e109b19619a997a6 Issue-ID: DCAEGEN2-1364 Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Diffstat (limited to 'sources/hv-collector-configuration/src/test')
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/HvVesCommandLineParserTest.kt (renamed from sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfigurationTest.kt)54
1 files changed, 44 insertions, 10 deletions
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfigurationTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/HvVesCommandLineParserTest.kt
index dbe757c4..0fdd41c9 100644
--- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ArgHvVesConfigurationTest.kt
+++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/HvVesCommandLineParserTest.kt
@@ -19,6 +19,7 @@
*/
package org.onap.dcae.collectors.veshv.config.impl
+import arrow.core.identity
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
@@ -27,20 +28,20 @@ import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.commandline.WrongArgumentError
import org.onap.dcae.collectors.veshv.tests.utils.absoluteResourcePath
-import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingFailure
-import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingSuccess
import java.io.File
/**
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
* @since May 2018
*/
-object ArgVesHvConfigurationTest : Spek({
- lateinit var cut: ArgHvVesConfiguration
+object HvVesCommandLineParserTest : Spek({
+ lateinit var cut: HvVesCommandLineParser
+ val DEFAULT_HEALTHCHECK_PORT = 6060
+ val emptyConfig = ""
val configFilePath = javaClass.absoluteResourcePath("sampleConfig.json")
beforeEachTest {
- cut = ArgHvVesConfiguration()
+ cut = HvVesCommandLineParser()
}
describe("parsing arguments") {
@@ -48,7 +49,7 @@ object ArgVesHvConfigurationTest : Spek({
lateinit var result: File
beforeEachTest {
- result = cut.parseExpectingSuccess(
+ result = cut.parseFileExpectingSuccess(
"--configuration-file", configFilePath
)
}
@@ -58,16 +59,49 @@ object ArgVesHvConfigurationTest : Spek({
}
}
- describe("required parameter is absent") {
+ given("required parameter is absent") {
on("missing configuration file path") {
it("should throw exception") {
assertThat(
- cut.parseExpectingFailure(
- "--non-existing-option", ""
+ cut.parseFileExpectingFailure(
+ "--non-existing-option", emptyConfig
)
).isInstanceOf(WrongArgumentError::class.java)
}
}
}
+
+ given("healthcheck port defined via cmd") {
+ val healthCheckPort = 888
+ val configWithHealthcheckPort = "--health-check-api-port $healthCheckPort"
+ on("parsing command") {
+ it("should assign proper port") {
+ assertThat(
+ cut.getHealthcheckPort(arrayOf(configWithHealthcheckPort))
+ ).isEqualTo(healthCheckPort)
+ }
+ }
+ }
+
+ given("no healthcheck port defined via cmd") {
+ on("parsing command") {
+ it("should return default port") {
+ assertThat(
+ cut.getHealthcheckPort(arrayOf(emptyConfig))
+ ).isEqualTo(DEFAULT_HEALTHCHECK_PORT)
+ }
+ }
+ }
}
-}) \ No newline at end of file
+})
+
+private fun HvVesCommandLineParser.parseFileExpectingSuccess(vararg cmdLine: String): File =
+ getConfigurationFile(cmdLine).fold(
+ { throw AssertionError("Parsing result should be present") },
+ ::identity
+ )
+
+private fun HvVesCommandLineParser.parseFileExpectingFailure(vararg cmdLine: String): WrongArgumentError =
+ getConfigurationFile(cmdLine).fold(
+ ::identity
+ ) { throw AssertionError("parsing should have failed") } \ No newline at end of file