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.assertj.core.api.Assertions.assertThat
24 import org.jetbrains.spek.api.Spek
25 import org.jetbrains.spek.api.dsl.describe
26 import org.jetbrains.spek.api.dsl.it
27 import org.onap.dcae.collectors.veshv.tests.utils.resourceAsStream
28 import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
29 import java.io.StringReader
32 * @author Pawel Biniek <pawel.biniek@nokia.com>
33 * @since February 2019
35 internal object FileConfigurationReaderTest : Spek({
36 describe("A configuration loader utility") {
37 val cut = FileConfigurationReader()
39 describe("partial configuration loading") {
40 it("parses enumerations") {
41 val input = """{"logLevel":"ERROR"}"""
43 val config = cut.loadConfig(StringReader(input))
44 assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
47 it("parses simple structure") {
50 "healthCheckApiPort" : 12002,
55 val config = cut.loadConfig(StringReader(input))
56 assertThat(config.server.nonEmpty()).isTrue()
57 assertThat(config.server.orNull()?.listenPort).isEqualTo(Some(12003))
60 it("parses disabled security configuration") {
65 val config = cut.loadConfig(StringReader(input))
67 assertThat(config.security.nonEmpty()).isTrue()
68 val security = config.security.orNull() as PartialSecurityConfig
69 assertThat(security.keys.nonEmpty()).isFalse()
72 it("parses invalid log level string to empty option") {
76 val config = cut.loadConfig(input.reader())
78 assertThat(config.logLevel.isEmpty())
82 describe("complete file loading") {
83 it("loads actual file") {
84 val config = cut.loadConfig(
85 javaClass.resourceAsStream("/sampleConfig.json"))
87 assertThat(config).isNotNull
88 assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
90 assertThat(config.security.nonEmpty()).isTrue()
91 val security = config.security.orNull() as PartialSecurityConfig
92 assertThat(security.keys.nonEmpty()).isTrue()
94 assertThat(config.cbs.nonEmpty()).isTrue()
95 val cbs = config.cbs.orNull() as PartialCbsConfig
96 assertThat(cbs.firstRequestDelaySec).isEqualTo(Some(7))
97 assertThat(cbs.requestIntervalSec).isEqualTo(Some(900))
99 assertThat(config.server.nonEmpty()).isTrue()
100 val server = config.server.orNull() as PartialServerConfig
102 assertThat(idleTimeoutSec).isEqualTo(Some(1200))
103 assertThat(listenPort).isEqualTo(Some(6000))
104 assertThat(maxPayloadSizeBytes).isEqualTo(Some(512000))