bc61b57d52a3b5db6ca28a19346ffce633c35c48
[dcaegen2/collectors/hv-ves.git] /
1 /*
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.config.impl
21
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
29 import java.io.Reader
30 import java.time.Duration
31
32 /**
33  * @author Pawel Biniek <pawel.biniek@nokia.com>
34  * @since February 2019
35  */
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))
41
42             val result = ConfigurationMerger().merge(actual, diff)
43
44             assertThat(result.logLevel).isEqualTo(Some(LogLevel.INFO))
45         }
46
47         val someListenPort = Some(45)
48         it("merges single embedded parameter into empty config") {
49             val actual = PartialConfiguration()
50             val diff = PartialConfiguration(listenPort = someListenPort)
51
52             val result = ConfigurationMerger().merge(actual, diff)
53
54             assertThat(result.listenPort).isEqualTo(someListenPort)
55         }
56
57         it("merges single parameter into full config") {
58             val actual = FileConfigurationReader().loadConfig(
59                     InputStreamReader(
60                             FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
61             val diff = PartialConfiguration(logLevel = Some(LogLevel.INFO))
62
63             val result = ConfigurationMerger().merge(actual, diff)
64
65             assertThat(result.logLevel).isEqualTo(Some(LogLevel.INFO))
66         }
67
68         it("merges single embedded parameter into full config") {
69             val actual = FileConfigurationReader().loadConfig(
70                     InputStreamReader(
71                             FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
72             val diff = PartialConfiguration(listenPort = someListenPort)
73
74             val result = ConfigurationMerger().merge(actual, diff)
75
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))
81         }
82
83         it("merges full config into single parameter") {
84             val actual = PartialConfiguration(logLevel = Some(LogLevel.INFO))
85             val diff = FileConfigurationReader().loadConfig(
86                     InputStreamReader(
87                             FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
88
89             val result = ConfigurationMerger().merge(actual, diff)
90
91             assertThat(result.logLevel).isEqualTo(Some(LogLevel.ERROR))
92             assertThat(result.maxPayloadSizeBytes).isEqualTo(Some(1048576))
93             assertThat(result.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
94
95             assertThat(result.keyStoreFile.isEmpty()).isFalse()
96             assertThat(result.firstRequestDelaySec.isEmpty()).isFalse()
97         }
98     }
99 })
100