ConfigurableTest.scala 3.2 KB
Newer Older
bow's avatar
bow committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * Biopet is built on top of GATK Queue for building bioinformatic
 * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
 * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
 * should also be able to execute Biopet tools and pipelines.
 *
 * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
 *
 * Contact us at: sasc@lumc.nl
 *
 * A dual licensing mode is applied. The source code within this project that are
 * not part of GATK Queue is freely available for non-commercial use under an AGPL
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
16
package nl.lumc.sasc.biopet.utils.config
17
18
19
20
21
22

import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
23
24
 * Test class for [[Configurable]]
 *
25
26
 * Created by pjvan_thof on 1/8/15.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
27
class ConfigurableTest extends TestNGSuite with Matchers {
Peter van 't Hof's avatar
Peter van 't Hof committed
28
  @Test def testConfigurable(): Unit = {
29
30
31
32
    val classC = new ClassC {
      override def configName = "classc"
      override val globalConfig = new Config(ConfigurableTest.map)
    }
33
34
35
36
37
38
39
40
41
42
43
44

    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"

Peter van 't Hof's avatar
Peter van 't Hof committed
45
    classC.get("notexist", default = "default").asString shouldBe "default"
46
47
48
49

    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"
50
51
52
53

    classC.get("bla", sample = "sample1", library = "library1").asString shouldBe "bla"
    classC.get("test", sample = "sample1", library = "library1").asString shouldBe "test"
    classC.get("test", sample = "sample1").asString shouldBe "test"
54
55
56
57
  }
}

abstract class Cfg extends Configurable {
58
59
60
61
62
63
  def get(key: String,
          default: String = null,
          submodule: String = null,
          freeVar: Boolean = true,
          sample: String = null,
          library: String = null) = {
64
    config(key, default, submodule, freeVar = freeVar, sample = sample, library = library)
65
66
67
68
69
70
  }
}

class ClassA(val root: Configurable) extends Cfg

class ClassB(val root: Configurable) extends Cfg {
71
  lazy val classA = new ClassA(this)
Peter van 't Hof's avatar
Peter van 't Hof committed
72
  // Why this needs to be lazy?
73
74
75
76
}

class ClassC(val root: Configurable) extends Cfg {
  def this() = this(null)
77
  lazy val classB = new ClassB(this)
Peter van 't Hof's avatar
Peter van 't Hof committed
78
  // Why this needs to be lazy?
79
80
81
82
83
84
85
86
87
88
}

object ConfigurableTest {
  val map = Map(
    "classa" -> Map(
      "k1" -> "a1"
    ), "classb" -> Map(
      "k1" -> "b1"
    ), "classc" -> Map(
      "k1" -> "c1"
89
90
91
92
93
94
95
96
97
    ), "samples" -> Map(
      "sample1" -> Map(
        "test" -> "test",
        "libraries" -> Map(
          "library1" -> Map(
            "bla" -> "bla"
          )
        )
      )
98
99
100
    )
  )
}