2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018-2019 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.config.impl
22 import arrow.core.identity
23 import org.assertj.core.api.Assertions.assertThat
24 import org.jetbrains.spek.api.Spek
25 import org.jetbrains.spek.api.dsl.describe
26 import org.jetbrains.spek.api.dsl.given
27 import org.jetbrains.spek.api.dsl.it
28 import org.jetbrains.spek.api.dsl.on
29 import org.onap.dcae.collectors.veshv.commandline.WrongArgumentError
30 import org.onap.dcae.collectors.veshv.tests.utils.absoluteResourcePath
34 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
37 object HvVesCommandLineParserTest : Spek({
38 lateinit var cut: HvVesCommandLineParser
39 val DEFAULT_HEALTHCHECK_PORT = 6060
41 val configFilePath = javaClass.absoluteResourcePath("sampleConfig.json")
44 cut = HvVesCommandLineParser()
47 describe("parsing arguments") {
48 given("all parameters are present in the long form") {
49 lateinit var result: File
52 result = cut.parseFileExpectingSuccess(
53 "--configuration-file", configFilePath
57 it("should read proper configuration file") {
58 assertThat(result.exists()).isTrue()
62 given("required parameter is absent") {
63 on("missing configuration file path") {
64 it("should throw exception") {
66 cut.parseFileExpectingFailure(
67 "--non-existing-option", emptyConfig
69 ).isInstanceOf(WrongArgumentError::class.java)
74 given("healthcheck port defined via cmd") {
75 val healthCheckPort = 888
76 val configWithHealthcheckPort = "--health-check-api-port $healthCheckPort"
77 on("parsing command") {
78 it("should assign proper port") {
80 cut.getHealthcheckPort(arrayOf(configWithHealthcheckPort))
81 ).isEqualTo(healthCheckPort)
86 given("no healthcheck port defined via cmd") {
87 on("parsing command") {
88 it("should return default port") {
90 cut.getHealthcheckPort(arrayOf(emptyConfig))
91 ).isEqualTo(DEFAULT_HEALTHCHECK_PORT)
98 private fun HvVesCommandLineParser.parseFileExpectingSuccess(vararg cmdLine: String): File =
99 getConfigurationFile(cmdLine).fold(
100 { throw AssertionError("Parsing result should be present") },
104 private fun HvVesCommandLineParser.parseFileExpectingFailure(vararg cmdLine: String): WrongArgumentError =
105 getConfigurationFile(cmdLine).fold(
107 ) { throw AssertionError("parsing should have failed") }