-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bf2c0c
commit aea0c9c
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |