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 it("merges single embedded parameter into empty config") {
48 val actual = PartialConfiguration()
49 val serverConfig = PartialServerConfig(listenPort = Some(45))
50 val diff = PartialConfiguration(server = Some(serverConfig))
52 val result = ConfigurationMerger().merge(actual, diff)
54 assertThat(result.server).isEqualTo(Some(serverConfig))
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 serverConfig = PartialServerConfig(listenPort = Some(45))
73 val diff = PartialConfiguration(server = Some(serverConfig))
75 val result = ConfigurationMerger().merge(actual, diff)
77 assertThat(result.server.orNull()?.listenPort).isEqualTo(serverConfig.listenPort)
78 assertThat(result.server.orNull()?.idleTimeoutSec?.isEmpty()).isFalse()
79 assertThat(result.server.orNull()?.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
80 assertThat(result.server.orNull()?.maxPayloadSizeBytes?.isEmpty()).isFalse()
81 assertThat(result.server.orNull()?.maxPayloadSizeBytes).isEqualTo(Some(512000))
84 it("merges full config into single parameter") {
85 val actual = PartialConfiguration(logLevel = Some(LogLevel.INFO))
86 val diff = FileConfigurationReader().loadConfig(
88 FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
90 val result = ConfigurationMerger().merge(actual, diff)
92 assertThat(result.logLevel).isEqualTo(Some(LogLevel.ERROR))
93 assertThat(result.server.isEmpty()).isFalse()
94 assertThat(result.server.orNull()?.maxPayloadSizeBytes).isEqualTo(Some(512000))
95 assertThat(result.server.orNull()?.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
97 assertThat(result.security.isEmpty()).isFalse()
98 assertThat(result.cbs.isEmpty()).isFalse()