Skip to content
Snippets Groups Projects
Commit 913d16ec authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added unit tests to Configurable

parent 199f0693
No related branches found
No related tags found
No related merge requests found
package nl.lumc.sasc.biopet.core.config
import nl.lumc.sasc.biopet.utils.{ ConfigUtils, ConfigUtilsTest }
import org.scalatest.Matchers
import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
/**
* Created by pjvan_thof on 1/8/15.
*/
class ConfigurableTest extends TestNGSuite with MockitoSugar with Matchers {
@Test def testConfigurable: Unit = {
Config.global.map = Map()
Config.global.loadConfigFile(ConfigurableTest.file)
val classC = new ClassC
classC.configPath shouldBe Nil
classC.configFullPath shouldBe List("classc")
classC.classB.configPath shouldBe List("classc")
classC.classB.configFullPath shouldBe List("classc", "classb")
classC.classB.classA.configPath shouldBe List("classc", "classb")
classC.classB.classA.configFullPath shouldBe List("classc", "classb", "classa")
classC.get("k1").asString shouldBe "c1"
classC.classB.get("k1").asString shouldBe "c1"
classC.classB.classA.get("k1").asString shouldBe "c1"
classC.get("notexist") shouldBe null
intercept[IllegalStateException] {
classC.get("notexist", required = true)
}
classC.get("k1", freeVar = false).asString shouldBe "c1"
classC.classB.get("k1", freeVar = false).asString shouldBe "b1"
classC.classB.classA.get("k1", freeVar = false).asString shouldBe "a1"
}
}
abstract class Cfg extends Configurable {
def get(key: String, default: String = null, submodule: String = null, required: Boolean = false, freeVar: Boolean = true) = {
config(key, default, submodule, required, freeVar = freeVar)
}
}
class ClassA(val root: Configurable) extends Cfg
class ClassB(val root: Configurable) extends Cfg {
val classA = new ClassA(this)
}
class ClassC(val root: Configurable) extends Cfg {
def this() = this(null)
val classB = new ClassB(this)
}
object ConfigurableTest {
val map = Map(
"classa" -> Map(
"k1" -> "a1"
), "classb" -> Map(
"k1" -> "b1"
), "classc" -> Map(
"k1" -> "c1"
)
)
val file = ConfigUtilsTest.writeTemp(ConfigUtils.mapToJson(map).spaces2)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment