/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.libraryweasel.vertx

import io.kotlintest.shouldBe
import io.kotlintest.specs.StringSpec
import io.vertx.core.AbstractVerticle
import io.vertx.core.Context
import io.vertx.core.Vertx

class LibraryWeaselVertxManagerTest: StringSpec({
    val libraryWeaselVertxManager = LibraryWeaselVertxManager()

    val simpleVerticle = object: AbstractVerticle() {

    }

    val exceptionVerticle = object : AbstractVerticle() {
        override fun init(vertx: Vertx?, context: Context?) {
            throw RuntimeException("?!?!?!?")
        }
    }

    "test adding simpleVerticle" {
        libraryWeaselVertxManager.addVerticle(simpleVerticle)
        Thread.sleep(100)
        libraryWeaselVertxManager.deploymentMap.size shouldBe 1
    }


    "test removing simpleVerticle" {
        libraryWeaselVertxManager.removeVerticle(simpleVerticle)
        Thread.sleep(100)
        libraryWeaselVertxManager.deploymentMap.size shouldBe 0
    }

    "test adding Verticle that throws an exception" {
        libraryWeaselVertxManager.addVerticle(exceptionVerticle)
        Thread.sleep(100)
        libraryWeaselVertxManager.deploymentMap.size shouldBe 0
    }

    "test removing Verticle that isn't already deployed" {
        libraryWeaselVertxManager.removeVerticle(simpleVerticle)
        Thread.sleep(100)
        libraryWeaselVertxManager.deploymentMap.size shouldBe 0
    }
})
