/ / Spray-Test gzip decode - scala, spray, spray-json, spray-client, spray-test

Spray-Test gzip decode - scala, spray, spray-json, spray-client, spray-test

J'essaie d'écrire test pour spray

class FullTestKitExampleSpec extends Specification with Specs2RouteTest with UserController with HttpService {
def actorRefFactory = system

"The service" should {

"return a greeting for GET requests to the root path" in {
Get("/user") ~> `Accept-Encoding`(gzip) ~> userRoute ~> check {
val responsex = response
responseAs[String] must contain("Test1")
}
}
}
}

J'ai suivre routeur

trait UserController extends HttpService with Json4sSupport with CORSSupport{
override implicit def json4sFormats: Formats = DefaultFormats

val userRoute = {
cors {
compressResponse(Gzip) {
path("user") {
get {
complete {
"Test1"
}
} ~
post {
entity(as[UserRegister]) { person =>
complete {
println(person.name)
person.name
}
}
}
}
}
}
}
}

J'utilise la compression GZIP pour la réponse, mais

Impossible de désactiver la réponse au type "java.lang.String" pour responseAs assertion: MalformedContent (jeton inconnu) Près de:, Some (org.json4s.ParserUtil $ ParseException: jeton inconnu Près: ))

Comment définir le code automatique GZIP HttpResponse sur String?

Réponses:

5 pour la réponse № 1

Inclure un decode(Gzip) dans votre pipeline:

import spray.httpx.encoding.Gzip
import spray.httpx.ResponseTransformation

class MySprayRouteSpec extends FlatSpec
with ShouldMatchers
with ResponseTransformation
with ScalatestRouteTest
{
Get("/") ~> mapHttpResponse(decode(Gzip))(userRoute) ~> check{
response.status should equal(OK)
}
}