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
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.impl
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
40 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
43 object RouterTest : Spek({
44 given("sample configuration") {
45 val config = routing {
48 fromDomain(PERF3GPP.domainName)
50 withFixedPartitioning(2)
54 fromDomain(SYSLOG.domainName)
56 withFixedPartitioning()
59 val cut = Router(config)
61 on("message with existing route (rtpm)") {
62 val message = VesMessage(commonHeader(PERF3GPP), ByteData.EMPTY)
63 val result = cut.findDestination(message)
65 it("should have route available") {
66 assertThat(result).isNotNull()
69 it("should be routed to proper partition") {
70 assertThat(result.map(RoutedMessage::partition)).isEqualTo(Some(2))
73 it("should be routed to proper topic") {
74 assertThat(result.map(RoutedMessage::topic)).isEqualTo(Some("ves_rtpm"))
77 it("should be routed with a given message") {
78 assertThat(result.map(RoutedMessage::message)).isEqualTo(Some(message))
82 on("message with existing route (trace)") {
83 val message = VesMessage(commonHeader(SYSLOG), ByteData.EMPTY)
84 val result = cut.findDestination(message)
86 it("should have route available") {
87 assertThat(result).isNotNull()
90 it("should be routed to proper partition") {
91 assertThat(result.map(RoutedMessage::partition)).isEqualTo(Some(0))
94 it("should be routed to proper topic") {
95 assertThat(result.map(RoutedMessage::topic)).isEqualTo(Some("ves_trace"))
98 it("should be routed with a given message") {
99 assertThat(result.map(RoutedMessage::message)).isEqualTo(Some(message))
103 on("message with unknown route") {
104 val message = VesMessage(commonHeader(HEARTBEAT), ByteData.EMPTY)
105 val result = cut.findDestination(message)
107 it("should not have route available") {
108 assertThat(result).isEqualTo(None)