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

Integrated Pipeline: further rework of the CalculationParsingEngine tests to...

Integrated Pipeline: further rework of the CalculationParsingEngine tests to make them more flexible
parent b4fd9381
......@@ -55,6 +55,8 @@ case class FileParsingSignalEndTree(
sealed trait FileParsingResult extends FileParsingResultSignal {
val result: ParseResult
val task: FileParsingTask
val start: Option[StartedParsingSession]
val end: Option[FinishedParsingSession]
val treeTask: FileTreeScanTask = task.treeTask
}
......
......@@ -12,10 +12,10 @@ import org.mockito.ArgumentMatchers.{ eq => raw, _ }
import org.mockito.Mockito._
import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer
import org.scalatest.WordSpec
import org.scalatest.{ Matchers, WordSpec }
import org.scalatest.mockito.MockitoSugar
class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestDataBuilders with MessageMatchers {
class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestDataBuilders with Matchers with FileParsingResultMatchers {
val parserInfo: JObject = JObject(
"name" -> JString("dummyParser")
......@@ -80,42 +80,33 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestD
val f = new Fixture
f.prepareParserStandardInvocation()
val result = f.worker.processRequest(sampleParseRequest, unusedPath)
assert(result.isInstanceOf[InMemoryResult], "results should have been kept in memory")
val inMemory = result.asInstanceOf[InMemoryResult]
assert(inMemory.start.nonEmpty, "expected a start event to be emitted")
assert(inMemory.end.nonEmpty, "expected a finish event to be emitted")
assert(result.start.nonEmpty, "expected a start event to be emitted")
assert(result.end.nonEmpty, "expected a finish event to be emitted")
}
"record all emitted events in the correct order" in {
val f = new Fixture
f.prepareParserStandardInvocation()
val result = f.worker.processRequest(sampleParseRequest, unusedPath)
assert(result.isInstanceOf[InMemoryResult], "results should have been kept in memory")
val inMemory = result.asInstanceOf[InMemoryResult]
inMemory.events.zip(sampleEvents).foreach(x => assert(x._1 == x._2))
assert(inMemory.events === sampleEvents, "emitted and recorded events do not match")
result should have(events(sampleEvents))
}
"handle parsing failures and return an appropriate result" in {
val f = new Fixture
f.prepareParserFailureInvocation()
val result = f.worker.processRequest(sampleParseRequest, unusedPath)
assert(result.isInstanceOf[InMemoryResult], "results should have been kept in memory")
val inMemory = result.asInstanceOf[InMemoryResult]
assert(inMemory.result == ParseResult.ParseFailure)
assert(inMemory.end.nonEmpty, "should have a termination event")
assert(inMemory.end.get.parserErrors.children.nonEmpty, "should have error messages")
result should have(status(ParseResult.ParseFailure))
assert(result.end.nonEmpty, "should have a termination event")
assert(result.end.get.parserErrors.children.nonEmpty, "should have error messages")
}
"gracefully fail parsing requests with unknown parsers" in {
val f = new Fixture
val anotherRequest = sampleParseRequest.withParserName("nonSenseParser")
val result = f.worker.processRequest(anotherRequest, unusedPath)
assert(result.isInstanceOf[InMemoryResult], "results should have been kept in memory")
val inMemory = result.asInstanceOf[InMemoryResult]
assert(inMemory.result == ParseResult.ParseFailure, "should have a failed status")
assert(inMemory.end.nonEmpty, "should have a termination event")
assert(inMemory.end.get.parserErrors.children.nonEmpty, "should have error messages")
result should have(status(ParseResult.ParseFailure))
assert(result.end.nonEmpty, "should have a termination event")
assert(result.end.get.parserErrors.children.nonEmpty, "should have error messages")
}
"specify the correct main file to the parser" in {
......
......@@ -4,6 +4,7 @@ import java.nio.file.{ Path, Paths }
import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.parsers.ParseResult.ParseResult
import eu.nomad_lab.parsers.{ FinishedParsingSession, ParseEvent, StartedParsingSession }
import org.scalatest.matchers.{ HavePropertyMatchResult, HavePropertyMatcher }
trait MessageMatchers
......@@ -104,4 +105,28 @@ trait FileParsingResultMatchers {
expected = expectedValue,
test = (x: FileParsingSignalEndTree) => x.numParsingTasks
)
def startSignal(expectedValue: Option[StartedParsingSession]): HavePropertyMatcher[FileParsingResult, Option[StartedParsingSession]] =
Helpers.propertyMatcher(
propertyName = "session start signal",
expected = expectedValue,
test = (x: FileParsingResult) => x.start
)
def endSignal(expectedValue: Option[FinishedParsingSession]): HavePropertyMatcher[FileParsingResult, Option[FinishedParsingSession]] =
Helpers.propertyMatcher(
propertyName = "session end signal",
expected = expectedValue,
test = (x: FileParsingResult) => x.end
)
def events(expectedValue: Seq[ParseEvent]): HavePropertyMatcher[FileParsingResult, Seq[ParseEvent]] =
Helpers.propertyMatcher(
propertyName = "emitted parsing events",
expected = expectedValue,
test = (x: FileParsingResult) => x match {
case x: InMemoryResult => x.events
}
)
}
\ No newline at end of file
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