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.impl
22 import com.nhaarman.mockitokotlin2.mock
23 import com.nhaarman.mockitokotlin2.whenever
24 import org.assertj.core.api.Assertions.assertThat
25 import org.jetbrains.spek.api.Spek
26 import org.jetbrains.spek.api.dsl.describe
27 import org.jetbrains.spek.api.dsl.it
28 import org.jetbrains.spek.api.dsl.on
29 import org.onap.dcae.collectors.veshv.config.api.model.CollectorConfiguration
30 import org.onap.dcae.collectors.veshv.config.api.model.CollectorConfiguration.Companion.DEFAULT_MAX_PAYLOAD_SIZE
31 import org.onap.dcae.collectors.veshv.config.api.model.Route
32 import org.onap.dcaegen2.services.sdk.model.streams.dmaap.KafkaSink
35 * @author Jakub Dudycz <jakub.dudycz@nokia.com>
38 internal object CollectorConfigurationTest : Spek({
40 describe("CollectorConfiguration") {
41 describe("calculating maxPayloadSizeBytes") {
42 on("defined routes") {
43 val sampleRouting = listOf(
44 Route(sink1.name(), sink1),
45 Route(sink2.name(), sink2),
46 Route(sink3.name(), sink3)
48 val configuration = CollectorConfiguration(sampleRouting)
50 it("should use the highest value among all routes") {
51 assertThat(configuration.maxPayloadSizeBytes)
52 .isEqualTo(highestMaxPayloadSize)
57 val configuration = CollectorConfiguration(emptyList())
59 it("should use default value") {
60 assertThat(configuration.maxPayloadSizeBytes)
61 .isEqualTo(DEFAULT_MAX_PAYLOAD_SIZE)
68 private const val highestMaxPayloadSize = 3
70 private val sink1 = mock<KafkaSink>().also {
71 whenever(it.name()).thenReturn("")
72 whenever(it.maxPayloadSizeBytes()).thenReturn(1)
75 private val sink2 = mock<KafkaSink>().also {
76 whenever(it.name()).thenReturn("")
77 whenever(it.maxPayloadSizeBytes()).thenReturn(2)
80 private val sink3 = mock<KafkaSink>().also {
81 whenever(it.name()).thenReturn("")
82 whenever(it.maxPayloadSizeBytes()).thenReturn(highestMaxPayloadSize)