Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,8 @@ case class FileParsingSignalEndTree( ...@@ -55,6 +55,8 @@ case class FileParsingSignalEndTree(
sealed trait FileParsingResult extends FileParsingResultSignal { sealed trait FileParsingResult extends FileParsingResultSignal {
val result: ParseResult val result: ParseResult
val task: FileParsingTask val task: FileParsingTask
val start: Option[StartedParsingSession]
val end: Option[FinishedParsingSession]
val treeTask: FileTreeScanTask = task.treeTask val treeTask: FileTreeScanTask = task.treeTask
} }
......
...@@ -12,10 +12,10 @@ import org.mockito.ArgumentMatchers.{ eq => raw, _ } ...@@ -12,10 +12,10 @@ import org.mockito.ArgumentMatchers.{ eq => raw, _ }
import org.mockito.Mockito._ import org.mockito.Mockito._
import org.mockito.invocation.InvocationOnMock import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer import org.mockito.stubbing.Answer
import org.scalatest.WordSpec import org.scalatest.{ Matchers, WordSpec }
import org.scalatest.mockito.MockitoSugar 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( val parserInfo: JObject = JObject(
"name" -> JString("dummyParser") "name" -> JString("dummyParser")
...@@ -80,42 +80,33 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestD ...@@ -80,42 +80,33 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestD
val f = new Fixture val f = new Fixture
f.prepareParserStandardInvocation() f.prepareParserStandardInvocation()
val result = f.worker.processRequest(sampleParseRequest, unusedPath) val result = f.worker.processRequest(sampleParseRequest, unusedPath)
assert(result.isInstanceOf[InMemoryResult], "results should have been kept in memory") assert(result.start.nonEmpty, "expected a start event to be emitted")
val inMemory = result.asInstanceOf[InMemoryResult] assert(result.end.nonEmpty, "expected a finish event to be emitted")
assert(inMemory.start.nonEmpty, "expected a start event to be emitted")
assert(inMemory.end.nonEmpty, "expected a finish event to be emitted")
} }
"record all emitted events in the correct order" in { "record all emitted events in the correct order" in {
val f = new Fixture val f = new Fixture
f.prepareParserStandardInvocation() f.prepareParserStandardInvocation()
val result = f.worker.processRequest(sampleParseRequest, unusedPath) val result = f.worker.processRequest(sampleParseRequest, unusedPath)
assert(result.isInstanceOf[InMemoryResult], "results should have been kept in memory") result should have(events(sampleEvents))
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")
} }
"handle parsing failures and return an appropriate result" in { "handle parsing failures and return an appropriate result" in {
val f = new Fixture val f = new Fixture
f.prepareParserFailureInvocation() f.prepareParserFailureInvocation()
val result = f.worker.processRequest(sampleParseRequest, unusedPath) val result = f.worker.processRequest(sampleParseRequest, unusedPath)
assert(result.isInstanceOf[InMemoryResult], "results should have been kept in memory") result should have(status(ParseResult.ParseFailure))
val inMemory = result.asInstanceOf[InMemoryResult] assert(result.end.nonEmpty, "should have a termination event")
assert(inMemory.result == ParseResult.ParseFailure) assert(result.end.get.parserErrors.children.nonEmpty, "should have error messages")
assert(inMemory.end.nonEmpty, "should have a termination event")
assert(inMemory.end.get.parserErrors.children.nonEmpty, "should have error messages")
} }
"gracefully fail parsing requests with unknown parsers" in { "gracefully fail parsing requests with unknown parsers" in {
val f = new Fixture val f = new Fixture
val anotherRequest = sampleParseRequest.withParserName("nonSenseParser") val anotherRequest = sampleParseRequest.withParserName("nonSenseParser")
val result = f.worker.processRequest(anotherRequest, unusedPath) val result = f.worker.processRequest(anotherRequest, unusedPath)
assert(result.isInstanceOf[InMemoryResult], "results should have been kept in memory") result should have(status(ParseResult.ParseFailure))
val inMemory = result.asInstanceOf[InMemoryResult] assert(result.end.nonEmpty, "should have a termination event")
assert(inMemory.result == ParseResult.ParseFailure, "should have a failed status") assert(result.end.get.parserErrors.children.nonEmpty, "should have error messages")
assert(inMemory.end.nonEmpty, "should have a termination event")
assert(inMemory.end.get.parserErrors.children.nonEmpty, "should have error messages")
} }
"specify the correct main file to the parser" in { "specify the correct main file to the parser" in {
......
...@@ -4,6 +4,7 @@ import java.nio.file.{ Path, Paths } ...@@ -4,6 +4,7 @@ import java.nio.file.{ Path, Paths }
import eu.nomad_lab.integrated_pipeline.messages._ import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.parsers.ParseResult.ParseResult import eu.nomad_lab.parsers.ParseResult.ParseResult
import eu.nomad_lab.parsers.{ FinishedParsingSession, ParseEvent, StartedParsingSession }
import org.scalatest.matchers.{ HavePropertyMatchResult, HavePropertyMatcher } import org.scalatest.matchers.{ HavePropertyMatchResult, HavePropertyMatcher }
trait MessageMatchers trait MessageMatchers
...@@ -104,4 +105,28 @@ trait FileParsingResultMatchers { ...@@ -104,4 +105,28 @@ trait FileParsingResultMatchers {
expected = expectedValue, expected = expectedValue,
test = (x: FileParsingSignalEndTree) => x.numParsingTasks 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment