Commit 4f941fd2 authored by Peter van 't Hof's avatar Peter van 't Hof

Added more testing and fixed a bug in join queries

parent 9817ac95
......@@ -206,7 +206,7 @@ class SummaryDb(val db: Database) extends Closeable {
/** Return a Query for [[Stats]] */
def statsFilter(runId: Option[Int] = None, pipeline: Option[Either[Int, String]] = None, module: Option[Option[Either[Int, String]]] = None,
sample: Option[Option[Either[Int, String]]] = None, lib: Option[Option[Either[Int, String]]] = None,
sample: Option[Option[Either[Int, String]]] = None, library: Option[Option[Either[Int, String]]] = None,
mustHaveSample: Boolean = false, mustHaveLibrary: Boolean = false) = {
var f: Query[Stats, Stats#TableElementType, Seq] = stats
runId.foreach(r => f = f.filter(_.runId === r))
......@@ -227,7 +227,7 @@ class SummaryDb(val db: Database) extends Closeable {
case Some(None) => f.filter(_.sampleId.isEmpty)
case _ => f
}
f = module match {
f = library match {
case Some(Some(Left(id))) => f.filter(_.libraryId === id)
case Some(Some(Right(name))) => f.join(libraries).on(_.libraryId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.libraryId.isEmpty)
......@@ -317,7 +317,7 @@ class SummaryDb(val db: Database) extends Closeable {
case Some(None) => f.filter(_.sampleId.isEmpty)
case _ => f
}
f = module match {
f = library match {
case Some(Some(Left(id))) => f.filter(_.libraryId === id)
case Some(Some(Right(name))) => f.join(libraries).on(_.libraryId === _.id).filter(_._2.name === name).map(_._1)
case Some(None) => f.filter(_.libraryId.isEmpty)
......
package nl.lumc.sasc.biopet.utils.summary.db
import java.io.File
import java.sql.Date
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
......@@ -36,10 +37,21 @@ class SummaryDbTest extends TestNGSuite with Matchers {
val db = SummaryDb.openSqliteSummary(dbFile)
db.createTables()
Await.result(db.createOrUpdateStat(0, 0, None, None, None, """{"content": "test" }"""), Duration.Inf)
Await.result(db.getStat(0, Left(0), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
Await.result(db.createOrUpdateStat(0, 0, None, None, None, """{"content": "test2" }"""), Duration.Inf)
Await.result(db.getStat(0, Left(0), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
val runId = Await.result(db.createRun("test", "", "", "", new Date(System.currentTimeMillis())), Duration.Inf)
val pipelineId = Await.result(db.createPipeline("test_pipeline", runId), Duration.Inf)
val moduleId = Await.result(db.createModule("test_module", runId, pipelineId), Duration.Inf)
val sampleId = Await.result(db.createSample("test_sample", runId), Duration.Inf)
val libraryId = Await.result(db.createLibrary("test_library", runId, sampleId), Duration.Inf)
Await.result(db.createOrUpdateStat(runId, pipelineId, None, None, None, """{"content": "test" }"""), Duration.Inf)
Await.result(db.getStat(runId, Left(pipelineId), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
Await.result(db.createOrUpdateStat(runId, pipelineId, None, None, None, """{"content": "test2" }"""), Duration.Inf)
Await.result(db.getStat(runId, Left(pipelineId), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
// Test join queries
Await.result(db.createOrUpdateStat(runId, pipelineId, Some(moduleId), Some(sampleId), Some(libraryId), """{"content": "test3" }"""), Duration.Inf)
Await.result(db.getStat(runId, Right("test_pipeline"), Some(Right("test_module")), Some(Right("test_sample")), Some(Right("test_library"))), Duration.Inf) shouldBe Some(Map("content" -> "test3"))
db.close()
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment