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
30 import java.net.InetSocketAddress
31 import java.time.Duration
34 * @author Pawel Biniek <pawel.biniek@nokia.com>
35 * @since February 2019
37 internal object FileConfigurationReaderTest : Spek({
38 describe("A configuration loader utility") {
39 val cut = FileConfigurationReader()
41 describe("partial configuration loading") {
42 it("parses enumerations") {
43 val input = """{"logLevel":"ERROR"}"""
45 val config = cut.loadConfig(StringReader(input))
46 assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
49 it("parses simple structure") {
52 "healthCheckApiPort" : 12002,
57 val config = cut.loadConfig(StringReader(input))
58 assertThat(config.server.nonEmpty()).isTrue()
59 assertThat(config.server.orNull()?.listenPort).isEqualTo(Some(12003))
62 it("parses disabled security configuration") {
67 val config = cut.loadConfig(StringReader(input))
69 assertThat(config.security.nonEmpty()).isTrue()
70 val security = config.security.orNull() as PartialSecurityConfig
71 assertThat(security.keys.nonEmpty()).isFalse()
74 it("parses invalid log level string to empty option") {
78 val config = cut.loadConfig(input.reader())
80 assertThat(config.logLevel.isEmpty())
84 describe("complete file loading") {
85 it("loads actual file") {
86 val config = cut.loadConfig(
87 javaClass.resourceAsStream("/sampleConfig.json"))
89 assertThat(config).isNotNull
90 assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
92 assertThat(config.security.nonEmpty()).isTrue()
93 val security = config.security.orNull() as PartialSecurityConfig
94 assertThat(security.keys.nonEmpty()).isTrue()
96 assertThat(config.cbs.nonEmpty()).isTrue()
97 val cbs = config.cbs.orNull() as PartialCbsConfig
98 assertThat(cbs.firstRequestDelaySec).isEqualTo(Some(Duration.ofSeconds(7)))
99 assertThat(cbs.requestIntervalSec).isEqualTo(Some(Duration.ofSeconds(900)))
101 assertThat(config.server.nonEmpty()).isTrue()
102 val server = config.server.orNull() as PartialServerConfig
104 assertThat(idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
105 assertThat(listenPort).isEqualTo(Some(6000))
106 assertThat(maxPayloadSizeBytes).isEqualTo(Some(512000))