aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-configuration/src/test
diff options
context:
space:
mode:
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