Skip to content

Commit

Permalink
removed lagacy test modules of cli. #39
Browse files Browse the repository at this point in the history
  • Loading branch information
stormcat24 committed Feb 8, 2015
1 parent 8aceda9 commit c647d9a
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 882 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package jp.co.cyberagent.aeromock.cli.job

import java.io.FileWriter
import java.nio.file.{Files, Path}
import java.nio.file.Files

import jp.co.cyberagent.aeromock.AeromockBadUsingException
import jp.co.cyberagent.aeromock.cli.option.JobOperation
import jp.co.cyberagent.aeromock.cli.report.junit.TestsuiteFactory
import jp.co.cyberagent.aeromock.cli.{CliJob, Job}
import jp.co.cyberagent.aeromock.config.Project
import jp.co.cyberagent.aeromock.core.http.Endpoint
import jp.co.cyberagent.aeromock.helper._
import jp.co.cyberagent.aeromock.template.{DataAsserts, PageValidation, TemplateContexts, TemplateService}
import jp.co.cyberagent.aeromock.util.ResourceUtil
import jp.co.cyberagent.aeromock.template.TemplateService
import scaldi.Injector

import scala.reflect.io.Directory
Expand Down Expand Up @@ -39,103 +34,14 @@ class ViewCheckJob(override val command: JobOperation)(implicit inj: Injector) e
dir.deleteRecursively()
Files.createDirectories(reportRoot)

val testsuiteFactory = new TestsuiteFactory

/**
* @inheritdoc
*/
override def execute(): Int = {

import jp.co.cyberagent.aeromock.template.AssertionResultType._

val contexts = TemplateContexts.getAllContexts(project)
val result = contexts.flatMap(context => validateDirectory(context.root, context.domain))
val resultGroup = result.groupBy(_.getAssertionResultType())

println( s"""
|****************************
|* Success Tests as follows *
|****************************
""".stripMargin)
resultGroup.get(SUCCESS) match {
case Some(tests) => tests.foreach(test => println(s"[${test.templateResult}] ${test.templatePath}"))
case None => println("Nothing")
}

println( s"""
|****************************
|* Test has problem as follows *
|****************************
""".stripMargin)

result.filter(_.getAssertionResultType() != SUCCESS).foreach { test =>
println(s" Template:[${test.templateResult}] ${test.templatePath}")
test match {
case PageValidation(templatePath, templateResult, Some(DataAsserts(_, failures, errors))) => {

errors.foreach { error =>
println(s"""| [${error}] ${error.dataPath}
| Detail:
| ${error.message}
|""".stripMargin)
}

failures.foreach { failure =>
println(s"""| [${failure}] ${failure.dataPath}
| Detail:
| ${failure.message}
|""".stripMargin)
}
}
case _ =>
}
}


val summary = result.foldLeft((0, 0, 0, 0))((l, r) => {
// _1: total, _2: success, _3: error, _4: failure
(l._1 + r.totalTests, l._2 + r.totalSuccesses, l._3 + r.totalErrors, l._4 + r.totalFailures)
})

println( s"""
|****************************
|* Test Result Summary *
|****************************
| Total: ${summary._1}
| ${green("Success")}: ${summary._2}
| ${red("Error")}: ${summary._3}
| ${blue("Failure")}: ${summary._4}
""".stripMargin)

0
}

val XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
val defaultNamespaces = scalaxb.toScope(Array.empty[(Option[String], String)]: _*)
val xmlPrinter = new scala.xml.PrettyPrinter(200, 4)

private def validateDirectory(directory: Path, domain: String): List[PageValidation] = {
import scalaxb._

directory.getChildren().flatMap {
case d if d.isDirectory() => validateDirectory(d, domain)
case path => {
val relativePath = path.getRelativePath(template.root)
log.info(s"Testing ${relativePath.toString}")
val endpoint = Endpoint(relativePath.withoutExtension().toString)
List(service.validateData(endpoint, domain) { pageValidation =>

val xmlFile = reportRoot / s"TEST${endpoint.raw.replace("/", "__")}.xml"
val testsuite = testsuiteFactory.create(pageValidation)
val xml = toXML(testsuite, None, "testsuite", defaultNamespaces)

ResourceUtil.processResrouce(new FileWriter(xmlFile.toFile)) { writer =>
writer.write(XML_DECLARATION + xmlPrinter.format(xml(0)))
}

})
}
}
}

}

This file was deleted.

This file was deleted.

Loading

0 comments on commit c647d9a

Please sign in to comment.