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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcae.collectors.veshv.simulators.xnf.impl
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
28 private const val DEFAULT_MEASUREMENTS_NUMBER = 2
29 private const val DEFAULT_COUNTERS_NUMBER = 2
31 private val uriRegex = """sample/uri(\d+)""".toRegex()
33 object PayloadGeneratorTest : Spek({
35 given("payload factory object") {
36 val payloadGenerator = PayloadGenerator()
38 on("two generated payloads") {
39 val generatedPayload0 = payloadGenerator.generatePayload()
40 val generatedPayload1 = payloadGenerator.generatePayload()
41 it("URIs should have different names") {
42 val matchResult0 = uriRegex.find(generatedPayload0.getPmObject(0).uri)!!.value
43 val matchResult1 = uriRegex.find(generatedPayload1.getPmObject(0).uri)!!.value
44 assertThat(matchResult0 != matchResult1).isTrue()
48 on("call with default parameters") {
49 val generatedPayload = payloadGenerator.generatePayload()
50 it("should contain default numbers of measurements") {
51 assertThat(generatedPayload.getPmObject(0).hvRanMeasCount).isEqualTo(DEFAULT_MEASUREMENTS_NUMBER)
53 it("should contain default numbers of counters in measurement") {
54 assertThat(generatedPayload.getPmObject(0).getHvRanMeas(0).counterSubidCount).isEqualTo(DEFAULT_COUNTERS_NUMBER)
58 on("call with specified parameters") {
59 val numOfCountPerMeas: Long = 5
60 val numOfMeasPerObject: Int = 10
61 val generatedPayload = payloadGenerator.generatePayload(numOfCountPerMeas, numOfMeasPerObject)
62 it("should contain specified number of measurements") {
63 assertThat(generatedPayload.getPmObject(0).hvRanMeasCount).isEqualTo(numOfMeasPerObject)
65 it("measurement should contain specified number of counters") {
66 assertThat(generatedPayload.getPmObject(0).hvRanMeasList
67 .filter { numOfCountPerMeas.toInt() == it.counterSubidCount }
69 .isEqualTo(numOfMeasPerObject)