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