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.Option
23 import com.google.gson.JsonParser
24 import com.nhaarman.mockitokotlin2.any
25 import com.nhaarman.mockitokotlin2.mock
26 import com.nhaarman.mockitokotlin2.whenever
27 import org.jetbrains.spek.api.Spek
28 import org.jetbrains.spek.api.dsl.describe
29 import org.jetbrains.spek.api.dsl.given
30 import org.jetbrains.spek.api.dsl.it
31 import org.jetbrains.spek.api.dsl.on
32 import org.onap.dcae.collectors.veshv.config.api.model.*
33 import org.onap.dcae.collectors.veshv.ssl.boundary.SecurityConfiguration
34 import org.onap.dcae.collectors.veshv.tests.utils.absoluteResourcePath
35 import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
36 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient
37 import reactor.core.publisher.Mono
38 import reactor.test.StepVerifier
39 import java.time.Duration
42 internal object ConfigurationModuleIT : Spek({
43 describe("configuration module") {
44 val cbsClientMock = mock<CbsClient>()
45 val configStateListenerMock = mock<ConfigurationStateListener>()
46 val sut = ConfigurationModule(configStateListenerMock, Mono.just(cbsClientMock))
47 val configPath = javaClass.absoluteResourcePath("/insecureSampleConfig.json")
49 given("sample configuration in file: $configPath") {
50 val arguments = arrayOf(
51 "--configuration-file",
53 "--health-check-api-port",
55 on("configuration changes in Config Binding Service") {
56 whenever(cbsClientMock.get(any()))
58 Mono.just(configurationJsonWithIntervalChanged),
59 Mono.just(configurationJsonWithIntervalChangedAgain),
60 Mono.just(configurationJsonWithIntervalRestored)
62 it("should wait $firstRequestDelayFromFile s as provided in configuration file and later" +
63 " fetch configurations in intervals specified within them") {
66 sut.hvVesConfigurationUpdates(arguments, sampleMdc)
70 .expectNoEvent(firstRequestDelayFromFile)
71 .expectNext(configurationWithIntervalChanged)
72 .expectNoEvent(requestIntervalFromCBS)
73 .expectNext(configurationWithIntervalChangedAgain)
74 .expectNoEvent(anotherRequestIntervalFromCBS)
75 .expectNext(configurationWithIntervalRestored)
83 private val firstRequestDelayFromFile = Duration.ofSeconds(3)
84 private val firstRequestDelayFromCBS = Duration.ofSeconds(999)
85 private val requestIntervalFromCBS = Duration.ofSeconds(10)
86 private val anotherRequestIntervalFromCBS = Duration.ofSeconds(20)
88 private val sampleMdc = { mapOf("k" to "v") }
89 private val emptyRouting = listOf<Route>()
91 private val configurationJsonWithIntervalChanged = JsonParser().parse("""{
92 "cbs.requestIntervalSec": ${requestIntervalFromCBS.seconds}
95 private val configurationJsonWithIntervalChangedAgain = JsonParser().parse("""{
96 "cbs.firstRequestDelaySec": ${firstRequestDelayFromCBS.seconds},
97 "cbs.requestIntervalSec": ${anotherRequestIntervalFromCBS.seconds}
100 private val configurationJsonWithIntervalRestored = JsonParser().parse("""{
101 "cbs.requestIntervalSec": ${requestIntervalFromCBS.seconds}
104 private val configurationWithIntervalChanged =
105 hvVesConfiguration(firstRequestDelayFromFile, requestIntervalFromCBS)
107 private val configurationWithIntervalChangedAgain =
108 hvVesConfiguration(firstRequestDelayFromCBS, anotherRequestIntervalFromCBS)
110 private val configurationWithIntervalRestored =
111 hvVesConfiguration(firstRequestDelayFromFile, requestIntervalFromCBS)
113 private fun hvVesConfiguration(firstRequestDelay: Duration, requestInterval: Duration): HvVesConfiguration {
114 return HvVesConfiguration(
115 ServerConfiguration(6061, Duration.ofSeconds(60)),
116 CbsConfiguration(firstRequestDelay, requestInterval),
117 SecurityConfiguration(Option.empty()),
118 CollectorConfiguration(emptyRouting, 1024 * 1024),