2015-07-17 16:18:18 +02:00
|
|
|
/*
|
2016-02-23 12:58:39 +01:00
|
|
|
* Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
|
2015-07-17 16:18:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package docs.http.scaladsl
|
|
|
|
|
|
2015-07-24 10:11:56 +02:00
|
|
|
import akka.stream.{ Materializer, ActorMaterializer }
|
2016-02-25 14:27:45 +01:00
|
|
|
import akka.testkit.AkkaSpec
|
2015-07-17 16:18:18 +02:00
|
|
|
|
|
|
|
|
class UnmarshalSpec extends AkkaSpec {
|
|
|
|
|
|
|
|
|
|
"use unmarshal" in {
|
|
|
|
|
import akka.http.scaladsl.unmarshalling.Unmarshal
|
2015-07-24 10:11:56 +02:00
|
|
|
import system.dispatcher // ExecutionContext
|
|
|
|
|
implicit val materializer: Materializer = ActorMaterializer()
|
2015-07-17 16:18:18 +02:00
|
|
|
|
|
|
|
|
import scala.concurrent.Await
|
2015-07-24 10:11:56 +02:00
|
|
|
import scala.concurrent.duration._
|
2015-07-17 16:18:18 +02:00
|
|
|
|
|
|
|
|
val intFuture = Unmarshal("42").to[Int]
|
|
|
|
|
val int = Await.result(intFuture, 1.second) // don't block in non-test code!
|
|
|
|
|
int shouldEqual 42
|
|
|
|
|
|
|
|
|
|
val boolFuture = Unmarshal("off").to[Boolean]
|
|
|
|
|
val bool = Await.result(boolFuture, 1.second) // don't block in non-test code!
|
|
|
|
|
bool shouldBe false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|