Próbuję pisać test na 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")
}
}
}
}
Mam śledzony router
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
}
}
}
}
}
}
}
}
Używam kompresji GZIP do odpowiedzi, ale
Nie można wywołać niepomyślnej reakcji na typ "java.lang.String" dla
responseAs
asercja: MalformedContent (nieznany token Near:, Some (org.json4s.ParserUtil $ ParseException: unknown token Blisko: ))
Jak ustawić kodowanie automatyczne GZIP HttpResponse na ciąg?
Odpowiedzi:
5 dla odpowiedzi № 1Uwzględnij a decode(Gzip)
w twoim rurociągu:
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)
}
}