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
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.main
22 import arrow.core.Left
23 import arrow.core.None
24 import com.nhaarman.mockitokotlin2.any
25 import com.nhaarman.mockitokotlin2.mock
26 import com.nhaarman.mockitokotlin2.whenever
27 import org.jetbrains.spek.api.Spek
28 import org.jetbrains.spek.api.dsl.describe
29 import org.jetbrains.spek.api.dsl.it
30 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.XnfSimulator
31 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters.VesHvClient
32 import org.onap.dcae.collectors.veshv.tests.utils.Assertions.assertThat
33 import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser
34 import org.onap.dcae.collectors.veshv.ves.message.generator.api.ParsingError
35 import org.onap.dcae.collectors.veshv.ves.message.generator.factory.MessageGeneratorFactory
36 import java.io.ByteArrayInputStream
39 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
40 * @since September 2018
42 internal class XnfSimulatorTest : Spek({
43 lateinit var cut: XnfSimulator
44 lateinit var vesClient: VesHvClient
45 lateinit var messageParametersParser: MessageParametersParser
46 lateinit var generatorFactory: MessageGeneratorFactory
50 messageParametersParser = mock()
51 generatorFactory = mock()
52 cut = XnfSimulator(vesClient, generatorFactory, messageParametersParser)
55 describe("startSimulation") {
56 it("should fail when empty input stream") {
58 val emptyInputStream = ByteArrayInputStream(byteArrayOf())
61 val result = cut.startSimulation(emptyInputStream)
64 assertThat(result).isLeft()
67 it("should fail when invalid JSON") {
69 val invalidJson = "invalid json".byteInputStream()
72 val result = cut.startSimulation(invalidJson)
75 assertThat(result).isLeft()
78 it("should fail when JSON syntax is valid but content is invalid") {
80 val json = "[1,2,3]".byteInputStream()
81 val cause = ParsingError("epic fail", None)
82 whenever(messageParametersParser.parse(any())).thenReturn(
86 val result = cut.startSimulation(json)
89 assertThat(result).left().isEqualTo(cause)
92 // TODO uncomment and fix this test after introducing HvVesProducer from onap SDK in XnfSimulator
93 // it("should return generated messages") {
95 // val json = "[true]".byteInputStream()
96 // val messageParams = listOf<MessageParameters>()
97 // val generatedMessages = Flux.empty<WireFrameMessage>()
98 // val sendingIo = IO {}
99 // whenever(messageParametersParser.parse(any())).thenReturn(Right(messageParams))
100 // whenever(messageGenerator.createMessageFlux(messageParams)).thenReturn(generatedMessages)
101 // whenever(vesClient.sendIo(generatedMessages)).thenReturn(sendingIo)
104 // val result = cut.startSimulation(json)
107 // assertThat(result).right().isSameAs(sendingIo)