Custom detekt rule for logger usage check
[dcaegen2/collectors/hv-ves.git] / sources / hv-collector-dcae-app-simulator / src / test / kotlin / org / onap / dcae / collectors / veshv / simulators / dcaeapp / impl / config / ArgDcaeAppSimConfigurationTest.kt
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.impl.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.tests.utils.parseExpectingFailure
28 import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingSuccess
29 import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
30
31
32 internal class ArgDcaeAppSimConfigurationTest : Spek({
33
34     lateinit var cut: ArgDcaeAppSimConfiguration
35     val listenPort = "1234"
36     val kafkaBootstrapServers = "localhosting:123,localhostinger:12345"
37     val kafkaTopics = "top1,top2"
38
39     beforeEachTest {
40         cut = ArgDcaeAppSimConfiguration()
41     }
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 = cut.parseExpectingSuccess(
50                         "--listen-port", listenPort,
51                         "--kafka-bootstrap-servers", kafkaBootstrapServers,
52                         "--kafka-topics", kafkaTopics
53                 )
54             }
55
56             it("should set proper port") {
57                 assertThat(result.apiPort).isEqualTo(listenPort.toInt())
58             }
59
60
61             it("should set proper kafka bootstrap servers") {
62                 assertThat(result.kafkaBootstrapServers).isEqualTo(kafkaBootstrapServers)
63             }
64
65             it("should set proper kafka topics") {
66                 assertThat(result.kafkaTopics).isEqualTo(
67                         setOf("top1", "top2")
68                 )
69             }
70         }
71
72         given("some parameters are present in the short form") {
73
74             beforeEachTest {
75                 result = cut.parseExpectingSuccess(
76                         "-p", listenPort,
77                         "--kafka-bootstrap-servers", kafkaBootstrapServers,
78                         "-f", kafkaTopics)
79             }
80
81             it("should set proper port") {
82                 assertThat(result.apiPort).isEqualTo(listenPort.toInt())
83             }
84
85             it("should set proper kafka bootstrap servers") {
86                 assertThat(result.kafkaBootstrapServers).isEqualTo(kafkaBootstrapServers)
87             }
88
89             it("should set proper kafka topics") {
90                 assertThat(result.kafkaTopics).isEqualTo(
91                         setOf("top1", "top2")
92                 )
93             }
94         }
95
96         describe("required parameter is absent") {
97             given("kafka topics are missing") {
98                 it("should throw exception") {
99                     assertThat(cut.parseExpectingFailure(
100                             "-p", listenPort,
101                             "-s", kafkaBootstrapServers
102                     )).isInstanceOf(WrongArgumentError::class.java)
103                 }
104             }
105
106             given("kafka bootstrap servers is missing") {
107                 it("should throw exception") {
108                     assertThat(cut.parseExpectingFailure(
109                             "-p", listenPort,
110                             "-f", kafkaTopics
111                     )).isInstanceOf(WrongArgumentError::class.java)
112                 }
113             }
114
115             given("listen port is missing") {
116                 it("should throw exception") {
117                     assertThat(cut.parseExpectingFailure(
118                             "-p", listenPort,
119                             "-s", kafkaBootstrapServers
120                     )).isInstanceOf(WrongArgumentError::class.java)
121                 }
122             }
123         }
124     }
125 })