HV VES Collector seed code
[dcaegen2/collectors/hv-ves.git] / hv-collector-core / src / test / kotlin / org / onap / dcae / collectors / veshv / impl / VesDecoderTest.kt
1 /*
2  * ============LICENSE_START=======================================================
3  * dcaegen2-collectors-veshv
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
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 com.google.protobuf.ByteString
23 import io.netty.buffer.Unpooled.wrappedBuffer
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.VesMessage
30 import org.onap.ves.VesEventV5.VesEvent
31 import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
32 import reactor.test.StepVerifier
33 import java.nio.charset.Charset
34
35
36 internal object VesDecoderTest : Spek({
37
38     given("ves message decoder") {
39         val cut = VesDecoder()
40
41         on("ves hv message bytes") {
42             val commonHeader = CommonEventHeader.getDefaultInstance()
43             val msg = VesEvent.newBuilder()
44                     .setCommonEventHeader(commonHeader)
45                     .setHvRanMeasFields(ByteString.copyFromUtf8("highvolume measurements"))
46                     .build()
47             val rawMessageBytes = wrappedBuffer(msg.toByteArray())
48
49
50             it("should decode only header and pass it on along with raw message") {
51                 val expectedMessage = VesMessage(
52                         commonHeader,
53                         rawMessageBytes
54                 )
55
56                 assertThat(cut.decode(rawMessageBytes)).isEqualTo(expectedMessage)
57
58             }
59         }
60
61         on("invalid ves hv message bytes") {
62             val rawMessageBytes = wrappedBuffer("ala ma kota".toByteArray(Charset.defaultCharset()))
63
64             it("should return empty result") {
65                 assertThat(cut.decode(rawMessageBytes)).isNull()
66             }
67         }
68     }
69 })