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.main
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.jetbrains.spek.api.dsl.on
28 import org.onap.dcae.collectors.veshv.domain.JdkKeys
29 import org.onap.dcae.collectors.veshv.model.ServerConfiguration
30 import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingFailure
31 import org.onap.dcae.collectors.veshv.tests.utils.parseExpectingSuccess
32 import org.onap.dcae.collectors.veshv.utils.commandline.WrongArgumentError
33 import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
34 import java.time.Duration
35 import kotlin.test.assertNotNull
38 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
41 object ArgVesHvConfigurationTest : Spek({
42 lateinit var cut: ArgVesHvConfiguration
43 val kafkaBootstrapServers = "dmaap-mr-wro:6666,dmaap-mr-gda:6666"
44 val healthCheckApiPort = "6070"
45 val configurationUrl = "http://test-address/test"
46 val firstRequestDelay = "10"
47 val requestInterval = "5"
48 val listenPort = "6969"
49 val keyStorePassword = "kspass"
50 val trustStorePassword = "tspass"
51 val logLevel = LogLevel.DEBUG.name
54 cut = ArgVesHvConfiguration()
57 describe("parsing arguments") {
58 given("all parameters are present in the long form") {
59 lateinit var result: ServerConfiguration
62 result = cut.parseExpectingSuccess(
63 "--kafka-bootstrap-servers", kafkaBootstrapServers,
64 "--health-check-api-port", healthCheckApiPort,
65 "--listen-port", listenPort,
66 "--config-url", configurationUrl,
67 "--first-request-delay", firstRequestDelay,
68 "--request-interval", requestInterval,
69 "--key-store", "/tmp/keys.p12",
70 "--trust-store", "/tmp/trust.p12",
71 "--key-store-password", keyStorePassword,
72 "--trust-store-password", trustStorePassword,
73 "--log-level", logLevel
77 it("should set proper kafka bootstrap servers") {
78 assertThat(result.kafkaConfiguration.bootstrapServers).isEqualTo(kafkaBootstrapServers)
81 it("should set proper listen port") {
82 assertThat(result.serverListenAddress.port).isEqualTo(listenPort.toInt())
86 it("should set default listen address") {
87 assertThat(result.serverListenAddress.address.hostAddress).isEqualTo("0.0.0.0")
90 it("should set proper health check api port") {
91 assertThat(result.healthCheckApiListenAddress.port).isEqualTo(healthCheckApiPort.toInt())
94 it("should set default health check api address") {
95 assertThat(result.healthCheckApiListenAddress.address.hostAddress).isEqualTo("0.0.0.0")
98 it("should set proper first consul request delay") {
99 assertThat(result.configurationProviderParams.firstRequestDelay)
100 .isEqualTo(Duration.ofSeconds(firstRequestDelay.toLong()))
103 it("should set proper consul request interval") {
104 assertThat(result.configurationProviderParams.requestInterval)
105 .isEqualTo(Duration.ofSeconds(requestInterval.toLong()))
108 it("should set proper config url") {
109 assertThat(result.configurationProviderParams.configurationUrl)
110 .isEqualTo(configurationUrl)
113 it("should set proper security configuration") {
114 assertThat(result.securityConfiguration.sslDisable).isFalse()
116 val keys = result.securityConfiguration.keys.orNull() as JdkKeys
117 assertNotNull(keys.keyStore)
118 assertNotNull(keys.trustStore)
119 assertThat(keys.keyStorePassword).isEqualTo(keyStorePassword.toCharArray())
120 assertThat(keys.trustStorePassword).isEqualTo(trustStorePassword.toCharArray())
123 it("should set proper log level") {
124 assertThat(result.logLevel).isEqualTo(LogLevel.DEBUG)
128 describe("required parameter is absent") {
129 on("missing listen port") {
130 it("should throw exception") {
132 cut.parseExpectingFailure(
133 "--config-url", configurationUrl,
135 "--first-request-delay", firstRequestDelay,
136 "--request-interval", requestInterval
138 ).isInstanceOf(WrongArgumentError::class.java)
141 on("missing configuration url") {
142 it("should throw exception") {
144 cut.parseExpectingFailure(
145 "--listen-port", listenPort,
147 "--first-request-delay", firstRequestDelay,
148 "--request-interval", requestInterval
150 ).isInstanceOf(WrongArgumentError::class.java)
155 describe("correct log level not provided") {
156 on("missing log level") {
157 it("should set default INFO value") {
158 val config = cut.parseExpectingSuccess(
159 "--kafka-bootstrap-servers", kafkaBootstrapServers,
160 "--health-check-api-port", healthCheckApiPort,
161 "--listen-port", listenPort,
162 "--config-url", configurationUrl,
163 "--first-request-delay", firstRequestDelay,
164 "--request-interval", requestInterval,
165 "--key-store", "/tmp/keys.p12",
166 "--trust-store", "/tmp/trust.p12",
167 "--key-store-password", keyStorePassword,
168 "--trust-store-password", trustStorePassword
171 assertThat(config.logLevel).isEqualTo(LogLevel.INFO)
175 on("incorrect log level") {
176 it("should set default INFO value") {
177 val config = cut.parseExpectingSuccess(
178 "--kafka-bootstrap-servers", kafkaBootstrapServers,
179 "--health-check-api-port", healthCheckApiPort,
180 "--listen-port", listenPort,
181 "--config-url", configurationUrl,
182 "--first-request-delay", firstRequestDelay,
183 "--request-interval", requestInterval,
184 "--key-store", "/tmp/keys.p12",
185 "--trust-store", "/tmp/trust.p12",
186 "--key-store-password", keyStorePassword,
187 "--trust-store-password", trustStorePassword,
191 assertThat(config.logLevel).isEqualTo(LogLevel.INFO)