2f13c52e6d9a83b4f470acf3d2c12a1a2e4126f3
[dcaegen2/collectors/hv-ves.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * dcaegen2-collectors-veshv
4  * ================================================================================
5  * Copyright (C) 2018-2019 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.vesevent
21
22 import org.assertj.core.api.Assertions.assertThat
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.jetbrains.spek.api.dsl.on
28 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.FAULT
29 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.PERF3GPP
30 import org.onap.dcae.collectors.veshv.tests.utils.commonHeader
31 import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventParameters
32 import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType
33 import reactor.test.test
34
35 /**
36  * @author Jakub Dudycz <jakub.dudycz@nokia.com>
37  * @since June 2018
38  */
39 object VesEventGeneratorTest : Spek({
40     describe("message factory") {
41         val maxPayloadSizeBytes = 1024
42         val cut = VesEventGenerator(PayloadGenerator(), maxPayloadSizeBytes)
43
44         given("single message parameters") {
45             on("messages amount not specified in parameters") {
46                 it("should createVesEventGenerator infinite flux") {
47                     val limit = 1000L
48                     cut
49                             .createMessageFlux(VesEventParameters(
50                                     commonHeader(PERF3GPP),
51                                     VesEventType.VALID
52                             ))
53                             .take(limit)
54                             .test()
55                             .expectNextCount(limit)
56                             .verifyComplete()
57                 }
58             }
59
60             on("messages amount = 0 specified in parameters") {
61                 it("should createVesEventGenerator empty message flux") {
62                     cut
63                             .createMessageFlux(VesEventParameters(
64                                     commonHeader(PERF3GPP),
65                                     VesEventType.VALID,
66                                     0
67                             ))
68                             .test()
69                             .verifyComplete()
70                 }
71             }
72
73             on("messages amount specified in parameters") {
74                 it("should createVesEventGenerator message flux of specified size") {
75                     cut
76                             .createMessageFlux(VesEventParameters(
77                                     commonHeader(PERF3GPP),
78                                     VesEventType.VALID,
79                                     5
80                             ))
81                             .test()
82                             .expectNextCount(5)
83                             .verifyComplete()
84                 }
85             }
86
87             on("message type requesting valid message") {
88                 it("should createVesEventGenerator flux of valid messages with given domain") {
89                     cut
90                             .createMessageFlux(VesEventParameters(
91                                     commonHeader(FAULT),
92                                     VesEventType.VALID,
93                                     1
94                             ))
95                             .test()
96                             .assertNext {
97                                 assertThat(it.toByteArray().size).isLessThan(maxPayloadSizeBytes)
98                                 assertThat(it.commonEventHeader.domain).isEqualTo(FAULT.domainName)
99                             }
100                             .verifyComplete()
101                 }
102             }
103
104             on("message type requesting too big payload") {
105                 it("should createVesEventGenerator flux of messages with given domain and payload exceeding threshold") {
106
107                     cut
108                             .createMessageFlux(VesEventParameters(
109                                     commonHeader(PERF3GPP),
110                                     VesEventType.TOO_BIG_PAYLOAD,
111                                     1
112                             ))
113                             .test()
114                             .assertNext {
115                                 assertThat(it.toByteArray().size).isGreaterThan(maxPayloadSizeBytes)
116                                 assertThat(it.commonEventHeader.domain).isEqualTo(PERF3GPP.domainName)
117                             }
118                             .verifyComplete()
119                 }
120             }
121
122
123
124             on("message type requesting fixed payload") {
125                 it("should createVesEventGenerator flux of valid messages with fixed payload") {
126                     cut
127                             .createMessageFlux(VesEventParameters(
128                                     commonHeader(FAULT),
129                                     VesEventType.FIXED_PAYLOAD,
130                                     1
131                             ))
132                             .test()
133                             .assertNext {
134                                 assertThat(it.toByteArray().size).isLessThan(maxPayloadSizeBytes)
135                                 assertThat(it.eventFields.size()).isEqualTo(VesEventGenerator.FIXED_PAYLOAD_SIZE)
136                                 assertThat(it.commonEventHeader.domain).isEqualTo(FAULT.domainName)
137                             }
138                             .verifyComplete()
139                 }
140             }
141         }
142     }
143 })