Skip to content

Commit aea0c9c

Browse files
stage and pipeline unit tests
1 parent 0bf2c0c commit aea0c9c

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ scalaVersion := "2.12.4"
66

77
libraryDependencies ++= Seq(
88
"com.typesafe.akka" %% "akka-actor" % "2.5.11",
9-
"com.typesafe.akka" %% "akka-testkit" % "2.5.11" % Test
9+
"com.typesafe.akka" %% "akka-testkit" % "2.5.11" % Test,
10+
"org.scalatest" % "scalatest_2.12" % "3.0.5" % "test"
1011
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.cosmin.pipeline
2+
3+
import scala.util.{Failure, Success}
4+
5+
class PipelineSpec extends UnitSpec {
6+
test("Test building pipeline") {
7+
val pipeline: Pipeline[String, String] = createDefaultPipeline
8+
9+
assert(2 == pipeline.stages.size)
10+
assertResult("input->f2") {
11+
val stage = pipeline.stages.head
12+
stage.execute("input".asInstanceOf[stage.In])
13+
}
14+
}
15+
16+
test("Test successful execution of a pipeline") {
17+
val pipeline: Pipeline[String, String] = createDefaultPipeline
18+
19+
pipeline.execute("msg") {
20+
case Success(out) => assert("msg->f1->f2".equals(out))
21+
case Failure(_) => fail("Pipeline execution expected be successful")
22+
}
23+
}
24+
25+
test("Test failed execution of a pipeline") {
26+
val pipeline: Pipeline[String, String] = createDefaultPipeline | (s => throw new RuntimeException)
27+
28+
pipeline.execute("msg") {
29+
case Success(out) => fail("Pipeline execution expected fail")
30+
case Failure(e) => assert(e.isInstanceOf[RuntimeException])
31+
}
32+
}
33+
34+
35+
private def createDefaultPipeline = {
36+
val firstFilter: String => String = s => s"$s->f1"
37+
val secondFilter: String => String = s => s"$s->f2"
38+
39+
Pipeline[String, String]() | firstFilter | secondFilter
40+
}
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.cosmin.pipeline
2+
3+
class StageSpec extends UnitSpec {
4+
test("Text execute stage filter") {
5+
val intToStringFilter: Filter[Int, String] = new Filter[Int, String] {
6+
override def execute = i => i.toString
7+
}
8+
val stage = Stage(intToStringFilter)
9+
10+
assertResult("1") (stage.execute(1.asInstanceOf[stage.In]))
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.cosmin.pipeline
2+
3+
import org.scalatest._
4+
5+
abstract class UnitSpec extends FunSuite with Matchers with
6+
OptionValues with Inside with Inspectors

0 commit comments

Comments
 (0)