forked from finagle/finch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ScalaConversionsSpec.scala and ScalaEndToEndSpec.scala added
- Loading branch information
1 parent
89ff4c4
commit 6294d28
Showing
2 changed files
with
65 additions
and
0 deletions.
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
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" | ||
} | ||
} |
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,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 | ||
} | ||
} |