2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018-2019 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.commandline.WrongArgumentError
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.logging.LogLevel
33 import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys
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 firstRequestDelay = "10"
46 val requestInterval = "5"
47 val listenPort = "6969"
48 val keyStorePassword = "kspass"
49 val trustStorePassword = "tspass"
50 val logLevel = LogLevel.DEBUG.name
53 cut = ArgVesHvConfiguration()
56 describe("parsing arguments") {
57 given("all parameters are present in the long form") {
58 lateinit var result: ServerConfiguration
61 result = cut.parseExpectingSuccess(
62 "--kafka-bootstrap-servers", kafkaBootstrapServers,
63 "--health-check-api-port", healthCheckApiPort,
64 "--listen-port", listenPort,
65 "--first-request-delay", firstRequestDelay,
66 "--request-interval", requestInterval,
67 "--key-store", "/tmp/keys.p12",
68 "--trust-store", "/tmp/trust.p12",
69 "--key-store-password", keyStorePassword,
70 "--trust-store-password", trustStorePassword,
71 "--log-level", logLevel
75 it("should set proper kafka bootstrap servers") {
76 assertThat(result.kafkaConfiguration.bootstrapServers).isEqualTo(kafkaBootstrapServers)
79 it("should set proper listen port") {
80 assertThat(result.serverListenAddress.port).isEqualTo(listenPort.toInt())
84 it("should set default listen address") {
85 assertThat(result.serverListenAddress.address.hostAddress).isEqualTo("0.0.0.0")
88 it("should set proper health check api port") {
89 assertThat(result.healthCheckApiListenAddress.port).isEqualTo(healthCheckApiPort.toInt())
92 it("should set default health check api address") {
93 assertThat(result.healthCheckApiListenAddress.address.hostAddress).isEqualTo("0.0.0.0")
96 it("should set proper first request delay") {
97 assertThat(result.configurationProviderParams.firstRequestDelay)
98 .isEqualTo(Duration.ofSeconds(firstRequestDelay.toLong()))
101 it("should set proper request interval") {
102 assertThat(result.configurationProviderParams.requestInterval)
103 .isEqualTo(Duration.ofSeconds(requestInterval.toLong()))
106 it("should set proper security configuration") {
107 assertThat(result.securityConfiguration.keys.isEmpty()).isFalse()
109 val keys = result.securityConfiguration.keys.orNull() as SecurityKeys
110 assertNotNull(keys.keyStore())
111 assertNotNull(keys.trustStore())
112 keys.keyStorePassword().useChecked {
113 assertThat(it).isEqualTo(keyStorePassword.toCharArray())
116 keys.trustStorePassword().useChecked {
117 assertThat(it).isEqualTo(trustStorePassword.toCharArray())
121 it("should set proper log level") {
122 assertThat(result.logLevel).isEqualTo(LogLevel.DEBUG)
126 describe("required parameter is absent") {
127 on("missing listen port") {
128 it("should throw exception") {
130 cut.parseExpectingFailure(
132 "--first-request-delay", firstRequestDelay,
133 "--request-interval", requestInterval
135 ).isInstanceOf(WrongArgumentError::class.java)
138 on("missing configuration url") {
139 it("should throw exception") {
141 cut.parseExpectingFailure(
142 "--listen-port", listenPort,
144 "--first-request-delay", firstRequestDelay,
145 "--request-interval", requestInterval
147 ).isInstanceOf(WrongArgumentError::class.java)
152 describe("correct log level not provided") {
153 on("missing log level") {
154 it("should set default INFO value") {
155 val config = cut.parseExpectingSuccess(
156 "--kafka-bootstrap-servers", kafkaBootstrapServers,
157 "--health-check-api-port", healthCheckApiPort,
158 "--listen-port", listenPort,
159 "--first-request-delay", firstRequestDelay,
160 "--request-interval", requestInterval,
161 "--key-store", "/tmp/keys.p12",
162 "--trust-store", "/tmp/trust.p12",
163 "--key-store-password", keyStorePassword,
164 "--trust-store-password", trustStorePassword
167 assertThat(config.logLevel).isEqualTo(LogLevel.INFO)
171 on("incorrect log level") {
172 it("should set default INFO value") {
173 val config = cut.parseExpectingSuccess(
174 "--kafka-bootstrap-servers", kafkaBootstrapServers,
175 "--health-check-api-port", healthCheckApiPort,
176 "--listen-port", listenPort,
177 "--first-request-delay", firstRequestDelay,
178 "--request-interval", requestInterval,
179 "--key-store", "/tmp/keys.p12",
180 "--trust-store", "/tmp/trust.p12",
181 "--key-store-password", keyStorePassword,
182 "--trust-store-password", trustStorePassword,
186 assertThat(config.logLevel).isEqualTo(LogLevel.INFO)