SummaryDbTest.scala 2.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
package nl.lumc.sasc.biopet.utils.summary.db

import java.io.File

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

import scala.concurrent.Await
import scala.concurrent.duration.Duration

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
13 14
 * Created by pjvanthof on 14/02/2017.
 */
15 16 17 18 19 20 21 22 23 24 25
class SummaryDbTest extends TestNGSuite with Matchers {

  @Test
  def testSettings: Unit = {
    val dbFile = File.createTempFile("summary.", ".db")
    dbFile.deleteOnExit()
    val db = SummaryDb.openSqliteSummary(dbFile)
    db.createTables()

    Await.result(db.createOrUpdateSetting(0, 0, None, None, None, """{"content": "test" }"""), Duration.Inf)
    val bla = Await.result(db.getSettings(Some(0)), Duration.Inf)
Peter van 't Hof's avatar
Peter van 't Hof committed
26
    Await.result(db.getSetting(0, Left(0), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
27
    Await.result(db.createOrUpdateSetting(0, 0, None, None, None, """{"content": "test2" }"""), Duration.Inf)
Peter van 't Hof's avatar
Peter van 't Hof committed
28
    Await.result(db.getSetting(0, Left(0), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
Peter van 't Hof's avatar
Peter van 't Hof committed
29
    db.close()
30 31 32 33 34 35 36 37 38 39
  }

  @Test
  def testStats: Unit = {
    val dbFile = File.createTempFile("summary.", ".db")
    dbFile.deleteOnExit()
    val db = SummaryDb.openSqliteSummary(dbFile)
    db.createTables()

    Await.result(db.createOrUpdateStat(0, 0, None, None, None, """{"content": "test" }"""), Duration.Inf)
Peter van 't Hof's avatar
Peter van 't Hof committed
40
    Await.result(db.getStat(0, Left(0), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
41
    Await.result(db.createOrUpdateStat(0, 0, None, None, None, """{"content": "test2" }"""), Duration.Inf)
Peter van 't Hof's avatar
Peter van 't Hof committed
42
    Await.result(db.getStat(0, Left(0), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
Peter van 't Hof's avatar
Peter van 't Hof committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    db.close()
  }

  @Test
  def testExecutable: Unit = {
    val dbFile = File.createTempFile("summary.", ".db")
    dbFile.deleteOnExit()
    val db = SummaryDb.openSqliteSummary(dbFile)
    db.createTables()

    Await.result(db.createOrUpdateExecutable(0, "name"), Duration.Inf)
    val bla1 = Await.result(db.getExecutables(Some(0)), Duration.Inf)
    Await.result(db.createOrUpdateExecutable(0, "name", Some("test")), Duration.Inf)
    Await.result(db.getExecutables(Some(0)), Duration.Inf).head shouldBe Schema.Executable(0, "name", Some("test"))
    db.close()
58 59 60
  }

}