Bump checkstyle version
[dcaegen2/collectors/hv-ves.git] / sources / hv-collector-core / src / test / kotlin / org / onap / dcae / collectors / veshv / impl / RouterTest.kt
1 /*
2  * ============LICENSE_START=======================================================
3  * dcaegen2-collectors-veshv
4  * ================================================================================
5  * Copyright (C) 2018 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.impl
21
22 import arrow.core.None
23 import arrow.core.Some
24 import org.assertj.core.api.Assertions.assertThat
25 import org.jetbrains.spek.api.Spek
26 import org.jetbrains.spek.api.dsl.given
27 import org.jetbrains.spek.api.dsl.it
28 import org.jetbrains.spek.api.dsl.on
29 import org.onap.dcae.collectors.veshv.domain.ByteData
30 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.PERF3GPP
31 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.HEARTBEAT
32 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.SYSLOG
33 import org.onap.dcae.collectors.veshv.model.RoutedMessage
34 import org.onap.dcae.collectors.veshv.model.VesMessage
35 import org.onap.dcae.collectors.veshv.model.routing
36 import org.onap.dcae.collectors.veshv.tests.utils.commonHeader
37
38
39 /**
40  * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
41  * @since May 2018
42  */
43 object RouterTest : Spek({
44     given("sample configuration") {
45         val config = routing {
46
47             defineRoute {
48                 fromDomain(PERF3GPP.domainName)
49                 toTopic("ves_rtpm")
50                 withFixedPartitioning(2)
51             }
52
53             defineRoute {
54                 fromDomain(SYSLOG.domainName)
55                 toTopic("ves_trace")
56                 withFixedPartitioning()
57             }
58         }.build()
59         val cut = Router(config)
60
61         on("message with existing route (rtpm)") {
62             val message = VesMessage(commonHeader(PERF3GPP), ByteData.EMPTY)
63             val result = cut.findDestination(message)
64
65             it("should have route available") {
66                 assertThat(result).isNotNull()
67             }
68
69             it("should be routed to proper partition") {
70                 assertThat(result.map(RoutedMessage::partition)).isEqualTo(Some(2))
71             }
72
73             it("should be routed to proper topic") {
74                 assertThat(result.map(RoutedMessage::topic)).isEqualTo(Some("ves_rtpm"))
75             }
76
77             it("should be routed with a given message") {
78                 assertThat(result.map(RoutedMessage::message)).isEqualTo(Some(message))
79             }
80         }
81
82         on("message with existing route (trace)") {
83             val message = VesMessage(commonHeader(SYSLOG), ByteData.EMPTY)
84             val result = cut.findDestination(message)
85
86             it("should have route available") {
87                 assertThat(result).isNotNull()
88             }
89
90             it("should be routed to proper partition") {
91                 assertThat(result.map(RoutedMessage::partition)).isEqualTo(Some(0))
92             }
93
94             it("should be routed to proper topic") {
95                 assertThat(result.map(RoutedMessage::topic)).isEqualTo(Some("ves_trace"))
96             }
97
98             it("should be routed with a given message") {
99                 assertThat(result.map(RoutedMessage::message)).isEqualTo(Some(message))
100             }
101         }
102
103         on("message with unknown route") {
104             val message = VesMessage(commonHeader(HEARTBEAT), ByteData.EMPTY)
105             val result = cut.findDestination(message)
106
107             it("should not have route available") {
108                 assertThat(result).isEqualTo(None)
109             }
110         }
111     }
112 })