2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 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.config.impl
22 import arrow.core.None
23 import arrow.core.Option
24 import arrow.core.Some
25 import com.nhaarman.mockitokotlin2.mock
26 import org.assertj.core.api.Assertions.assertThat
27 import org.assertj.core.api.Assertions.fail
28 import org.jetbrains.spek.api.Spek
29 import org.jetbrains.spek.api.dsl.describe
30 import org.jetbrains.spek.api.dsl.it
31 import org.onap.dcae.collectors.veshv.config.api.model.Routing
32 import org.onap.dcae.collectors.veshv.config.impl.ConfigurationValidator.Companion.DEFAULT_LOG_LEVEL
33 import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
34 import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys
35 import java.time.Duration
37 internal object ConfigurationValidatorTest : Spek({
38 describe("ConfigurationValidator") {
39 val cut = ConfigurationValidator()
41 describe("validating partial configuration with missing fields") {
42 val config = PartialConfiguration(
43 Some(PartialServerConfig(listenPort = Some(1)))
46 it("should return ValidationError") {
47 val result = cut.validate(config)
48 assertThat(result.isLeft()).isTrue()
52 describe("validating configuration with empty log level") {
53 val config = PartialConfiguration(
54 Some(PartialServerConfig(
56 Some(Duration.ofSeconds(2)),
59 Some(PartialCbsConfig(
60 Some(Duration.ofSeconds(5)),
61 Some(Duration.ofSeconds(3))
63 Some(PartialSecurityConfig(
66 Some(PartialCollectorConfig(
74 it("should use default log level") {
75 val result = cut.validate(config)
78 fail("Configuration should have been created successfully")
81 assertThat(it.logLevel).isEqualTo(DEFAULT_LOG_LEVEL)
87 describe("validating complete configuration") {
88 val idleTimeoutSec = Duration.ofSeconds(10L)
89 val firstReqDelaySec = Duration.ofSeconds(10L)
90 val securityKeys = Some(mock<SecurityKeys>())
92 val config = PartialConfiguration(
93 Some(PartialServerConfig(
98 Some(PartialCbsConfig(
99 Some(firstReqDelaySec),
100 Some(Duration.ofSeconds(3))
102 Some(PartialSecurityConfig(
105 Some(PartialCollectorConfig(
113 it("should create valid configuration") {
114 val result = cut.validate(config)
117 fail("Configuration should have been created successfully")
120 assertThat(it.server.idleTimeout)
121 .isEqualTo(idleTimeoutSec)
123 assertThat(it.security.keys)
124 .isEqualTo(securityKeys)
126 assertThat(it.cbs.firstRequestDelay)
127 .isEqualTo(firstReqDelaySec)
129 assertThat(it.collector.routing)
130 .isEqualTo(emptyRouting)
136 describe("validating configuration with security disabled") {
137 val idleTimeoutSec = Duration.ofSeconds(10)
138 val firstReqDelaySec = Duration.ofSeconds(10)
139 val securityKeys: Option<SecurityKeys> = None
141 val config = PartialConfiguration(
142 Some(PartialServerConfig(
144 Some(idleTimeoutSec),
147 Some(PartialCbsConfig(
148 Some(firstReqDelaySec),
149 Some(Duration.ofSeconds(3))
151 Some(PartialSecurityConfig(
154 Some(PartialCollectorConfig(
162 it("should create valid configuration") {
163 val result = cut.validate(config)
166 fail("Configuration should have been created successfully but was $it")
169 assertThat(it.server.idleTimeout)
170 .isEqualTo(idleTimeoutSec)
172 assertThat(it.security.keys)
173 .isEqualTo(securityKeys)
175 assertThat(it.cbs.firstRequestDelay)
176 .isEqualTo(firstReqDelaySec)
178 assertThat(it.collector.routing)
179 .isEqualTo(emptyRouting)
188 val emptyRouting = Routing(emptyList())
189 val someFromEmptyRouting = Some(emptyRouting)