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.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.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
31 internal class ArgDcaeAppSimulatorConfigurationTest : Spek({
33 lateinit var cut: ArgDcaeAppSimConfiguration
34 val listenPort = "1234"
35 val kafkaBootstrapServers = "localhosting:123,localhostinger:12345"
36 val kafkaTopics = "top1,top2"
39 cut = ArgDcaeAppSimConfiguration()
42 fun parseExpectingSuccess(vararg cmdLine: String): DcaeAppSimConfiguration =
43 cut.parse(cmdLine).fold(
44 { throw AssertionError("Parsing result should be present") },
48 fun parseExpectingFailure(vararg cmdLine: String) =
49 cut.parse(cmdLine).fold(
51 { throw AssertionError("parsing should have failed") }
54 describe("parsing arguments") {
55 lateinit var result: DcaeAppSimConfiguration
57 given("all parameters are present in the long form") {
60 result = parseExpectingSuccess(
61 "--listen-port", listenPort,
62 "--kafka-bootstrap-servers", kafkaBootstrapServers,
63 "--kafka-topics", kafkaTopics
67 it("should set proper port") {
68 assertThat(result.apiPort).isEqualTo(listenPort.toInt())
72 it("should set proper kafka bootstrap 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(
88 "--kafka-bootstrap-servers", kafkaBootstrapServers,
92 it("should set proper port") {
93 assertThat(result.apiPort).isEqualTo(listenPort.toInt())
96 it("should set proper kafka bootstrap servers") {
97 assertThat(result.kafkaBootstrapServers).isEqualTo(kafkaBootstrapServers)
100 it("should set proper kafka topics") {
101 assertThat(result.kafkaTopics).isEqualTo(
102 setOf("top1", "top2")
107 describe("required parameter is absent") {
108 given("kafka topics are missing") {
109 it("should throw exception") {
110 assertThat(parseExpectingFailure(
112 "-s", kafkaBootstrapServers
113 )).isInstanceOf(WrongArgumentError::class.java)
117 given("kafka bootstrap servers is missing") {
118 it("should throw exception") {
119 assertThat(parseExpectingFailure(
122 )).isInstanceOf(WrongArgumentError::class.java)
126 given("listen port is missing") {
127 it("should throw exception") {
128 assertThat(parseExpectingFailure(
130 "-s", kafkaBootstrapServers
131 )).isInstanceOf(WrongArgumentError::class.java)