Skip to content

Commit

Permalink
ScalaConversionsSpec.scala and ScalaEndToEndSpec.scala added
Browse files Browse the repository at this point in the history
  • Loading branch information
gabfssilva committed Jul 27, 2017
1 parent 89ff4c4 commit 6294d28
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/src/test/scala/io/finch/ScalaConversionsSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.finch

class ScalaConversionsSpec extends FinchSpec {
behavior of "ScalaConversions"

it should "convert Scala Futures into Twitter Futures" in {
import scala.concurrent.{Future => ScalaFuture}
import com.twitter.util.{Future=>TwitterFuture}
import io.finch.internal.ScalaToTwitterConversions._
import com.twitter.util.Await

import scala.concurrent.ExecutionContext.Implicits.global

val future: TwitterFuture[String] = ScalaFuture {
"value"
}.asTwitterFuture

val result = Await.result(future)

result shouldBe "value"
}
}
43 changes: 43 additions & 0 deletions core/src/test/scala/io/finch/ScalaEndToEndSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.finch

import com.twitter.finagle.Service
import com.twitter.finagle.http.{Request, Response, Status}
import com.twitter.util.Await

class ScalaEndToEndSpec extends FinchSpec {
behavior of "Finch"

it should "convert value Endpoints into Services, using Scala Futures" in {
import scala.concurrent.{Future => ScalaFuture}
import scala.concurrent.ExecutionContext.Implicits._

val e: Endpoint[String] = get("foo") {
ScalaFuture {
Ok("bar")
}
}

val s: Service[Request, Response] = e.toServiceAs[Text.Plain]

val rep = Await.result(s(Request("/foo")))
rep.contentString shouldBe "bar"
rep.status shouldBe Status.Ok
}

it should "convert value parameterized Endpoints into Services, using Scala Futures" in {
import scala.concurrent.{Future => ScalaFuture}
import scala.concurrent.ExecutionContext.Implicits._

val e: Endpoint[String] = get("foo" :: string) { param: String =>
ScalaFuture {
Ok(param)
}
}

val s: Service[Request, Response] = e.toServiceAs[Text.Plain]

val rep = Await.result(s(Request("/foo/bar")))
rep.contentString shouldBe "bar"
rep.status shouldBe Status.Ok
}
}

0 comments on commit 6294d28

Please sign in to comment.