Commit ddda9ebd authored by Wai Yi Leung's avatar Wai Yi Leung
Browse files

Merge branch 'feature-report_core_testing' into 'develop'

Feature report core testing



See merge request !330
parents 435b7849 2777f0f7
......@@ -93,9 +93,9 @@ trait ReportBuilder extends ToolCommand {
private var total = 0
private var _sampleId: Option[String] = None
protected def sampleId = _sampleId
protected[report] def sampleId = _sampleId
private var _libId: Option[String] = None
protected def libId = _libId
protected[report] def libId = _libId
case class ExtFile(resourcePath: String, targetPath: String)
......@@ -152,6 +152,8 @@ trait ReportBuilder extends ToolCommand {
total = ReportBuilder.countPages(indexPage)
logger.info(total + " pages to be generated")
done = 0
logger.info("Generate pages")
val jobs = generatePage(summary, indexPage, cmdArgs.outputDir,
args = pageArgs ++ cmdArgs.pageArgs.toMap ++
......@@ -216,7 +218,7 @@ object ReportBuilder {
protected val engine = new TemplateEngine()
/** Cache of temp file for templates from the classpath / jar */
private var templateCache: Map[String, File] = Map()
private[report] var templateCache: Map[String, File] = Map()
/** This will give the total number of pages including all nested pages */
def countPages(page: ReportPage): Int = {
......
{
"samples": {
"sampleName": {
"libraries": {
"libName": {
}
}
}
}
}
\ No newline at end of file
<%@ var arg: String%>
${arg}
\ No newline at end of file
package nl.lumc.sasc.biopet.core.report
import java.io.File
import java.nio.file.Paths
import com.google.common.io.Files
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
/**
* Created by pjvanthof on 24/02/16.
*/
class MultisampleReportBuilderTest extends TestNGSuite with Matchers {
private def resourcePath(p: String): String = {
Paths.get(getClass.getResource(p).toURI).toString
}
@Test
def testGeneratePages(): Unit = {
val builder = new MultisampleReportBuilder {
def reportName: String = "test"
def indexPage: ReportPage = ReportPage("Samples" -> generateSamplesPage(Map()) :: Nil, Nil, Map())
def samplePage(sampleId: String, args: Map[String, Any]): ReportPage =
ReportPage("Libraries" -> generateLibraryPage(Map("sampleId" -> Some(sampleId))) :: Nil, Nil, Map())
def libraryPage(sampleId: String, libraryId: String, args: Map[String, Any]) = ReportPage(Nil, Nil, Map())
}
val tempDir = Files.createTempDir()
tempDir.deleteOnExit()
val args = Array("-s", resourcePath("/empty_summary.json"), "-o", tempDir.getAbsolutePath)
builder.main(args)
builder.extFiles.foreach(x => new File(tempDir, "ext" + File.separator + x.targetPath) should exist)
def createFile(path: String*) = new File(tempDir, path.mkString(File.separator))
createFile("index.html") should exist
createFile("Samples", "index.html") should exist
createFile("Samples", "sampleName", "index.html") should exist
createFile("Samples", "sampleName", "Libraries", "index.html") should exist
createFile("Samples", "sampleName", "Libraries", "libName", "index.html") should exist
}
}
package nl.lumc.sasc.biopet.core.report
import java.io.File
import java.nio.file.Paths
import com.google.common.io.Files
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.{ DataProvider, Test }
/**
* Created by pjvanthof on 24/02/16.
*/
class ReportBuilderTest extends TestNGSuite with Matchers {
private def resourcePath(p: String): String = {
Paths.get(getClass.getResource(p).toURI).toString
}
@DataProvider(name = "testGeneratePages")
def generatePageProvider = {
val sample = Array(Some("sampleName"), None)
val lib = Array(Some("libName"), None)
val nested = Array(false, true)
for (s <- sample; l <- lib; n <- nested) yield Array(s, l, n)
}
@Test(dataProvider = "testGeneratePages")
def testGeneratePages(sample: Option[String], lib: Option[String], nested: Boolean): Unit = {
val builder = new ReportBuilder {
def reportName: String = "test"
def indexPage: ReportPage = ReportPage(
(if (nested) "p1" -> ReportPage(Nil, Nil, Map()) :: Nil else Nil), Nil, Map())
}
val tempDir = Files.createTempDir()
tempDir.deleteOnExit()
val args = Array("-s", resourcePath("/empty_summary.json"), "-o", tempDir.getAbsolutePath) ++
sample.map(x => Array("-a", s"sampleId=$x")).getOrElse(Array()) ++
lib.map(x => Array("-a", s"libId=$x")).getOrElse(Array())
builder.main(args)
builder.sampleId shouldBe sample
builder.libId shouldBe lib
builder.extFiles.foreach(x => new File(tempDir, "ext" + File.separator + x.targetPath) should exist)
new File(tempDir, "index.html") should exist
new File(tempDir, "p1" + File.separator + "index.html").exists() shouldBe nested
}
@Test
def testCountPages: Unit = {
ReportBuilder.countPages(ReportPage(Nil, Nil, Map())) shouldBe 1
ReportBuilder.countPages(ReportPage(
"p1" -> ReportPage(Nil, Nil, Map()) :: Nil,
Nil, Map())) shouldBe 2
ReportBuilder.countPages(ReportPage(
"p1" -> ReportPage(Nil, Nil, Map()) :: "p2" -> ReportPage(Nil, Nil, Map()) :: Nil,
Nil, Map())) shouldBe 3
ReportBuilder.countPages(ReportPage(
"p1" -> ReportPage("p1" -> ReportPage(Nil, Nil, Map()) :: Nil, Nil, Map()) :: Nil,
Nil, Map())) shouldBe 3
ReportBuilder.countPages(ReportPage(
"p1" -> ReportPage(Nil, Nil, Map()) :: "p2" -> ReportPage("p1" -> ReportPage(Nil, Nil, Map()) :: Nil, Nil, Map()) :: Nil,
Nil, Map())) shouldBe 4
}
@Test
def testRenderTemplate: Unit = {
ReportBuilder.templateCache = Map()
ReportBuilder.templateCache shouldBe empty
ReportBuilder.renderTemplate("/template.ssp", Map("arg" -> "test")) shouldBe "test"
ReportBuilder.templateCache.size shouldBe 1
ReportBuilder.renderTemplate("/template.ssp", Map("arg" -> "bla")) shouldBe "bla"
ReportBuilder.templateCache.size shouldBe 1
}
}
package nl.lumc.sasc.biopet.core.report
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
/**
* Created by pjvanthof on 24/02/16.
*/
class ReportSectionTest extends TestNGSuite with Matchers {
@Test
def testSectionRender: Unit = {
ReportSection("/template.ssp", Map("arg" -> "test")).render() shouldBe "test"
ReportSection("/template.ssp").render(Map("arg" -> "test")) shouldBe "test"
}
}
Supports Markdown
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