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.config
22 import arrow.core.Failure
23 import arrow.core.Success
24 import org.assertj.core.api.Assertions.assertThat
25 import org.jetbrains.spek.api.Spek
26 import org.jetbrains.spek.api.dsl.describe
27 import org.jetbrains.spek.api.dsl.given
28 import org.jetbrains.spek.api.dsl.it
29 import org.jetbrains.spek.api.dsl.on
30 import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
31 import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgBasedClientConfiguration
32 import org.onap.dcae.collectors.veshv.simulators.xnf.config.ClientConfiguration
33 import org.onap.dcae.collectors.veshv.simulators.xnf.config.DefaultValues
34 import java.nio.file.Paths
37 object ArgBasedClientConfigurationTest : Spek({
38 lateinit var cut: ArgBasedClientConfiguration
39 val messagesAmount = 3L
40 val vesHost = "localhosting"
41 val pk = Paths.get("/", "etc", "ves", "pk.pem")
42 val cert = Paths.get("/", "etc", "ssl", "certs", "ca-bundle.crt")
43 val trustCert = Paths.get("/", "etc", "ves", "trusted.crt")
46 cut = ArgBasedClientConfiguration()
49 fun parse(vararg cmdLine: String): ClientConfiguration {
50 val result = cut.parse(cmdLine)
51 return when (result) {
52 is Success -> result.value
53 is Failure -> throw AssertionError("Parsing result should be present")
57 describe("parsing arguments") {
58 lateinit var result: ClientConfiguration
60 given("all parameters are present in the long form") {
63 result = parse("--ves-port", "6969",
64 "--ves-host", vesHost,
65 "--messages", messagesAmount.toString(),
66 "--private-key-file", pk.toFile().absolutePath,
67 "--cert-file", cert.toFile().absolutePath,
68 "--trust-cert-file", trustCert.toFile().absolutePath)
71 it("should set proper port") {
72 assertThat(result.vesPort).isEqualTo(6969)
76 it("should set proper config url") {
77 assertThat(result.messagesAmount).isEqualTo(messagesAmount)
80 it("should set proper security configuration") {
81 assertThat(result.security).isEqualTo(
82 SecurityConfiguration(pk, cert, trustCert)
87 given("some parameters are present in the short form") {
90 result = parse("-h", "ves-hv", "--ves-port", "666", "-m", messagesAmount.toString())
93 it("should set proper port") {
94 assertThat(result.vesPort).isEqualTo(666)
97 it("should set proper messages amount") {
98 assertThat(result.messagesAmount).isEqualTo(messagesAmount)
102 given("all optional parameters are absent") {
105 result = parse("-h", "ves-hv", "-p", "666")
108 it("should set default messages amount") {
109 assertThat(result.messagesAmount).isEqualTo(DefaultValues.MESSAGES_AMOUNT)
112 on("security config") {
113 val securityConfiguration = result.security
115 it("should set default trust cert file") {
116 assertThat(securityConfiguration.trustedCert.toString()).isEqualTo(DefaultValues.TRUST_CERT_FILE)
119 it("should set default server cert file") {
120 assertThat(securityConfiguration.cert.toString()).isEqualTo(DefaultValues.CERT_FILE)
123 it("should set default private key file") {
124 assertThat(securityConfiguration.privateKey.toString()).isEqualTo(DefaultValues.PRIVATE_KEY_FILE)