cb8d5005a271757dad6f35eb971beafd31e2d85b
[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 = JsonConfigurationParser().parse(
59                     InputStreamReader(
60                             JsonConfigurationParserTest.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 = JsonConfigurationParser().parse(
70                     InputStreamReader(
71                             JsonConfigurationParserTest.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(1200L))
79         }
80
81         it("merges full config into single parameter") {
82             val actual = PartialConfiguration(logLevel = Some(LogLevel.INFO))
83             val diff = JsonConfigurationParser().parse(
84                     InputStreamReader(
85                             JsonConfigurationParserTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
86
87             val result = ConfigurationMerger().merge(actual, diff)
88
89             assertThat(result.logLevel).isEqualTo(Some(LogLevel.ERROR))
90             assertThat(result.idleTimeoutSec).isEqualTo(Some(1200L))
91
92             assertThat(result.keyStoreFile.isEmpty()).isFalse()
93             assertThat(result.firstRequestDelaySec.isEmpty()).isFalse()
94         }
95     }
96 })
97