VESEvent payload generation introduction
[dcaegen2/collectors/hv-ves.git] / hv-collector-client-simulator / src / test / kotlin / org / onap / dcae / collectors / veshv / simulators / xnf / impl / MessageFactoryTest.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.simulators.xnf.impl
21
22 import com.google.protobuf.ByteString
23 import org.jetbrains.spek.api.Spek
24 import org.jetbrains.spek.api.dsl.describe
25 import org.jetbrains.spek.api.dsl.given
26 import org.jetbrains.spek.api.dsl.it
27 import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters
28 import org.onap.ves.VesEventV5
29 import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain.HVRANMEAS
30 import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Priority.MEDIUM
31 import reactor.test.test
32
33 const val SAMPLE_START_EPOCH: Long = 120034455
34 const val SAMPLE_LAST_EPOCH: Long = 120034455
35
36 /**
37  * @author Jakub Dudycz <jakub.dudycz@nokia.com>
38  * @since June 2018
39  */
40 object MessageFactoryTest : Spek({
41     describe("message factory") {
42
43         val factory = MessageFactory.INSTANCE
44
45         given("only common header") {
46             it("should return infinite flux") {
47                 val limit = 1000L
48                 factory.createMessageFlux(getSampleMessageParameters()).take(limit).test()
49                         .expectNextCount(limit)
50                         .verifyComplete()
51             }
52         }
53         given("common header and messages amount") {
54             it("should return message flux of specified size") {
55                 factory.createMessageFlux((getSampleMessageParameters(5))).test()
56                         .expectNextCount(5)
57                         .verifyComplete()
58             }
59         }
60     }
61 })
62
63 fun getSampleMessageParameters(amount: Long = -1): MessageParameters{
64     val commonHeader = VesEventV5.VesEvent.CommonEventHeader.newBuilder()
65             .setVersion("sample-version")
66             .setDomain(HVRANMEAS)
67             .setSequence(1)
68             .setPriority(MEDIUM)
69             .setEventId("sample-event-id")
70             .setEventName("sample-event-name")
71             .setEventType("sample-event-type")
72             .setStartEpochMicrosec(SAMPLE_START_EPOCH)
73             .setLastEpochMicrosec(SAMPLE_LAST_EPOCH)
74             .setNfNamingCode("sample-nf-naming-code")
75             .setNfcNamingCode("sample-nfc-naming-code")
76             .setReportingEntityId("sample-reporting-entity-id")
77             .setReportingEntityName(ByteString.copyFromUtf8("sample-reporting-entity-name"))
78             .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
79             .setSourceName("sample-source-name")
80             .build()
81
82     return MessageParameters(commonHeader, amount)
83 }