aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-configuration/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sources/hv-collector-configuration/src/test')
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModuleIT.kt120
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt58
-rw-r--r--sources/hv-collector-configuration/src/test/resources/insecureSampleConfig.json8
3 files changed, 156 insertions, 30 deletions
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModuleIT.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModuleIT.kt
new file mode 100644
index 00000000..1b2dbc2b
--- /dev/null
+++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/api/ConfigurationModuleIT.kt
@@ -0,0 +1,120 @@
+/*
+ * ============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.api
+
+import arrow.core.Option
+import com.google.gson.JsonParser
+import com.nhaarman.mockitokotlin2.any
+import com.nhaarman.mockitokotlin2.mock
+import com.nhaarman.mockitokotlin2.whenever
+import org.jetbrains.spek.api.Spek
+import org.jetbrains.spek.api.dsl.describe
+import org.jetbrains.spek.api.dsl.given
+import org.jetbrains.spek.api.dsl.it
+import org.jetbrains.spek.api.dsl.on
+import org.onap.dcae.collectors.veshv.config.api.model.*
+import org.onap.dcae.collectors.veshv.ssl.boundary.SecurityConfiguration
+import org.onap.dcae.collectors.veshv.tests.utils.absoluteResourcePath
+import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient
+import reactor.core.publisher.Mono
+import reactor.test.StepVerifier
+import java.time.Duration
+
+
+internal object ConfigurationModuleIT : Spek({
+ describe("configuration module") {
+ val cbsClientMock = mock<CbsClient>()
+ val configStateListenerMock = mock<ConfigurationStateListener>()
+ val sut = ConfigurationModule(configStateListenerMock, Mono.just(cbsClientMock))
+ val configPath = javaClass.absoluteResourcePath("/insecureSampleConfig.json")
+
+ given("sample configuration in file: $configPath") {
+ val arguments = arrayOf(
+ "--configuration-file",
+ configPath,
+ "--health-check-api-port",
+ "6062")
+ on("configuration changes in Config Binding Service") {
+ whenever(cbsClientMock.get(any()))
+ .thenReturn(
+ Mono.just(configurationJsonWithIntervalChanged),
+ Mono.just(configurationJsonWithIntervalChangedAgain),
+ Mono.just(configurationJsonWithIntervalRestored)
+ )
+ it("should wait $firstRequestDelayFromFile s as provided in configuration file and later" +
+ " fetch configurations in intervals specified within them") {
+ StepVerifier
+ .withVirtualTime {
+ sut.hvVesConfigurationUpdates(arguments, sampleMdc)
+ .take(3)
+ }
+ .expectSubscription()
+ .expectNoEvent(firstRequestDelayFromFile)
+ .expectNext(configurationWithIntervalChanged)
+ .expectNoEvent(requestIntervalFromCBS)
+ .expectNext(configurationWithIntervalChangedAgain)
+ .expectNoEvent(anotherRequestIntervalFromCBS)
+ .expectNext(configurationWithIntervalRestored)
+ .verifyComplete()
+ }
+ }
+ }
+ }
+})
+
+private val firstRequestDelayFromFile = Duration.ofSeconds(3)
+private val firstRequestDelayFromCBS = Duration.ofSeconds(999)
+private val requestIntervalFromCBS = Duration.ofSeconds(10)
+private val anotherRequestIntervalFromCBS = Duration.ofSeconds(20)
+
+private val sampleMdc = { mapOf("k" to "v") }
+private val emptyRouting = listOf<Route>()
+
+private val configurationJsonWithIntervalChanged = JsonParser().parse("""{
+ "cbs.requestIntervalSec": ${requestIntervalFromCBS.seconds}
+}""").asJsonObject
+
+private val configurationJsonWithIntervalChangedAgain = JsonParser().parse("""{
+ "cbs.firstRequestDelaySec": ${firstRequestDelayFromCBS.seconds},
+ "cbs.requestIntervalSec": ${anotherRequestIntervalFromCBS.seconds}
+}""").asJsonObject
+
+private val configurationJsonWithIntervalRestored = JsonParser().parse("""{
+ "cbs.requestIntervalSec": ${requestIntervalFromCBS.seconds}
+}""").asJsonObject
+
+private val configurationWithIntervalChanged =
+ hvVesConfiguration(firstRequestDelayFromFile, requestIntervalFromCBS)
+
+private val configurationWithIntervalChangedAgain =
+ hvVesConfiguration(firstRequestDelayFromCBS, anotherRequestIntervalFromCBS)
+
+private val configurationWithIntervalRestored =
+ hvVesConfiguration(firstRequestDelayFromFile, requestIntervalFromCBS)
+
+private fun hvVesConfiguration(firstRequestDelay: Duration, requestInterval: Duration): HvVesConfiguration {
+ return HvVesConfiguration(
+ ServerConfiguration(6061, Duration.ofSeconds(60)),
+ CbsConfiguration(firstRequestDelay, requestInterval),
+ SecurityConfiguration(Option.empty()),
+ CollectorConfiguration(emptyRouting, 1024 * 1024),
+ LogLevel.DEBUG)
+} \ No newline at end of file
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt
index 8c3c22aa..31415454 100644
--- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt
+++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt
@@ -22,7 +22,6 @@ package org.onap.dcae.collectors.veshv.config.impl
import arrow.core.Some
import com.google.gson.JsonParser
import com.nhaarman.mockitokotlin2.any
-import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
@@ -34,10 +33,8 @@ import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.config.api.ConfigurationStateListener
-import org.onap.dcae.collectors.veshv.config.api.model.CbsConfiguration
import org.onap.dcaegen2.services.sdk.model.streams.ImmutableAafCredentials
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamFromGsonParsers
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.retry.Retry
@@ -52,12 +49,15 @@ internal object CbsConfigurationProviderTest : Spek({
describe("Configuration provider") {
- val cbsClient = mock<CbsClient>()
- val cbsClientMock = Mono.just(cbsClient)
+ val cbsClientAdapter = mock<CbsClientAdapter>()
val configStateListener = mock<ConfigurationStateListener>()
given("configuration is never in cbs") {
- val configProvider = constructConfigurationProvider(cbsClientMock, configStateListener)
+ val cbsClientMock = mock<CbsClient>()
+ val configProvider = constructConfigurationProvider(
+ constructCbsClientAdapter(cbsClientMock, configStateListener),
+ configStateListener
+ )
on("waiting for configuration") {
val waitTime = Duration.ofMillis(100)
@@ -70,16 +70,16 @@ internal object CbsConfigurationProviderTest : Spek({
}
given("valid configuration from cbs") {
- val configProvider = constructConfigurationProvider(cbsClientMock, configStateListener)
+ val configProvider = constructConfigurationProvider(cbsClientAdapter, configStateListener)
on("new configuration") {
- whenever(cbsClient.updates(any(), eq(firstRequestDelay), eq(requestInterval)))
+ whenever(cbsClientAdapter.configurationUpdates(any()))
.thenReturn(Flux.just(validConfiguration))
it("should use received configuration") {
StepVerifier.create(configProvider().take(1))
.consumeNextWith {
-
+ assertThat(it.requestIntervalSec).isEqualTo(Some(5L))
assertThat(it.listenPort).isEqualTo(Some(6061))
assertThat(it.idleTimeoutSec).isEqualTo(Some(60L))
@@ -106,11 +106,11 @@ internal object CbsConfigurationProviderTest : Spek({
given("invalid configuration from cbs") {
val iterationCount = 3L
val configProvider = constructConfigurationProvider(
- cbsClientMock, configStateListener, iterationCount
+ cbsClientAdapter, configStateListener, iterationCount
)
on("new configuration") {
- whenever(cbsClient.updates(any(), eq(firstRequestDelay), eq(requestInterval)))
+ whenever(cbsClientAdapter.configurationUpdates(any()))
.thenReturn(Flux.just(invalidConfiguration))
it("should interrupt the flux") {
@@ -146,6 +146,7 @@ private val validConfiguration = JsonParser().parse("""
{
"server.listenPort": 6061,
"server.idleTimeoutSec": 60,
+ "cbs.requestIntervalSec": 5,
"streams_publishes": {
"$PERF3GPP_REGIONAL": {
"type": "kafka",
@@ -190,26 +191,23 @@ private val invalidConfiguration = JsonParser().parse("""
}""").asJsonObject
private val firstRequestDelay = Duration.ofMillis(1)
-private val requestInterval = Duration.ofMillis(1)
-private val streamParser = StreamFromGsonParsers.kafkaSinkParser()
private val configParser = JsonConfigurationParser()
-private fun constructConfigurationProvider(cbsClientMono: Mono<CbsClient>,
+private fun retry(iterationCount: Long = 1) = Retry
+ .onlyIf<Any> { it.iteration() <= iterationCount }
+ .fixedBackoff(Duration.ofNanos(1))
+
+private fun constructCbsClientAdapter(cbsClientMock: CbsClient, configStateListener: ConfigurationStateListener) =
+ CbsClientAdapter(Mono.just(cbsClientMock), configStateListener, firstRequestDelay, retry())
+
+private fun constructConfigurationProvider(cbsClientAdapter: CbsClientAdapter,
configurationStateListener: ConfigurationStateListener,
iterationCount: Long = 1
-): CbsConfigurationProvider {
-
- val retry = Retry
- .onlyIf<Any> { it.iteration() <= iterationCount }
- .fixedBackoff(Duration.ofNanos(1))
-
- return CbsConfigurationProvider(
- cbsClientMono,
- CbsConfiguration(firstRequestDelay, requestInterval),
- configParser,
- streamParser,
- configurationStateListener,
- { mapOf("k" to "v") },
- retry
- )
-}
+): CbsConfigurationProvider =
+ CbsConfigurationProvider(
+ cbsClientAdapter,
+ configParser,
+ configurationStateListener,
+ { mapOf("k" to "v") },
+ retry(iterationCount)
+ )
diff --git a/sources/hv-collector-configuration/src/test/resources/insecureSampleConfig.json b/sources/hv-collector-configuration/src/test/resources/insecureSampleConfig.json
new file mode 100644
index 00000000..4fc59212
--- /dev/null
+++ b/sources/hv-collector-configuration/src/test/resources/insecureSampleConfig.json
@@ -0,0 +1,8 @@
+{
+ "logLevel": "DEBUG",
+ "server.listenPort": 6061,
+ "server.idleTimeoutSec": 60,
+ "cbs.firstRequestDelaySec": 3,
+ "cbs.requestIntervalSec": 5,
+ "security.sslDisable": "true"
+} \ No newline at end of file