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 JsonConfigurationParserTest : Spek({
39 describe("A configuration parser utility") {
40 val cut = JsonConfigurationParser()
42 describe("partial configuration parsing") {
43 it("parses enumerations") {
44 val input = """{"logLevel":"ERROR"}"""
46 val config = cut.parse(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.parse(StringReader(input))
57 assertThat(config.listenPort).isEqualTo(Some(12003))
58 assertThat(config.firstRequestDelaySec).isEqualTo(Some(10L))
61 it("parses disabled security configuration") {
63 "security.sslDisable": true
65 val config = cut.parse(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.parse(input.reader())
76 assertThat(config.logLevel.isEmpty())
80 describe("complete json parsing") {
81 it("parses actual json") {
82 val config = cut.parse(
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(1200L))
91 assertThat(config.firstRequestDelaySec).isEqualTo(Some(7L))
92 assertThat(config.requestIntervalSec).isEqualTo(Some(900L))
94 assertThat(config.sslDisable).isEqualTo(Some(false))
95 assertThat(config.keyStoreFile).isEqualTo(Some("test.ks.pkcs12"))
96 assertThat(config.keyStorePassword).isEqualTo(Some("changeMe"))
97 assertThat(config.trustStoreFile).isEqualTo(Some("trust.ks.pkcs12"))
98 assertThat(config.trustStorePassword).isEqualTo(Some("changeMeToo"))