2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 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.simulators.dcaeapp.config
22 import arrow.core.Failure
23 import arrow.core.Success
24 import arrow.core.identity
25 import org.assertj.core.api.Assertions.assertThat
26 import org.jetbrains.spek.api.Spek
27 import org.jetbrains.spek.api.dsl.describe
28 import org.jetbrains.spek.api.dsl.given
29 import org.jetbrains.spek.api.dsl.it
30 import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
33 internal class ArgBasedDcaeAppSimConfigurationTest : Spek({
35 lateinit var cut: ArgBasedDcaeAppSimConfiguration
36 val kafkaBootstrapServers = "localhosting:123,localhostinger:12345"
37 val kafkaTopics = "top1,top2"
40 cut = ArgBasedDcaeAppSimConfiguration()
43 fun parseExpectingSuccess(vararg cmdLine: String): DcaeAppSimConfiguration =
44 cut.parse(cmdLine).fold(
45 { throw AssertionError("Parsing result should be present") },
49 fun parseExpectingFailure(vararg cmdLine: String) =
50 cut.parse(cmdLine).fold(
52 { throw AssertionError("parsing should have failed") }
55 describe("parsing arguments") {
56 lateinit var result: DcaeAppSimConfiguration
58 given("all parameters are present in the long form") {
61 result = parseExpectingSuccess("--listen-port", "6969",
62 "--kafka-bootstrap-servers", kafkaBootstrapServers,
63 "--kafka-topics", kafkaTopics
67 it("should set proper port") {
68 assertThat(result.apiPort).isEqualTo(6969)
72 it("should set proper kafka boostrap servers") {
73 assertThat(result.kafkaBootstrapServers).isEqualTo(kafkaBootstrapServers)
76 it("should set proper kafka topics") {
77 assertThat(result.kafkaTopics).isEqualTo(
83 given("some parameters are present in the short form") {
86 result = parseExpectingSuccess("-p", "666",
87 "--kafka-bootstrap-servers", kafkaBootstrapServers,
91 it("should set proper port") {
92 assertThat(result.apiPort).isEqualTo(666)
95 it("should set proper kafka boostrap servers") {
96 assertThat(result.kafkaBootstrapServers).isEqualTo(kafkaBootstrapServers)
99 it("should set proper kafka topics") {
100 assertThat(result.kafkaTopics).isEqualTo(
101 setOf("top1", "top2")
106 given("all optional parameters are absent") {
109 result = parseExpectingSuccess("-s", kafkaBootstrapServers, "-f", kafkaTopics)
112 it("should set default port") {
113 assertThat(result.apiPort).isEqualTo(DefaultValues.API_PORT)
117 describe("required parameter is absent") {
118 given("kafka topics are missing") {
119 it("should throw exception") {
120 assertThat(parseExpectingFailure("-s", kafkaBootstrapServers))
121 .isInstanceOf(WrongArgumentError::class.java)
125 given("kafka bootstrap servers are missing") {
126 it("should throw exception") {
127 assertThat(parseExpectingFailure("-f", kafkaTopics))
128 .isInstanceOf(WrongArgumentError::class.java)