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

Integrated Pipeline: removed remaining references to FileTreeScanTask class in test code

parent 4bd38cf6
......@@ -37,11 +37,11 @@ class ArchiveUnpackingFlowSpec extends WordSpec with MockitoSugar with TestDataB
}
class DirectoryTreeFixture extends Fixture {
val treeTask = aFileTree().withTreeType(TreeType.Directory).build()
val fileTree = aFileTree().withTreeType(TreeType.Directory).build()
}
class ZipArchiveTreeFixture extends Fixture {
val treeTask = aFileTree().withTreeType(TreeType.Zip).build()
val fileTree = aFileTree().withTreeType(TreeType.Zip).build()
when(archiveHandler.extractZipArchive(any())).thenReturn(Paths.get("/magic"))
}
......@@ -50,7 +50,7 @@ class ArchiveUnpackingFlowSpec extends WordSpec with MockitoSugar with TestDataB
"forward file parsing tasks unchanged" in {
val f = new DirectoryTreeFixture
val task = aFileParsingTask().withFileTree(f.treeTask).build()
val task = aFileParsingTask().withFileTree(f.fileTree).build()
f.source.sendNext(task)
f.findFirstMatchingStreamElement(be(task))
verifyZeroInteractions(f.archiveHandler)
......@@ -58,8 +58,8 @@ class ArchiveUnpackingFlowSpec extends WordSpec with MockitoSugar with TestDataB
"forward end file tree signals unchanged" in {
val f = new DirectoryTreeFixture()
f.source.sendNext(aFileParsingTask().withFileTree(f.treeTask))
val task = aFileParsingSignalEndTree().withFileTree(f.treeTask).build()
f.source.sendNext(aFileParsingTask().withFileTree(f.fileTree))
val task = aFileParsingSignalEndTree().withFileTree(f.fileTree).build()
f.source.sendNext(task)
f.findFirstMatchingStreamElement(be(task))
verifyZeroInteractions(f.archiveHandler)
......@@ -79,7 +79,7 @@ class ArchiveUnpackingFlowSpec extends WordSpec with MockitoSugar with TestDataB
"add the temporary extracted file path to file parsing tasks" in {
import FileParsingTaskMatchers._
val f = new ZipArchiveTreeFixture()
val task = aFileParsingTask().withFileTree(f.treeTask).withRelativePath("foo")
val task = aFileParsingTask().withFileTree(f.fileTree).withRelativePath("foo")
f.source.sendNext(task)
f.findFirstMatchingStreamElement(be(a[FileParsingTask]) and
have(relativePath("foo"), extractedPathString(Some("/magic/foo"))))
......@@ -87,8 +87,8 @@ class ArchiveUnpackingFlowSpec extends WordSpec with MockitoSugar with TestDataB
"forward end file tree signals unchanged" in {
val f = new ZipArchiveTreeFixture()
f.source.sendNext(aFileParsingTask().withFileTree(f.treeTask))
val task = aFileParsingSignalEndTree().withFileTree(f.treeTask).build()
f.source.sendNext(aFileParsingTask().withFileTree(f.fileTree))
val task = aFileParsingSignalEndTree().withFileTree(f.fileTree).build()
f.source.sendNext(task)
f.findFirstMatchingStreamElement(be(task))
}
......@@ -98,21 +98,21 @@ class ArchiveUnpackingFlowSpec extends WordSpec with MockitoSugar with TestDataB
"fail if file tree end signal arrive before the start tree signal" in {
val f = new DirectoryTreeFixture
f.source.sendNext(aFileParsingSignalEndTree().withFileTree(f.treeTask).build())
f.source.sendNext(aFileParsingSignalEndTree().withFileTree(f.fileTree).build())
f.expectStreamFailure(be(an[IllegalArgumentException]))
}
"fail if file parsing task arrives after the end tree signal" in {
val f = new DirectoryTreeFixture
f.source.sendNext(aFileParsingSignalEndTree().withFileTree(f.treeTask).build())
f.source.sendNext(aFileParsingTask().withFileTree(f.treeTask).build())
f.source.sendNext(aFileParsingSignalEndTree().withFileTree(f.fileTree).build())
f.source.sendNext(aFileParsingTask().withFileTree(f.fileTree).build())
f.expectStreamFailure(be(an[IllegalArgumentException]))
}
"fail if a file tree end signal arrives more than once" in {
val f = new DirectoryTreeFixture
f.source.sendNext(aFileParsingSignalEndTree().withFileTree(f.treeTask).build())
f.source.sendNext(aFileParsingSignalEndTree().withFileTree(f.treeTask).build())
f.source.sendNext(aFileParsingSignalEndTree().withFileTree(f.fileTree).build())
f.source.sendNext(aFileParsingSignalEndTree().withFileTree(f.fileTree).build())
f.expectStreamFailure(be(an[IllegalArgumentException]))
}
}
......
......@@ -148,7 +148,7 @@ class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar wit
Seq(anInMemoryResult(), aFileParsingSignalEndTree()),
have(
FileTreeParsingResultMatchers.numParsingTasks(2),
FileTreeParsingResultMatchers.treeTask(aFileTree())
FileTreeParsingResultMatchers.fileTree(aFileTree())
)
)
......@@ -269,12 +269,12 @@ class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar wit
"process a file parsing result from another file tree" in {
import FileParsingResultMatchers._
val f = createFixture()
val fileTree = aFileTree().withBasePath("/universe/magic")
f.manager.processSignal(anInMemoryResult().withFileTree(fileTree).withRelativePath("bar"))
val myFileTree = aFileTree().withBasePath("/universe/magic")
f.manager.processSignal(anInMemoryResult().withFileTree(myFileTree).withRelativePath("bar"))
val argument: ArgumentCaptor[FileParsingResult] = ArgumentCaptor.forClass(classOf[FileParsingResult])
verify(f.processingMock, atLeastOnce()).processFileParsingResult(argument.capture())
val results = argument.getAllValues.asScala
exactly(1, results) should have(treeTask(fileTree), relativePath("bar"))
exactly(1, results) should have(fileTree(myFileTree), relativePath("bar"))
}
}
......@@ -282,11 +282,11 @@ class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar wit
"interleave requests from another file tree" in {
import FileTreeParsingResultMatchers._
val f = createFixture()
val fileTree = aFileTree().withBasePath("/universe/magic")
f.manager.processSignal(anInMemoryResult().withFileTree(fileTree))
f.manager.processSignal(aFileParsingSignalEndTree().withFileTree(fileTree).withTaskCount(1))
val myFileTree = aFileTree().withBasePath("/universe/magic")
f.manager.processSignal(anInMemoryResult().withFileTree(myFileTree))
f.manager.processSignal(aFileParsingSignalEndTree().withFileTree(myFileTree).withTaskCount(1))
f.manager.hasSignalToEmit() should be(true)
f.manager.getNextSignalToEmit() should have(treeTask(fileTree), numParsingTasks(1))
f.manager.getNextSignalToEmit() should have(fileTree(myFileTree), numParsingTasks(1))
}
}
......
......@@ -4,7 +4,6 @@ import eu.nomad_lab.TreeType
import eu.nomad_lab.TreeType.TreeType
import eu.nomad_lab.integrated_pipeline.{ FileTree, ParsingTaskGenerator }
import eu.nomad_lab.integrated_pipeline.io_integrations.{ DirectoryTreeParsingTaskGenerator, ZipTreeParsingTaskGenerator }
import eu.nomad_lab.integrated_pipeline.messages.FileParsingTask
import eu.nomad_lab.parsers.AllParsers
import org.scalatest.{ Matchers, WordSpec }
......
......@@ -18,8 +18,8 @@ class TreeScannerSpec extends WordSpec with TestDataBuilders with MockitoSugar
private def argsCaptor(): ArgumentCaptor[TreeParserEvent] = ArgumentCaptor.forClass(classOf[TreeParserEvent])
private val sampleTreeTask = aFileTree().withBasePath(".").build()
private val invalidTreeTask = aFileTree().withBasePath("/imaginary/foo/magic").build()
private val sampleFileTree = aFileTree().withBasePath(".").build()
private val invalidFileTree = aFileTree().withBasePath("/imaginary/foo/magic").build()
class Fixture(sampleData: Iterator[Either[TreeParserEventScanError, FileParsingTask]]) {
val events = mock[EventListener]
......@@ -46,24 +46,24 @@ class TreeScannerSpec extends WordSpec with TestDataBuilders with MockitoSugar
def noTaskReceived(): Fixture = {
val data: Iterator[Either[TreeParserEventScanError, FileParsingTask]] = (1 to 3).map { i =>
Right(aFileParsingTask().withFileTree(sampleTreeTask).withRelativePath(s"file$i").build())
Right(aFileParsingTask().withFileTree(sampleFileTree).withRelativePath(s"file$i").build())
}.iterator
new Fixture(data)
}
def taskReceivedWillCreateScanError(): Fixture = {
val data: Iterator[Either[TreeParserEventScanError, FileParsingTask]] = Iterator.single(
Left(aTreeParserEventScanError().withFileTree(sampleTreeTask).withRelativePath("nullPointer").
Left(aTreeParserEventScanError().withFileTree(sampleFileTree).withRelativePath("nullPointer").
withError(new UnsupportedOperationException("failing test case")) build ())
)
val f = new Fixture(data)
f.treeParser.processSignal(sampleTreeTask)
f.treeParser.processSignal(sampleFileTree)
f
}
def taskReceivedNoSignalsFetched(): Fixture = {
val f = noTaskReceived()
f.treeParser.processSignal(sampleTreeTask)
f.treeParser.processSignal(sampleFileTree)
f
}
......@@ -93,14 +93,14 @@ class TreeScannerSpec extends WordSpec with TestDataBuilders with MockitoSugar
"register with the provided EventListener when receiving the first message" in {
val f = createFixture()
f.treeParser.processSignal(sampleTreeTask)
f.treeParser.processSignal(sampleFileTree)
verify(f.events).registerReporter(f.treeParser, Some("TreeParserSpec"))
}
"notify the provided EventListener when receiving a new file tree scan task" in {
import MatcherTreeParserEventStart._
val f = createFixture()
f.treeParser.processSignal(sampleTreeTask)
f.treeParser.processSignal(sampleFileTree)
val captor = argsCaptor()
verify(f.events).processEvent(any(), captor.capture())
captor.getValue should (be(a[TreeParserEventStart]) and have(basePath(".")))
......@@ -108,14 +108,14 @@ class TreeScannerSpec extends WordSpec with TestDataBuilders with MockitoSugar
"ignore file tree scan tasks if the tree root does not exist on file-system" in {
val f = createFixture()
f.treeParser.processSignal(invalidTreeTask)
f.treeParser.processSignal(invalidFileTree)
f.treeParser.hasSignalToEmit() should be(false)
}
"send an error event to the eventListener if the tree root does not exist on file-system" in {
import MatcherTreeParserEventTreeFailure._
val f = createFixture()
f.treeParser.processSignal(invalidTreeTask)
f.treeParser.processSignal(invalidFileTree)
val captor = argsCaptor()
verify(f.events, atLeastOnce).processEvent(any(), captor.capture())
val events = captor.getAllValues.asScala.collect { case x: TreeParserEventTreeFailure => x }
......@@ -183,7 +183,7 @@ class TreeScannerSpec extends WordSpec with TestDataBuilders with MockitoSugar
val f = createFixture()
val result = f.treeParser.getNextSignalToEmit()
result should be(a[FileParsingSignalEndTree])
result.asInstanceOf[FileParsingSignalEndTree] should have(treeTask(sampleTreeTask), numParsingTasks(3))
result.asInstanceOf[FileParsingSignalEndTree] should have(fileTree(sampleFileTree), numParsingTasks(3))
}
"notify the provided EventListener when emitting the end tree signal" in {
......
......@@ -20,7 +20,7 @@ object FileTreeTaskMatchers {
}
object FileParsingTaskMatchers {
def treeTask(expectedValue: FileTree): HavePropertyMatcher[FileParsingTaskSignal, FileTree] =
def fileTree(expectedValue: FileTree): HavePropertyMatcher[FileParsingTaskSignal, FileTree] =
MatcherHelpers.propertyMatcher(
propertyName = "parent tree task",
expected = expectedValue,
......@@ -60,7 +60,7 @@ object FileParsingTaskMatchers {
object FileParsingResultMatchers {
def treeTask(expectedValue: FileTree): HavePropertyMatcher[FileParsingResultSignal, FileTree] =
def fileTree(expectedValue: FileTree): HavePropertyMatcher[FileParsingResultSignal, FileTree] =
MatcherHelpers.propertyMatcher(
propertyName = "parent tree task",
expected = expectedValue,
......@@ -126,9 +126,9 @@ object FileParsingResultMatchers {
object FileTreeParsingResultMatchers {
def treeTask(expectedValue: FileTree): HavePropertyMatcher[FileTreeParsingResult, FileTree] =
def fileTree(expectedValue: FileTree): HavePropertyMatcher[FileTreeParsingResult, FileTree] =
MatcherHelpers.propertyMatcher(
propertyName = "origin tree task",
propertyName = "origin file tree",
expected = expectedValue,
test = (x: FileTreeParsingResult) => x.fileTree
)
......
Markdown is supported
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