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(
59 Some(PartialCbsConfig(
63 Some(PartialSecurityConfig(
66 // TOD0: retrieve when ConfigurationMerger is implemented
67 // Some(PartialCollectorConfig(
70 // someFromEmptyRouting
75 it("should use default log level") {
76 val result = cut.validate(config)
79 fail("Configuration should have been created successfully")
82 assertThat(it.logLevel).isEqualTo(DEFAULT_LOG_LEVEL)
88 describe("validating complete configuration") {
89 val idleTimeoutSec = 10
90 val firstReqDelaySec = 10
91 val securityKeys = Some(mock<SecurityKeys>())
93 val config = PartialConfiguration(
94 Some(PartialServerConfig(
99 Some(PartialCbsConfig(
100 Some(firstReqDelaySec),
103 Some(PartialSecurityConfig(
106 // TOD0: retrieve when ConfigurationMerger is implemented
107 // Some(PartialCollectorConfig(
109 // Some(emptyList()),
110 // someFromEmptyRouting
115 it("should create valid configuration") {
116 val result = cut.validate(config)
119 fail("Configuration should have been created successfully")
122 assertThat(it.server.idleTimeout)
123 .isEqualTo(Duration.ofSeconds(idleTimeoutSec.toLong()))
125 assertThat(it.security.keys)
126 .isEqualTo(securityKeys)
128 assertThat(it.cbs.firstRequestDelay)
129 .isEqualTo(Duration.ofSeconds(firstReqDelaySec.toLong()))
131 // TOD0: retrieve when ConfigurationMerger is implemented
132 // assertThat(it.collector.routing)
133 // .isEqualTo(emptyRouting)
139 describe("validating configuration with security disabled") {
140 val idleTimeoutSec = 10
141 val firstReqDelaySec = 10
142 val securityKeys: Option<SecurityKeys> = None
144 val config = PartialConfiguration(
145 Some(PartialServerConfig(
147 Some(idleTimeoutSec),
150 Some(PartialCbsConfig(
151 Some(firstReqDelaySec),
154 Some(PartialSecurityConfig(
157 // TOD0: retrieve when ConfigurationMerger is implemented
158 // Some(PartialCollectorConfig(
160 // Some(emptyList()),
161 // someFromEmptyRouting
166 it("should create valid configuration") {
167 val result = cut.validate(config)
170 fail("Configuration should have been created successfully but was $it")
173 assertThat(it.server.idleTimeout)
174 .isEqualTo(Duration.ofSeconds(idleTimeoutSec.toLong()))
176 assertThat(it.security.keys)
177 .isEqualTo(securityKeys)
179 assertThat(it.cbs.firstRequestDelay)
180 .isEqualTo(Duration.ofSeconds(firstReqDelaySec.toLong()))
182 // TOD0: retrieve when ConfigurationMerger is implemented
183 // assertThat(it.collector.routing)
184 // .isEqualTo(emptyRouting)
193 // TOD0: retrieve when ConfigurationMerger is implemented
194 //val emptyRouting = Routing(emptyList())
195 //val someFromEmptyRouting = Some(emptyRouting)