817df8e07901f14800a8fa497c50202dcfcf28e7
[dcaegen2/collectors/hv-ves.git] /
1 /*
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.simulators.dcaeapp.config
21
22 import org.assertj.core.api.Assertions.assertThat
23 import org.jetbrains.spek.api.Spek
24 import org.jetbrains.spek.api.dsl.describe
25 import org.jetbrains.spek.api.dsl.given
26 import org.jetbrains.spek.api.dsl.it
27 import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentException
28 import kotlin.test.assertFailsWith
29
30
31 internal class ArgBasedDcaeAppSimConfigurationTest : Spek({
32
33     lateinit var cut: ArgBasedDcaeAppSimConfiguration
34     val kafkaBootstrapServers = "localhosting:123,localhostinger:12345"
35     val kafkaTopics = "top1,top2"
36
37     beforeEachTest {
38         cut = ArgBasedDcaeAppSimConfiguration()
39     }
40
41     fun parse(vararg cmdLine: String) = cut.parse(cmdLine)
42
43     describe("parsing arguments") {
44         lateinit var result: DcaeAppSimConfiguration
45
46         given("all parameters are present in the long form") {
47
48             beforeEachTest {
49                 result = parse("--listen-port", "6969",
50                         "--kafka-bootstrap-servers", kafkaBootstrapServers,
51                         "--kafka-topics", kafkaTopics
52                 )
53             }
54
55             it("should set proper port") {
56                 assertThat(result.apiPort).isEqualTo(6969)
57             }
58
59
60             it("should set proper kafka boostrap servers") {
61                 assertThat(result.kafkaBootstrapServers).isEqualTo(kafkaBootstrapServers)
62             }
63
64             it("should set proper kafka topics") {
65                 assertThat(result.kafkaTopics).isEqualTo(
66                         setOf("top1", "top2")
67                 )
68             }
69         }
70
71         given("some parameters are present in the short form") {
72
73             beforeEachTest {
74                 result = parse("-p", "666", "--kafka-bootstrap-servers", kafkaBootstrapServers, "-f", kafkaTopics)
75             }
76
77             it("should set proper port") {
78                 assertThat(result.apiPort).isEqualTo(666)
79             }
80
81             it("should set proper kafka boostrap servers") {
82                 assertThat(result.kafkaBootstrapServers).isEqualTo(kafkaBootstrapServers)
83             }
84
85             it("should set proper kafka topics") {
86                 assertThat(result.kafkaTopics).isEqualTo(
87                         setOf("top1", "top2")
88                 )
89             }
90         }
91
92         given("all optional parameters are absent") {
93
94             beforeEachTest {
95                 result = parse("-s", kafkaBootstrapServers, "-f", kafkaTopics)
96             }
97
98             it("should set default port") {
99                 assertThat(result.apiPort).isEqualTo(DefaultValues.API_PORT)
100             }
101         }
102
103
104         describe("required parameter is absent") {
105             given("kafka topics are missing") {
106                 it("should throw exception") {
107                     assertFailsWith<WrongArgumentException> { parse("-s", kafkaBootstrapServers) }
108                 }
109             }
110
111             given("kafka bootstrap servers are missing") {
112                 it("should throw exception") {
113                     assertFailsWith<WrongArgumentException> { parse("-f", kafkaTopics) }
114                 }
115             }
116         }
117     }
118
119
120 })