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 java.time.Duration
34 import kotlin.test.assertNotNull
37 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
40 object ArgVesHvConfigurationTest : Spek({
41 lateinit var cut: ArgVesHvConfiguration
42 val kafkaBootstrapServers = "dmaap-mr-wro:6666,dmaap-mr-gda:6666"
43 val healthCheckApiPort = "6070"
44 val configurationUrl = "http://test-address/test"
45 val firstRequestDelay = "10"
46 val requestInterval = "5"
47 val listenPort = "6969"
48 val keyStorePassword = "kspass"
49 val trustStorePassword = "tspass"
52 cut = ArgVesHvConfiguration()
55 describe("parsing arguments") {
56 given("all parameters are present in the long form") {
57 lateinit var result: ServerConfiguration
60 result = cut.parseExpectingSuccess(
61 "--kafka-bootstrap-servers", kafkaBootstrapServers,
62 "--health-check-api-port", healthCheckApiPort,
63 "--listen-port", listenPort,
64 "--config-url", configurationUrl,
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
74 it("should set proper kafka bootstrap servers") {
75 assertThat(result.kafkaConfiguration.bootstrapServers).isEqualTo(kafkaBootstrapServers)
78 it("should set proper listen port") {
79 assertThat(result.serverListenAddress.port).isEqualTo(listenPort.toInt())
83 it("should set default listen address") {
84 assertThat(result.serverListenAddress.address.hostAddress).isEqualTo("0.0.0.0")
87 it("should set proper health check api port") {
88 assertThat(result.healthCheckApiListenAddress.port).isEqualTo(healthCheckApiPort.toInt())
91 it("should set default health check api address") {
92 assertThat(result.healthCheckApiListenAddress.address.hostAddress).isEqualTo("0.0.0.0")
95 it("should set proper first consul request delay") {
96 assertThat(result.configurationProviderParams.firstRequestDelay)
97 .isEqualTo(Duration.ofSeconds(firstRequestDelay.toLong()))
100 it("should set proper consul request interval") {
101 assertThat(result.configurationProviderParams.requestInterval)
102 .isEqualTo(Duration.ofSeconds(requestInterval.toLong()))
105 it("should set proper config url") {
106 assertThat(result.configurationProviderParams.configurationUrl)
107 .isEqualTo(configurationUrl)
110 it("should set proper security configuration") {
111 assertThat(result.securityConfiguration.sslDisable).isFalse()
113 val keys = result.securityConfiguration.keys.orNull() as JdkKeys
114 assertNotNull(keys.keyStore)
115 assertNotNull(keys.trustStore)
116 assertThat(keys.keyStorePassword).isEqualTo(keyStorePassword.toCharArray())
117 assertThat(keys.trustStorePassword).isEqualTo(trustStorePassword.toCharArray())
121 describe("required parameter is absent") {
122 on("missing listen port") {
123 it("should throw exception") {
124 assertThat(cut.parseExpectingFailure(
125 "--config-url", configurationUrl,
127 "--first-request-delay", firstRequestDelay,
128 "--request-interval", requestInterval)
129 ).isInstanceOf(WrongArgumentError::class.java)
132 on("missing configuration url") {
133 it("should throw exception") {
134 assertThat(cut.parseExpectingFailure(
135 "--listen-port", listenPort,
137 "--first-request-delay", firstRequestDelay,
138 "--request-interval", requestInterval)
139 ).isInstanceOf(WrongArgumentError::class.java)