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 ArgVesHvConfigurationTest : Spek({
38 lateinit var cut: ArgHvVesConfiguration
39 val configFilePath = javaClass.absoluteResourcePath("sampleConfig.json")
42 cut = ArgHvVesConfiguration()
45 describe("parsing arguments") {
46 given("all parameters are present in the long form") {
47 lateinit var result: File
50 result = cut.parseExpectingSuccess(
51 "--configuration-file", configFilePath
55 it("should read proper configuration file") {
56 assertThat(result.exists()).isTrue()
60 describe("required parameter is absent") {
61 on("missing configuration file path") {
62 it("should throw exception") {
64 cut.parseExpectingFailure(
65 "--non-existing-option", ""
67 ).isInstanceOf(WrongArgumentError::class.java)
74 fun ArgHvVesConfiguration.parseExpectingSuccess(vararg cmdLine: String): File =
75 parseToFile(cmdLine).fold(
76 { throw AssertionError("Parsing result should be present") },
80 fun ArgHvVesConfiguration.parseExpectingFailure(vararg cmdLine: String): WrongArgumentError =
81 parseToFile(cmdLine).fold(
83 ) { throw AssertionError("parsing should have failed") }