aboutsummaryrefslogtreecommitdiffstats
path: root/hv-collector-xnf-simulator/src/test/kotlin/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'hv-collector-xnf-simulator/src/test/kotlin/org/onap')
-rw-r--r--hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt126
-rw-r--r--hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt83
-rw-r--r--hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGeneratorTest.kt74
3 files changed, 283 insertions, 0 deletions
diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt
new file mode 100644
index 00000000..f2f92fff
--- /dev/null
+++ b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/config/ArgConfigurationProviderTest.kt
@@ -0,0 +1,126 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.main.config
+
+import arrow.core.identity
+import org.assertj.core.api.Assertions.assertThat
+import org.jetbrains.spek.api.Spek
+import org.jetbrains.spek.api.dsl.describe
+import org.jetbrains.spek.api.dsl.given
+import org.jetbrains.spek.api.dsl.it
+import org.jetbrains.spek.api.dsl.on
+import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
+import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgConfigurationProvider
+import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgConfigurationProvider.*
+import org.onap.dcae.collectors.veshv.simulators.xnf.config.SimulatorConfiguration
+import java.nio.file.Paths
+
+
+object ArgConfigurationProviderTest : Spek({
+ lateinit var cut: ArgConfigurationProvider
+ val messagesAmount = 3L
+ val vesHost = "localhosting"
+ val pk = Paths.get("/", "etc", "ves", "pk.pem")
+ val cert = Paths.get("/", "etc", "ssl", "certs", "ca-bundle.crt")
+ val trustCert = Paths.get("/", "etc", "ves", "trusted.crt")
+
+ beforeEachTest {
+ cut = ArgConfigurationProvider()
+ }
+
+ fun parse(vararg cmdLine: String): SimulatorConfiguration =
+ cut.parse(cmdLine).fold(
+ {throw AssertionError("Parsing result should be present")},
+ ::identity
+ )
+
+ describe("parsing arguments") {
+ lateinit var result: SimulatorConfiguration
+
+ given("all parameters are present in the long form") {
+
+ beforeEachTest {
+ result = parse("--ves-port", "6969",
+ "--ves-host", vesHost,
+ "--messages", messagesAmount.toString(),
+ "--private-key-file", pk.toFile().absolutePath,
+ "--cert-file", cert.toFile().absolutePath,
+ "--trust-cert-file", trustCert.toFile().absolutePath)
+ }
+
+ it("should set proper port") {
+ assertThat(result.vesPort).isEqualTo(6969)
+ }
+
+
+ it("should set proper config url") {
+ assertThat(result.messagesAmount).isEqualTo(messagesAmount)
+ }
+
+ it("should set proper security configuration") {
+ assertThat(result.security).isEqualTo(
+ SecurityConfiguration(pk, cert, trustCert)
+ )
+ }
+ }
+
+ given("some parameters are present in the short form") {
+
+ beforeEachTest {
+ result = parse("-h", "ves-hv", "--ves-port", "666", "-m", messagesAmount.toString())
+ }
+
+ it("should set proper port") {
+ assertThat(result.vesPort).isEqualTo(666)
+ }
+
+ it("should set proper messages amount") {
+ assertThat(result.messagesAmount).isEqualTo(messagesAmount)
+ }
+ }
+
+ given("all optional parameters are absent") {
+
+ beforeEachTest {
+ result = parse("-h", "ves-hv", "-p", "666")
+ }
+
+ it("should set default messages amount") {
+ assertThat(result.messagesAmount).isEqualTo(DefaultValues.MESSAGES_AMOUNT)
+ }
+
+ on("security config") {
+ val securityConfiguration = result.security
+
+ it("should set default trust cert file") {
+ assertThat(securityConfiguration.trustedCert.toString()).isEqualTo(DefaultValues.TRUST_CERT_FILE)
+ }
+
+ it("should set default server cert file") {
+ assertThat(securityConfiguration.cert.toString()).isEqualTo(DefaultValues.CERT_FILE)
+ }
+
+ it("should set default private key file") {
+ assertThat(securityConfiguration.privateKey.toString()).isEqualTo(DefaultValues.PRIVATE_KEY_FILE)
+ }
+ }
+ }
+ }
+})
diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt
new file mode 100644
index 00000000..6f8a95a4
--- /dev/null
+++ b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt
@@ -0,0 +1,83 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.simulators.xnf.impl
+
+import com.google.protobuf.ByteString
+import org.jetbrains.spek.api.Spek
+import org.jetbrains.spek.api.dsl.describe
+import org.jetbrains.spek.api.dsl.given
+import org.jetbrains.spek.api.dsl.it
+import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters
+import org.onap.ves.VesEventV5
+import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain.HVRANMEAS
+import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Priority.MEDIUM
+import reactor.test.test
+
+const val SAMPLE_START_EPOCH: Long = 120034455
+const val SAMPLE_LAST_EPOCH: Long = 120034455
+
+/**
+ * @author Jakub Dudycz <jakub.dudycz@nokia.com>
+ * @since June 2018
+ */
+object MessageFactoryTest : Spek({
+ describe("message factory") {
+
+ val factory = MessageGeneratorImpl.INSTANCE
+
+ given("only common header") {
+ it("should return infinite flux") {
+ val limit = 1000L
+ factory.createMessageFlux(getSampleMessageParameters()).take(limit).test()
+ .expectNextCount(limit)
+ .verifyComplete()
+ }
+ }
+ given("common header and messages amount") {
+ it("should return message flux of specified size") {
+ factory.createMessageFlux((getSampleMessageParameters(5))).test()
+ .expectNextCount(5)
+ .verifyComplete()
+ }
+ }
+ }
+})
+
+fun getSampleMessageParameters(amount: Long = -1): MessageParameters{
+ val commonHeader = VesEventV5.VesEvent.CommonEventHeader.newBuilder()
+ .setVersion("sample-version")
+ .setDomain(HVRANMEAS)
+ .setSequence(1)
+ .setPriority(MEDIUM)
+ .setEventId("sample-event-id")
+ .setEventName("sample-event-name")
+ .setEventType("sample-event-type")
+ .setStartEpochMicrosec(SAMPLE_START_EPOCH)
+ .setLastEpochMicrosec(SAMPLE_LAST_EPOCH)
+ .setNfNamingCode("sample-nf-naming-code")
+ .setNfcNamingCode("sample-nfc-naming-code")
+ .setReportingEntityId("sample-reporting-entity-id")
+ .setReportingEntityName(ByteString.copyFromUtf8("sample-reporting-entity-name"))
+ .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
+ .setSourceName("sample-source-name")
+ .build()
+
+ return MessageParameters(commonHeader, amount)
+}
diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGeneratorTest.kt b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGeneratorTest.kt
new file mode 100644
index 00000000..73129a7f
--- /dev/null
+++ b/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGeneratorTest.kt
@@ -0,0 +1,74 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.collectors.veshv.simulators.xnf.impl
+
+import org.jetbrains.spek.api.Spek
+import org.jetbrains.spek.api.dsl.given
+import org.jetbrains.spek.api.dsl.it
+import org.assertj.core.api.Assertions.assertThat
+import org.jetbrains.spek.api.dsl.on
+
+private const val DEFAULT_MEASUREMENTS_NUMBER = 2
+private const val DEFAULT_COUNTERS_NUMBER = 2
+
+private val uriRegex = """sample/uri(\d+)""".toRegex()
+
+object PayloadGeneratorTest : Spek({
+
+ given("payload factory object") {
+ val payloadGenerator = PayloadGenerator()
+
+ on("two generated payloads") {
+ val generatedPayload0 = payloadGenerator.generatePayload()
+ val generatedPayload1 = payloadGenerator.generatePayload()
+ it("URIs should have different names") {
+ val matchResult0 = uriRegex.find(generatedPayload0.getPmObject(0).uri)!!.value
+ val matchResult1 = uriRegex.find(generatedPayload1.getPmObject(0).uri)!!.value
+ assertThat(matchResult0 != matchResult1).isTrue()
+ }
+ }
+
+ on("call with default parameters") {
+ val generatedPayload = payloadGenerator.generatePayload()
+ it("should contain default numbers of measurements") {
+ assertThat(generatedPayload.getPmObject(0).hvRanMeasCount).isEqualTo(DEFAULT_MEASUREMENTS_NUMBER)
+ }
+ it("should contain default numbers of counters in measurement") {
+ assertThat(generatedPayload.getPmObject(0).getHvRanMeas(0).counterSubidCount).isEqualTo(DEFAULT_COUNTERS_NUMBER)
+ }
+ }
+
+ on("call with specified parameters") {
+ val numOfCountPerMeas: Long = 5
+ val numOfMeasPerObject: Int = 10
+ val generatedPayload = payloadGenerator.generatePayload(numOfCountPerMeas, numOfMeasPerObject)
+ it("should contain specified number of measurements") {
+ assertThat(generatedPayload.getPmObject(0).hvRanMeasCount).isEqualTo(numOfMeasPerObject)
+ }
+ it("measurement should contain specified number of counters") {
+ assertThat(generatedPayload.getPmObject(0).hvRanMeasList
+ .filter { numOfCountPerMeas.toInt() == it.counterSubidCount }
+ .size)
+ .isEqualTo(numOfMeasPerObject)
+ }
+
+ }
+ }
+})