dbdf4ad07bc7ce1388f7ad8802dcdcf001f80e77
[dcaegen2/collectors/hv-ves.git] /
1 /*
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.config.impl
21
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
33
34 /**
35  * @author Jakub Dudycz <jakub.dudycz@nokia.com>
36  * @since May 2018
37  */
38 internal object CollectorConfigurationTest : Spek({
39
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)
47                 )
48                 val configuration = CollectorConfiguration(sampleRouting)
49
50                 it("should use the highest value among all routes") {
51                     assertThat(configuration.maxPayloadSizeBytes)
52                             .isEqualTo(highestMaxPayloadSize)
53                 }
54             }
55
56             on("empty routing") {
57                 val configuration = CollectorConfiguration(emptyList())
58
59                 it("should use default value") {
60                     assertThat(configuration.maxPayloadSizeBytes)
61                             .isEqualTo(DEFAULT_MAX_PAYLOAD_SIZE)
62                 }
63             }
64         }
65     }
66 })
67
68 private const val highestMaxPayloadSize = 3
69
70 private val sink1 = mock<KafkaSink>().also {
71     whenever(it.name()).thenReturn("")
72     whenever(it.maxPayloadSizeBytes()).thenReturn(1)
73 }
74
75 private val sink2 = mock<KafkaSink>().also {
76     whenever(it.name()).thenReturn("")
77     whenever(it.maxPayloadSizeBytes()).thenReturn(2)
78 }
79
80 private val sink3 = mock<KafkaSink>().also {
81     whenever(it.name()).thenReturn("")
82     whenever(it.maxPayloadSizeBytes()).thenReturn(highestMaxPayloadSize)
83 }