MessageMatchers.scala 6.84 KB
Newer Older
1
package eu.nomad_lab.integrated_pipeline_tests.matchers
2
3
4

import java.nio.file.{ Path, Paths }

5
import eu.nomad_lab.TreeType.TreeType
6
import eu.nomad_lab.integrated_pipeline.FileTree
7
import eu.nomad_lab.integrated_pipeline.OutputType.OutputType
8
9
import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.parsers.ParseResult.ParseResult
10
import eu.nomad_lab.parsers.{ FinishedParsingSession, ParseEvent, StartedParsingSession }
11
import org.scalatest.matchers.HavePropertyMatcher
12

13
object FileTreeTaskMatchers {
14
  def basePath(expectedValue: Path): HavePropertyMatcher[FileTree, Path] =
15
    MatcherHelpers.propertyMatcher(
16
17
      propertyName = "tree base path",
      expected = expectedValue,
18
      test = (x: FileTree) => x.treeBasePath
19
    )
20
21
}

22
object FileParsingTaskMatchers {
23
  def treeTask(expectedValue: FileTree): HavePropertyMatcher[FileParsingTaskSignal, FileTree] =
24
    MatcherHelpers.propertyMatcher(
25
26
27
28
      propertyName = "parent tree task",
      expected = expectedValue,
      test = (x: FileParsingTaskSignal) => x.treeTask
    )
29

30
  def relativePath(expectedValue: Path): HavePropertyMatcher[FileParsingTask, Path] =
31
    MatcherHelpers.propertyMatcher(
32
33
34
      propertyName = "relative file path",
      expected = expectedValue,
      test = (x: FileParsingTask) => x.relativePath
35
    )
36

37
  def relativePath(expectedValue: String): HavePropertyMatcher[FileParsingTask, Path] = {
38
39
40
    relativePath(Paths.get(expectedValue))
  }

41
  def extractedPath(expectedValue: Option[Path]): HavePropertyMatcher[FileParsingTask, Option[Path]] =
42
    MatcherHelpers.propertyMatcher(
43
44
45
      propertyName = "temporary extracted file path",
      expected = expectedValue,
      test = (x: FileParsingTask) => x.extractedPath
46
    )
47

48
  def extractedPathString(expectedValue: Option[String]): HavePropertyMatcher[FileParsingTask, Option[Path]] = {
49
50
    extractedPath(expectedValue.map(Paths.get(_)))
  }
51

52
  def numParsingTasks(expectedValue: Long): HavePropertyMatcher[FileParsingSignalEndTree, Long] =
53
    MatcherHelpers.propertyMatcher(
54
55
56
57
58
      propertyName = "number of identified candidate calculations",
      expected = expectedValue,
      test = (x: FileParsingSignalEndTree) => x.numParsingTasks
    )

59
60
}

61
object FileParsingResultMatchers {
62

63
  def treeTask(expectedValue: FileTree): HavePropertyMatcher[FileParsingResultSignal, FileTree] =
64
    MatcherHelpers.propertyMatcher(
65
66
67
68
      propertyName = "parent tree task",
      expected = expectedValue,
      test = (x: FileParsingResultSignal) => x.treeTask
    )
69

70
  def status(expectedValue: ParseResult): HavePropertyMatcher[FileParsingResult, ParseResult] =
71
    MatcherHelpers.propertyMatcher(
72
73
74
75
      propertyName = "parsing result status",
      expected = expectedValue,
      test = (x: FileParsingResult) => x.result
    )
76

77
  def relativePath(expectedValue: Path): HavePropertyMatcher[FileParsingResult, Path] =
78
    MatcherHelpers.propertyMatcher(
79
80
81
82
83
84
85
      propertyName = "relative file path",
      expected = expectedValue,
      test = (x: FileParsingResult) => x.task.relativePath
    )

  def relativePath(expectedValue: String): HavePropertyMatcher[FileParsingResult, Path] =
    relativePath(Paths.get(expectedValue))
86
87

  def numParsingTasks(expectedValue: Long): HavePropertyMatcher[FileParsingSignalEndTree, Long] =
88
    MatcherHelpers.propertyMatcher(
89
90
91
92
      propertyName = "number of identified candidate calculations",
      expected = expectedValue,
      test = (x: FileParsingSignalEndTree) => x.numParsingTasks
    )
93
94

  def startSignal(expectedValue: Option[StartedParsingSession]): HavePropertyMatcher[FileParsingResult, Option[StartedParsingSession]] =
95
    MatcherHelpers.propertyMatcher(
96
97
98
99
100
101
      propertyName = "session start signal",
      expected = expectedValue,
      test = (x: FileParsingResult) => x.start
    )

  def endSignal(expectedValue: Option[FinishedParsingSession]): HavePropertyMatcher[FileParsingResult, Option[FinishedParsingSession]] =
102
    MatcherHelpers.propertyMatcher(
103
104
105
106
107
108
      propertyName = "session end signal",
      expected = expectedValue,
      test = (x: FileParsingResult) => x.end
    )

  def events(expectedValue: Seq[ParseEvent]): HavePropertyMatcher[FileParsingResult, Seq[ParseEvent]] =
109
    MatcherHelpers.propertyMatcher(
110
111
112
113
114
115
116
      propertyName = "emitted parsing events",
      expected = expectedValue,
      test = (x: FileParsingResult) => x match {
      case x: InMemoryResult => x.events
    }
    )

117
  def errorMessage(first: String, other: String*): HavePropertyMatcher[FileParsingResult, String] =
118
    MatcherHelpers.subStringPropertyMatcher(
119
120
121
122
123
124
      propertyName = "error message content",
      expected = first +: other,
      test = (x: FileParsingResult) => x.error.getOrElse(""),
      display = (x: FileParsingResult) => x.error.toString
    )

125
126
}

127
object FileTreeParsingResultMatchers {
128

129
  def treeTask(expectedValue: FileTree): HavePropertyMatcher[FileTreeParsingResult, FileTree] =
130
    MatcherHelpers.propertyMatcher(
131
132
133
134
135
136
      propertyName = "origin tree task",
      expected = expectedValue,
      test = (x: FileTreeParsingResult) => x.treeScanTask
    )

  def basePath(expectedValue: Path): HavePropertyMatcher[FileTreeParsingResult, Path] =
137
    MatcherHelpers.propertyMatcher(
138
139
140
141
142
143
144
145
146
      propertyName = "tree base path",
      expected = expectedValue,
      test = (x: FileTreeParsingResult) => x.treeScanTask.treeBasePath
    )

  def basePath(expectedValue: String): HavePropertyMatcher[FileTreeParsingResult, Path] =
    basePath(Paths.get(expectedValue))

  def treeType(expectedValue: TreeType): HavePropertyMatcher[FileTreeParsingResult, TreeType] =
147
    MatcherHelpers.propertyMatcher(
148
149
150
151
152
153
      propertyName = "file tree type",
      expected = expectedValue,
      test = (x: FileTreeParsingResult) => x.treeScanTask.treeType
    )

  def numParsingTasks(expectedValue: Long): HavePropertyMatcher[FileTreeParsingResult, Long] =
154
    MatcherHelpers.propertyMatcher(
155
156
157
158
159
160
      propertyName = "number of processed calculations",
      expected = expectedValue,
      test = (x: FileTreeParsingResult) => x.numCalculationsFound
    )

  def numFailedTasks(expectedValue: Long): HavePropertyMatcher[FileTreeParsingResult, Long] =
161
    MatcherHelpers.propertyMatcher(
162
163
164
165
166
167
      propertyName = "number of failed calculations",
      expected = expectedValue,
      test = (x: FileTreeParsingResult) => x.numParsingFailures
    )

  def outputPath(expectedValue: Path): HavePropertyMatcher[FileTreeParsingResult, Path] =
168
    MatcherHelpers.propertyMatcher(
169
170
171
172
173
174
      propertyName = "output location",
      expected = expectedValue,
      test = (x: FileTreeParsingResult) => x.outputLocation
    )

  def outputPath(expectedValue: String): HavePropertyMatcher[FileTreeParsingResult, Path] =
175
    outputPath(Paths.get(expectedValue))
176
177

  def outputType(expectedValue: OutputType): HavePropertyMatcher[FileTreeParsingResult, OutputType] =
178
    MatcherHelpers.propertyMatcher(
179
180
181
182
183
      propertyName = "output format",
      expected = expectedValue,
      test = (x: FileTreeParsingResult) => x.outputFormat
    )

184
}