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.Some
23 import org.jetbrains.spek.api.Spek
24 import org.assertj.core.api.Assertions.assertThat
25 import org.jetbrains.spek.api.dsl.describe
26 import org.jetbrains.spek.api.dsl.it
27 import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
28 import java.io.InputStreamReader
30 import java.time.Duration
33 * @author Pawel Biniek <pawel.biniek@nokia.com>
34 * @since February 2019
36 internal object ConfigurationMergerTest : Spek({
37 describe("Merges partial configurations into one") {
38 it("merges single parameter into empty config") {
39 val actual = PartialConfiguration()
40 val diff = PartialConfiguration(logLevel = Some(LogLevel.INFO))
42 val result = ConfigurationMerger().merge(actual, diff)
44 assertThat(result.logLevel).isEqualTo(Some(LogLevel.INFO))
47 val someListenPort = Some(45)
48 it("merges single embedded parameter into empty config") {
49 val actual = PartialConfiguration()
50 val diff = PartialConfiguration(listenPort = someListenPort)
52 val result = ConfigurationMerger().merge(actual, diff)
54 assertThat(result.listenPort).isEqualTo(someListenPort)
57 it("merges single parameter into full config") {
58 val actual = FileConfigurationReader().loadConfig(
60 FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
61 val diff = PartialConfiguration(logLevel = Some(LogLevel.INFO))
63 val result = ConfigurationMerger().merge(actual, diff)
65 assertThat(result.logLevel).isEqualTo(Some(LogLevel.INFO))
68 it("merges single embedded parameter into full config") {
69 val actual = FileConfigurationReader().loadConfig(
71 FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
72 val diff = PartialConfiguration(listenPort = someListenPort)
74 val result = ConfigurationMerger().merge(actual, diff)
76 assertThat(result.listenPort).isEqualTo(someListenPort)
77 assertThat(result.idleTimeoutSec.isEmpty()).isFalse()
78 assertThat(result.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
79 assertThat(result.maxPayloadSizeBytes.isEmpty()).isFalse()
80 assertThat(result.maxPayloadSizeBytes).isEqualTo(Some(1048576))
83 it("merges full config into single parameter") {
84 val actual = PartialConfiguration(logLevel = Some(LogLevel.INFO))
85 val diff = FileConfigurationReader().loadConfig(
87 FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
89 val result = ConfigurationMerger().merge(actual, diff)
91 assertThat(result.logLevel).isEqualTo(Some(LogLevel.ERROR))
92 assertThat(result.maxPayloadSizeBytes).isEqualTo(Some(1048576))
93 assertThat(result.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
95 assertThat(result.keyStoreFile.isEmpty()).isFalse()
96 assertThat(result.firstRequestDelaySec.isEmpty()).isFalse()