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.api
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.config.api.model.Routing
28 import org.onap.dcae.collectors.veshv.config.impl.FileConfigurationReader
29 import org.onap.dcae.collectors.veshv.config.impl.PartialCbsConfig
30 import org.onap.dcae.collectors.veshv.config.impl.PartialKafkaConfig
31 import org.onap.dcae.collectors.veshv.config.impl.PartialSecurityConfig
32 import org.onap.dcae.collectors.veshv.config.impl.PartialServerConfig
33 import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
34 import java.io.InputStreamReader
35 import java.io.StringReader
36 import java.net.InetSocketAddress
39 * @author Pawel Biniek <pawel.biniek@nokia.com>
40 * @since February 2019
42 internal object FileConfigurationReaderTest : Spek({
43 describe("A configuration loader utility") {
45 describe("partial configuration loading") {
46 it("parses enumerations") {
47 val input = """{"logLevel":"ERROR"}"""
49 val config = FileConfigurationReader().loadConfig(StringReader(input))
50 assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
53 it("parses simple structure") {
56 "healthCheckApiPort" : 12002,
61 val config = FileConfigurationReader().loadConfig(StringReader(input))
62 assertThat(config.server.nonEmpty()).isTrue()
63 assertThat(config.server.orNull()?.healthCheckApiPort).isEqualTo(Some(12002))
64 assertThat(config.server.orNull()?.listenPort).isEqualTo(Some(12003))
67 it("parses ip address") {
68 val input = """{ "kafka" : {
76 val config = FileConfigurationReader().loadConfig(StringReader(input))
77 assertThat(config.kafka.nonEmpty()).isTrue()
78 val kafka = config.kafka.orNull() as PartialKafkaConfig
79 assertThat(kafka.kafkaServers.nonEmpty()).isTrue()
80 val addresses = kafka.kafkaServers.orNull() as Array<InetSocketAddress>
83 InetSocketAddress("192.168.255.1", 5005),
84 InetSocketAddress("192.168.255.26", 5006)
88 it("parses routing array with RoutingAdapter") {
93 "fromDomain": "perf3gpp",
94 "toTopic": "HV_VES_PERF3GPP"
99 val config = FileConfigurationReader().loadConfig(StringReader(input))
100 assertThat(config.kafka.nonEmpty()).isTrue()
101 val kafka = config.kafka.orNull() as PartialKafkaConfig
102 assertThat(kafka.routing.nonEmpty()).isTrue()
103 val routing = kafka.routing.orNull() as Routing
105 assertThat(routes.size).isEqualTo(1)
106 assertThat(routes[0].domain).isEqualTo("perf3gpp")
107 assertThat(routes[0].targetTopic).isEqualTo("HV_VES_PERF3GPP")
112 describe("complete file loading") {
113 it("loads actual file") {
114 val config = FileConfigurationReader().loadConfig(
116 FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")))
117 assertThat(config).isNotNull
118 assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
120 assertThat(config.security.nonEmpty()).isTrue()
121 val security = config.security.orNull() as PartialSecurityConfig
122 assertThat(security.sslDisable.orNull()).isFalse()
123 assertThat(security.keys.nonEmpty()).isTrue()
125 assertThat(config.cbs.nonEmpty()).isTrue()
126 val cbs = config.cbs.orNull() as PartialCbsConfig
127 assertThat(cbs.firstRequestDelaySec).isEqualTo(Some(7))
128 assertThat(cbs.requestIntervalSec).isEqualTo(Some(900))
130 assertThat(config.kafka.nonEmpty()).isTrue()
131 val kafka = config.kafka.orNull() as PartialKafkaConfig
132 assertThat(kafka.kafkaServers.nonEmpty()).isTrue()
133 assertThat(kafka.routing.nonEmpty()).isTrue()
135 assertThat(config.server.nonEmpty()).isTrue()
136 val server = config.server.orNull() as PartialServerConfig
138 assertThat(dummyMode).isEqualTo(Some(false))
139 assertThat(healthCheckApiPort).isEqualTo(Some(5000))
140 assertThat(idleTimeoutSec).isEqualTo(Some(1200))
141 assertThat(listenPort).isEqualTo(Some(6000))
142 assertThat(maximumPayloadSizeBytes).isEqualTo(Some(512000))