Commit d0413d5d authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

Integrated Pipeline: renamed TreeParserProcessEvent to TreeParserEvent, moved...

Integrated Pipeline: renamed TreeParserProcessEvent to TreeParserEvent, moved matcher construction helpers to a separate object
parent 072a9c78
package eu.nomad_lab.integrated_pipeline
import eu.nomad_lab.integrated_pipeline.messages.{ CalculationParserProcessEvent, ResultWriterProcessEvent, TreeParserProcessEvent }
import eu.nomad_lab.integrated_pipeline.messages.{ CalculationParserProcessEvent, ResultWriterProcessEvent, TreeParserEvent }
import scala.collection.parallel.mutable
......@@ -56,7 +56,7 @@ trait EventListener {
registeredResultWriters.get(reference)
}
def processEvent(reporter: TreeParserId, message: TreeParserProcessEvent): Unit = {}
def processEvent(reporter: TreeParserId, message: TreeParserEvent): Unit = {}
def processEvent(reporter: CalculationParserId, message: CalculationParserProcessEvent): Unit = {}
......
......@@ -4,7 +4,7 @@ import eu.nomad_lab.integrated_pipeline.messages._
trait EventLogger extends EventListener with StrictLogging {
override def processEvent(reporter: TreeParserId, message: TreeParserProcessEvent): Unit = {
override def processEvent(reporter: TreeParserId, message: TreeParserEvent): Unit = {
message match {
case x: TreeParserEventStart => logger.info(
s"[TreeParser $reporter] start processing file tree " +
......
......@@ -2,22 +2,22 @@ package eu.nomad_lab.integrated_pipeline.messages
import java.nio.file.Path
sealed trait TreeParserProcessEvent
sealed trait TreeParserEvent
case class TreeParserEventStart(
treeTask: FileTreeScanTask
) extends TreeParserProcessEvent
) extends TreeParserEvent
case class TreeParserEventCandidate(
treeTask: FileTreeScanTask,
relativePath: Path,
parser: String
) extends TreeParserProcessEvent
) extends TreeParserEvent
case class TreeParserEventEnd(
treeTask: FileTreeScanTask,
numCandidates: Long
) extends TreeParserProcessEvent
) extends TreeParserEvent
sealed trait CalculationParserProcessEvent
......
package eu.nomad_lab.integrated_pipeline_tests
import eu.nomad_lab.integrated_pipeline.messages.{ CalculationParserProcessEvent, ResultWriterProcessEvent, TreeParserProcessEvent }
import eu.nomad_lab.integrated_pipeline.messages.{ CalculationParserProcessEvent, ResultWriterProcessEvent, TreeParserEvent }
import eu.nomad_lab.integrated_pipeline.{ CalculationParsingEngine, EventListener, ParsingResultsProcessingManager, TreeParser }
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{ Matchers, WordSpec }
......@@ -8,7 +8,7 @@ import org.scalatest.{ Matchers, WordSpec }
trait EventListenerBehaviour extends Matchers with MockitoSugar with TestDataBuilders { this: WordSpec =>
//FIXME: add events
private val sampleTreeParserEvents: Seq[TreeParserProcessEvent] = Seq(
private val sampleTreeParserEvents: Seq[TreeParserEvent] = Seq(
aTreeParserEventStart(),
aTreeParserEventCandidate(),
aTreeParserEventEnd()
......
package eu.nomad_lab.integrated_pipeline_tests
import org.scalatest.matchers.{ HavePropertyMatchResult, HavePropertyMatcher }
object MatcherHelpers {
def propertyMatcher[T, E](propertyName: String, expected: E, test: T => E): HavePropertyMatcher[T, E] = {
new HavePropertyMatcher[T, E] {
def apply(element: T): HavePropertyMatchResult[E] = {
val actual = test(element)
HavePropertyMatchResult(actual == expected, propertyName, expected, actual)
}
override def toString(): String = s"$propertyName '$expected'"
}
}
def subStringPropertyMatcher[T](propertyName: String, expected: Seq[String],
test: T => String, display: T => String, ignoreCase: Boolean = true): HavePropertyMatcher[T, String] = {
new HavePropertyMatcher[T, String] {
def apply(element: T): HavePropertyMatchResult[String] = {
val message = if (ignoreCase) test(element).toLowerCase else test(element)
HavePropertyMatchResult(
matches = expected.forall(test => message.contains(
if (ignoreCase) test.toLowerCase else test
)),
propertyName = "error message content",
expectedValue = expected.mkString("all of '", "', '", "'"),
actualValue = display(element)
)
}
override def toString(): String = s"$propertyName '${expected.mkString("all of '", "', '", "'")}'"
}
}
}
......@@ -9,45 +9,9 @@ import eu.nomad_lab.parsers.ParseResult.ParseResult
import eu.nomad_lab.parsers.{ FinishedParsingSession, ParseEvent, StartedParsingSession }
import org.scalatest.matchers.{ HavePropertyMatchResult, HavePropertyMatcher }
trait MessageMatchers
extends FileTreeTaskMatchers
with FileParsingTaskMatchers
object MessageMatchers extends MessageMatchers
private object Helpers {
def propertyMatcher[T, E](propertyName: String, expected: E, test: T => E): HavePropertyMatcher[T, E] = {
new HavePropertyMatcher[T, E] {
def apply(element: T): HavePropertyMatchResult[E] = {
val actual = test(element)
HavePropertyMatchResult(actual == expected, propertyName, expected, actual)
}
override def toString(): String = s"$propertyName '$expected'"
}
}
def subStringPropertyMatcher[T](propertyName: String, expected: Seq[String],
test: T => String, display: T => String, ignoreCase: Boolean = true): HavePropertyMatcher[T, String] = {
new HavePropertyMatcher[T, String] {
def apply(element: T): HavePropertyMatchResult[String] = {
val message = if (ignoreCase) test(element).toLowerCase else test(element)
HavePropertyMatchResult(
matches = expected.forall(test => message.contains(
if (ignoreCase) test.toLowerCase else test
)),
propertyName = "error message content",
expectedValue = expected.mkString("all of '", "', '", "'"),
actualValue = display(element)
)
}
override def toString(): String = s"$propertyName '${expected.mkString("all of '", "', '", "'")}'"
}
}
}
trait FileTreeTaskMatchers {
def basePath(expectedValue: Path): HavePropertyMatcher[FileTreeScanTask, Path] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "tree base path",
expected = expectedValue,
test = (x: FileTreeScanTask) => x.treeBasePath
......@@ -56,14 +20,14 @@ trait FileTreeTaskMatchers {
trait FileParsingTaskMatchers {
def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileParsingTaskSignal, FileTreeScanTask] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "parent tree task",
expected = expectedValue,
test = (x: FileParsingTaskSignal) => x.treeTask
)
def relativePath(expectedValue: Path): HavePropertyMatcher[FileParsingTask, Path] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: FileParsingTask) => x.relativePath
......@@ -74,7 +38,7 @@ trait FileParsingTaskMatchers {
}
def extractedPath(expectedValue: Option[Path]): HavePropertyMatcher[FileParsingTask, Option[Path]] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "temporary extracted file path",
expected = expectedValue,
test = (x: FileParsingTask) => x.extractedPath
......@@ -85,7 +49,7 @@ trait FileParsingTaskMatchers {
}
def numParsingTasks(expectedValue: Long): HavePropertyMatcher[FileParsingSignalEndTree, Long] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "number of identified candidate calculations",
expected = expectedValue,
test = (x: FileParsingSignalEndTree) => x.numParsingTasks
......@@ -96,21 +60,21 @@ trait FileParsingTaskMatchers {
trait FileParsingResultMatchers {
def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileParsingResultSignal, FileTreeScanTask] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "parent tree task",
expected = expectedValue,
test = (x: FileParsingResultSignal) => x.treeTask
)
def status(expectedValue: ParseResult): HavePropertyMatcher[FileParsingResult, ParseResult] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "parsing result status",
expected = expectedValue,
test = (x: FileParsingResult) => x.result
)
def relativePath(expectedValue: Path): HavePropertyMatcher[FileParsingResult, Path] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: FileParsingResult) => x.task.relativePath
......@@ -120,28 +84,28 @@ trait FileParsingResultMatchers {
relativePath(Paths.get(expectedValue))
def numParsingTasks(expectedValue: Long): HavePropertyMatcher[FileParsingSignalEndTree, Long] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "number of identified candidate calculations",
expected = expectedValue,
test = (x: FileParsingSignalEndTree) => x.numParsingTasks
)
def startSignal(expectedValue: Option[StartedParsingSession]): HavePropertyMatcher[FileParsingResult, Option[StartedParsingSession]] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "session start signal",
expected = expectedValue,
test = (x: FileParsingResult) => x.start
)
def endSignal(expectedValue: Option[FinishedParsingSession]): HavePropertyMatcher[FileParsingResult, Option[FinishedParsingSession]] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "session end signal",
expected = expectedValue,
test = (x: FileParsingResult) => x.end
)
def events(expectedValue: Seq[ParseEvent]): HavePropertyMatcher[FileParsingResult, Seq[ParseEvent]] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "emitted parsing events",
expected = expectedValue,
test = (x: FileParsingResult) => x match {
......@@ -150,7 +114,7 @@ trait FileParsingResultMatchers {
)
def errorMessage(first: String, other: String*): HavePropertyMatcher[FileParsingResult, String] =
Helpers.subStringPropertyMatcher(
MatcherHelpers.subStringPropertyMatcher(
propertyName = "error message content",
expected = first +: other,
test = (x: FileParsingResult) => x.error.getOrElse(""),
......@@ -162,14 +126,14 @@ trait FileParsingResultMatchers {
trait FileTreeParsingResultMatchers {
def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileTreeParsingResult, FileTreeScanTask] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "origin tree task",
expected = expectedValue,
test = (x: FileTreeParsingResult) => x.treeScanTask
)
def basePath(expectedValue: Path): HavePropertyMatcher[FileTreeParsingResult, Path] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "tree base path",
expected = expectedValue,
test = (x: FileTreeParsingResult) => x.treeScanTask.treeBasePath
......@@ -179,28 +143,28 @@ trait FileTreeParsingResultMatchers {
basePath(Paths.get(expectedValue))
def treeType(expectedValue: TreeType): HavePropertyMatcher[FileTreeParsingResult, TreeType] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "file tree type",
expected = expectedValue,
test = (x: FileTreeParsingResult) => x.treeScanTask.treeType
)
def numParsingTasks(expectedValue: Long): HavePropertyMatcher[FileTreeParsingResult, Long] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "number of processed calculations",
expected = expectedValue,
test = (x: FileTreeParsingResult) => x.numCalculationsFound
)
def numFailedTasks(expectedValue: Long): HavePropertyMatcher[FileTreeParsingResult, Long] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "number of failed calculations",
expected = expectedValue,
test = (x: FileTreeParsingResult) => x.numParsingFailures
)
def outputPath(expectedValue: Path): HavePropertyMatcher[FileTreeParsingResult, Path] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "output location",
expected = expectedValue,
test = (x: FileTreeParsingResult) => x.outputLocation
......@@ -210,7 +174,7 @@ trait FileTreeParsingResultMatchers {
basePath(Paths.get(expectedValue))
def outputType(expectedValue: OutputType): HavePropertyMatcher[FileTreeParsingResult, OutputType] =
Helpers.propertyMatcher(
MatcherHelpers.propertyMatcher(
propertyName = "output format",
expected = expectedValue,
test = (x: FileTreeParsingResult) => x.outputFormat
......
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