2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2010 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.ves.message.generator.impl.wireframe
22 import com.google.protobuf.InvalidProtocolBufferException
23 import org.assertj.core.api.Assertions
24 import org.assertj.core.api.Assertions.assertThat
25 import org.jetbrains.spek.api.Spek
26 import org.jetbrains.spek.api.dsl.it
27 import org.jetbrains.spek.api.dsl.on
28 import org.onap.dcae.collectors.veshv.domain.ByteData
29 import org.onap.dcae.collectors.veshv.domain.WireFrameMessage
30 import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameParameters
31 import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType
32 import org.onap.ves.VesEventOuterClass
33 import reactor.test.test
34 import kotlin.test.assertTrue
37 * @author Jakub Dudycz <jakub.dudycz@nokia.com>
38 * @since February 2019
40 object WireFrameGeneratorTest : Spek({
42 val maxPayloadSizeBytes = 1024
43 val cut = WireFrameGenerator()
45 on("message type requesting invalid GPB data ") {
46 it("should createVesEventGenerator flux of messages with invalid payload") {
48 .createMessageFlux(WireFrameParameters(
49 WireFrameType.INVALID_GPB_DATA, 1
53 assertTrue(it.validate().isRight())
54 assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes)
55 Assertions.assertThatExceptionOfType(InvalidProtocolBufferException::class.java)
56 .isThrownBy { extractCommonEventHeader(it.payload) }
62 on("message type requesting invalid wire frame ") {
63 it("should createVesEventGenerator flux of messages with invalid version") {
65 .createMessageFlux(WireFrameParameters(
66 WireFrameType.INVALID_WIRE_FRAME, 1
70 assertTrue(it.validate().isLeft())
71 assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes)
72 assertThat(it.versionMajor).isNotEqualTo(WireFrameMessage.SUPPORTED_VERSION_MINOR)
80 fun extractCommonEventHeader(bytes: ByteData): VesEventOuterClass.CommonEventHeader =
81 VesEventOuterClass.VesEvent.parseFrom(bytes.unsafeAsArray()).commonEventHeader