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

Integrated Pipeline: PropertyMatchers are now objects imported at the unit-test scope

-trait-import on the suite level was causing name clashes between message and event matchers
parent e06c857d
......@@ -75,7 +75,8 @@ class ArchiveUnpackingFlowSpec extends WordSpec with MockitoSugar with TestDataB
verify(f.archiveHandler).extractZipArchive(Paths.get("/foo"))
}
"add the temporary extracted file path to file parsing tasks" in new FileParsingTaskMatchers {
"add the temporary extracted file path to file parsing tasks" in {
import FileParsingTaskMatchers._
val f = new ZipArchiveTreeFixture()
val task = aFileParsingTask().withTreeTask(f.treeTask).withRelativePath("foo")
f.source.sendNext(task)
......
......@@ -16,7 +16,7 @@ import org.mockito.stubbing.Answer
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{ Matchers, WordSpec }
class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestDataBuilders with Matchers with FileParsingResultMatchers {
class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestDataBuilders with Matchers {
val parserInfo: JObject = JObject(
"name" -> JString("dummyParser")
......@@ -85,6 +85,7 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestD
}
"record all emitted events in the correct order" in {
import FileParsingResultMatchers._
val f = new Fixture
f.prepareParserStandardInvocation()
val result = f.worker.processSignal(sampleParseRequest).asInstanceOf[FileParsingResult]
......@@ -92,6 +93,7 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestD
}
"handle parsing failures and return an appropriate result" in {
import FileParsingResultMatchers._
val f = new Fixture
f.prepareParserFailureInvocation()
val result = f.worker.processSignal(sampleParseRequest).asInstanceOf[FileParsingResult]
......@@ -99,6 +101,7 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestD
}
"gracefully fail parsing requests with unknown parsers" in {
import FileParsingResultMatchers._
val f = new Fixture
val anotherRequest = sampleParseRequest.withParserName("nonSenseParser")
val result = f.worker.processSignal(anotherRequest).asInstanceOf[FileParsingResult]
......@@ -124,6 +127,7 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestD
}
"gracefully fail parsing tasks from zip archives without extracted file path" in {
import FileParsingResultMatchers._
val f = new Fixture
val treeTask = aFileTreeScanTask().withTreeType(TreeType.Zip)
val task = sampleParseRequest.withTreeTask(treeTask)
......@@ -132,6 +136,7 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar with TestD
}
"gracefully fail parsing requests with unknown or not supported file tree types" in {
import FileParsingResultMatchers._
val f = new Fixture
Seq(TreeType.Unknown, TreeType.File, TreeType.Tar).foreach { treeType =>
val treeTask = aFileTreeScanTask().withTreeType(treeType)
......
......@@ -18,7 +18,7 @@ import org.mockito.stubbing.Answer
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{ Matchers, WordSpec }
class CalculationParsingFlowSpec extends WordSpec with MockitoSugar with TestDataBuilders with Matchers with FileParsingResultMatchers {
class CalculationParsingFlowSpec extends WordSpec with MockitoSugar with TestDataBuilders with Matchers {
val sampleTreeScan = FileTreeScanTask(
treeBasePath = Paths.get("/foo/bar"),
......@@ -67,6 +67,7 @@ class CalculationParsingFlowSpec extends WordSpec with MockitoSugar with TestDat
"managing a single worker" should {
"emit parsing results for every incoming parsing request in order of input" in {
import FileParsingResultMatchers._
val f = new Fixture(1)
f.source.sendNext(f.input1).sendNext(f.input2).sendNext(f.input3)
f.findMatchingStreamElementsOrdered(Seq(
......
......@@ -6,7 +6,7 @@ import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.parsers.ParseResult.ParseResult
import org.scalatest.matchers.HavePropertyMatcher
trait TreeParserEventMatchers {
object TreeParserEventMatchers {
def basePath(expectedValue: Path): HavePropertyMatcher[TreeParserEvent, Path] =
MatcherHelpers.propertyMatcher(
......@@ -44,7 +44,7 @@ trait TreeParserEventMatchers {
}
trait CalculationParserEventMatchers {
object CalculationParserEventMatchers {
def basePath(expectedValue: Path): HavePropertyMatcher[CalculationParserEvent, Path] =
MatcherHelpers.propertyMatcher(
......
......@@ -9,7 +9,7 @@ import eu.nomad_lab.parsers.ParseResult.ParseResult
import eu.nomad_lab.parsers.{ FinishedParsingSession, ParseEvent, StartedParsingSession }
import org.scalatest.matchers.{ HavePropertyMatchResult, HavePropertyMatcher }
trait FileTreeTaskMatchers {
object FileTreeTaskMatchers {
def basePath(expectedValue: Path): HavePropertyMatcher[FileTreeScanTask, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "tree base path",
......@@ -18,7 +18,7 @@ trait FileTreeTaskMatchers {
)
}
trait FileParsingTaskMatchers {
object FileParsingTaskMatchers {
def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileParsingTaskSignal, FileTreeScanTask] =
MatcherHelpers.propertyMatcher(
propertyName = "parent tree task",
......@@ -57,7 +57,7 @@ trait FileParsingTaskMatchers {
}
trait FileParsingResultMatchers {
object FileParsingResultMatchers {
def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileParsingResultSignal, FileTreeScanTask] =
MatcherHelpers.propertyMatcher(
......@@ -123,7 +123,7 @@ trait FileParsingResultMatchers {
}
trait FileTreeParsingResultMatchers {
object FileTreeParsingResultMatchers {
def treeTask(expectedValue: FileTreeScanTask): HavePropertyMatcher[FileTreeParsingResult, FileTreeScanTask] =
MatcherHelpers.propertyMatcher(
......
......@@ -13,8 +13,7 @@ import org.scalatest.{ Matchers, WordSpec }
import scala.collection.JavaConverters._
class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar with TestDataBuilders
with Matchers with FileTreeParsingResultMatchers
with MessageProcessorBehaviour[FileParsingResultSignal, FileTreeParsingResult] {
with Matchers with MessageProcessorBehaviour[FileParsingResultSignal, FileTreeParsingResult] {
private class Fixture {
......@@ -87,7 +86,10 @@ class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar wit
behave like processorWithOutboundSignalReady(
twoResultsEndWithTwoEntriesReceived(mock[ParsingResultsProcessor]),
Seq(anInMemoryResult(), aFileParsingSignalEndTree()),
have(numParsingTasks(2), treeTask(aFileTreeScanTask()))
have(
FileTreeParsingResultMatchers.numParsingTasks(2),
FileTreeParsingResultMatchers.treeTask(aFileTreeScanTask())
)
)
}
......@@ -173,6 +175,7 @@ class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar wit
}
"send a result for each tree once all associated file parsing results are processed" in {
import FileTreeParsingResultMatchers._
val f = new Fixture
val treeTask1 = aFileTreeScanTask().withBasePath("/path1")
val treeTask2 = aFileTreeScanTask().withBasePath("/path2")
......
......@@ -7,7 +7,6 @@ import org.scalatest.WordSpec
import org.scalatest.mockito.MockitoSugar
import org.mockito.Mockito._
import org.mockito.ArgumentMatchers._
import org.mockito.ArgumentMatchers.{ eq => raw }
import scala.collection.JavaConverters._
......@@ -25,9 +24,6 @@ class TreeParserSpec extends WordSpec
private def argsCaptor(): ArgumentCaptor[TreeParserEvent] = ArgumentCaptor.forClass(classOf[TreeParserEvent])
private val eventsMatcher = new TreeParserEventMatchers {}
private val taskMatchers = new FileParsingTaskMatchers {}
private val sampleTreeTask = aFileTreeScanTask().withBasePath("/foo").build()
def fixture(): (TreeParser, EventListener) = {
......@@ -82,7 +78,7 @@ class TreeParserSpec extends WordSpec
}
"notify the provided EventListener when receiving a new file tree scan task" in {
import eventsMatcher._
import TreeParserEventMatchers._
val (f, test) = noTaskReceived()
f.processSignal(sampleTreeTask)
val captor = argsCaptor()
......@@ -95,11 +91,11 @@ class TreeParserSpec extends WordSpec
behave like processorWithOutboundSignalReady(
() => taskReceivedNoSignalsFetched()._1,
Seq(aFileTreeScanTask()),
be(a[FileParsingTask]) and have(taskMatchers.relativePath("file1"))
be(a[FileParsingTask]) and have(FileParsingTaskMatchers.relativePath("file1"))
)
"emit parse requests for all potential calculations in the file tree" in {
import taskMatchers._
import FileParsingTaskMatchers._
val (f, _) = taskReceivedNoSignalsFetched()
val signals = (1 to 3).map { _ => f.getNextSignalToEmit() }.collect { case x: FileParsingTask => x }
signals should have length 3
......@@ -109,7 +105,7 @@ class TreeParserSpec extends WordSpec
}
"notify the provided EventListener for each emitted candidate calculation" in {
import eventsMatcher._
import TreeParserEventMatchers._
val (f, test) = taskReceivedNoSignalsFetched()
(1 to 3).foreach { _ => f.getNextSignalToEmit() }
val captor = argsCaptor()
......@@ -126,7 +122,7 @@ class TreeParserSpec extends WordSpec
behave like processorWithOutboundSignalReady(
() => oneParsingTaskLeftToEmit()._1,
Seq(aFileTreeScanTask()),
be(a[FileParsingTask]) and have(taskMatchers.relativePath("file3"))
be(a[FileParsingTask]) and have(FileParsingTaskMatchers.relativePath("file3"))
)
}
......@@ -134,11 +130,11 @@ class TreeParserSpec extends WordSpec
behave like processorWithOutboundSignalReady(
() => allParsingTasksFetched()._1,
Seq(aFileTreeScanTask()),
be(a[FileParsingSignalEndTree]) and have(taskMatchers.numParsingTasks(3))
be(a[FileParsingSignalEndTree]) and have(FileParsingTaskMatchers.numParsingTasks(3))
)
"emit an end tree signal with the correct number of entries" in {
import taskMatchers._
import FileParsingTaskMatchers._
val (f, _) = allParsingTasksFetched()
val result = f.getNextSignalToEmit()
result should be(a[FileParsingSignalEndTree])
......@@ -146,7 +142,7 @@ class TreeParserSpec extends WordSpec
}
"notify the provided EventListener when emitting the end tree signal" in {
import eventsMatcher._
import TreeParserEventMatchers._
val (f, test) = allParsingTasksFetched()
f.getNextSignalToEmit()
val captor = argsCaptor()
......
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