diff options
author | pbiniek <pawel.biniek@nokia.com> | 2019-03-15 16:11:00 +0100 |
---|---|---|
committer | pbiniek <pawel.biniek@nokia.com> | 2019-03-28 11:40:46 +0100 |
commit | 1b7ac38627977e8ef2209a3a98a8cd0c2da785dd (patch) | |
tree | b4d52b436921c7be335e9b20d69c7f8daf753cee /sources/hv-collector-configuration/src/test | |
parent | d6e646205cf290f46e980ad2470225c7d0b42618 (diff) |
Added partial config merger and updated config file format
Change-Id: I470d3a8b2d43f5b45d958320b620205457d1cf23
Issue-ID: DCAEGEN2-1370
Signed-off-by: Pawel Biniek <pawel.biniek@nokia.com>
Diffstat (limited to 'sources/hv-collector-configuration/src/test')
4 files changed, 142 insertions, 44 deletions
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMergerTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMergerTest.kt new file mode 100644 index 00000000..d5b18e68 --- /dev/null +++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMergerTest.kt @@ -0,0 +1,102 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2019 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.config.impl + +import arrow.core.Some +import org.jetbrains.spek.api.Spek +import org.assertj.core.api.Assertions.assertThat +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it +import org.onap.dcae.collectors.veshv.utils.logging.LogLevel +import java.io.InputStreamReader +import java.io.Reader +import java.time.Duration + +/** + * @author Pawel Biniek <pawel.biniek@nokia.com> + * @since February 2019 + */ +internal object ConfigurationMergerTest : Spek({ + describe("Merges partial configurations into one") { + it("merges single parameter into empty config") { + val actual = PartialConfiguration() + val diff = PartialConfiguration(logLevel = Some(LogLevel.INFO)) + + val result = ConfigurationMerger().merge(actual, diff) + + assertThat(result.logLevel).isEqualTo(Some(LogLevel.INFO)) + } + + it("merges single embedded parameter into empty config") { + val actual = PartialConfiguration() + val serverConfig = PartialServerConfig(listenPort = Some(45)) + val diff = PartialConfiguration(server = Some(serverConfig)) + + val result = ConfigurationMerger().merge(actual, diff) + + assertThat(result.server).isEqualTo(Some(serverConfig)) + } + + it("merges single parameter into full config") { + val actual = FileConfigurationReader().loadConfig( + InputStreamReader( + FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader) + val diff = PartialConfiguration(logLevel = Some(LogLevel.INFO)) + + val result = ConfigurationMerger().merge(actual, diff) + + assertThat(result.logLevel).isEqualTo(Some(LogLevel.INFO)) + } + + it("merges single embedded parameter into full config") { + val actual = FileConfigurationReader().loadConfig( + InputStreamReader( + FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader) + val serverConfig = PartialServerConfig(listenPort = Some(45)) + val diff = PartialConfiguration(server = Some(serverConfig)) + + val result = ConfigurationMerger().merge(actual, diff) + + assertThat(result.server.orNull()?.listenPort).isEqualTo(serverConfig.listenPort) + assertThat(result.server.orNull()?.idleTimeoutSec?.isEmpty()).isFalse() + assertThat(result.server.orNull()?.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200))) + assertThat(result.server.orNull()?.maxPayloadSizeBytes?.isEmpty()).isFalse() + assertThat(result.server.orNull()?.maxPayloadSizeBytes).isEqualTo(Some(512000)) + } + + it("merges full config into single parameter") { + val actual = PartialConfiguration(logLevel = Some(LogLevel.INFO)) + val diff = FileConfigurationReader().loadConfig( + InputStreamReader( + FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader) + + val result = ConfigurationMerger().merge(actual, diff) + + assertThat(result.logLevel).isEqualTo(Some(LogLevel.ERROR)) + assertThat(result.server.isEmpty()).isFalse() + assertThat(result.server.orNull()?.maxPayloadSizeBytes).isEqualTo(Some(512000)) + assertThat(result.server.orNull()?.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200))) + + assertThat(result.security.isEmpty()).isFalse() + assertThat(result.cbs.isEmpty()).isFalse() + } + } +}) + diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt index 62b43ded..37192868 100644 --- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt +++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt @@ -53,22 +53,21 @@ internal object ConfigurationValidatorTest : Spek({ val config = PartialConfiguration( Some(PartialServerConfig( Some(1), - Some(2), + Some(Duration.ofSeconds(2)), Some(3) )), Some(PartialCbsConfig( - Some(5), - Some(3) + Some(Duration.ofSeconds(5)), + Some(Duration.ofSeconds(3)) )), Some(PartialSecurityConfig( Some(mock()) )), -// TOD0: retrieve when ConfigurationMerger is implemented -// Some(PartialCollectorConfig( -// Some(4), -// Some(emptyList()), -// someFromEmptyRouting -// )), + Some(PartialCollectorConfig( + Some(4), + Some(emptyList()), + someFromEmptyRouting + )), None ) @@ -86,8 +85,8 @@ internal object ConfigurationValidatorTest : Spek({ } describe("validating complete configuration") { - val idleTimeoutSec = 10 - val firstReqDelaySec = 10 + val idleTimeoutSec = Duration.ofSeconds(10L) + val firstReqDelaySec = Duration.ofSeconds(10L) val securityKeys = Some(mock<SecurityKeys>()) val config = PartialConfiguration( @@ -98,17 +97,16 @@ internal object ConfigurationValidatorTest : Spek({ )), Some(PartialCbsConfig( Some(firstReqDelaySec), - Some(3) + Some(Duration.ofSeconds(3)) )), Some(PartialSecurityConfig( securityKeys )), -// TOD0: retrieve when ConfigurationMerger is implemented -// Some(PartialCollectorConfig( -// Some(4), -// Some(emptyList()), -// someFromEmptyRouting -// )), + Some(PartialCollectorConfig( + Some(4), + Some(emptyList()), + someFromEmptyRouting + )), Some(LogLevel.INFO) ) @@ -120,25 +118,24 @@ internal object ConfigurationValidatorTest : Spek({ }, { assertThat(it.server.idleTimeout) - .isEqualTo(Duration.ofSeconds(idleTimeoutSec.toLong())) + .isEqualTo(idleTimeoutSec) assertThat(it.security.keys) .isEqualTo(securityKeys) assertThat(it.cbs.firstRequestDelay) - .isEqualTo(Duration.ofSeconds(firstReqDelaySec.toLong())) + .isEqualTo(firstReqDelaySec) -// TOD0: retrieve when ConfigurationMerger is implemented -// assertThat(it.collector.routing) -// .isEqualTo(emptyRouting) + assertThat(it.collector.routing) + .isEqualTo(emptyRouting) } ) } } describe("validating configuration with security disabled") { - val idleTimeoutSec = 10 - val firstReqDelaySec = 10 + val idleTimeoutSec = Duration.ofSeconds(10) + val firstReqDelaySec = Duration.ofSeconds(10) val securityKeys: Option<SecurityKeys> = None val config = PartialConfiguration( @@ -149,17 +146,16 @@ internal object ConfigurationValidatorTest : Spek({ )), Some(PartialCbsConfig( Some(firstReqDelaySec), - Some(3) + Some(Duration.ofSeconds(3)) )), Some(PartialSecurityConfig( securityKeys )), -// TOD0: retrieve when ConfigurationMerger is implemented -// Some(PartialCollectorConfig( -// Some(4), -// Some(emptyList()), -// someFromEmptyRouting -// )), + Some(PartialCollectorConfig( + Some(4), + Some(emptyList()), + someFromEmptyRouting + )), Some(LogLevel.INFO) ) @@ -171,17 +167,16 @@ internal object ConfigurationValidatorTest : Spek({ }, { assertThat(it.server.idleTimeout) - .isEqualTo(Duration.ofSeconds(idleTimeoutSec.toLong())) + .isEqualTo(idleTimeoutSec) assertThat(it.security.keys) .isEqualTo(securityKeys) assertThat(it.cbs.firstRequestDelay) - .isEqualTo(Duration.ofSeconds(firstReqDelaySec.toLong())) + .isEqualTo(firstReqDelaySec) -// TOD0: retrieve when ConfigurationMerger is implemented -// assertThat(it.collector.routing) -// .isEqualTo(emptyRouting) + assertThat(it.collector.routing) + .isEqualTo(emptyRouting) } ) } @@ -190,6 +185,5 @@ internal object ConfigurationValidatorTest : Spek({ } }) -// TOD0: retrieve when ConfigurationMerger is implemented -//val emptyRouting = Routing(emptyList()) -//val someFromEmptyRouting = Some(emptyRouting) +val emptyRouting = Routing(emptyList()) +val someFromEmptyRouting = Some(emptyRouting) diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt index 73be3e43..4e35bfb3 100644 --- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt +++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt @@ -27,6 +27,8 @@ import org.jetbrains.spek.api.dsl.it import org.onap.dcae.collectors.veshv.tests.utils.resourceAsStream import org.onap.dcae.collectors.veshv.utils.logging.LogLevel import java.io.StringReader +import java.net.InetSocketAddress +import java.time.Duration /** * @author Pawel Biniek <pawel.biniek@nokia.com> @@ -93,13 +95,13 @@ internal object FileConfigurationReaderTest : Spek({ assertThat(config.cbs.nonEmpty()).isTrue() val cbs = config.cbs.orNull() as PartialCbsConfig - assertThat(cbs.firstRequestDelaySec).isEqualTo(Some(7)) - assertThat(cbs.requestIntervalSec).isEqualTo(Some(900)) + assertThat(cbs.firstRequestDelaySec).isEqualTo(Some(Duration.ofSeconds(7))) + assertThat(cbs.requestIntervalSec).isEqualTo(Some(Duration.ofSeconds(900))) assertThat(config.server.nonEmpty()).isTrue() val server = config.server.orNull() as PartialServerConfig server.run { - assertThat(idleTimeoutSec).isEqualTo(Some(1200)) + assertThat(idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200))) assertThat(listenPort).isEqualTo(Some(6000)) assertThat(maxPayloadSizeBytes).isEqualTo(Some(512000)) } diff --git a/sources/hv-collector-configuration/src/test/resources/sampleConfig.json b/sources/hv-collector-configuration/src/test/resources/sampleConfig.json index 8b440ebe..07f0702f 100644 --- a/sources/hv-collector-configuration/src/test/resources/sampleConfig.json +++ b/sources/hv-collector-configuration/src/test/resources/sampleConfig.json @@ -19,4 +19,4 @@ "trustStorePassword": "changeMeToo" } } -}
\ No newline at end of file +} |