Skip to content

Commit

Permalink
stage and pipeline unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cosminseceleanu committed Mar 18, 2018
1 parent 0bf2c0c commit aea0c9c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ scalaVersion := "2.12.4"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.5.11",
"com.typesafe.akka" %% "akka-testkit" % "2.5.11" % Test
"com.typesafe.akka" %% "akka-testkit" % "2.5.11" % Test,
"org.scalatest" % "scalatest_2.12" % "3.0.5" % "test"
)
41 changes: 41 additions & 0 deletions src/test/scala/com/cosmin/pipeline/PipelineSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.cosmin.pipeline

import scala.util.{Failure, Success}

class PipelineSpec extends UnitSpec {
test("Test building pipeline") {
val pipeline: Pipeline[String, String] = createDefaultPipeline

assert(2 == pipeline.stages.size)
assertResult("input->f2") {
val stage = pipeline.stages.head
stage.execute("input".asInstanceOf[stage.In])
}
}

test("Test successful execution of a pipeline") {
val pipeline: Pipeline[String, String] = createDefaultPipeline

pipeline.execute("msg") {
case Success(out) => assert("msg->f1->f2".equals(out))
case Failure(_) => fail("Pipeline execution expected be successful")
}
}

test("Test failed execution of a pipeline") {
val pipeline: Pipeline[String, String] = createDefaultPipeline | (s => throw new RuntimeException)

pipeline.execute("msg") {
case Success(out) => fail("Pipeline execution expected fail")
case Failure(e) => assert(e.isInstanceOf[RuntimeException])
}
}


private def createDefaultPipeline = {
val firstFilter: String => String = s => s"$s->f1"
val secondFilter: String => String = s => s"$s->f2"

Pipeline[String, String]() | firstFilter | secondFilter
}
}
12 changes: 12 additions & 0 deletions src/test/scala/com/cosmin/pipeline/StageSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cosmin.pipeline

class StageSpec extends UnitSpec {
test("Text execute stage filter") {
val intToStringFilter: Filter[Int, String] = new Filter[Int, String] {
override def execute = i => i.toString
}
val stage = Stage(intToStringFilter)

assertResult("1") (stage.execute(1.asInstanceOf[stage.In]))
}
}
6 changes: 6 additions & 0 deletions src/test/scala/com/cosmin/pipeline/UnitSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cosmin.pipeline

import org.scalatest._

abstract class UnitSpec extends FunSuite with Matchers with
OptionValues with Inside with Inspectors

0 comments on commit aea0c9c

Please sign in to comment.