Merge pull request #18381 from ktoso/wip-reenable-tests-ktoso
=htp #18361 reenable pending tests ported from spray
This commit is contained in:
commit
dfed97818f
2 changed files with 31 additions and 19 deletions
|
|
@ -4,9 +4,12 @@
|
||||||
|
|
||||||
package akka.http.scaladsl.server.directives
|
package akka.http.scaladsl.server.directives
|
||||||
|
|
||||||
|
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
|
||||||
|
import akka.http.scaladsl.marshallers.xml.ScalaXmlSupport
|
||||||
|
import akka.stream.scaladsl.Sink
|
||||||
import org.scalatest.FreeSpec
|
import org.scalatest.FreeSpec
|
||||||
|
|
||||||
import scala.concurrent.Promise
|
import scala.concurrent.{ Future, Promise }
|
||||||
import akka.http.scaladsl.marshallers.xml.ScalaXmlSupport._
|
import akka.http.scaladsl.marshallers.xml.ScalaXmlSupport._
|
||||||
import akka.http.scaladsl.marshalling._
|
import akka.http.scaladsl.marshalling._
|
||||||
import akka.http.scaladsl.server._
|
import akka.http.scaladsl.server._
|
||||||
|
|
@ -16,6 +19,8 @@ import headers._
|
||||||
import StatusCodes._
|
import StatusCodes._
|
||||||
import MediaTypes._
|
import MediaTypes._
|
||||||
|
|
||||||
|
import scala.xml.NodeSeq
|
||||||
|
|
||||||
class RouteDirectivesSpec extends FreeSpec with GenericRoutingSpec {
|
class RouteDirectivesSpec extends FreeSpec with GenericRoutingSpec {
|
||||||
|
|
||||||
"The `complete` directive should" - {
|
"The `complete` directive should" - {
|
||||||
|
|
@ -57,7 +62,7 @@ class RouteDirectivesSpec extends FreeSpec with GenericRoutingSpec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"allow easy handling of futured ToResponseMarshallers" in pending /*{
|
"allow easy handling of futured ToResponseMarshallers" in {
|
||||||
trait RegistrationStatus
|
trait RegistrationStatus
|
||||||
case class Registered(name: String) extends RegistrationStatus
|
case class Registered(name: String) extends RegistrationStatus
|
||||||
case object AlreadyRegistered extends RegistrationStatus
|
case object AlreadyRegistered extends RegistrationStatus
|
||||||
|
|
@ -76,8 +81,8 @@ class RouteDirectivesSpec extends FreeSpec with GenericRoutingSpec {
|
||||||
case Registered(_) ⇒ HttpEntity.Empty
|
case Registered(_) ⇒ HttpEntity.Empty
|
||||||
case AlreadyRegistered ⇒
|
case AlreadyRegistered ⇒
|
||||||
import spray.json.DefaultJsonProtocol._
|
import spray.json.DefaultJsonProtocol._
|
||||||
import spray.httpx.SprayJsonSupport._
|
import SprayJsonSupport._
|
||||||
(StatusCodes.BadRequest, Map("error" -> "User already Registered"))
|
StatusCodes.BadRequest -> Map("error" -> "User already Registered")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,10 +93,10 @@ class RouteDirectivesSpec extends FreeSpec with GenericRoutingSpec {
|
||||||
}
|
}
|
||||||
Get("/register/karl") ~> route ~> check {
|
Get("/register/karl") ~> route ~> check {
|
||||||
status shouldEqual StatusCodes.OK
|
status shouldEqual StatusCodes.OK
|
||||||
entity shouldEqual HttpEntity.Empty
|
responseAs[String] shouldEqual ""
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
"do Content-Type negotiation for multi-marshallers" in pendingUntilFixed {
|
"do Content-Type negotiation for multi-marshallers" in {
|
||||||
val route = get & complete(Data("Ida", 83))
|
val route = get & complete(Data("Ida", 83))
|
||||||
|
|
||||||
import akka.http.scaladsl.model.headers.Accept
|
import akka.http.scaladsl.model.headers.Accept
|
||||||
|
|
@ -105,10 +110,9 @@ class RouteDirectivesSpec extends FreeSpec with GenericRoutingSpec {
|
||||||
Get().withHeaders(Accept(MediaTypes.`text/xml`)) ~> route ~> check {
|
Get().withHeaders(Accept(MediaTypes.`text/xml`)) ~> route ~> check {
|
||||||
responseAs[xml.NodeSeq] shouldEqual <data><name>Ida</name><age>83</age></data>
|
responseAs[xml.NodeSeq] shouldEqual <data><name>Ida</name><age>83</age></data>
|
||||||
}
|
}
|
||||||
pending
|
Get().withHeaders(Accept(MediaTypes.`text/plain`)) ~> Route.seal(route) ~> check {
|
||||||
/*Get().withHeaders(Accept(MediaTypes.`text/plain`)) ~> HttpService.sealRoute(route) ~> check {
|
|
||||||
status shouldEqual StatusCodes.NotAcceptable
|
status shouldEqual StatusCodes.NotAcceptable
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,16 +137,17 @@ class RouteDirectivesSpec extends FreeSpec with GenericRoutingSpec {
|
||||||
|
|
||||||
case class Data(name: String, age: Int)
|
case class Data(name: String, age: Int)
|
||||||
object Data {
|
object Data {
|
||||||
//import spray.json.DefaultJsonProtocol._
|
import spray.json.DefaultJsonProtocol._
|
||||||
//import spray.httpx.SprayJsonSupport._
|
import SprayJsonSupport._
|
||||||
|
import ScalaXmlSupport._
|
||||||
|
|
||||||
val jsonMarshaller: ToEntityMarshaller[Data] = FIXME // jsonFormat2(Data.apply)
|
val jsonMarshaller: ToEntityMarshaller[Data] = jsonFormat2(Data.apply)
|
||||||
val xmlMarshaller: ToEntityMarshaller[Data] = FIXME
|
|
||||||
/*Marshaller.delegate[Data, xml.NodeSeq](MediaTypes.`text/xml`) { (data: Data) ⇒
|
|
||||||
<data><name>{ data.name }</name><age>{ data.age }</age></data>
|
|
||||||
}*/
|
|
||||||
|
|
||||||
implicit val dataMarshaller: ToResponseMarshaller[Data] = FIXME
|
val xmlMarshaller: ToEntityMarshaller[Data] = Marshaller.combined { (data: Data) ⇒
|
||||||
//ToResponseMarshaller.oneOf(MediaTypes.`application/json`, MediaTypes.`text/xml`)(jsonMarshaller, xmlMarshaller)
|
<data><name>{ data.name }</name><age>{ data.age }</age></data>
|
||||||
|
}
|
||||||
|
|
||||||
|
implicit val dataMarshaller: ToResponseMarshaller[Data] =
|
||||||
|
Marshaller.oneOf(jsonMarshaller, xmlMarshaller)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,13 @@ object Marshaller
|
||||||
*/
|
*/
|
||||||
def opaque[A, B](marshal: A ⇒ B): Marshaller[A, B] =
|
def opaque[A, B](marshal: A ⇒ B): Marshaller[A, B] =
|
||||||
strict { value ⇒ Marshalling.Opaque(() ⇒ marshal(value)) }
|
strict { value ⇒ Marshalling.Opaque(() ⇒ marshal(value)) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper for creating a [[Marshaller]] combined of the provided `marshal` function
|
||||||
|
* and an implicit Marshaller which is able to produce the required final type.
|
||||||
|
*/
|
||||||
|
def combined[A, B, C](marshal: A ⇒ B)(implicit m2: Marshaller[B, C]): Marshaller[A, C] =
|
||||||
|
Marshaller[A, C] { ec ⇒ a ⇒ m2.compose(marshal).apply(a)(ec) }
|
||||||
}
|
}
|
||||||
//#
|
//#
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue