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 org.assertj.core.api.Assertions.assertThat
23 import org.jetbrains.spek.api.Spek
24 import org.jetbrains.spek.api.dsl.given
25 import org.jetbrains.spek.api.dsl.it
26 import org.jetbrains.spek.api.dsl.on
27 import org.onap.dcae.collectors.veshv.domain.ByteData
28 import org.onap.dcae.collectors.veshv.domain.VesEventDomain
29 import org.onap.dcae.collectors.veshv.model.VesMessage
30 import org.onap.dcae.collectors.veshv.tests.utils.commonHeader
31 import org.onap.dcae.collectors.veshv.tests.utils.vesEventBytes
32 import org.onap.ves.VesEventOuterClass.CommonEventHeader.*
34 internal object MessageValidatorTest : Spek({
36 given("Message validator") {
37 val cut = MessageValidator
39 on("ves hv message including header with fully initialized fields") {
40 val commonHeader = commonHeader()
42 it("should accept message with fully initialized message header") {
43 val vesMessage = VesMessage(commonHeader, vesEventBytes(commonHeader))
44 assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isTrue()
47 VesEventDomain.values()
49 it("should accept message with $domain domain") {
50 val header = commonHeader(domain)
51 val vesMessage = VesMessage(header, vesEventBytes(header))
52 assertThat(cut.isValid(vesMessage))
58 on("ves hv message bytes") {
59 val vesMessage = VesMessage(getDefaultInstance(), ByteData.EMPTY)
60 it("should not accept message with default header") {
61 assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
65 val priorityTestCases = mapOf(
66 Priority.PRIORITY_NOT_PROVIDED to false,
70 priorityTestCases.forEach { value, expectedResult ->
71 on("ves hv message including header with priority $value") {
72 val commonEventHeader = commonHeader(priority = value)
73 val vesMessage = VesMessage(commonEventHeader, vesEventBytes(commonEventHeader))
75 it("should resolve validation result") {
76 assertThat(cut.isValid(vesMessage)).describedAs("message validation results")
77 .isEqualTo(expectedResult)
82 on("ves hv message including header with not initialized fields") {
83 val commonHeader = newBuilder()
85 .setEventName("Sample event name")
86 .setEventId("Sample event Id")
87 .setSourceName("Sample Source")
89 val rawMessageBytes = vesEventBytes(commonHeader)
91 it("should not accept not fully initialized message header") {
92 val vesMessage = VesMessage(commonHeader, rawMessageBytes)
93 assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
97 on("ves hv message including header.vesEventListenerVersion with non-string major part") {
98 val commonHeader = commonHeader(vesEventListenerVersion = "sample-version")
99 val rawMessageBytes = vesEventBytes(commonHeader)
102 it("should not accept message header") {
103 val vesMessage = VesMessage(commonHeader, rawMessageBytes)
104 assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
108 on("ves hv message including header.vesEventListenerVersion with major part != 7") {
109 val commonHeader = commonHeader(vesEventListenerVersion = "1.2.3")
110 val rawMessageBytes = vesEventBytes(commonHeader)
112 it("should not accept message header") {
113 val vesMessage = VesMessage(commonHeader, rawMessageBytes)
114 assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()
118 on("ves hv message including header.vesEventListenerVersion with minor part not starting with a digit") {
119 val commonHeader = commonHeader(vesEventListenerVersion = "7.test")
120 val rawMessageBytes = vesEventBytes(commonHeader)
122 it("should not accept message header") {
123 val vesMessage = VesMessage(commonHeader, rawMessageBytes)
124 assertThat(cut.isValid(vesMessage)).describedAs("message validation result").isFalse()