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 arrow.core.getOrElse
24 import org.assertj.core.api.Assertions.assertThat
25 import org.jetbrains.spek.api.Spek
26 import org.jetbrains.spek.api.dsl.describe
27 import org.jetbrains.spek.api.dsl.it
28 import org.onap.dcae.collectors.veshv.tests.utils.resourceAsStream
29 import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
30 import java.io.StringReader
31 import java.time.Duration
32 import kotlin.test.fail
35 * @author Pawel Biniek <pawel.biniek@nokia.com>
36 * @since February 2019
38 internal object FileConfigurationReaderTest : Spek({
39 describe("A configuration loader utility") {
40 val cut = FileConfigurationReader()
42 describe("partial configuration loading") {
43 it("parses enumerations") {
44 val input = """{"logLevel":"ERROR"}"""
46 val config = cut.loadConfig(StringReader(input))
47 assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
50 it("parses simple structure and creates correct objects") {
52 "server.listenPort" : 12003,
53 "cbs.firstRequestDelaySec": 10
56 val config = cut.loadConfig(StringReader(input))
57 assertThat(config.listenPort).isEqualTo(Some(12003))
58 assertThat(config.firstRequestDelaySec).isEqualTo(Some(Duration.ofSeconds(10)))
61 it("parses disabled security configuration") {
63 "security.sslDisable": true
65 val config = cut.loadConfig(StringReader(input))
67 assertThat(config.sslDisable.getOrElse { fail("Should be Some") }).isTrue()
70 it("parses invalid log level string to empty option") {
74 val config = cut.loadConfig(input.reader())
76 assertThat(config.logLevel.isEmpty())
80 describe("complete file loading") {
81 it("loads actual file") {
82 val config = cut.loadConfig(
83 javaClass.resourceAsStream("/sampleConfig.json"))
85 assertThat(config).isNotNull
86 assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
88 assertThat(config.listenPort).isEqualTo(Some(6000))
89 assertThat(config.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
90 assertThat(config.maxPayloadSizeBytes).isEqualTo(Some(1048576))
92 assertThat(config.firstRequestDelaySec).isEqualTo(Some(Duration.ofSeconds(7)))
93 assertThat(config.requestIntervalSec).isEqualTo(Some(Duration.ofSeconds(900)))
95 assertThat(config.sslDisable).isEqualTo(Some(false))
96 assertThat(config.keyStoreFile).isEqualTo(Some("test.ks.pkcs12"))
97 assertThat(config.keyStorePassword).isEqualTo(Some("changeMe"))
98 assertThat(config.trustStoreFile).isEqualTo(Some("trust.ks.pkcs12"))
99 assertThat(config.trustStorePassword).isEqualTo(Some("changeMeToo"))