summaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-xnf-simulator/src/test
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2019-02-19 18:06:33 +0100
committerJakub Dudycz <jakub.dudycz@nokia.com>2019-02-21 12:54:54 +0100
commitbacba429e2dd6b3048da7e75800f5ad200952599 (patch)
treef62d89972415e8e8da51fd042b980048efea0ecd /sources/hv-collector-xnf-simulator/src/test
parent82b27ff5bccc925fe03d05f259cf881fafc8a1ce (diff)
Use sdk/hvves-producer in hvves/xnf-simulator
Change-Id: I8f493b0edd2cbaef136a22d914ad24198bb63a7f Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com> Issue-ID: DCAEGEN2-1253
Diffstat (limited to 'sources/hv-collector-xnf-simulator/src/test')
-rw-r--r--sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/HvVesClientTest.kt69
-rw-r--r--sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt64
2 files changed, 112 insertions, 21 deletions
diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/HvVesClientTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/HvVesClientTest.kt
new file mode 100644
index 00000000..daf30617
--- /dev/null
+++ b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/HvVesClientTest.kt
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START=======================================================
+ * dcaegen2-collectors-veshv
+ * ================================================================================
+ * Copyright (C) 2019 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
+
+import com.nhaarman.mockitokotlin2.any
+import com.nhaarman.mockitokotlin2.eq
+import com.nhaarman.mockitokotlin2.mock
+import com.nhaarman.mockitokotlin2.verify
+import com.nhaarman.mockitokotlin2.whenever
+import org.jetbrains.spek.api.Spek
+import org.jetbrains.spek.api.dsl.describe
+import org.jetbrains.spek.api.dsl.it
+import org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters.HvVesClient
+import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.HvVesProducer
+import org.onap.ves.VesEventOuterClass
+import reactor.core.publisher.Flux
+import reactor.core.publisher.Mono
+import java.nio.ByteBuffer
+
+
+/**
+ * @author Jakub Dudycz <jakub.dudycz@nokia.com>
+ * @since February 2019
+ */
+internal class HvVesClientTest : Spek({
+ describe("HvVesClient") {
+ val hvVesProducer: HvVesProducer = mock()
+ val cut = HvVesClient(hvVesProducer)
+
+ describe("handling ves events stream") {
+
+ val vesEvents = Flux.empty<VesEventOuterClass.VesEvent>()
+ whenever(hvVesProducer.send(any())).thenReturn(Mono.empty())
+ cut.sendVesEvents(vesEvents)
+
+ it("should perform sending operation") {
+ verify(hvVesProducer).send(vesEvents)
+ }
+ }
+
+ describe("handling raw message stream") {
+
+ val rawMessages = Flux.empty<ByteBuffer>()
+ whenever(hvVesProducer.sendRaw(any(), any())).thenReturn(Mono.empty())
+ cut.sendRawPayload(rawMessages)
+
+ it("should perform sending operation") {
+ verify(hvVesProducer).sendRaw(eq(rawMessages), any())
+ }
+ }
+ }
+}) \ No newline at end of file
diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt
index 192725b9..123f12ae 100644
--- a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt
+++ b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt
@@ -21,18 +21,28 @@ package org.onap.dcae.collectors.veshv.main
import arrow.core.Left
import arrow.core.None
+import arrow.core.Right
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.mock
+import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import org.onap.dcae.collectors.veshv.simulators.xnf.impl.XnfSimulator
-import org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters.VesHvClient
+import org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters.HvVesClient
+import org.onap.dcae.collectors.veshv.simulators.xnf.impl.factory.ClientFactory
import org.onap.dcae.collectors.veshv.tests.utils.Assertions.assertThat
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser
import org.onap.dcae.collectors.veshv.ves.message.generator.api.ParsingError
+import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventParameters
+import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType
import org.onap.dcae.collectors.veshv.ves.message.generator.factory.MessageGeneratorFactory
+import org.onap.dcae.collectors.veshv.ves.message.generator.generators.VesEventGenerator
+import org.onap.ves.VesEventOuterClass
+import org.onap.ves.VesEventOuterClass.CommonEventHeader
+import reactor.core.publisher.Flux
+import reactor.core.publisher.Mono
import java.io.ByteArrayInputStream
/**
@@ -41,15 +51,15 @@ import java.io.ByteArrayInputStream
*/
internal class XnfSimulatorTest : Spek({
lateinit var cut: XnfSimulator
- lateinit var vesClient: VesHvClient
+ lateinit var clientFactory: ClientFactory
lateinit var messageParametersParser: MessageParametersParser
lateinit var generatorFactory: MessageGeneratorFactory
beforeEachTest {
- vesClient = mock()
+ clientFactory = mock()
messageParametersParser = mock()
generatorFactory = mock()
- cut = XnfSimulator(vesClient, generatorFactory, messageParametersParser)
+ cut = XnfSimulator(clientFactory, generatorFactory, messageParametersParser)
}
describe("startSimulation") {
@@ -89,22 +99,34 @@ internal class XnfSimulatorTest : Spek({
assertThat(result).left().isEqualTo(cause)
}
- // TODO uncomment and fix this test after introducing HvVesProducer from onap SDK in XnfSimulator
-// it("should return generated messages") {
-// // given
-// val json = "[true]".byteInputStream()
-// val messageParams = listOf<MessageParameters>()
-// val generatedMessages = Flux.empty<WireFrameMessage>()
-// val sendingIo = IO {}
-// whenever(messageParametersParser.parse(any())).thenReturn(Right(messageParams))
-// whenever(messageGenerator.createMessageFlux(messageParams)).thenReturn(generatedMessages)
-// whenever(vesClient.sendIo(generatedMessages)).thenReturn(sendingIo)
-//
-// // when
-// val result = cut.startSimulation(json)
-//
-// // then
-// assertThat(result).right().isSameAs(sendingIo)
-// }
+ it("should return generated ves messages") {
+ // given
+ val vesEventGenerator: VesEventGenerator = mock()
+ val vesClient: HvVesClient = mock()
+
+ val json = "[true]".byteInputStream()
+
+ val vesEventParams = VesEventParameters(
+ CommonEventHeader.getDefaultInstance(),
+ VesEventType.VALID,
+ 1
+ )
+ val messageParams = listOf(vesEventParams)
+
+ val generatedMessages = Flux.empty<VesEventOuterClass.VesEvent>()
+
+
+ whenever(messageParametersParser.parse(any())).thenReturn(Right(messageParams))
+ whenever(generatorFactory.createVesEventGenerator()).thenReturn(vesEventGenerator)
+ whenever(vesEventGenerator.createMessageFlux(vesEventParams)).thenReturn(generatedMessages)
+ whenever(clientFactory.create()).thenReturn(vesClient)
+ whenever(vesClient.sendVesEvents(generatedMessages)).thenReturn(Mono.just(Unit))
+
+ // when
+ cut.startSimulation(json).map { it.unsafeRunSync() }
+
+ // then
+ verify(vesClient).sendVesEvents(generatedMessages)
+ }
}
}) \ No newline at end of file