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 arrow.effects.IO
23 import org.assertj.core.api.Assertions.assertThat
24 import org.jetbrains.spek.api.Spek
25 import org.jetbrains.spek.api.dsl.describe
26 import org.jetbrains.spek.api.dsl.given
27 import org.jetbrains.spek.api.dsl.it
28 import org.jetbrains.spek.api.dsl.on
29 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.OngoingSimulations
30 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusFailure
31 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusNotFound
32 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusOngoing
33 import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusSuccess
34 import org.onap.dcae.collectors.veshv.tests.utils.waitUntilSucceeds
35 import java.time.Duration
37 import java.util.concurrent.Executors
40 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
41 * @since September 2018
43 internal class OngoingSimulationsTest : Spek({
44 val executor = Executors.newSingleThreadExecutor()
45 val cut = OngoingSimulations(executor)
47 describe("simulations repository") {
48 given("not existing task task id") {
49 val id = UUID.randomUUID()
52 val result = cut.status(id)
54 it("should have 'not found' status") {
55 assertThat(result).isEqualTo(StatusNotFound)
60 given("never ending task") {
61 val task = IO.async<Unit> { }
63 on("startAsynchronousSimulation") {
64 val result = cut.startAsynchronousSimulation(task)
66 it("should have ongoing status") {
67 assertThat(cut.status(result)).isEqualTo(StatusOngoing)
72 given("failing task") {
73 val cause = RuntimeException("facepalm")
74 val task = IO.raiseError<Unit>(cause)
76 on("startAsynchronousSimulation") {
77 val result = cut.startAsynchronousSimulation(task)
79 it("should have failing status") {
81 assertThat(cut.status(result)).isEqualTo(StatusFailure(cause))
87 given("successful task") {
88 val task = IO { println("great success!") }
90 on("startAsynchronousSimulation") {
91 val result = cut.startAsynchronousSimulation(task)
93 it("should have successful status") {
95 assertThat(cut.status(result)).isEqualTo(StatusSuccess)
106 afterEachTest { cut.clear() }