9760208f0df4ceb7b0290f8b2a96b03ae232c497
[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 org.jetbrains.spek.api.Spek
23 import org.jetbrains.spek.api.dsl.given
24 import org.jetbrains.spek.api.dsl.it
25 import org.assertj.core.api.Assertions.assertThat
26 import org.jetbrains.spek.api.dsl.on
27 import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator
28
29 private const val DEFAULT_MEASUREMENTS_NUMBER = 2
30 private const val DEFAULT_COUNTERS_NUMBER = 2
31
32 private val uriRegex = """sample/uri(\d+)""".toRegex()
33
34 object PayloadGeneratorTest : Spek({
35
36     given("payload factory object") {
37         val payloadGenerator = PayloadGenerator()
38
39         on("two generated payloads") {
40             val generatedPayload0 = payloadGenerator.generatePayload()
41             val generatedPayload1 = payloadGenerator.generatePayload()
42             it("URIs should have different names") {
43                 val matchResult0 = uriRegex.find(generatedPayload0.getPmObject(0).uri)!!.value
44                 val matchResult1 = uriRegex.find(generatedPayload1.getPmObject(0).uri)!!.value
45                 assertThat(matchResult0 != matchResult1).isTrue()
46             }
47         }
48
49         on("call with default parameters") {
50             val generatedPayload = payloadGenerator.generatePayload()
51             it("should contain default numbers of measurements") {
52                 assertThat(generatedPayload.getPmObject(0).hvRanMeasCount).isEqualTo(DEFAULT_MEASUREMENTS_NUMBER)
53             }
54             it("should contain default numbers of counters in measurement") {
55                 assertThat(generatedPayload.getPmObject(0).getHvRanMeas(0).counterSubidCount).isEqualTo(DEFAULT_COUNTERS_NUMBER)
56             }
57         }
58
59         on("call with specified parameters") {
60             val numOfCountPerMeas: Long = 5
61             val numOfMeasPerObject: Int = 10
62             val generatedPayload = payloadGenerator.generatePayload(numOfCountPerMeas, numOfMeasPerObject)
63             it("should contain specified number of measurements") {
64                 assertThat(generatedPayload.getPmObject(0).hvRanMeasCount).isEqualTo(numOfMeasPerObject)
65             }
66             it("measurement should contain specified number of counters") {
67                 assertThat(generatedPayload.getPmObject(0).hvRanMeasList
68                         .filter { numOfCountPerMeas.toInt() == it.counterSubidCount }
69                         .size)
70                         .isEqualTo(numOfMeasPerObject)
71             }
72
73         }
74     }
75 })