Akka Route TestKit, yanıtı Dize olarak işaretleyemedi

0

Soru

Aşağıdaki testim var:

 "fail if date is wrongly formatted" in {
    val endpoint = s"/api/prof?date=wrongdate"
    Get(endpoint) ~> check {
      status shouldBe StatusCodes.BadRequest
      val resp = responseAs[String]
      resp shouldBe "could not be parsed"
    }
 }

Ancak, sınama aşağıdakilerle başarısız olur:

Could not unmarshal response to type 'java.lang.String' for `responseAs` assertion: akka.http.scaladsl.unmarshalling.Unmarshaller$UnsupportedContentTypeException: Unsupported Content-Type [Some(text/plain; charset=UTF-8)], supported: application/json

Response was: HttpResponse(400 Bad Request,List(),HttpEntity.Strict(text/plain; charset=UTF-8,106 bytes total),HttpProtocol(HTTP/1.1))

Yanıt gövdesini bir Dize olarak nasıl alabilirim?

akka akka-http scala scala-2.12
2021-11-23 15:46:11
1

En iyi cevabı

1

Muhtemelen kapsamda JSON için örtülü bir işaretleyiciniz var, bu yüzden testinizde işaretçi olarak alınıyor.

Gibi bir şey eklemek

implicit val responseBodyUnmarshaller =
  Unmarshaller.strict[HttpResponse, HttpEntity](_.entity)
    .andThen(Unmarshaller.stringUnmarshaller)

bunu ele almalıyım.

2021-11-23 17:52:23

Diğer dillerde

Bu sayfa diğer dillerde

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................