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.main
22 import org.assertj.core.api.Assertions.assertThat
23 import org.jetbrains.spek.api.Spek
24 import org.jetbrains.spek.api.dsl.describe
25 import org.jetbrains.spek.api.dsl.given
26 import org.jetbrains.spek.api.dsl.it
27 import org.jetbrains.spek.api.dsl.on
28 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.OngoingSimulations
29 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusFailure
30 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusNotFound
31 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusOngoing
32 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusSuccess
33 import org.onap.dcae.collectors.veshv.tests.utils.waitUntilSucceeds
34 import reactor.core.publisher.Mono
35 import reactor.core.scheduler.Schedulers
39 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
40 * @since September 2018
42 internal class OngoingSimulationsTest : Spek({
43 val scheduler = Schedulers.single()
44 val cut = OngoingSimulations(scheduler)
46 describe("simulations repository") {
47 given("not existing task task id") {
48 val id = UUID.randomUUID()
50 on("asking for status") {
51 val result = cut.status(id)
53 it("should have 'not found' status") {
54 assertThat(result).isEqualTo(StatusNotFound)
60 on("quering about any pending task") {
61 it("should return false") {
62 assertThat(cut.isAnySimulationPending()).isFalse()
67 given("never ending task") {
68 val task = neverendingTask()
70 on("startAsynchronousSimulation") {
71 val result = cut.startAsynchronousSimulation(task)
73 it("should have ongoing status") {
74 assertThat(cut.status(result)).isEqualTo(StatusOngoing)
77 it("should return true when asked about any pending tasks") {
78 assertThat(cut.isAnySimulationPending()).isTrue()
83 given("failing task") {
84 val (cause, task) = failingTask()
86 on("startAsynchronousSimulation") {
87 val taskID = cut.startAsynchronousSimulation(task)
89 it("should have failing status") {
91 assertThat(cut.status(taskID)).isEqualTo(StatusFailure(cause))
95 it("should return false when asked about any pending tasks") {
97 assertThat(cut.isAnySimulationPending()).isFalse()
103 given("successful task") {
104 val task = succesfulTask()
106 on("startAsynchronousSimulation") {
107 val taskID = cut.startAsynchronousSimulation(task)
109 it("should have successful status") {
111 assertThat(cut.status(taskID)).isEqualTo(StatusSuccess)
115 it("should return false when asked about any pending tasks") {
117 assertThat(cut.isAnySimulationPending()).isFalse()
128 afterEachTest { cut.clear() }
131 private fun neverendingTask() = Mono.never<Void>()
133 private fun succesfulTask(): Mono<Void> = Mono.empty<Void>()
135 println("great success")
138 private fun failingTask(): Pair<RuntimeException, Mono<Void>> {
139 val cause = RuntimeException("facepalm")
140 val task = Mono.error<Void>(cause)
141 return Pair(cause, task)