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
36 import java.util.concurrent.Executors
39 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
40 * @since September 2018
42 internal class OngoingSimulationsTest : Spek({
43 val executor = Executors.newSingleThreadExecutor()
44 val cut = OngoingSimulations(executor)
46 describe("simulations repository") {
47 given("not existing task task id") {
48 val id = UUID.randomUUID()
51 val result = cut.status(id)
53 it("should have 'not found' status") {
54 assertThat(result).isEqualTo(StatusNotFound)
59 given("never ending task") {
60 val task = IO.async<Unit> { }
62 on("startAsynchronousSimulation") {
63 val result = cut.startAsynchronousSimulation(task)
65 it("should have ongoing status") {
66 assertThat(cut.status(result)).isEqualTo(StatusOngoing)
71 given("failing task") {
72 val cause = RuntimeException("facepalm")
73 val task = IO.raiseError<Unit>(cause)
75 on("startAsynchronousSimulation") {
76 val result = cut.startAsynchronousSimulation(task)
78 it("should have failing status") {
80 assertThat(cut.status(result)).isEqualTo(StatusFailure(cause))
86 given("successful task") {
87 val task = IO { println("great success!") }
89 on("startAsynchronousSimulation") {
90 val result = cut.startAsynchronousSimulation(task)
92 it("should have successful status") {
94 assertThat(cut.status(result)).isEqualTo(StatusSuccess)
105 afterEachTest { cut.clear() }