diff options
author | 2019-04-08 13:48:42 +0200 | |
---|---|---|
committer | 2019-04-09 15:50:41 +0200 | |
commit | 325387e62a0793871dc1eb97f02a4ae90a977664 (patch) | |
tree | e61544a1df539fffd2ae5efc5961155306bfb347 /sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt | |
parent | e55809c0219be0898138c436d82ceba212b92df9 (diff) |
Parse whole dynamic configuration
Change-Id: I96e4cf3ac75920ed909da9063ba0b788b55474e4
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-1386
Diffstat (limited to 'sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt')
-rw-r--r-- | sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt | 101 |
1 files changed, 58 insertions, 43 deletions
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 e43acfa3..5fa1fd62 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 @@ -23,14 +23,17 @@ import arrow.core.None import arrow.core.Option import arrow.core.Some import arrow.core.getOrElse +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.whenever import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.fail import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.describe import org.jetbrains.spek.api.dsl.it -import org.onap.dcae.collectors.veshv.config.api.model.Routing +import org.onap.dcae.collectors.veshv.config.api.model.Route import org.onap.dcae.collectors.veshv.config.impl.ConfigurationValidator.Companion.DEFAULT_LOG_LEVEL import org.onap.dcae.collectors.veshv.utils.logging.LogLevel +import org.onap.dcaegen2.services.sdk.model.streams.dmaap.KafkaSink import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys import java.io.File import java.time.Duration @@ -81,7 +84,7 @@ internal object ConfigurationValidatorTest : Spek({ keyStorePassword = Some(KEYSTORE_PASSWORD), trustStoreFile = Some(TRUSTSTORE), trustStorePassword = Some(TRUSTSTORE_PASSWORD), - routing = Some(emptyRouting), + streamPublishers = Some(sampleStreamsDefinition), logLevel = Some(LogLevel.TRACE) ) @@ -92,9 +95,12 @@ internal object ConfigurationValidatorTest : Spek({ fail("Configuration should have been created successfully") }, { - assertThat(it.server.listenPort).isEqualTo(defaultListenPort) - assertThat(it.server.idleTimeout).isEqualTo(defaultIdleTimeoutSec) - assertThat(it.server.maxPayloadSizeBytes).isEqualTo(defaultMaxPayloadSizeBytes) + assertThat(it.server.listenPort) + .isEqualTo(defaultListenPort) + assertThat(it.server.maxPayloadSizeBytes) + .isEqualTo(defaultMaxPayloadSizeBytes) + assertThat(it.server.idleTimeout) + .isEqualTo(Duration.ofSeconds(defaultIdleTimeoutSec)) val securityKeys = it.security.keys .getOrElse { fail("Should be immutableSecurityKeys") } as SecurityKeys @@ -103,10 +109,14 @@ internal object ConfigurationValidatorTest : Spek({ securityKeys.keyStorePassword().use { assertThat(it).isEqualTo(KEYSTORE_PASSWORD.toCharArray()) } securityKeys.trustStorePassword().use { assertThat(it).isEqualTo(TRUSTSTORE_PASSWORD.toCharArray()) } - assertThat(it.cbs.firstRequestDelay).isEqualTo(defaultFirstReqDelaySec) - assertThat(it.cbs.requestInterval).isEqualTo(defaultRequestIntervalSec) + assertThat(it.cbs.firstRequestDelay) + .isEqualTo(Duration.ofSeconds(defaultFirstReqDelaySec)) + assertThat(it.cbs.requestInterval) + .isEqualTo(Duration.ofSeconds(defaultRequestIntervalSec)) + + assertThat(it.collector.routing) + .isEqualTo(sampleRouting) - assertThat(it.collector.routing).isEqualTo(emptyRouting) assertThat(it.logLevel).isEqualTo(LogLevel.TRACE) } ) @@ -130,16 +140,16 @@ internal object ConfigurationValidatorTest : Spek({ }, { assertThat(it.server.idleTimeout) - .isEqualTo(defaultIdleTimeoutSec) + .isEqualTo(Duration.ofSeconds(defaultIdleTimeoutSec)) assertThat(it.security.keys) .isEqualTo(None) assertThat(it.cbs.firstRequestDelay) - .isEqualTo(defaultFirstReqDelaySec) + .isEqualTo(Duration.ofSeconds(defaultFirstReqDelaySec)) assertThat(it.collector.routing) - .isEqualTo(emptyRouting) + .isEqualTo(sampleRouting) } ) } @@ -172,42 +182,47 @@ internal object ConfigurationValidatorTest : Spek({ }) private fun partialConfiguration(listenPort: Option<Int> = Some(defaultListenPort), - idleTimeoutSec: Option<Duration> = Some(defaultIdleTimeoutSec), + idleTimeoutSec: Option<Long> = Some(defaultIdleTimeoutSec), maxPayloadSizeBytes: Option<Int> = Some(defaultMaxPayloadSizeBytes), - firstReqDelaySec: Option<Duration> = Some(defaultFirstReqDelaySec), - requestIntervalSec: Option<Duration> = Some(defaultRequestIntervalSec), + firstReqDelaySec: Option<Long> = Some(defaultFirstReqDelaySec), + requestIntervalSec: Option<Long> = Some(defaultRequestIntervalSec), sslDisable: Option<Boolean> = Some(false), keyStoreFile: Option<String> = Some(KEYSTORE), keyStorePassword: Option<String> = Some(KEYSTORE_PASSWORD), trustStoreFile: Option<String> = Some(TRUSTSTORE), trustStorePassword: Option<String> = Some(TRUSTSTORE_PASSWORD), - routing: Option<Routing> = Some(emptyRouting), + streamPublishers: Option<List<KafkaSink>> = Some(sampleStreamsDefinition), logLevel: Option<LogLevel> = Some(LogLevel.INFO) -) = - PartialConfiguration( - listenPort = listenPort, - idleTimeoutSec = idleTimeoutSec, - maxPayloadSizeBytes = maxPayloadSizeBytes, - firstRequestDelaySec = firstReqDelaySec, - requestIntervalSec = requestIntervalSec, - sslDisable = sslDisable, - keyStoreFile = keyStoreFile, - keyStorePassword = keyStorePassword, - trustStoreFile = trustStoreFile, - trustStorePassword = trustStorePassword, - routing = routing, - logLevel = logLevel - ) - -val defaultListenPort = 1234 -val defaultRequestIntervalSec = Duration.ofSeconds(3) -val defaultMaxPayloadSizeBytes = 2 -val defaultIdleTimeoutSec = Duration.ofSeconds(10L) -val defaultFirstReqDelaySec = Duration.ofSeconds(10L) - -val KEYSTORE = "test.ks.pkcs12" -val KEYSTORE_PASSWORD = "changeMe" -val TRUSTSTORE = "trust.ks.pkcs12" -val TRUSTSTORE_PASSWORD = "changeMeToo" - -val emptyRouting: Routing = emptyList() +) = PartialConfiguration( + listenPort = listenPort, + idleTimeoutSec = idleTimeoutSec, + maxPayloadSizeBytes = maxPayloadSizeBytes, + firstRequestDelaySec = firstReqDelaySec, + requestIntervalSec = requestIntervalSec, + sslDisable = sslDisable, + keyStoreFile = keyStoreFile, + keyStorePassword = keyStorePassword, + trustStoreFile = trustStoreFile, + trustStorePassword = trustStorePassword, + streamPublishers = streamPublishers, + logLevel = logLevel +) + +const val defaultListenPort = 1234 +const val defaultMaxPayloadSizeBytes = 2 +const val defaultRequestIntervalSec = 3L +const val defaultIdleTimeoutSec = 10L +const val defaultFirstReqDelaySec = 10L + +const val KEYSTORE = "test.ks.pkcs12" +const val KEYSTORE_PASSWORD = "changeMe" +const val TRUSTSTORE = "trust.ks.pkcs12" +const val TRUSTSTORE_PASSWORD = "changeMeToo" + +const val sampleSinkName = "perf3gpp" + +private val sampleSink = mock<KafkaSink>().also { + whenever(it.name()).thenReturn(sampleSinkName) +} +val sampleStreamsDefinition = listOf(sampleSink) +val sampleRouting = listOf(Route(sampleSink.name(), sampleSink))
\ No newline at end of file |